-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor GLTFScenegraphLoader (#1062)
- Loading branch information
Showing
9 changed files
with
101 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,50 @@ | ||
/* global window */ | ||
import {GLTFParser} from '@loaders.gl/gltf'; | ||
import {DracoDecoder} from '@loaders.gl/draco'; | ||
import {assert} from '@luma.gl/core'; | ||
import {GLTFLoader} from '@loaders.gl/gltf'; | ||
import createGLTFObjects from './create-gltf-objects'; | ||
|
||
async function waitWhileCondition(condition) { | ||
while (condition()) { | ||
await new Promise(resolve => window.requestAnimationFrame(resolve)); | ||
} | ||
} | ||
|
||
async function parse(data, options, uri, loader) { | ||
const gltfParser = new GLTFParser(); | ||
const gltf = await gltfParser.parse(data, { | ||
assert(options.gl); | ||
|
||
const gltf = await GLTFLoader.parse(data, { | ||
...options, | ||
uri, | ||
decompress: true, | ||
DracoDecoder | ||
decompress: true | ||
}); | ||
|
||
const gltfObjects = createGLTFObjects(options.gl, gltf, options); | ||
|
||
if (options.waitForFullLoad) { | ||
const remaining = []; | ||
|
||
gltfObjects.scenes.forEach(scene => { | ||
scene.traverse(model => { | ||
Object.values(model.model.program.uniforms).forEach(uniform => { | ||
if (uniform.loaded === false) { | ||
remaining.push(uniform); | ||
} | ||
}); | ||
await waitForGLTFAssets(gltfObjects); | ||
} | ||
|
||
return Object.assign({gltf}, gltfObjects); | ||
} | ||
|
||
async function waitForGLTFAssets(gltfObjects) { | ||
const remaining = []; | ||
|
||
gltfObjects.scenes.forEach(scene => { | ||
scene.traverse(model => { | ||
Object.values(model.model.program.uniforms).forEach(uniform => { | ||
if (uniform.loaded === false) { | ||
remaining.push(uniform); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
await waitWhileCondition(() => remaining.some(uniform => !uniform.loaded)); | ||
} | ||
|
||
return Object.assign({gltfParser, gltf}, gltfObjects); | ||
return await waitWhileCondition(() => remaining.some(uniform => !uniform.loaded)); | ||
} | ||
|
||
export const GLBScenegraphLoader = { | ||
name: 'GLTF Binary Scenegraph Loader', | ||
extension: 'glb', | ||
parse | ||
}; | ||
async function waitWhileCondition(condition) { | ||
while (condition()) { | ||
await new Promise(resolve => window.requestAnimationFrame(resolve)); | ||
} | ||
} | ||
|
||
export const GLTFScenegraphLoader = { | ||
export default { | ||
name: 'GLTF Scenegraph Loader', | ||
extension: 'gltf', | ||
extensions: ['gltf, glb'], | ||
parse | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.