From 03d0b21a8668af58baf57a186ad58aa8ff546428 Mon Sep 17 00:00:00 2001 From: Marshall Quander <marshall@quander.me> Date: Thu, 5 Jul 2018 15:57:28 -0700 Subject: [PATCH] Fix a bug in GLTF cache --- src/components/gltf-model-plus.js | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/components/gltf-model-plus.js b/src/components/gltf-model-plus.js index 55d62b10e..ee8d52291 100644 --- a/src/components/gltf-model-plus.js +++ b/src/components/gltf-model-plus.js @@ -168,30 +168,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); } /** -- GitLab