diff --git a/src/components/gltf-model-plus.js b/src/components/gltf-model-plus.js index 61445a2bd6185ac8ca621a2e1a1351ccb207302f..b1195922467eb57dd6b536e688b147c164e502ea 100644 --- a/src/components/gltf-model-plus.js +++ b/src/components/gltf-model-plus.js @@ -182,30 +182,15 @@ function nextTick() { } function cachedLoadGLTF(src, preferredTechnique, onProgress) { - return new Promise((resolve, reject) => { - // Load the gltf model from the cache if it exists. - if (GLTFCache[src]) { - // Use a cloned copy of the cached model. - resolve(cloneGltf(GLTFCache[src])); - } else { - // Otherwise load the new gltf model. + // Load the gltf model from the cache if it exists. + if (!GLTFCache[src]) { + GLTFCache[src] = new Promise((resolve, reject) => { const gltfLoader = new THREE.GLTFLoader(); gltfLoader.preferredTechnique = preferredTechnique; - - gltfLoader.load( - src, - model => { - if (!GLTFCache[src]) { - // Store a cloned copy of the gltf model. - GLTFCache[src] = cloneGltf(model); - } - resolve(model); - }, - onProgress, - reject - ); - } - }); + gltfLoader.load(src, resolve, onProgress, reject); + }); + } + return GLTFCache[src].then(cloneGltf); } /**