Permalink
Browse files

Code clean up + a little bit of optimization

  • Loading branch information...
1 parent 2231fb0 commit a32f3b35bbfbf87f98af6c3e9766ea8cfc6e3141 @stephomi committed Jan 8, 2014
Showing with 347 additions and 330 deletions.
  1. +3 −3 editor/adaptive.js
  2. +7 −7 editor/cut.js
  3. +15 −15 editor/decimation.js
  4. +53 −54 editor/sculpt.js
  5. +4 −4 editor/topology.js
  6. +32 −32 math3d/camera.js
  7. +110 −99 math3d/geometry.js
  8. +2 −2 math3d/grid.js
  9. +13 −13 math3d/picking.js
  10. +2 −2 misc/export.js
  11. +7 −7 misc/import.js
  12. +25 −25 object/aabb.js
  13. +2 −2 object/background.js
  14. +61 −54 object/mesh.js
  15. +1 −1 object/triangle.js
  16. +10 −10 sculptgl.js
View
@@ -19,9 +19,9 @@ Topology.prototype.adaptTopology = function (iTris, d2Thickness)
var cx = center[0],
cy = center[1],
cz = center[2];
- var dx = 0,
- dy = 0,
- dz = 0;
+ var dx = 0.0,
+ dy = 0.0,
+ dz = 0.0;
for (i = 0; i < nbVerts; ++i)
{
var iVert = iVerts[i];
View
@@ -22,7 +22,7 @@ Topology.prototype.cut = function (planeOrigin, planeNormal, fillHoles)
this.states_.pushState(iTrisCulled, iVertsCulled);
this.states_.pushState(iTrisIntersect, iVertsIntersect);
- var tmp = [0, 0, 0];
+ var tmp = [0.0, 0.0, 0.0];
var nbVertsIntersect = iVertsIntersect.length;
for (i = 0; i < nbVertsIntersect; ++i)
{
@@ -54,16 +54,16 @@ Topology.prototype.cut = function (planeOrigin, planeNormal, fillHoles)
this.iTrisToDelete_ = iTrisCulled;
//Update triangles on edges
+ var trisToUpdate = [];
for (i = nbTrianglesBefore; i < nbTrianglesAfter; ++i)
- mesh.updateTriangleAabbAndNormal(i);
+ trisToUpdate.push(i);
+ mesh.updateTrianglesAabbAndNormal(trisToUpdate);
//Update vertices on edges
var iVertsOnEdge = [];
for (i = nbVerticesBefore; i < nbVerticesAfter; ++i)
- {
iVertsOnEdge.push(i);
- mesh.updateVertexNormal(i);
- }
+ mesh.updateVerticesNormal(iVertsOnEdge);
var lengthMeanSq = 0.0;
if (fillHoles)
@@ -243,7 +243,7 @@ Topology.prototype.getProjectedVertex = function (iv1, iv2, planeOrigin, planeNo
vertices.push(new Vertex(ivMid));
var i = iv1 * 3;
var j = iv2 * 3;
- var coordInter = [0, 0, 0]
+ var coordInter = [0.0, 0.0, 0.0]
Geometry.intersectLinePlane([vAr[i], vAr[i + 1], vAr[i + 2]], [vAr[j], vAr[j + 1], vAr[j + 2]], planeOrigin, planeNormal, coordInter);
i = ivMid * 3;
vAr[i] = coordInter[0];
@@ -350,7 +350,7 @@ Topology.prototype.fillHoles = function (holes, planeOrigin, planeNormal)
orz = planeOrigin[2];
var perp = Geometry.getPerpendicularVector(planeNormal);
- var perp2 = [0, 0, 0];
+ var perp2 = [0.0, 0.0, 0.0];
vec3.cross(perp2, perp, planeNormal);
var nbHoles = holes.length;
View
@@ -19,7 +19,7 @@ Topology.prototype.decimation = function (iTris, detailMinSquared)
var cenx = center[0],
ceny = center[1],
cenz = center[2];
- var tmp = [0, 0, 0];
+ var tmp = [0.0, 0.0, 0.0];
for (var i = 0; i < iTris.length; ++i)
{
@@ -47,26 +47,26 @@ Topology.prototype.decimation = function (iTris, detailMinSquared)
v3y = vAr[id + 1],
v3z = vAr[id + 2];
- var dx = (v1x + v2x + v3x) / 3 - cenx,
- dy = (v1y + v2y + v3y) / 3 - ceny,
- dz = (v1z + v2z + v3z) / 3 - cenz;
+ var dx = (v1x + v2x + v3x) / 3.0 - cenx,
+ dy = (v1y + v2y + v3y) / 3.0 - ceny,
+ dz = (v1z + v2z + v3z) / 3.0 - cenz;
var fallOff = dx * dx + dy * dy + dz * dz;
if (this.checkPlane_)
{
var po = this.planeOrigin_;
var pn = this.planeNormal_;
- if (vec3.dot(pn, vec3.sub(tmp, [v1x, v1y, v1z], po)) < 0 &&
- vec3.dot(pn, vec3.sub(tmp, [v2x, v2y, v2z], po)) < 0 &&
- vec3.dot(pn, vec3.sub(tmp, [v3x, v3y, v3z], po)) < 0)
+ if (vec3.dot(pn, vec3.sub(tmp, [v1x, v1y, v1z], po)) < 0.0 &&
+ vec3.dot(pn, vec3.sub(tmp, [v2x, v2y, v2z], po)) < 0.0 &&
+ vec3.dot(pn, vec3.sub(tmp, [v3x, v3y, v3z], po)) < 0.0)
continue;
- fallOff = 1;
+ fallOff = 1.0;
}
else if (fallOff < radiusSquared)
- fallOff = 1;
- else if (fallOff < radiusSquared * 2)
+ fallOff = 1.0;
+ else if (fallOff < radiusSquared * 2.0)
{
fallOff = (Math.sqrt(fallOff) - radius) / (radius * Math.SQRT2 - radius);
- fallOff = 3 * fallOff * fallOff * fallOff * fallOff - 4 * fallOff * fallOff * fallOff + 1;
+ fallOff = 3.0 * fallOff * fallOff * fallOff * fallOff - 4.0 * fallOff * fallOff * fallOff + 1.0;
}
else
continue;
@@ -323,7 +323,7 @@ Topology.prototype.edgeCollapse = function (iTri1, iTri2, iv1, iv2, ivOpp1, ivOp
cAr[id] = (cAr[id] + cAr[id2]) * 0.5,
cAr[id + 1] = (cAr[id + 1] + cAr[id2 + 1]) * 0.5,
cAr[id + 2] = (cAr[id + 2] + cAr[id2 + 2]) * 0.5;
- var len = 1 / Math.sqrt(nx * nx + ny * ny + nz * nz);
+ var len = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
nx *= len;
ny *= len;
nz *= len;
@@ -353,9 +353,9 @@ Topology.prototype.edgeCollapse = function (iTri1, iTri2, iv1, iv2, ivOpp1, ivOp
mesh.computeRingVertices(iv1);
//flat smooth the vertex...
- var meanX = 0,
- meanY = 0,
- meanZ = 0;
+ var meanX = 0.0,
+ meanY = 0.0,
+ meanZ = 0.0;
var nbRing1 = ring1.length;
for (i = 0; i < nbRing1; ++i)
{
Oops, something went wrong.

0 comments on commit a32f3b3

Please sign in to comment.