Browse Source

Add bone graph to SkinnedMesh

Takahiro 8 years ago
parent
commit
6a53e95c22
1 changed files with 25 additions and 0 deletions
  1. 25 0
      examples/js/loaders/GLTFLoader.js

+ 25 - 0
examples/js/loaders/GLTFLoader.js

@@ -1622,6 +1622,31 @@ THREE.GLTFLoader = ( function () {
 
 									child.bind( new THREE.Skeleton( bones, boneInverses, false ), skinEntry.bindShapeMatrix );
 
+									var buildBoneGraph = function ( parentJson, parentObject, property ) {
+
+										var children = parentJson[ property ];
+
+										if ( children === undefined ) return;
+
+										for ( var i = 0, il = children.length; i < il; i ++ ) {
+
+											var nodeId = children[ i ];
+											var bone = __nodes[ nodeId ];
+											var boneJson = json.nodes[ nodeId ];
+
+											if ( bone !== undefined && bone.isBone === true && boneJson !== undefined ) {
+
+												parentObject.add( bone );
+												buildBoneGraph( boneJson, bone, 'children' );
+
+											}
+
+										}
+
+									}
+
+									buildBoneGraph( node, child, 'skeletons' );
+
 								}
 
 								_node.add( child );