|
@@ -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 );
|