Skip to content

Commit

Permalink
Prevent instance collections from sharing the same Model
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Oct 20, 2015
1 parent be59252 commit 3b9d78e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 28 deletions.
9 changes: 7 additions & 2 deletions Apps/Sandcastle/gallery/Cities.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
var city = scene.primitives.add(new Cesium.Cesium3DTileset({
//url : 'http://localhost:8002/tilesets/Cambridge',
//url : 'http://localhost:8002/tilesets/London_Canary_Wharf',
url : 'http://localhost:8002/tilesets/trees',
//url : 'http://localhost:8002/tilesets/trees',
//url : 'http://localhost:8002/tilesets/Philly',
//url : 'http://localhost:8002/tilesets/Seattle',
url : 'http://localhost:8002/tilesets/SeattleTrees',

// Defaults:
maximumScreenSpaceError : 16,
Expand All @@ -49,7 +52,9 @@
viewer.camera.setView({
//position : Cesium.Cartesian3.fromDegrees(-71.1106, 42.3736, 5000.0) // Cambridge
//position : Cesium.Cartesian3.fromDegrees(0.0183, 51.5036, 5000.0) // Canary Wharf
position : Cesium.Cartesian3.fromRadians(-1.2911323805815227, 0.7097150757974291, 5000.0) // NYC Trees
//position : Cesium.Cartesian3.fromRadians(-1.2911323805815227, 0.7097150757974291, 5000.0) // NYC Trees
//position : Cesium.Cartesian3.fromDegrees(-75.1667, 39.9500, 5000.0) // Philly trees
position : Cesium.Cartesian3.fromDegrees(-122.3331, 47.6097, 5000.0) // Seattle
});

scene.debugShowFramesPerSecond = true;
Expand Down
3 changes: 1 addition & 2 deletions Source/Scene/Instanced3DModel3DTileContentProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ define([
url : undefined,
headers : undefined,
gltf : undefined,
basePath : undefined
basePath : that._url
};

//>>includeStart('debug', pragmas.debug);
Expand All @@ -162,7 +162,6 @@ define([
} else {
collectionOptions.gltf = gltfView;
collectionOptions.basePath = that._url;
collectionOptions.cacheKey = that._url;
}

var ellipsoid = Ellipsoid.WGS84;
Expand Down
11 changes: 1 addition & 10 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,15 +841,6 @@ define([
return JSON.parse(json);
}

/**
* Get the default cache key from the provided url
*
* @private
*/
Model._getDefaultCacheKey = function(url) {
return getAbsoluteURL(url);
};

/**
* <p>
* Creates a model from a glTF asset. When the model is ready to render, i.e., when the external binary, image,
Expand Down Expand Up @@ -922,7 +913,7 @@ define([
var url = options.url;
// If no cache key is provided, use the absolute URL, since two URLs with
// different relative paths could point to the same model.
var cacheKey = defaultValue(options.cacheKey, Model._getDefaultCacheKey(url));
var cacheKey = defaultValue(options.cacheKey, getAbsoluteURL(url));

options = clone(options);
options.basePath = getBasePath(url);
Expand Down
20 changes: 6 additions & 14 deletions Source/Scene/ModelInstanceCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ define([
this._headers = options.headers;
this._gltf = options.gltf;
this._basePath = options.basePath;
this._cacheKey = options.cacheKey;
this._asynchronous = options.asynchronous;

this.debugShowBoundingVolume = defaultValue(options.debugShowBoundingVolume, false);
Expand Down Expand Up @@ -524,9 +523,10 @@ define([
headers : collection._headers,
gltf : collection._gltf,
basePath : collection._basePath,
cacheKey : collection._cacheKey,
cacheKey : undefined,
asynchronous : collection._asynchronous,
allowPicking : collection._allowPicking,
releaseGltfJson : false,
precreatedAttributes : undefined,
vertexShaderLoaded : undefined,
fragmentShaderLoaded : undefined,
Expand Down Expand Up @@ -586,23 +586,18 @@ define([
}
};

// Instanced models will create different renderer resources, so change the cache key.
var cacheKey = collection._cacheKey;
var url = collection._url;
if (defined(url)) {
cacheKey = defaultValue(cacheKey, Model._getDefaultCacheKey(url));
cacheKey += '#instanced';
}

modelOptions.precreatedAttributes = instancedAttributes;
modelOptions.vertexShaderLoaded = getVertexShaderCallback(collection);
modelOptions.fragmentShaderLoaded = getFragmentShaderCallback(collection);
modelOptions.uniformMapLoaded = getUniformMapCallback(collection, context);
modelOptions.pickVertexShaderLoaded = getPickVertexShaderCallback(collection);
modelOptions.pickFragmentShaderLoaded = getPickFragmentShaderCallback(collection);
modelOptions.pickUniformMapLoaded = getPickUniformMapCallback(collection);
modelOptions.cacheKey = cacheKey;
modelOptions.ignoreCommands = true;
modelOptions.releaseGltfJson = true;

// Collections cannot share the same models, so create a unique cache key
modelOptions.cacheKey = 'ModelInstanceCollection' + Math.random();
} else {
modelOptions.fragmentShaderLoaded = getFragmentShaderNonInstancedCallback();
}
Expand Down Expand Up @@ -637,21 +632,18 @@ define([
var allowPicking = collection.allowPicking;

var boundingVolume = collection._boundingVolume;
var boundingVolumeModel = collection._boundingVolumeModel;

if (collection._instancingSupported) {
for (i = 0; i < commandsLength; ++i) {
command = clone(drawCommands[i]);
command.instanceCount = instancesLength;
command.modelMatrix = boundingVolumeModel;
command.boundingVolume = boundingVolume;
command.cull = collection._cull;
collection._drawCommands.push(command);

if (allowPicking) {
command = clone(pickCommands[i]);
command.instanceCount = instancesLength;
command.modelMatrix = boundingVolumeModel;
command.boundingVolume = boundingVolume;
command.cull = collection._cull;
collection._pickCommands.push(command);
Expand Down

0 comments on commit 3b9d78e

Please sign in to comment.