diff --git a/lib/loadObj.js b/lib/loadObj.js index e26fb34..4bf6388 100644 --- a/lib/loadObj.js +++ b/lib/loadObj.js @@ -160,7 +160,9 @@ function loadObj(objPath, options) { var normal = new Cartesian3(); var ray = new Ray(); var plane = new Plane(Cesium.Cartesian3.UNIT_X, 0); + function projectTo2D(positions) { + var i; var positions2D = new Array(positions.length); var obb = OrientedBoundingBox.fromPoints(positions); var halfAxes = obb.halfAxes; @@ -175,7 +177,6 @@ function loadObj(objPath, options) { // If all the points are on a line, just remove one of the zero dimensions if (xMag === 0 && (yMag === 0 || zMag === 0)) { - var i; for (i = 0; i < positions.length; i++) { positions2D[i] = new Cartesian2(positions[i].y, positions[i].z); } @@ -328,15 +329,14 @@ function loadObj(objPath, options) { // Given the cartesian 2 vertices of a polygon, determine if convex function isConvex(positions2D) { - var i; - var turnDirection = getTurnDirection(positions2D[0], positions2D[1], positions2D[2]); - for (i=1; i < positions2D.length-2; ++i) { - var currentTurnDirection = getTurnDirection(positions2D[i], positions2D[i+1], positions2D[i+2]); + var turnDirection = getTurnDirection(positions2D[0], positions2D[1], positions2D[2]); + for (var i=1; i < positions2D.length-2; ++i) { + var currentTurnDirection = getTurnDirection(positions2D[i], positions2D[i+1], positions2D[i+2]); if (turnDirection * currentTurnDirection < 0) { return false; } - } - return true; + } + return true; } var scratch3 = new Cartesian3(); @@ -470,7 +470,7 @@ function loadObj(objPath, options) { } lineBuffer += line; if (lineBuffer.substring(0, 2) === 'f ') { - while ( (result = facePattern.exec(lineBuffer)) !== null ) { + while ((result = facePattern.exec(lineBuffer)) !== null) { faceVertices.push(result[0]); facePositions.push(result[1]); faceUvs.push(result[2]);