Explorar el Código

FBXLoader: refactor genGeo

Lewy Blue hace 7 años
padre
commit
740ad18fbd
Se han modificado 1 ficheros con 43 adiciones y 59 borrados
  1. 43 59
      examples/js/loaders/FBXLoader.js

+ 43 - 59
examples/js/loaders/FBXLoader.js

@@ -661,6 +661,7 @@
 
 	}
 
+
 	// Generate a THREE.BufferGeometry from a node in FBXTree.Objects.subNodes.Geometry
 	function genGeometry( geometryNode, deformer ) {
 
@@ -709,7 +710,6 @@
 
 		}
 
-
 		var weightTable = {};
 
 		if ( deformer ) {
@@ -809,7 +809,7 @@
 
 					}
 
-					var WIndex = [ 0, 0, 0, 0 ];
+					var wIndex = [ 0, 0, 0, 0 ];
 					var Weight = [ 0, 0, 0, 0 ];
 
 					weights.forEach( function ( weight, weightIndex ) {
@@ -824,8 +824,8 @@
 								comparedWeightArray[ comparedWeightIndex ] = currentWeight;
 								currentWeight = comparedWeight;
 
-								var tmp = WIndex[ comparedWeightIndex ];
-								WIndex[ comparedWeightIndex ] = currentIndex;
+								var tmp = wIndex[ comparedWeightIndex ];
+								wIndex[ comparedWeightIndex ] = currentIndex;
 								currentIndex = tmp;
 
 							}
@@ -834,7 +834,7 @@
 
 					} );
 
-					weightIndices = WIndex;
+					weightIndices = wIndex;
 					weights = Weight;
 
 				}
@@ -864,6 +864,12 @@
 
 			}
 
+			if ( materialInfo && materialInfo.mappingType !== 'AllSame' ) {
+
+				var materialIndex = getData( polygonVertexIndex, polygonIndex, vertexIndex, materialInfo )[ 0 ];
+
+			}
+
 			if ( uvInfo ) {
 
 				for ( var i = 0; i < uvInfo.length; i ++ ) {
@@ -877,9 +883,9 @@
 					}
 
 					faceUVs[ i ].push(
-						data[ 0 ],
-						data[ 1 ]
-					);
+										data[ 0 ],
+										data[ 1 ]
+									);
 
 				}
 
@@ -888,7 +894,7 @@
 			faceLength ++;
 
 			// we have reached the end of a face - it may have 4 sides though
-			// in which case the data is split into to represent 3 sides faces
+			// in which case the data is split to represent two 3 sided faces
 			if ( endOfFace ) {
 
 				for ( var i = 2; i < faceLength; i ++ ) {
@@ -905,11 +911,7 @@
 					vertexBuffer.push( vertexPositions[ vertexPositionIndexes[ i * 3 + 1 ] ] );
 					vertexBuffer.push( vertexPositions[ vertexPositionIndexes[ i * 3 + 2 ] ] );
 
-				}
-
-				if ( deformer ) {
-
-					for ( var i = 2; i < faceLength; i ++ ) {
+					if ( deformer ) {
 
 						vertexWeightsBuffer.push( faceWeights[ 0 ] );
 						vertexWeightsBuffer.push( faceWeights[ 1 ] );
@@ -943,11 +945,31 @@
 
 					}
 
-				}
+					if ( colorInfo ) {
+
+						colorsBuffer.push( faceColors[ 0 ] );
+						colorsBuffer.push( faceColors[ 1 ] );
+						colorsBuffer.push( faceColors[ 2 ] );
+
+						colorsBuffer.push( faceColors[ ( i - 1 ) * 3 ] );
+						colorsBuffer.push( faceColors[ ( i - 1 ) * 3 + 1 ] );
+						colorsBuffer.push( faceColors[ ( i - 1 ) * 3 + 2 ] );
+
+						colorsBuffer.push( faceColors[ i * 3 ] );
+						colorsBuffer.push( faceColors[ i * 3 + 1 ] );
+						colorsBuffer.push( faceColors[ i * 3 + 2 ] );
+
+					}
 
-				if ( normalInfo ) {
+					if ( materialInfo && materialInfo.mappingType !== 'AllSame' ) {
 
-					for ( var i = 2; i < faceLength; i ++ ) {
+						materialIndexBuffer.push( materialIndex );
+						materialIndexBuffer.push( materialIndex );
+						materialIndexBuffer.push( materialIndex );
+
+					}
+
+					if ( normalInfo ) {
 
 						normalBuffer.push( faceNormals[ 0 ] );
 						normalBuffer.push( faceNormals[ 1 ] );
@@ -963,15 +985,11 @@
 
 					}
 
-				}
-
-				if ( uvInfo ) {
+					if ( uvInfo ) {
 
-					for ( var j = 0; j < uvInfo.length; j ++ ) {
+						for ( var j = 0; j < uvInfo.length; j ++ ) {
 
-						if ( uvsBuffer[ j ] === undefined ) uvsBuffer[ j ] = [];
-
-						for ( var i = 2; i < faceLength; i ++ ) {
+							if ( uvsBuffer[ j ] === undefined ) uvsBuffer[ j ] = [];
 
 							uvsBuffer[ j ].push( faceUVs[ j ][ 0 ] );
 							uvsBuffer[ j ].push( faceUVs[ j ][ 1 ] );
@@ -988,41 +1006,6 @@
 
 				}
 
-				if ( colorInfo ) {
-
-					for ( var i = 2; i < faceLength; i ++ ) {
-
-
-						colorsBuffer.push( faceColors[ 0 ] );
-						colorsBuffer.push( faceColors[ 1 ] );
-						colorsBuffer.push( faceColors[ 2 ] );
-
-						colorsBuffer.push( faceColors[ ( i - 1 ) * 3 ] );
-						colorsBuffer.push( faceColors[ ( i - 1 ) * 3 + 1 ] );
-						colorsBuffer.push( faceColors[ ( i - 1 ) * 3 + 2 ] );
-
-						colorsBuffer.push( faceColors[ i * 3 ] );
-						colorsBuffer.push( faceColors[ i * 3 + 1 ] );
-						colorsBuffer.push( faceColors[ i * 3 + 2 ] );
-
-					}
-
-				}
-
-				if ( materialInfo && materialInfo.mappingType !== 'AllSame' ) {
-
-					var materialIndex = getData( polygonVertexIndex, polygonIndex, vertexIndex, materialInfo )[ 0 ];
-
-					for ( var i = 2; i < faceLength; i ++ ) {
-
-						materialIndexBuffer.push( materialIndex );
-						materialIndexBuffer.push( materialIndex );
-						materialIndexBuffer.push( materialIndex );
-
-					}
-
-				}
-
 				polygonIndex ++;
 
 				endOfFace = false;
@@ -1131,6 +1114,7 @@
 
 	}
 
+
 	// Parse normal from FBXTree.Objects.subNodes.Geometry.subNodes.LayerElementNormal if it exists
 	function getNormals( NormalNode ) {