Skip to content

Commit 680c12a

Browse files
committed
GLTFLoader: Clean up node hierarchy build
1 parent 59020b2 commit 680c12a

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

examples/jsm/loaders/GLTFLoader.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4017,6 +4017,31 @@ class GLTFParser {
40174017

40184018
} );
40194019

4020+
} ).then( function ( node ) {
4021+
4022+
if ( nodeDef.children === undefined ) return node;
4023+
4024+
const pending = [];
4025+
const childrenDef = nodeDef.children;
4026+
4027+
for ( let i = 0, il = childrenDef.length; i < il; i ++ ) {
4028+
4029+
pending.push( parser.getDependency( 'node', childrenDef[ i ] ) );
4030+
4031+
}
4032+
4033+
return Promise.all( pending ).then( function ( children ) {
4034+
4035+
for ( let i = 0, il = children.length; i < il; i ++ ) {
4036+
4037+
node.add( children[ i ] );
4038+
4039+
}
4040+
4041+
return node;
4042+
4043+
} );
4044+
40204045
} );
40214046

40224047
}
@@ -4048,11 +4073,17 @@ class GLTFParser {
40484073

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

4051-
pending.push( buildNodeHierarchy( nodeIds[ i ], scene, json, parser ) );
4076+
pending.push( parser.getDependency( 'node', nodeIds[ i ] ) );
40524077

40534078
}
40544079

4055-
return Promise.all( pending ).then( function () {
4080+
return Promise.all( pending ).then( function ( nodes ) {
4081+
4082+
for ( let i = 0, il = nodes.length; i < il; i ++ ) {
4083+
4084+
scene.add( nodes[ i ] );
4085+
4086+
}
40564087

40574088
// Removes dangling associations, associations that reference a node that
40584089
// didn't make it into the scene.
@@ -4096,37 +4127,6 @@ class GLTFParser {
40964127

40974128
}
40984129

4099-
function buildNodeHierarchy( nodeId, parentObject, json, parser ) {
4100-
4101-
const nodeDef = json.nodes[ nodeId ];
4102-
4103-
return parser.getDependency( 'node', nodeId ).then( function ( node ) {
4104-
4105-
// build node hierachy
4106-
4107-
parentObject.add( node );
4108-
4109-
const pending = [];
4110-
4111-
if ( nodeDef.children ) {
4112-
4113-
const children = nodeDef.children;
4114-
4115-
for ( let i = 0, il = children.length; i < il; i ++ ) {
4116-
4117-
const child = children[ i ];
4118-
pending.push( buildNodeHierarchy( child, node, json, parser ) );
4119-
4120-
}
4121-
4122-
}
4123-
4124-
return Promise.all( pending );
4125-
4126-
} );
4127-
4128-
}
4129-
41304130
/**
41314131
* @param {BufferGeometry} geometry
41324132
* @param {GLTF.Primitive} primitiveDef

0 commit comments

Comments
 (0)