Skip to content

Commit

Permalink
Update FBXLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaer Kazmer committed Nov 21, 2019
1 parent 3c0f915 commit 17ed36d
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions FBXLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}

Expand Down Expand Up @@ -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 ) {
Expand All @@ -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 );
Expand Down

0 comments on commit 17ed36d

Please sign in to comment.