Skip to content

Commit 1f90c60

Browse files
committed
[HUBS] [r148] GLTFLoader: Clean up node hierarchy build (mrdoob#25058)
[HUBS] This change is needed for glTF LOD support. This commit will be in r148. We can remove this commit when upgrading our Three.js fork to r148 or newer.
1 parent f2b8b44 commit 1f90c60

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

examples/jsm/loaders/GLTFLoader.js

Lines changed: 33 additions & 34 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
}
@@ -4028,7 +4053,6 @@ class GLTFParser {
40284053
*/
40294054
loadScene( sceneIndex ) {
40304055

4031-
const json = this.json;
40324056
const extensions = this.extensions;
40334057
const sceneDef = this.json.scenes[ sceneIndex ];
40344058
const parser = this;
@@ -4048,11 +4072,17 @@ class GLTFParser {
40484072

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

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

40534077
}
40544078

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

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

40974127
}
40984128

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-
41304129
/**
41314130
* @param {BufferGeometry} geometry
41324131
* @param {GLTF.Primitive} primitiveDef

0 commit comments

Comments
 (0)