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

Fix a bug in GLTF cache #448

Merged
merged 1 commit into from
Jul 6, 2018
Merged
Changes from all 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
29 changes: 7 additions & 22 deletions src/components/gltf-model-plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down