|
@@ -663,8 +663,8 @@
|
|
|
|
|
|
if ( 'Indexes' in subDeformerNode.subNodes ) {
|
|
|
|
|
|
- subDeformer.indices = parseIntArray( subDeformerNode.subNodes.Indexes.properties.a );
|
|
|
- subDeformer.weights = parseFloatArray( subDeformerNode.subNodes.Weights.properties.a );
|
|
|
+ subDeformer.indices = parseNumberArray( subDeformerNode.subNodes.Indexes.properties.a );
|
|
|
+ subDeformer.weights = parseNumberArray( subDeformerNode.subNodes.Weights.properties.a );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -763,8 +763,8 @@
|
|
|
|
|
|
// First, each index is going to be its own vertex.
|
|
|
|
|
|
- var vertexBuffer = parseFloatArray( subNodes.Vertices.properties.a );
|
|
|
- var indexBuffer = parseIntArray( subNodes.PolygonVertexIndex.properties.a );
|
|
|
+ var vertexBuffer = parseNumberArray( subNodes.Vertices.properties.a );
|
|
|
+ var indexBuffer = parseNumberArray( subNodes.PolygonVertexIndex.properties.a );
|
|
|
|
|
|
if ( subNodes.LayerElementNormal ) {
|
|
|
|
|
@@ -1016,43 +1016,47 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- // Convert the material indices of each vertex into rendering groups on the geometry.
|
|
|
+ if ( materialInfo.mappingType !== 'AllSame' ) {
|
|
|
|
|
|
- var materialIndexBuffer = bufferInfo.materialIndexBuffer;
|
|
|
- var prevMaterialIndex = materialIndexBuffer[ 0 ];
|
|
|
- var startIndex = 0;
|
|
|
+ // Convert the material indices of each vertex into rendering groups on the geometry.
|
|
|
+ var materialIndexBuffer = bufferInfo.materialIndexBuffer;
|
|
|
+ var prevMaterialIndex = materialIndexBuffer[ 0 ];
|
|
|
+ var startIndex = 0;
|
|
|
|
|
|
- for ( var i = 0; i < materialIndexBuffer.length; ++ i ) {
|
|
|
+ for ( var i = 0; i < materialIndexBuffer.length; ++ i ) {
|
|
|
|
|
|
- if ( materialIndexBuffer[ i ] !== prevMaterialIndex ) {
|
|
|
+ if ( materialIndexBuffer[ i ] !== prevMaterialIndex ) {
|
|
|
|
|
|
- geo.addGroup( startIndex, i - startIndex, prevMaterialIndex );
|
|
|
+ geo.addGroup( startIndex, i - startIndex, prevMaterialIndex );
|
|
|
|
|
|
- prevMaterialIndex = materialIndexBuffer[ i ];
|
|
|
- startIndex = i;
|
|
|
+ prevMaterialIndex = materialIndexBuffer[ i ];
|
|
|
+ startIndex = i;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ // the loop above doesn't add the last group, do that here.
|
|
|
+ if ( geo.groups.length > 0 ) {
|
|
|
|
|
|
- // the loop above doesn't add the last group, do that here.
|
|
|
- if ( geo.groups.length > 0 ) {
|
|
|
+ var lastGroup = geo.groups[ geo.groups.length - 1 ];
|
|
|
+ var lastIndex = lastGroup.start + lastGroup.count;
|
|
|
|
|
|
- var lastGroup = geo.groups[ geo.groups.length - 1 ];
|
|
|
- var lastIndex = lastGroup.start + lastGroup.count;
|
|
|
+ if ( lastIndex !== materialIndexBuffer.length ) {
|
|
|
|
|
|
- if ( lastIndex !== materialIndexBuffer.length ) {
|
|
|
+ geo.addGroup( lastIndex, materialIndexBuffer.length - lastIndex, prevMaterialIndex );
|
|
|
|
|
|
- geo.addGroup( lastIndex, materialIndexBuffer.length - lastIndex, prevMaterialIndex );
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ // case where there are multiple materials but the whole geometry is only
|
|
|
+ // using one of them
|
|
|
+ if ( geo.groups.length === 0 ) {
|
|
|
|
|
|
- // catch case where the whole geometry has a single non-zero index
|
|
|
- if ( geo.groups.length === 0 && materialIndexBuffer[ 0 ] !== 0 ) {
|
|
|
+ geo.addGroup( 0, materialIndexBuffer.length, materialIndexBuffer[ 0 ] );
|
|
|
|
|
|
- geo.addGroup( 0, materialIndexBuffer.length, materialIndexBuffer[ 0 ] );
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1069,17 +1073,17 @@
|
|
|
|
|
|
var mappingType = NormalNode.properties.MappingInformationType;
|
|
|
var referenceType = NormalNode.properties.ReferenceInformationType;
|
|
|
- var buffer = parseFloatArray( NormalNode.subNodes.Normals.properties.a );
|
|
|
+ var buffer = parseNumberArray( NormalNode.subNodes.Normals.properties.a );
|
|
|
var indexBuffer = [];
|
|
|
if ( referenceType === 'IndexToDirect' ) {
|
|
|
|
|
|
if ( 'NormalIndex' in NormalNode.subNodes ) {
|
|
|
|
|
|
- indexBuffer = parseIntArray( NormalNode.subNodes.NormalIndex.properties.a );
|
|
|
+ indexBuffer = parseNumberArray( NormalNode.subNodes.NormalIndex.properties.a );
|
|
|
|
|
|
} else if ( 'NormalsIndex' in NormalNode.subNodes ) {
|
|
|
|
|
|
- indexBuffer = parseIntArray( NormalNode.subNodes.NormalsIndex.properties.a );
|
|
|
+ indexBuffer = NormalNode.subNodes.NormalsIndex.properties.a;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1104,11 +1108,11 @@
|
|
|
|
|
|
var mappingType = UVNode.properties.MappingInformationType;
|
|
|
var referenceType = UVNode.properties.ReferenceInformationType;
|
|
|
- var buffer = parseFloatArray( UVNode.subNodes.UV.properties.a );
|
|
|
+ var buffer = parseNumberArray( UVNode.subNodes.UV.properties.a );
|
|
|
var indexBuffer = [];
|
|
|
if ( referenceType === 'IndexToDirect' ) {
|
|
|
|
|
|
- indexBuffer = parseIntArray( UVNode.subNodes.UVIndex.properties.a );
|
|
|
+ indexBuffer = parseNumberArray( UVNode.subNodes.UVIndex.properties.a );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1131,11 +1135,11 @@
|
|
|
|
|
|
var mappingType = ColorNode.properties.MappingInformationType;
|
|
|
var referenceType = ColorNode.properties.ReferenceInformationType;
|
|
|
- var buffer = parseFloatArray( ColorNode.subNodes.Colors.properties.a );
|
|
|
+ var buffer = ColorNode.subNodes.Colors.properties.a;
|
|
|
var indexBuffer = [];
|
|
|
if ( referenceType === 'IndexToDirect' ) {
|
|
|
|
|
|
- indexBuffer = parseFloatArray( ColorNode.subNodes.ColorIndex.properties.a );
|
|
|
+ indexBuffer = ColorNode.subNodes.ColorIndex.properties.a;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1171,7 +1175,7 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- var materialIndexBuffer = parseIntArray( MaterialNode.subNodes.Materials.properties.a );
|
|
|
+ var materialIndexBuffer = parseNumberArray( MaterialNode.subNodes.Materials.properties.a );
|
|
|
|
|
|
// Since materials are stored as indices, there's a bit of a mismatch between FBX and what
|
|
|
// we expect. So we create an intermediate buffer that points to the index in the buffer,
|
|
@@ -1359,9 +1363,9 @@
|
|
|
|
|
|
var degree = order - 1;
|
|
|
|
|
|
- var knots = parseFloatArray( geometryNode.subNodes.KnotVector.properties.a );
|
|
|
+ var knots = geometryNode.subNodes.KnotVector.properties.a;
|
|
|
var controlPoints = [];
|
|
|
- var pointsValues = parseFloatArray( geometryNode.subNodes.Points.properties.a );
|
|
|
+ var pointsValues = geometryNode.subNodes.Points.properties.a;
|
|
|
|
|
|
for ( var i = 0, l = pointsValues.length; i < l; i += 4 ) {
|
|
|
|
|
@@ -2615,6 +2619,7 @@
|
|
|
|
|
|
}
|
|
|
returnObject.curves.get( id )[ curveNode.attr ] = curveNode;
|
|
|
+
|
|
|
if ( curveNode.attr === 'R' ) {
|
|
|
|
|
|
var curves = curveNode.curves;
|
|
@@ -3011,11 +3016,11 @@
|
|
|
version: null,
|
|
|
id: animationCurve.id,
|
|
|
internalID: animationCurve.id,
|
|
|
- times: parseFloatArray( animationCurve.subNodes.KeyTime.properties.a ).map( convertFBXTimeToSeconds ),
|
|
|
- values: parseFloatArray( animationCurve.subNodes.KeyValueFloat.properties.a ),
|
|
|
+ times: parseNumberArray( animationCurve.subNodes.KeyTime.properties.a ).map( convertFBXTimeToSeconds ),
|
|
|
+ values: parseNumberArray( animationCurve.subNodes.KeyValueFloat.properties.a ),
|
|
|
|
|
|
- attrFlag: parseIntArray( animationCurve.subNodes.KeyAttrFlags.properties.a ),
|
|
|
- attrData: parseFloatArray( animationCurve.subNodes.KeyAttrDataFloat.properties.a )
|
|
|
+ attrFlag: parseNumberArray( animationCurve.subNodes.KeyAttrFlags.properties.a ),
|
|
|
+ attrData: animationCurve.subNodes.KeyAttrDataFloat.properties.a,
|
|
|
};
|
|
|
|
|
|
}
|
|
@@ -4305,6 +4310,43 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
+ // ...parentName.properties.a
|
|
|
+ if ( propName === 'a' ) {
|
|
|
+
|
|
|
+ switch ( parentName ) {
|
|
|
+
|
|
|
+ case 'Matrix':
|
|
|
+ case 'TransformLink':
|
|
|
+ case 'Transform':
|
|
|
+ propValue = new THREE.Matrix4().fromArray( parseNumberArray( propValue ) );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'ColorIndex':
|
|
|
+ case 'Colors':
|
|
|
+ case 'KeyAttrDataFloat':
|
|
|
+ case 'KnotVector':
|
|
|
+ case 'NormalIndex':
|
|
|
+ case 'NormalsIndex':
|
|
|
+ case 'Points':
|
|
|
+ propValue = parseNumberArray( propValue );
|
|
|
+ break;
|
|
|
+
|
|
|
+ // TODO: for the following properties this check is not catching all occurences
|
|
|
+ // case 'KeyTime':
|
|
|
+ // case 'Normals':
|
|
|
+ // case 'UV':
|
|
|
+ // case 'Vertices':
|
|
|
+ // case 'KeyValueFloat':
|
|
|
+ // case 'Weights':
|
|
|
+
|
|
|
+ // case 'Materials':
|
|
|
+ // case 'PolygonVertexIndex':
|
|
|
+ // case 'UVIndex':
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
// Connections
|
|
|
if ( propName === 'C' ) {
|
|
|
|
|
@@ -4344,7 +4386,6 @@
|
|
|
// already exists in properties, then append this
|
|
|
if ( propName in currentNode.properties ) {
|
|
|
|
|
|
- // console.log( "duped entry found\nkey: " + propName + "\nvalue: " + propValue );
|
|
|
if ( Array.isArray( currentNode.properties[ propName ] ) ) {
|
|
|
|
|
|
currentNode.properties[ propName ].push( propValue );
|
|
@@ -4359,6 +4400,7 @@
|
|
|
|
|
|
if ( Array.isArray( currentNode.properties[ propName ] ) ) {
|
|
|
|
|
|
+
|
|
|
currentNode.properties[ propName ].push( propValue );
|
|
|
|
|
|
} else {
|
|
@@ -4427,7 +4469,7 @@
|
|
|
case 'Lcl_Translation':
|
|
|
case 'Lcl_Rotation':
|
|
|
case 'Lcl_Scaling':
|
|
|
- innerPropValue = parseFloatArray( innerPropValue );
|
|
|
+ innerPropValue = parseNumberArray( innerPropValue );
|
|
|
break;
|
|
|
|
|
|
}
|
|
@@ -4590,9 +4632,20 @@
|
|
|
node.properties[ node.name ] = node.propertyList[ 0 ];
|
|
|
subNodes[ node.name ] = node;
|
|
|
|
|
|
- // Later phase expects single property array is in node.properties.a as String.
|
|
|
- // TODO: optimize
|
|
|
- node.properties.a = value.toString();
|
|
|
+ switch ( node.name ) {
|
|
|
+
|
|
|
+ case 'Matrix':
|
|
|
+ case 'TransformLink':
|
|
|
+ case 'Transform':
|
|
|
+ node.properties.a = new THREE.Matrix4().fromArray( value );
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ node.properties.a = value;
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -5442,40 +5495,24 @@
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Parses comma separated list of float numbers and returns them in an array.
|
|
|
+ * Parses comma separated list of numbers and returns them in an array.
|
|
|
+ * If an array is passed just return it - this is because the TextParser sometimes
|
|
|
+ * returns strings instead of arrays, while the BinaryParser always returns arrays
|
|
|
+ * TODO: this function should only need to be called from inside the TextParser
|
|
|
* @example
|
|
|
* // Returns [ 5.6, 9.4, 2.5, 1.4 ]
|
|
|
- * parseFloatArray( "5.6,9.4,2.5,1.4" )
|
|
|
+ * parseNumberArray( "5.6,9.4,2.5,1.4" )
|
|
|
* @returns {number[]}
|
|
|
*/
|
|
|
- function parseFloatArray( string ) {
|
|
|
-
|
|
|
- var array = string.split( ',' );
|
|
|
-
|
|
|
- for ( var i = 0, l = array.length; i < l; i ++ ) {
|
|
|
-
|
|
|
- array[ i ] = parseFloat( array[ i ] );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return array;
|
|
|
+ function parseNumberArray( value ) {
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Parses comma separated list of int numbers and returns them in an array.
|
|
|
- * @example
|
|
|
- * // Returns [ 5, 8, 2, 3 ]
|
|
|
- * parseFloatArray( "5,8,2,3" )
|
|
|
- * @returns {number[]}
|
|
|
- */
|
|
|
- function parseIntArray( string ) {
|
|
|
+ if ( Array.isArray( value ) ) return value;
|
|
|
|
|
|
- var array = string.split( ',' );
|
|
|
+ var array = value.split( ',' );
|
|
|
|
|
|
for ( var i = 0, l = array.length; i < l; i ++ ) {
|
|
|
|
|
|
- array[ i ] = parseInt( array[ i ] );
|
|
|
+ array[ i ] = parseFloat( array[ i ] );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -5505,12 +5542,6 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- function parseMatrixArray( floatString ) {
|
|
|
-
|
|
|
- return new THREE.Matrix4().fromArray( parseFloatArray( floatString ) );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Converts ArrayBuffer to String.
|
|
|
* @param {ArrayBuffer} buffer
|