瀏覽代碼

Simplify faces creation with for loop

Daniel Hritzkiv 9 年之前
父節點
當前提交
7360ed9c5e
共有 1 個文件被更改,包括 9 次插入6 次删除
  1. 9 6
      examples/js/exporters/OBJExporter.js

+ 9 - 6
examples/js/exporters/OBJExporter.js

@@ -15,6 +15,8 @@ THREE.OBJExporter.prototype = {
 		var indexVertex = 0;
 		var indexVertexUvs = 0;
 		var indexNormals = 0;
+		
+		var faceVertexKeys = ["a", "b", "c"];
 
 		var parseMesh = function ( mesh ) {
 
@@ -112,18 +114,19 @@ THREE.OBJExporter.prototype = {
 					}
 
 				}
-
+				
 				// faces
-
-
+				
 				for ( var i = 0, j = 1, l = faces.length; i < l; i ++, j += 3 ) {
 
 					var face = faces[ i ];
 
 					output += 'f ';
-					output += ( indexVertex + face.a + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j + 0 + 1 ) : '' ) + '/' + ( indexNormals + j + 0 + 1 ) + ' ';
-					output += ( indexVertex + face.b + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j + 1 + 1 ) : '' ) + '/' + ( indexNormals + j + 1 + 1 ) + ' ';
-					output += ( indexVertex + face.c + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j + 2 + 1 ) : '' ) + '/' + ( indexNormals + j + 2 + 1 ) + '\n';
+					
+					for ( var m = 0; m < 3; m ++ ) {
+						output += ( indexVertex + face[ faceVertexKeys[ m ] ] + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j + m + 1 ) : '' ) + '/' + ( indexNormals + j + m + 1 );
+						output += m === 2 ? "\n" : " ";
+					}
 
 				}