diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index 080d3c90b820..0d7c8093b35f 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -2848,6 +2848,11 @@ define([ resources.textures = cachedResources.textures; resources.samplers = cachedResources.samplers; resources.renderStates = cachedResources.renderStates; + + // Vertex arrays are unique to this model, create instead of using the cache. + if (defined(model._precreatedAttributes)) { + createVertexArrays(model, context); + } } else { createDecompressedViews(model, context); createBuffers(model, context, frameState); // using glTF bufferViews @@ -3302,6 +3307,11 @@ define([ cachedResources.renderStates = resources.renderStates; cachedResources.ready = true; + // Vertex arrays are unique to this model, do not store in cache. + if (defined(this._precreatedAttributes)) { + cachedResources.vertexArrays = {}; + } + if (this.releaseGltfJson) { releaseCachedGltf(this); } @@ -3422,6 +3432,11 @@ define([ * model = model && model.destroy(); */ Model.prototype.destroy = function() { + // Vertex arrays are unique to this model, destroy here. + if (defined(this._precreatedAttributes)) { + destroy(this._rendererResources.vertexArrays); + } + this._rendererResources = undefined; this._cachedRendererResources = this._cachedRendererResources && this._cachedRendererResources.release(); diff --git a/Source/Scene/ModelInstanceCollection.js b/Source/Scene/ModelInstanceCollection.js index b6a6516aab79..31615f062d37 100644 --- a/Source/Scene/ModelInstanceCollection.js +++ b/Source/Scene/ModelInstanceCollection.js @@ -526,7 +526,6 @@ define([ cacheKey : undefined, asynchronous : collection._asynchronous, allowPicking : collection._allowPicking, - releaseGltfJson : false, precreatedAttributes : undefined, vertexShaderLoaded : undefined, fragmentShaderLoaded : undefined, @@ -594,10 +593,10 @@ define([ modelOptions.pickFragmentShaderLoaded = getPickFragmentShaderCallback(collection); modelOptions.pickUniformMapLoaded = getPickUniformMapCallback(collection); modelOptions.ignoreCommands = true; - modelOptions.releaseGltfJson = true; - // Collections cannot share the same models, so create a unique cache key - modelOptions.cacheKey = 'ModelInstanceCollection' + Math.random(); + if (defined(collection._url)) { + modelOptions.cacheKey = collection._url + '#instanced'; + } } else { modelOptions.fragmentShaderLoaded = getFragmentShaderNonInstancedCallback(); }