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

GLTFLoader: Clean up node hierarchy build #25058

Merged
merged 1 commit into from
Dec 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 33 additions & 34 deletions examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4017,6 +4017,31 @@ class GLTFParser {

} );

} ).then( function ( node ) {

if ( nodeDef.children === undefined ) return node;

const pending = [];
const childrenDef = nodeDef.children;

for ( let i = 0, il = childrenDef.length; i < il; i ++ ) {

pending.push( parser.getDependency( 'node', childrenDef[ i ] ) );

}

return Promise.all( pending ).then( function ( children ) {

for ( let i = 0, il = children.length; i < il; i ++ ) {

node.add( children[ i ] );

}

return node;

} );

} );

}
Expand All @@ -4028,7 +4053,6 @@ class GLTFParser {
*/
loadScene( sceneIndex ) {

const json = this.json;
const extensions = this.extensions;
const sceneDef = this.json.scenes[ sceneIndex ];
const parser = this;
Expand All @@ -4048,11 +4072,17 @@ class GLTFParser {

for ( let i = 0, il = nodeIds.length; i < il; i ++ ) {

pending.push( buildNodeHierarchy( nodeIds[ i ], scene, json, parser ) );
pending.push( parser.getDependency( 'node', nodeIds[ i ] ) );

}

return Promise.all( pending ).then( function () {
return Promise.all( pending ).then( function ( nodes ) {

for ( let i = 0, il = nodes.length; i < il; i ++ ) {

scene.add( nodes[ i ] );

}

// Removes dangling associations, associations that reference a node that
// didn't make it into the scene.
Expand Down Expand Up @@ -4096,37 +4126,6 @@ class GLTFParser {

}

function buildNodeHierarchy( nodeId, parentObject, json, parser ) {

const nodeDef = json.nodes[ nodeId ];

return parser.getDependency( 'node', nodeId ).then( function ( node ) {

// build node hierachy

parentObject.add( node );

const pending = [];

if ( nodeDef.children ) {

const children = nodeDef.children;

for ( let i = 0, il = children.length; i < il; i ++ ) {

const child = children[ i ];
pending.push( buildNodeHierarchy( child, node, json, parser ) );

}

}

return Promise.all( pending );

} );

}

/**
* @param {BufferGeometry} geometry
* @param {GLTF.Primitive} primitiveDef
Expand Down