Ver Fonte

Merge pull request #12703 from looeee/FBXLoader_gengeom_refactor

FBXLoader: refactor genGeo method
Mr.doob há 7 anos atrás
pai
commit
0b4266d074
1 ficheiros alterados com 39 adições e 56 exclusões
  1. 39 56
      examples/js/loaders/FBXLoader.js

+ 39 - 56
examples/js/loaders/FBXLoader.js

@@ -731,7 +731,6 @@
 
 		}
 
-
 		var weightTable = {};
 
 		if ( deformer ) {
@@ -831,7 +830,7 @@
 
 					}
 
-					var WIndex = [ 0, 0, 0, 0 ];
+					var wIndex = [ 0, 0, 0, 0 ];
 					var Weight = [ 0, 0, 0, 0 ];
 
 					weights.forEach( function ( weight, weightIndex ) {
@@ -846,8 +845,8 @@
 								comparedWeightArray[ comparedWeightIndex ] = currentWeight;
 								currentWeight = comparedWeight;
 
-								var tmp = WIndex[ comparedWeightIndex ];
-								WIndex[ comparedWeightIndex ] = currentIndex;
+								var tmp = wIndex[ comparedWeightIndex ];
+								wIndex[ comparedWeightIndex ] = currentIndex;
 								currentIndex = tmp;
 
 							}
@@ -856,7 +855,7 @@
 
 					} );
 
-					weightIndices = WIndex;
+					weightIndices = wIndex;
 					weights = Weight;
 
 				}
@@ -886,6 +885,12 @@
 
 			}
 
+			if ( materialInfo && materialInfo.mappingType !== 'AllSame' ) {
+
+				var materialIndex = getData( polygonVertexIndex, polygonIndex, vertexIndex, materialInfo )[ 0 ];
+
+			}
+
 			if ( uvInfo ) {
 
 				for ( var i = 0; i < uvInfo.length; i ++ ) {
@@ -910,7 +915,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 ++ ) {
@@ -927,11 +932,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 ] );
@@ -965,11 +966,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 ( materialInfo && materialInfo.mappingType !== 'AllSame' ) {
 
-				if ( normalInfo ) {
+						materialIndexBuffer.push( materialIndex );
+						materialIndexBuffer.push( materialIndex );
+						materialIndexBuffer.push( materialIndex );
+
+					}
 
-					for ( var i = 2; i < faceLength; i ++ ) {
+					if ( normalInfo ) {
 
 						normalBuffer.push( faceNormals[ 0 ] );
 						normalBuffer.push( faceNormals[ 1 ] );
@@ -985,15 +1006,11 @@
 
 					}
 
-				}
-
-				if ( uvInfo ) {
-
-					for ( var j = 0; j < uvInfo.length; j ++ ) {
+					if ( uvInfo ) {
 
-						if ( uvsBuffer[ j ] === undefined ) uvsBuffer[ j ] = [];
+						for ( var j = 0; j < uvInfo.length; 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 ] );
@@ -1010,41 +1027,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;
@@ -1153,6 +1135,7 @@
 
 	}
 
+
 	// Parse normal from FBXTree.Objects.subNodes.Geometry.subNodes.LayerElementNormal if it exists
 	function getNormals( NormalNode ) {