提交 79321a61 编写于 作者: M Mr.doob

FBXLoader2: Performance optimisations and clean up.

上级 461a9574
...@@ -633,6 +633,7 @@ ...@@ -633,6 +633,7 @@
var currentWeight = weight; var currentWeight = weight;
var currentIndex = weightIndices[ weightIndex ]; var currentIndex = weightIndices[ weightIndex ];
Weight.forEach( function ( comparedWeight, comparedWeightIndex, comparedWeightArray ) { Weight.forEach( function ( comparedWeight, comparedWeightIndex, comparedWeightArray ) {
if ( currentWeight > comparedWeight ) { if ( currentWeight > comparedWeight ) {
...@@ -738,15 +739,19 @@ ...@@ -738,15 +739,19 @@
} }
// Convert the material indices of each vertex into rendering groups on the geometry. // Convert the material indices of each vertex into rendering groups on the geometry.
var prevMaterialIndex = bufferInfo.materialIndexBuffer[ 0 ];
var materialIndexBuffer = bufferInfo.materialIndexBuffer;
var prevMaterialIndex = materialIndexBuffer[ 0 ];
var startIndex = 0; var startIndex = 0;
for ( var materialBufferIndex = 0; materialBufferIndex < bufferInfo.materialIndexBuffer.length; ++ materialBufferIndex ) {
if ( bufferInfo.materialIndexBuffer[ materialBufferIndex ] !== prevMaterialIndex ) { for ( var i = 0; i < materialIndexBuffer.length; ++ i ) {
if ( materialIndexBuffer[ i ] !== prevMaterialIndex ) {
geo.addGroup( startIndex, i - startIndex, prevMaterialIndex );
geo.addGroup( startIndex, materialBufferIndex - startIndex, prevMaterialIndex ); prevMaterialIndex = materialIndexBuffer[ i ];
startIndex = materialBufferIndex; startIndex = i;
prevMaterialIndex = bufferInfo.materialIndexBuffer[ materialBufferIndex ];
} }
...@@ -2518,11 +2523,7 @@ ...@@ -2518,11 +2523,7 @@
version: null, version: null,
id: animationCurve.id, id: animationCurve.id,
internalID: animationCurve.id, internalID: animationCurve.id,
times: parseFloatArray( animationCurve.subNodes.KeyTime.properties.a ).map( function ( time ) { times: parseFloatArray( animationCurve.subNodes.KeyTime.properties.a ).map( convertFBXTimeToSeconds ),
return ConvertFBXTimeToSeconds( time );
} ),
values: parseFloatArray( animationCurve.subNodes.KeyValueFloat.properties.a ), values: parseFloatArray( animationCurve.subNodes.KeyValueFloat.properties.a ),
attrFlag: parseIntArray( animationCurve.subNodes.KeyAttrFlags.properties.a ), attrFlag: parseIntArray( animationCurve.subNodes.KeyAttrFlags.properties.a ),
...@@ -3038,7 +3039,7 @@ ...@@ -3038,7 +3039,7 @@
} }
var AXES = [ 'x', 'y', 'z' ];
function hasCurve( animationNode, attribute ) { function hasCurve( animationNode, attribute ) {
...@@ -3049,13 +3050,14 @@ ...@@ -3049,13 +3050,14 @@
} }
var attributeNode = animationNode[ attribute ]; var attributeNode = animationNode[ attribute ];
if ( ! attributeNode ) { if ( ! attributeNode ) {
return false; return false;
} }
return [ 'x', 'y', 'z' ].every( function ( key ) { return AXES.every( function ( key ) {
return attributeNode.curves[ key ] !== null; return attributeNode.curves[ key ] !== null;
...@@ -3065,17 +3067,17 @@ ...@@ -3065,17 +3067,17 @@
function hasKeyOnFrame( attributeNode, frame ) { function hasKeyOnFrame( attributeNode, frame ) {
return [ 'x', 'y', 'z' ].every( function ( key ) { return AXES.every( function ( key ) {
return isKeyExistOnFrame( attributeNode.curves[ key ], frame ); return isKeyExistOnFrame( attributeNode.curves[ key ], frame );
function isKeyExistOnFrame( curve, frame ) { } );
return curve.values[ frame ] !== undefined; }
} function isKeyExistOnFrame( curve, frame ) {
} ); return curve.values[ frame ] !== undefined;
} }
...@@ -3672,8 +3674,7 @@ ...@@ -3672,8 +3674,7 @@
case "ColorRGB": case "ColorRGB":
case "Vector3D": case "Vector3D":
var tmp = innerPropValue.split( ',' ); innerPropValue = new THREE.Vector3().fromArray( innerPropValue.split( ',' ).map( parseFloatMap ) );
innerPropValue = new THREE.Vector3( tmp[ 0 ], tmp[ 1 ], tmp[ 2 ] );
break; break;
} }
...@@ -3907,7 +3908,7 @@ ...@@ -3907,7 +3908,7 @@
* @param {number} time - FBX tick timestamp to convert. * @param {number} time - FBX tick timestamp to convert.
* @returns {number} - FBX tick in real world time. * @returns {number} - FBX tick in real world time.
*/ */
function ConvertFBXTimeToSeconds( time ) { function convertFBXTimeToSeconds( time ) {
// Constant is FBX ticks per second. // Constant is FBX ticks per second.
return time / 46186158000; return time / 46186158000;
...@@ -3923,18 +3924,12 @@ ...@@ -3923,18 +3924,12 @@
*/ */
function parseFloatArray( string ) { function parseFloatArray( string ) {
var array = string.split( ',' ); return string.split( ',' ).map( parseFloatMap );
for ( var i = 0, l = array.length; i < l; i ++ ) {
array[ i ] = parseFloat( array[ i ] );
}
return array;
} }
function parseFloatMap( string ) { return parseFloat( string ); }
/** /**
* Parses comma separated list of int numbers and returns them in an array. * Parses comma separated list of int numbers and returns them in an array.
* @example * @example
...@@ -3944,18 +3939,12 @@ ...@@ -3944,18 +3939,12 @@
*/ */
function parseIntArray( string ) { function parseIntArray( string ) {
var array = string.split( ',' ); return string.split( ',' ).map( parseIntMap );
for ( var i = 0, l = array.length; i < l; i ++ ) {
array[ i ] = parseInt( array[ i ] );
}
return array;
} }
function parseIntMap( string ) { return parseInt( string ); }
/** /**
* Parses Vector3 property from FBXTree. Property is given as .value.x, .value.y, etc. * Parses Vector3 property from FBXTree. Property is given as .value.x, .value.y, etc.
* @param {FBXVector3} property - Property to parse as Vector3. * @param {FBXVector3} property - Property to parse as Vector3.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册