Skip to content

Commit

Permalink
Wait for loading manager in fbx loading case
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaer Kazmer committed Nov 7, 2019
1 parent 45421eb commit 68b92be
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion model-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,20 @@ const _loadModelFilesystem = async filesystem => {
const modelFileUrl = modelFile.url;
console.log(`using model file: ${modelFile.pathname}`);
if (/\.fbx$/.test(modelFile.pathname)) {
let accept, reject;
const managerLoadPromise = new Promise((a, r) => {
accept = a;
reject = r;
});
manager.onLoad = () => {
accept();
};
const model = await new Promise((accept, reject) => {
new THREE.FBXLoader(manager).load(modelFileUrl, scene => {
accept({scene});
}, function onprogress() {}, reject);
});
await managerLoadPromise;
return model;
} else {
const model = await new Promise((accept, reject) => {
Expand Down Expand Up @@ -120,11 +129,21 @@ const loadModelUrl = async (href, filename = href) => {
_patchModel(model);
return model;
} else if (fileType === 'fbx') {
const manager = new THREE.LoadingManager();
let accept, reject;
const managerLoadPromise = new Promise((a, r) => {
accept = a;
reject = r;
});
manager.onLoad = () => {
accept();
};
const model = await new Promise((accept, reject) => {
new THREE.FBXLoader().load(href, scene => {
new THREE.FBXLoader(manager).load(href, scene => {
accept({scene});
}, xhr => {}, reject);
});
await managerLoadPromise;
_patchModel(model);
return model;
} else if (fileType === 'zip') {
Expand Down

0 comments on commit 68b92be

Please sign in to comment.