-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added basePath as option for Model.fromGltf #5403
Conversation
@moneimne can you please
|
0848220
to
0cebca6
Compare
Updated |
Source/Scene/Model.js
Outdated
} | ||
if (!defined(options.cacheKey)) { | ||
if (defined(providedBasePath)) { | ||
options.cacheKey = cacheKey + options.basePath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these are both URLs, we should use the joinUrls function to concat them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is ok this way since the cache key doesn't need to be a url, it just needs to be a unique way to identify a model.
Source/Scene/Model.js
Outdated
if (defined(providedBasePath)) { | ||
options.cacheKey = cacheKey + options.basePath; | ||
} | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this and below to } else {
Our code style convention for if/else blocks is
if (...) {
...
} else if (...) {
...
} else {
...
}
Source/Scene/Model.js
Outdated
options.basePath = getBaseUri(url, true); | ||
options.cacheKey = cacheKey; | ||
var providedBasePath = options.basePath; | ||
if (!defined(options.basePath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set defined(options.basePath)
to a variable so you don't call defined twice (lines 1191 and 1195)
Source/Scene/Model.js
Outdated
if (!defined(options.basePath)) { | ||
options.basePath = getBaseUri(url, true); | ||
} | ||
if (!defined(options.cacheKey)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These if blocks can be re-written to be one line
Those are all of the comments that I have. Functionality is great |
Thanks for the reviews, @hpinkos! Made the changes. |
Source/Scene/Model.js
Outdated
@@ -1186,8 +1187,16 @@ define([ | |||
var cacheKey = defaultValue(options.cacheKey, getAbsoluteUri(url)); | |||
|
|||
options = clone(options); | |||
options.basePath = getBaseUri(url, true); | |||
options.cacheKey = cacheKey; | |||
if (defined(options.basePath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can still be simplified a bit further
options.cacheKey = cacheKey;
if (defined(options.basePath)) {
options.cacheKey += options.basePath;
} else {
options.basePath = getBaseUri(url, true);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this would do what we want. We only want to append basePath
to cacheKey
if a cache key isn't specified in options
by the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the code could be simplified like:
var cacheKey = defaultValue(options.cacheKey, getAbsoluteUri(url));
var basePath = defaultValue(options.basePath, getBaseUri(url, true));
if (!defined(options.basePath) && !defined(options.cacheKey)) {
cacheKey += basePath;
}
options.cacheKey = cacheKey;
options.basePath = basePath;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, gotcha. Sorry I missed that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works! Just had to change the condition to use defined(options.basePath)
without the not.
Specs/Scene/ModelSpec.js
Outdated
@@ -272,6 +273,17 @@ defineSuite([ | |||
expect(model._baseUri).toEndWith(params); | |||
}); | |||
|
|||
it('fromGltf cache key different when given base path', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reword this description to 'fromGltf
takes a base path'
Source/Scene/Model.js
Outdated
@@ -1186,8 +1187,16 @@ define([ | |||
var cacheKey = defaultValue(options.cacheKey, getAbsoluteUri(url)); | |||
|
|||
options = clone(options); | |||
options.basePath = getBaseUri(url, true); | |||
options.cacheKey = cacheKey; | |||
if (defined(options.basePath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the code could be simplified like:
var cacheKey = defaultValue(options.cacheKey, getAbsoluteUri(url));
var basePath = defaultValue(options.basePath, getBaseUri(url, true));
if (!defined(options.basePath) && !defined(options.cacheKey)) {
cacheKey += basePath;
}
options.cacheKey = cacheKey;
options.basePath = basePath;
Source/Scene/Model.js
Outdated
@@ -1127,6 +1127,7 @@ define([ | |||
* @param {Object} options Object with the following properties: | |||
* @param {String} options.url The url to the .gltf file. | |||
* @param {Object} [options.headers] HTTP headers to send with the request. | |||
* @param {String} [options.basePath=''] The base path that paths in the glTF JSON are relative to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the =''
since the default basePath
is derived from the url.
Updated |
Great, thanks @moneimne! |
Fix for #5320