Skip to content
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

Merged
merged 5 commits into from
Jun 2, 2017

Conversation

moneimne
Copy link
Contributor

@moneimne moneimne commented Jun 1, 2017

Fix for #5320

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 1, 2017

@moneimne can you please

@moneimne
Copy link
Contributor Author

moneimne commented Jun 1, 2017

Updated

}
if (!defined(options.cacheKey)) {
if (defined(providedBasePath)) {
options.cacheKey = cacheKey + options.basePath;
Copy link
Contributor

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

Copy link
Contributor

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.

if (defined(providedBasePath)) {
options.cacheKey = cacheKey + options.basePath;
}
else {
Copy link
Contributor

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 {
    ...
}

options.basePath = getBaseUri(url, true);
options.cacheKey = cacheKey;
var providedBasePath = options.basePath;
if (!defined(options.basePath)) {
Copy link
Contributor

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)

if (!defined(options.basePath)) {
options.basePath = getBaseUri(url, true);
}
if (!defined(options.cacheKey)) {
Copy link
Contributor

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

@hpinkos
Copy link
Contributor

hpinkos commented Jun 2, 2017

Those are all of the comments that I have. Functionality is great

@moneimne
Copy link
Contributor Author

moneimne commented Jun 2, 2017

Thanks for the reviews, @hpinkos! Made the changes.

@@ -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)) {
Copy link
Contributor

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);
}

Copy link
Contributor Author

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.

Copy link
Contributor

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;

Copy link
Contributor

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

Copy link
Contributor Author

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.

@@ -272,6 +273,17 @@ defineSuite([
expect(model._baseUri).toEndWith(params);
});

it('fromGltf cache key different when given base path', function() {
Copy link
Contributor

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'

@@ -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)) {
Copy link
Contributor

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;

@@ -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.
Copy link
Contributor

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.

@moneimne
Copy link
Contributor Author

moneimne commented Jun 2, 2017

Updated

@hpinkos
Copy link
Contributor

hpinkos commented Jun 2, 2017

Great, thanks @moneimne!

@hpinkos hpinkos merged commit 825e692 into CesiumGS:master Jun 2, 2017
@moneimne moneimne deleted the addBasePathToFromGltf branch June 2, 2017 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants