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
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Change Log
* Fixed an issue where translucent objects could flicker when picking on mouse move. [#5307](https://github.com/AnalyticalGraphicsInc/cesium/issues/5307)
* Fixed a bug where billboards with `sizeInMeters` set to true would move upwards when zooming out. [#5373](https://github.com/AnalyticalGraphicsInc/cesium/issues/5373)
* Fixed a bug where `SampledProperty.setInterpolationOptions` does not ignore undefined `options`. [#3575](https://github.com/AnalyticalGraphicsInc/cesium/issues/3575)
* Added `basePath` option to `Cesium.Model.fromGltf`. [#5320](https://github.com/AnalyticalGraphicsInc/cesium/issues/5320)

### 1.33 - 2017-05-01

Expand Down
13 changes: 11 additions & 2 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

* @param {Boolean} [options.show=true] Determines if the model primitive will be shown.
* @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms the model from model to world coordinates.
* @param {Number} [options.scale=1.0] A uniform scale applied to this model.
Expand Down Expand Up @@ -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.

if (defined(options.cacheKey)) {
options.cacheKey = cacheKey;
} else {
options.cacheKey = cacheKey + options.basePath;
}
} else {
options.basePath = getBaseUri(url, true);
options.cacheKey = cacheKey;
}
var model = new Model(options);

options.headers = defined(options.headers) ? clone(options.headers) : {};
Expand Down
339 changes: 339 additions & 0 deletions Specs/Data/Models/Box-Textured-BasePath/CesiumTexturedBoxTest.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,339 @@
{
"accessors": {
"accessor_21": {
"bufferView": "bufferView_29",
"byteOffset": 0,
"byteStride": 0,
"componentType": 5123,
"count": 36,
"type": "SCALAR"
},
"accessor_23": {
"bufferView": "bufferView_30",
"byteOffset": 0,
"byteStride": 12,
"componentType": 5126,
"count": 24,
"max": [
0.5,
0.5,
0.5
],
"min": [
-0.5,
-0.5,
-0.5
],
"type": "VEC3"
},
"accessor_25": {
"bufferView": "bufferView_30",
"byteOffset": 288,
"byteStride": 12,
"componentType": 5126,
"count": 24,
"max": [
1,
1,
1
],
"min": [
-1,
-1,
-1
],
"type": "VEC3"
},
"accessor_27": {
"bufferView": "bufferView_30",
"byteOffset": 576,
"byteStride": 8,
"componentType": 5126,
"count": 24,
"max": [
6,
1
],
"min": [
0,
0
],
"type": "VEC2"
}
},
"animations": {},
"asset": {
"generator": "collada2gltf@",
"premultipliedAlpha": true,
"profile": {
"api": "WebGL",
"version": "1.0.2"
},
"version": "1.0"
},
"bufferViews": {
"bufferView_29": {
"buffer": "CesiumTexturedBoxTest",
"byteLength": 72,
"byteOffset": 0,
"target": 34963
},
"bufferView_30": {
"buffer": "CesiumTexturedBoxTest",
"byteLength": 768,
"byteOffset": 72,
"target": 34962
}
},
"buffers": {
"CesiumTexturedBoxTest": {
"byteLength": 840,
"type": "arraybuffer",
"uri": "CesiumTexturedBoxTest.bin"
}
},
"images": {
"Image0001": {
"name": "Image0001",
"uri": "Cesium_Logo_Flat.jpg"
}
},
"materials": {
"Effect-Texture": {
"name": "Texture",
"technique": "technique0",
"values": {
"diffuse": "texture_Image0001",
"shininess": 256,
"specular": [
0.20000000298023224,
0.20000000298023224,
0.20000000298023224,
1
]
}
}
},
"meshes": {
"Geometry-mesh002": {
"name": "Mesh",
"primitives": [
{
"attributes": {
"NORMAL": "accessor_25",
"POSITION": "accessor_23",
"TEXCOORD_0": "accessor_27"
},
"indices": "accessor_21",
"material": "Effect-Texture",
"mode": 4
}
]
}
},
"nodes": {
"Geometry-mesh002Node": {
"children": [],
"matrix": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
],
"meshes": [
"Geometry-mesh002"
],
"name": "Mesh"
},
"groupLocator030Node": {
"children": [
"txtrLocator026Node"
],
"matrix": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
],
"name": "Texture_Group"
},
"node_3": {
"children": [
"Geometry-mesh002Node",
"groupLocator030Node"
],
"matrix": [
1,
0,
0,
0,
0,
0,
-1,
0,
0,
1,
0,
0,
0,
0,
0,
1
],
"name": "Y_UP_Transform"
},
"txtrLocator026Node": {
"children": [],
"matrix": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
],
"name": "Cesium_Logo_Flat__Image___Texture_"
}
},
"programs": {
"program_0": {
"attributes": [
"a_normal",
"a_position",
"a_texcoord0"
],
"fragmentShader": "CesiumTexturedBoxTest0FS",
"vertexShader": "CesiumTexturedBoxTest0VS"
}
},
"samplers": {
"sampler_0": {
"magFilter": 9729,
"minFilter": 9987,
"wrapS": 10497,
"wrapT": 10497
}
},
"scene": "defaultScene",
"scenes": {
"defaultScene": {
"nodes": [
"node_3"
]
}
},
"shaders": {
"CesiumTexturedBoxTest0FS": {
"type": 35632,
"uri": "CesiumTexturedBoxTest0FS.glsl"
},
"CesiumTexturedBoxTest0VS": {
"type": 35633,
"uri": "CesiumTexturedBoxTest0VS.glsl"
}
},
"skins": {},
"techniques": {
"technique0": {
"attributes": {
"a_normal": "normal",
"a_position": "position",
"a_texcoord0": "texcoord0"
},
"parameters": {
"diffuse": {
"type": 35678
},
"modelViewMatrix": {
"semantic": "MODELVIEW",
"type": 35676
},
"normal": {
"semantic": "NORMAL",
"type": 35665
},
"normalMatrix": {
"semantic": "MODELVIEWINVERSETRANSPOSE",
"type": 35675
},
"position": {
"semantic": "POSITION",
"type": 35665
},
"projectionMatrix": {
"semantic": "PROJECTION",
"type": 35676
},
"shininess": {
"type": 5126
},
"specular": {
"type": 35666
},
"texcoord0": {
"semantic": "TEXCOORD_0",
"type": 35664
}
},
"program": "program_0",
"states": {
"enable": [
2929,
2884
]
},
"uniforms": {
"u_diffuse": "diffuse",
"u_modelViewMatrix": "modelViewMatrix",
"u_normalMatrix": "normalMatrix",
"u_projectionMatrix": "projectionMatrix",
"u_shininess": "shininess",
"u_specular": "specular"
}
}
},
"textures": {
"texture_Image0001": {
"format": 6408,
"internalFormat": 6408,
"sampler": "sampler_0",
"source": "Image0001",
"target": 3553,
"type": 5121
}
}
}
Loading