From 6b4d6b11c3daafb00ada4d2c1e885504ec840fe8 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Tue, 12 May 2015 11:30:28 -0400 Subject: [PATCH] OBJExporter: Minor clean up. --- examples/js/exporters/OBJExporter.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/examples/js/exporters/OBJExporter.js b/examples/js/exporters/OBJExporter.js index b3f85cda8b..79d0aa0fd1 100644 --- a/examples/js/exporters/OBJExporter.js +++ b/examples/js/exporters/OBJExporter.js @@ -45,7 +45,7 @@ THREE.OBJExporter.prototype = { var faces = geometry.faces; var faceVertexUvs = geometry.faceVertexUvs[ 0 ]; - var hasVertexUvs = (faces.length === faceVertexUvs.length); + var hasVertexUvs = faces.length === faceVertexUvs.length; if ( hasVertexUvs ) { @@ -53,7 +53,7 @@ THREE.OBJExporter.prototype = { var vertexUvs = faceVertexUvs[ i ]; - for ( var j = 0; j < vertexUvs.length; j ++ ) { + for ( var j = 0, jl = vertexUvs.length; j < jl; j ++ ) { var uv = vertexUvs[ j ]; @@ -71,7 +71,7 @@ THREE.OBJExporter.prototype = { var normalMatrixWorld = new THREE.Matrix3(); normalMatrixWorld.getNormalMatrix( mesh.matrixWorld ); - + for ( var i = 0, l = faces.length; i < l; i ++ ) { var face = faces[ i ]; @@ -79,10 +79,11 @@ THREE.OBJExporter.prototype = { if ( vertexNormals.length === 3 ) { - for ( var j = 0; j < vertexNormals.length; j ++ ) { + for ( var j = 0, jl = vertexNormals.length; j < jl; j ++ ) { + + var normal = vertexNormals[ j ].clone(); + normal.applyMatrix3( normalMatrixWorld ); - var normal = vertexNormals[ j ].clone (); - normal.applyMatrix3( normalMatrixWorld ).normalize(); output += 'vn ' + normal.x + ' ' + normal.y + ' ' + normal.z + '\n'; nbNormals ++; @@ -91,8 +92,8 @@ THREE.OBJExporter.prototype = { } else { - var normal = face.normal.clone (); - normal.applyMatrix3( normalMatrixWorld ).normalize(); + var normal = face.normal.clone(); + normal.applyMatrix3( normalMatrixWorld ); for ( var j = 0; j < 3; j ++ ) { @@ -108,15 +109,15 @@ 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 ) : '') + '/' + ( indexNormals + j ) + ' '; - output += ( indexVertex + face.b + 1 ) + '/' + (hasVertexUvs ? ( indexVertexUvs + j + 1 ) : '') + '/' + ( indexNormals + j + 1 ) + ' '; - output += ( indexVertex + face.c + 1 ) + '/' + (hasVertexUvs ? ( indexVertexUvs + j + 2 ) : '') + '/' + ( indexNormals + j + 2 ) + '\n'; + output += ( indexVertex + face.a + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j ) : '' ) + '/' + ( indexNormals + j ) + ' '; + output += ( indexVertex + face.b + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j + 1 ) : '' ) + '/' + ( indexNormals + j + 1 ) + ' '; + output += ( indexVertex + face.c + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j + 2 ) : '' ) + '/' + ( indexNormals + j + 2 ) + '\n'; } -- GitLab