From 17ed36d5b1266f452a4bec63e0054f00f6771a7e Mon Sep 17 00:00:00 2001 From: Avaer Kazmer Date: Thu, 21 Nov 2019 05:20:54 -0500 Subject: [PATCH] Update FBXLoader --- FBXLoader.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/FBXLoader.js b/FBXLoader.js index 6a5a133..a210b95 100644 --- a/FBXLoader.js +++ b/FBXLoader.js @@ -928,7 +928,7 @@ THREE.FBXLoader = ( function () { // duplicate the bone here and and it as a child of the first bone if ( subBone !== null ) { - // bone.add( subBone ); + bone.add( subBone ); } @@ -2058,10 +2058,12 @@ THREE.FBXLoader = ( function () { if ( morphTargets.length === 0 ) return; + parentGeo.morphTargetsRelative = true; + parentGeo.morphAttributes.position = []; // parentGeo.morphAttributes.normal = []; // not implemented - var self = this; + var self = this; morphTargets.forEach( function ( morphTarget ) { morphTarget.rawTargets.forEach( function ( rawTarget ) { @@ -2086,33 +2088,29 @@ THREE.FBXLoader = ( function () { // Normal and position attributes only have data for the vertices that are affected by the morph genMorphGeometry: function ( parentGeo, parentGeoNode, morphGeoNode, preTransform, name ) { - var morphGeo = new THREE.BufferGeometry(); - if ( morphGeoNode.attrName ) morphGeo.name = morphGeoNode.attrName; - var vertexIndices = ( parentGeoNode.PolygonVertexIndex !== undefined ) ? parentGeoNode.PolygonVertexIndex.a : []; - // make a copy of the parent's vertex positions - var vertexPositions = ( parentGeoNode.Vertices !== undefined ) ? parentGeoNode.Vertices.a.slice() : []; - - var morphPositions = ( morphGeoNode.Vertices !== undefined ) ? morphGeoNode.Vertices.a : []; + var morphPositionsSparse = ( morphGeoNode.Vertices !== undefined ) ? morphGeoNode.Vertices.a : []; var indices = ( morphGeoNode.Indexes !== undefined ) ? morphGeoNode.Indexes.a : []; + var length = parentGeo.attributes.position.count * 3; + var morphPositions = new Float32Array( length ); + for ( var i = 0; i < indices.length; i ++ ) { var morphIndex = indices[ i ] * 3; - // FBX format uses blend shapes rather than morph targets. This can be converted - // by additively combining the blend shape positions with the original geometry's positions - vertexPositions[ morphIndex ] += morphPositions[ i * 3 ]; - vertexPositions[ morphIndex + 1 ] += morphPositions[ i * 3 + 1 ]; - vertexPositions[ morphIndex + 2 ] += morphPositions[ i * 3 + 2 ]; + morphPositions[ morphIndex ] = morphPositionsSparse[ i * 3 ]; + morphPositions[ morphIndex + 1 ] = morphPositionsSparse[ i * 3 + 1 ]; + morphPositions[ morphIndex + 2 ] = morphPositionsSparse[ i * 3 + 2 ]; } // TODO: add morph normal support var morphGeoInfo = { vertexIndices: vertexIndices, - vertexPositions: vertexPositions, + vertexPositions: morphPositions, + }; var morphBuffers = this.genBuffers( morphGeoInfo );