From 7360ed9c5ec5cb45fd13701587ef87e92512c333 Mon Sep 17 00:00:00 2001 From: Daniel Hritzkiv Date: Mon, 30 Nov 2015 18:45:34 -0500 Subject: [PATCH] Simplify faces creation with for loop --- examples/js/exporters/OBJExporter.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/examples/js/exporters/OBJExporter.js b/examples/js/exporters/OBJExporter.js index 45d89bf220..82b362b37a 100644 --- a/examples/js/exporters/OBJExporter.js +++ b/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" : " "; + } } -- GitLab