Skip to content
Browse files

A bit of memory optimization

  • Loading branch information...
1 parent ceae47c commit 88e996b6f90bc8b6fb67bf128c8652cfcfbf841d @stephomi committed Jan 19, 2014
Showing with 483 additions and 367 deletions.
  1. +78 −42 editor/cut.js
  2. +2 −2 editor/decimation.js
  3. +25 −12 editor/sculpt.js
  4. +258 −208 editor/subdivision.js
  5. +7 −4 gui/gui.js
  6. +13 −15 math3d/geometry.js
  7. +58 −37 math3d/picking.js
  8. +24 −25 object/aabb.js
  9. +10 −2 object/mesh.js
  10. +2 −16 object/states.js
  11. +6 −4 sculptgl.js
View
120 editor/cut.js
@@ -24,11 +24,18 @@ Topology.prototype.cut = function (planeOrigin, planeNormal, fillHoles)
var tmp = [0.0, 0.0, 0.0];
var nbVertsIntersect = iVertsIntersect.length;
+
+ var pox = planeOrigin[0],
+ poy = planeOrigin[1],
+ poz = planeOrigin[2];
+ var pnx = planeNormal[0],
+ pny = planeNormal[1],
+ pnz = planeNormal[2];
for (i = 0; i < nbVertsIntersect; ++i)
{
var iv = iVertsIntersect[i];
var iv3 = iv * 3;
- if (vec3.dot(planeNormal, vec3.sub(tmp, [vAr[iv3], vAr[iv3 + 1], vAr[iv3 + 2]], planeOrigin)) > 0)
+ if ((pnx * (vAr[iv3] - pox) + pny * (vAr[iv3 + 1] - poy) + pnz * (vAr[iv3 + 2] - poz)) > 0.0)
iVertsCulled.push(iv);
}
@@ -70,7 +77,7 @@ Topology.prototype.cut = function (planeOrigin, planeNormal, fillHoles)
lengthMeanSq = this.triangulateVerticesOnPlane(iVertsOnEdge, planeOrigin, planeNormal);
this.applyDeletion(true);
- this.states_.recomputeOctree(mesh.octree_.aabbSplit_);
+ mesh.computeOctree(mesh.octree_.aabbSplit_);
return lengthMeanSq;
};
@@ -226,42 +233,53 @@ Topology.prototype.makeTwoTrianglesSnapOnPlane = function (iTri, iv1, iv2, iv3,
};
/** Return id of projected vertex on plane along the segment */
-Topology.prototype.getProjectedVertex = function (iv1, iv2, planeOrigin, planeNormal)
+Topology.prototype.getProjectedVertex = (function ()
{
- var mesh = this.mesh_;
- var vAr = mesh.vertexArray_;
- var cAr = mesh.colorArray_;
- var nAr = mesh.normalArray_;
- var vertices = mesh.vertices_;
-
- var key = [Math.min(iv1, iv2), Math.max(iv1, iv2)];
- var ivMid = this.verticesMap_[key];
- if (ivMid === undefined)
+ var v1 = [0.0, 0.0, 0.0];
+ var v2 = [0.0, 0.0, 0.0];
+ var coordInter = [0.0, 0.0, 0.0];
+ return function (iv1, iv2, planeOrigin, planeNormal)
{
- ivMid = vertices.length;
- this.verticesMap_[key] = ivMid;
- vertices.push(new Vertex(ivMid));
- var i = iv1 * 3;
- var j = iv2 * 3;
- 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];
- vAr[i + 1] = coordInter[1];
- vAr[i + 2] = coordInter[2];
-
- nAr[i] = nAr[j];
- nAr[i + 1] = nAr[j + 1];
- nAr[i + 2] = nAr[j + 2];
-
- cAr[i] = cAr[j];
- cAr[i + 1] = cAr[j + 1];
- cAr[i + 2] = cAr[j + 2];
- vertices[iv1].ringVertices_.push(ivMid);
- vertices[ivMid].ringVertices_.push(iv1);
- }
- return ivMid;
-};
+ var mesh = this.mesh_;
+ var vAr = mesh.vertexArray_;
+ var cAr = mesh.colorArray_;
+ var nAr = mesh.normalArray_;
+ var vertices = mesh.vertices_;
+
+ var key = [Math.min(iv1, iv2), Math.max(iv1, iv2)];
+ var ivMid = this.verticesMap_[key];
+ if (ivMid === undefined)
+ {
+ ivMid = vertices.length;
+ this.verticesMap_[key] = ivMid;
+ vertices.push(new Vertex(ivMid));
+ var i = iv1 * 3;
+ var j = iv2 * 3;
+ v1[0] = vAr[i];
+ v1[1] = vAr[i + 1];
+ v1[2] = vAr[i + 2];
+ v2[0] = vAr[j];
+ v2[1] = vAr[j + 1];
+ v2[2] = vAr[j + 2];
+ Geometry.intersectLinePlane(v1, v2, planeOrigin, planeNormal, coordInter);
+ i = ivMid * 3;
+ vAr[i] = coordInter[0];
+ vAr[i + 1] = coordInter[1];
+ vAr[i + 2] = coordInter[2];
+
+ nAr[i] = nAr[j];
+ nAr[i + 1] = nAr[j + 1];
+ nAr[i + 2] = nAr[j + 2];
+
+ cAr[i] = cAr[j];
+ cAr[i + 1] = cAr[j + 1];
+ cAr[i + 2] = cAr[j + 2];
+ vertices[iv1].ringVertices_.push(ivMid);
+ vertices[ivMid].ringVertices_.push(iv1);
+ }
+ return ivMid;
+ };
+})();
/** Delaunay triangulation to make triangles on the plane */
Topology.prototype.triangulateVerticesOnPlane = function (iVertsOnEdge, planeOrigin, planeNormal)
@@ -322,9 +340,12 @@ Topology.prototype.triangulateVerticesOnPlane = function (iVertsOnEdge, planeOri
var nbPoints = hole.length;
for (j = 1; j < nbPoints; ++j)
{
- var iv1 = hole[j - 1] * 3;
- var iv2 = hole[j] * 3;
- lengthMeanSq += vec3.sqrDist([vAr[iv1], vAr[iv1 + 1], vAr[iv1 + 2]], [vAr[iv2], vAr[iv2 + 1], vAr[iv2 + 2]]);
+ var id1 = hole[j - 1] * 3;
+ var id2 = hole[j] * 3;
+ var dx = vAr[id1] - vAr[id2],
+ dy = vAr[id1 + 1] - vAr[id2 + 1],
+ dz = vAr[id1 + 2] - vAr[id2 + 2];
+ lengthMeanSq += dx * dx + dy * dy + dz * dz;
}
totalPoint += nbPoints - 1;
}
@@ -349,9 +370,19 @@ Topology.prototype.fillHoles = function (holes, planeOrigin, planeNormal)
ory = planeOrigin[1],
orz = planeOrigin[2];
+ var nx = planeNormal[0],
+ ny = planeNormal[1],
+ nz = planeNormal[2];
+
var perp = Geometry.getPerpendicularVector(planeNormal);
var perp2 = [0.0, 0.0, 0.0];
vec3.cross(perp2, perp, planeNormal);
+ var px = perp[0],
+ py = perp[1],
+ pz = perp[2];
+ var p2x = perp2[0],
+ p2y = perp2[1],
+ p2z = perp2[2];
var nbHoles = holes.length;
for (i = 0; i < nbHoles; ++i)
@@ -363,8 +394,10 @@ Topology.prototype.fillHoles = function (holes, planeOrigin, planeNormal)
for (j = 0; j < nbPoints; ++j)
{
var id = hole[j];
- var vecPoint = [vAr[id * 3] - orx, vAr[id * 3 + 1] - ory, vAr[id * 3 + 2] - orz];
- var pt = new poly2tri.Point(vec3.dot(perp, vecPoint), vec3.dot(perp2, vecPoint));
+ var vpx = vAr[id * 3] - orx,
+ vpy = vAr[id * 3 + 1] - ory,
+ vpz = vAr[id * 3 + 2] - orz;
+ var pt = new poly2tri.Point(px * vpx + py * vpy + pz * vpz, p2x * vpx + p2y * vpy + p2z * vpz);
pt.id_ = id;
contour[j] = pt;
}
@@ -382,7 +415,10 @@ Topology.prototype.fillHoles = function (holes, planeOrigin, planeNormal)
var ptTris = trisPlane[j].points_;
var idTri = triangles.length;
var t = new Triangle(idTri);
- t.normal_ = planeNormal.slice();
+ var normal = t.normal_;
+ normal[0] = nx;
+ normal[1] = ny;
+ normal[2] = nz;
triangles.push(t);
var iv1 = ptTris[0].id_,
iv2 = ptTris[1].id_,
View
4 editor/decimation.js
@@ -320,8 +320,8 @@ Topology.prototype.edgeCollapse = function (iTri1, iTri2, iv1, iv2, ivOpp1, ivOp
var nx = nAr[id] + nAr[id2],
ny = nAr[id + 1] + nAr[id2 + 1],
nz = nAr[id + 2] + nAr[id2 + 2];
- cAr[id] = (cAr[id] + cAr[id2]) * 0.5,
- cAr[id + 1] = (cAr[id + 1] + cAr[id2 + 1]) * 0.5,
+ 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.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
nx *= len;
View
37 editor/sculpt.js
@@ -325,7 +325,8 @@ Sculpt.prototype = {
dy = vy - cy,
dz = vz - cz;
var dist = Math.sqrt(dx * dx + dy * dy + dz * dz) / radius;
- var fallOff = 3.0 * dist * dist * dist * dist - 4.0 * dist * dist * dist + 1.0;
+ var fallOff = dist * dist;
+ fallOff = 3.0 * fallOff * fallOff - 4.0 * fallOff * dist + 1.0;
fallOff = fallOff * (distToPlane * deformIntensityFlatten - deformIntensityBrush);
if (limitMove && fallOff > dMove)
fallOff = dMove;
@@ -358,7 +359,8 @@ Sculpt.prototype = {
dy = vAr[ind + 1] - cy,
dz = vAr[ind + 2] - cz;
var dist = Math.sqrt(dx * dx + dy * dy + dz * dz) / radius;
- var fallOff = 3.0 * dist * dist * dist * dist - 4.0 * dist * dist * dist + 1.0;
+ var fallOff = dist * dist;
+ fallOff = 3.0 * fallOff * fallOff - 4.0 * fallOff * dist + 1.0;
fallOff = deformIntensity * fallOff;
vAr[ind] += nAr[ind] * fallOff;
vAr[ind + 1] += nAr[ind + 1] * fallOff;
@@ -410,7 +412,8 @@ Sculpt.prototype = {
dy = vAr[ind + 1] - cy,
dz = vAr[ind + 2] - cz;
var dist = Math.sqrt(dx * dx + dy * dy + dz * dz) / radius;
- var fallOff = 3.0 * dist * dist * dist * dist - 4.0 * dist * dist * dist + 1.0;
+ var fallOff = dist * dist;
+ fallOff = 3.0 * fallOff * fallOff - 4.0 * fallOff * dist + 1.0;
fallOff *= deltaScale;
vAr[ind] += dx * fallOff;
vAr[ind + 1] += dy * fallOff;
@@ -474,19 +477,24 @@ Sculpt.prototype = {
var cx = center[0],
cy = center[1],
cz = center[2];
+ var coord = [0.0, 0.0, 0.0];
for (var i = 0; i < nbVerts; ++i)
{
var ind = iVerts[i] * 3;
var dx = vAr[ind] - cx,
dy = vAr[ind + 1] - cy,
dz = vAr[ind + 2] - cz;
var dist = Math.sqrt(dx * dx + dy * dy + dz * dz) / radius;
- var fallOff = 3.0 * dist * dist * dist * dist - 4.0 * dist * dist * dist + 1.0;
- var coord = [vAr[ind], vAr[ind + 1], vAr[ind + 2]];
+ var fallOff = dist * dist;
+ fallOff = 3.0 * fallOff * fallOff - 4.0 * fallOff * dist + 1.0;
quat.setAxisAngle(rot, nPlane, angle * fallOff);
- vec3.sub(coord, coord, center);
+ coord[0] = vAr[ind] - cx;
+ coord[1] = vAr[ind + 1] - cz;
+ coord[2] = vAr[ind + 2] - cy;
vec3.transformQuat(coord, coord, rot);
- vec3.add(coord, coord, center);
+ coord[0] += cx;
+ coord[1] += cy;
+ coord[2] += cz;
vAr[ind] = coord[0];
vAr[ind + 1] = coord[1];
vAr[ind + 2] = coord[2];
@@ -561,7 +569,8 @@ Sculpt.prototype = {
dy = vy - cy,
dz = vz - cz;
var distToCen = Math.sqrt(dx * dx + dy * dy + dz * dz) / radius;
- var fallOff = 3.0 * distToCen * distToCen * distToCen * distToCen - 4.0 * distToCen * distToCen * distToCen + 1.0;
+ var fallOff = distToCen * distToCen;
+ fallOff = 3.0 * fallOff * fallOff - 4.0 * fallOff * distToCen + 1.0;
fallOff = distToPlane * deformIntensity * fallOff;
if (limitMove && fallOff > dMove)
fallOff = dMove;
@@ -594,7 +603,8 @@ Sculpt.prototype = {
dy = cy - vy,
dz = cz - vz;
var distToCen = Math.sqrt(dx * dx + dy * dy + dz * dz) / radius;
- var fallOff = 3.0 * distToCen * distToCen * distToCen * distToCen - 4.0 * distToCen * distToCen * distToCen + 1.0;
+ var fallOff = distToCen * distToCen;
+ fallOff = 3.0 * fallOff * fallOff - 4.0 * fallOff * distToCen + 1.0;
fallOff = deformIntensity * fallOff;
dx *= fallOff;
dy *= fallOff;
@@ -648,7 +658,8 @@ Sculpt.prototype = {
dy = cy - vy,
dz = cz - vz;
var distToCen = Math.sqrt(dx * dx + dy * dy + dz * dz) / radius;
- var fallOff = 3.0 * distToCen * distToCen * distToCen * distToCen - 4.0 * distToCen * distToCen * distToCen + 1.0;
+ var fallOff = distToCen * distToCen;
+ fallOff = 3.0 * fallOff * fallOff - 4.0 * fallOff * distToCen + 1.0;
var brushModifier = deformIntensity * Math.pow(2 - fallOff, -5) * brushFactor;
fallOff *= 0.1;
dx = dx * fallOff + anx * brushModifier;
@@ -718,7 +729,8 @@ Sculpt.prototype = {
dy = vAr[ind + 1] - cy,
dz = vAr[ind + 2] - cz;
var dist = Math.sqrt(dx * dx + dy * dy + dz * dz) / radius;
- var fallOff = 3.0 * dist * dist * dist * dist - 4.0 * dist * dist * dist + 1.0;
+ var fallOff = dist * dist;
+ fallOff = 3.0 * fallOff * fallOff - 4.0 * fallOff * dist + 1.0;
vAr[ind] += dirx * fallOff;
vAr[ind + 1] += diry * fallOff;
vAr[ind + 2] += dirz * fallOff;
@@ -748,7 +760,8 @@ Sculpt.prototype = {
dy = vAr[ind + 1] - cy,
dz = vAr[ind + 2] - cz;
var dist = Math.sqrt(dx * dx + dy * dy + dz * dz) / radius;
- var fallOff = 3.0 * dist * dist * dist * dist - 4.0 * dist * dist * dist + 1.0;
+ var fallOff = dist * dist;
+ fallOff = 3.0 * fallOff * fallOff - 4.0 * fallOff * dist + 1.0;
fallOff *= intensity;
var fallOffCompl = 1.0 - fallOff;
cAr[ind] = cAr[ind] * fallOffCompl + cr * fallOff;
View
466 editor/subdivision.js
@@ -185,55 +185,66 @@ Topology.prototype.initSplit = function (iTris, iTrisSubd, split, detailMaxSquar
};
/** Find the edge to be split (0 otherwise) */
-Topology.prototype.findSplit = function (iTri, detailMaxSquared, checkInsideSphere)
+Topology.prototype.findSplit = (function ()
{
- var mesh = this.mesh_;
- var vAr = mesh.vertexArray_;
- var iAr = mesh.indexArray_;
-
- var id = iTri * 3;
- var ind1 = iAr[id],
- ind2 = iAr[id + 1],
- ind3 = iAr[id + 2];
- id = ind1 * 3;
- var v1 = [vAr[id], vAr[id + 1], vAr[id + 2]];
- id = ind2 * 3;
- var v2 = [vAr[id], vAr[id + 1], vAr[id + 2]];
- id = ind3 * 3;
- var v3 = [vAr[id], vAr[id + 1], vAr[id + 2]];
-
- if (this.checkPlane_)
- {
- var po = this.planeOrigin_;
- var pn = this.planeNormal_;
- var tmp = [0, 0, 0];
- if (vec3.dot(pn, vec3.sub(tmp, v1, po)) < 0 &&
- vec3.dot(pn, vec3.sub(tmp, v2, po)) < 0 &&
- vec3.dot(pn, vec3.sub(tmp, v3, po)) < 0)
- return 0;
- }
- else if (checkInsideSphere)
+ var v1 = [0.0, 0.0, 0.0];
+ var v2 = [0.0, 0.0, 0.0];
+ var v3 = [0.0, 0.0, 0.0];
+ var tmp = [0.0, 0.0, 0.0];
+ return function (iTri, detailMaxSquared, checkInsideSphere)
{
- if (!Geometry.sphereIntersectTriangleEdges(this.center_, this.radiusSquared_ * 2, v1, v2, v3))
+ var mesh = this.mesh_;
+ var vAr = mesh.vertexArray_;
+ var iAr = mesh.indexArray_;
+
+ var id = iTri * 3;
+ var ind1 = iAr[id],
+ ind2 = iAr[id + 1],
+ ind3 = iAr[id + 2];
+ id = ind1 * 3;
+ v1[0] = vAr[id];
+ v1[1] = vAr[id + 1];
+ v1[2] = vAr[id + 2];
+ id = ind2 * 3;
+ v2[0] = vAr[id];
+ v2[1] = vAr[id + 1];
+ v2[2] = vAr[id + 2];
+ id = ind3 * 3;
+ v3[0] = vAr[id];
+ v3[1] = vAr[id + 1];
+ v3[2] = vAr[id + 2];
+
+ if (this.checkPlane_)
{
- if (!Geometry.pointInsideTriangle(this.center_, v1, v2, v3))
- {
+ var po = this.planeOrigin_;
+ var pn = this.planeNormal_;
+ if (vec3.dot(pn, vec3.sub(tmp, v1, po)) < 0.0 &&
+ vec3.dot(pn, vec3.sub(tmp, v2, po)) < 0.0 &&
+ vec3.dot(pn, vec3.sub(tmp, v3, po)) < 0.0)
return 0;
+ }
+ else if (checkInsideSphere === true)
+ {
+ if (!Geometry.triangleInsideSphere(this.center_, this.radiusSquared_, v1, v2, v3))
+ {
+ if (!Geometry.pointInsideTriangle(this.center_, v1, v2, v3))
+ {
+ return 0;
+ }
}
}
- }
- var temp = [0, 0, 0];
- var length1 = vec3.sqrLen(vec3.sub(temp, v1, v2)),
- length2 = vec3.sqrLen(vec3.sub(temp, v2, v3)),
- length3 = vec3.sqrLen(vec3.sub(temp, v1, v3));
- if (length1 > length2 && length1 > length3)
- return length1 > detailMaxSquared ? 1 : 0;
- else if (length2 > length3)
- return length2 > detailMaxSquared ? 2 : 0;
- else
- return length3 > detailMaxSquared ? 3 : 0;
-};
+ var length1 = vec3.sqrLen(vec3.sub(tmp, v1, v2)),
+ length2 = vec3.sqrLen(vec3.sub(tmp, v2, v3)),
+ length3 = vec3.sqrLen(vec3.sub(tmp, v1, v3));
+ if (length1 > length2 && length1 > length3)
+ return length1 > detailMaxSquared ? 1 : 0;
+ else if (length2 > length3)
+ return length2 > detailMaxSquared ? 2 : 0;
+ else
+ return length3 > detailMaxSquared ? 3 : 0;
+ };
+})();
/** Subdivide all the triangles that need to be subdivided */
Topology.prototype.subdivideTriangles = function (iTrisSubd, split, detailMaxSquared)
@@ -270,195 +281,234 @@ Topology.prototype.subdivideTriangles = function (iTrisSubd, split, detailMaxSqu
* 3. Compute angle between those two normals
* 4. Move the new vertex along its normal with a strengh proportional to the angle computed at step 3.
*/
-Topology.prototype.halfEdgeSplit = function (iTri, iv1, iv2, iv3)
+Topology.prototype.halfEdgeSplit = (function ()
{
- var mesh = this.mesh_;
- var vertices = mesh.vertices_;
- var triangles = mesh.triangles_;
- var vAr = mesh.vertexArray_;
- var nAr = mesh.normalArray_;
- var cAr = mesh.colorArray_;
- var iAr = mesh.indexArray_;
-
- var leaf = triangles[iTri].leaf_;
- var iTrisLeaf = leaf.iTris_;
- var v1 = vertices[iv1],
- v2 = vertices[iv2],
- v3 = vertices[iv3];
-
- var vMap = this.verticesMap_;
- var key = [Math.min(iv1, iv2), Math.max(iv1, iv2)];
- var isNewVertex = false;
- var ivMid = vMap[key];
- if (ivMid === undefined)
+ var key = [0, 0];
+ return function (iTri, iv1, iv2, iv3)
{
- ivMid = vertices.length;
- isNewVertex = true;
- vMap[key] = ivMid;
- }
-
- v3.ringVertices_.push(ivMid);
- var id = iTri * 3;
- iAr[id] = iv1;
- iAr[id + 1] = ivMid;
- iAr[id + 2] = iv3;
-
- var iNewTri = triangles.length;
- var newTri = new Triangle(iNewTri);
- id = iNewTri * 3;
- iAr[id] = ivMid;
- iAr[id + 1] = iv2;
- iAr[id + 2] = iv3;
- newTri.stateFlag_ = Mesh.stateMask_;
+ var mesh = this.mesh_;
+ var vertices = mesh.vertices_;
+ var triangles = mesh.triangles_;
+ var vAr = mesh.vertexArray_;
+ var nAr = mesh.normalArray_;
+ var cAr = mesh.colorArray_;
+ var iAr = mesh.indexArray_;
+
+ var leaf = triangles[iTri].leaf_;
+ var iTrisLeaf = leaf.iTris_;
+ var v1 = vertices[iv1],
+ v2 = vertices[iv2],
+ v3 = vertices[iv3];
- v3.tIndices_.push(iNewTri);
- v2.replaceTriangle(iTri, iNewTri);
- newTri.leaf_ = leaf;
- newTri.posInLeaf_ = iTrisLeaf.length;
- if (isNewVertex) //new vertex
- {
- var ind = vertices.length;
- var vMidTest = new Vertex(ind);
-
- id = iv1 * 3;
- var v1x = vAr[id],
- v1y = vAr[id + 1],
- v1z = vAr[id + 2];
- var n1x = nAr[id],
- n1y = nAr[id + 1],
- n1z = nAr[id + 2];
- var c1r = cAr[id],
- c1g = cAr[id + 1],
- c1b = cAr[id + 2];
-
- id = iv2 * 3;
- var v2x = vAr[id],
- v2y = vAr[id + 1],
- v2z = vAr[id + 2];
- var n2x = nAr[id],
- n2y = nAr[id + 1],
- n2z = nAr[id + 2];
- var c2r = cAr[id],
- c2g = cAr[id + 1],
- c2b = cAr[id + 2];
-
- var n1n2x = n1x + n2x,
- n1n2y = n1y + n2y,
- n1n2z = n1z + n2z;
- var len = 1 / Math.sqrt(n1n2x * n1n2x + n1n2y * n1n2y + n1n2z * n1n2z);
- id = ind * 3;
- nAr[id] = n1n2x * len;
- nAr[id + 1] = n1n2y * len;
- nAr[id + 2] = n1n2z * len;
-
- cAr[id] = (c1r + c2r) * 0.5;
- cAr[id + 1] = (c1g + c2g) * 0.5;
- cAr[id + 2] = (c1b + c2b) * 0.5;
-
- var offset = 0;
- if (!this.linearSubdivision_)
+ var vMap = this.verticesMap_;
+ key[0] = Math.min(iv1, iv2);
+ key[1] = Math.max(iv1, iv2);
+ var isNewVertex = false;
+ var ivMid = vMap[key];
+ if (ivMid === undefined)
{
- var dot = n1x * n2x + n1y * n2y + n1z * n2z;
- var angle = 0;
- if (dot <= -1) angle = Math.PI;
- else if (dot >= 1) angle = 0;
- else angle = Math.acos(dot);
-
- var edgex = v1x - v2x,
- edgey = v1y - v2y,
- edgez = v1z - v2z;
- len = Math.sqrt(edgex * edgex + edgey * edgey + edgez * edgez);
- offset = angle * len * 0.12;
- if ((edgex * (n1x - n2x) + edgey * (n1y - n2y) + edgez * (n1z - n2z)) < 0)
- offset = -offset;
+ ivMid = vertices.length;
+ isNewVertex = true;
+ vMap[key] = ivMid;
}
- vAr[id] = (v1x + v2x) * 0.5 + nAr[id] * offset;
- vAr[id + 1] = (v1y + v2y) * 0.5 + nAr[id + 1] * offset;
- vAr[id + 2] = (v1z + v2z) * 0.5 + nAr[id + 2] * offset;
+ v3.ringVertices_.push(ivMid);
+ var id = iTri * 3;
+ iAr[id] = iv1;
+ iAr[id + 1] = ivMid;
+ iAr[id + 2] = iv3;
+
+ var iNewTri = triangles.length;
+ var newTri = new Triangle(iNewTri);
+ id = iNewTri * 3;
+ iAr[id] = ivMid;
+ iAr[id + 1] = iv2;
+ iAr[id + 2] = iv3;
+ newTri.stateFlag_ = Mesh.stateMask_;
+
+ v3.tIndices_.push(iNewTri);
+ v2.replaceTriangle(iTri, iNewTri);
+ newTri.leaf_ = leaf;
+ newTri.posInLeaf_ = iTrisLeaf.length;
+ if (isNewVertex) //new vertex
+ {
+ var ind = vertices.length;
+ var vMidTest = new Vertex(ind);
+
+ id = iv1 * 3;
+ var v1x = vAr[id],
+ v1y = vAr[id + 1],
+ v1z = vAr[id + 2];
+ var n1x = nAr[id],
+ n1y = nAr[id + 1],
+ n1z = nAr[id + 2];
+ var c1r = cAr[id],
+ c1g = cAr[id + 1],
+ c1b = cAr[id + 2];
+
+ id = iv2 * 3;
+ var v2x = vAr[id],
+ v2y = vAr[id + 1],
+ v2z = vAr[id + 2];
+ var n2x = nAr[id],
+ n2y = nAr[id + 1],
+ n2z = nAr[id + 2];
+ var c2r = cAr[id],
+ c2g = cAr[id + 1],
+ c2b = cAr[id + 2];
+
+ var n1n2x = n1x + n2x,
+ n1n2y = n1y + n2y,
+ n1n2z = n1z + n2z;
+ var len = 1 / Math.sqrt(n1n2x * n1n2x + n1n2y * n1n2y + n1n2z * n1n2z);
+ id = ind * 3;
+ nAr[id] = n1n2x * len;
+ nAr[id + 1] = n1n2y * len;
+ nAr[id + 2] = n1n2z * len;
+
+ cAr[id] = (c1r + c2r) * 0.5;
+ cAr[id + 1] = (c1g + c2g) * 0.5;
+ cAr[id + 2] = (c1b + c2b) * 0.5;
+
+ var offset = 0;
+ if (!this.linearSubdivision_)
+ {
+ var dot = n1x * n2x + n1y * n2y + n1z * n2z;
+ var angle = 0;
+ if (dot <= -1) angle = Math.PI;
+ else if (dot >= 1) angle = 0;
+ else angle = Math.acos(dot);
+
+ var edgex = v1x - v2x,
+ edgey = v1y - v2y,
+ edgez = v1z - v2z;
+ len = Math.sqrt(edgex * edgex + edgey * edgey + edgez * edgez);
+ offset = angle * len * 0.12;
+ if ((edgex * (n1x - n2x) + edgey * (n1y - n2y) + edgez * (n1z - n2z)) < 0)
+ offset = -offset;
+ }
- vMidTest.stateFlag_ = Mesh.stateMask_;
- vMidTest.ringVertices_.push(iv1, iv2, iv3);
- v1.replaceRingVertex(iv2, ivMid);
- v2.replaceRingVertex(iv1, ivMid);
- vMidTest.tIndices_.push(iTri, iNewTri);
- vertices.push(vMidTest);
- }
- else
- {
- var vm = vertices[ivMid];
- vm.ringVertices_.push(iv3);
- vm.tIndices_.push(iTri, iNewTri);
- }
- iTrisLeaf.push(iNewTri);
- triangles.push(newTri);
-};
+ vAr[id] = (v1x + v2x) * 0.5 + nAr[id] * offset;
+ vAr[id + 1] = (v1y + v2y) * 0.5 + nAr[id + 1] * offset;
+ vAr[id + 2] = (v1z + v2z) * 0.5 + nAr[id + 2] * offset;
+
+ vMidTest.stateFlag_ = Mesh.stateMask_;
+ vMidTest.ringVertices_.push(iv1, iv2, iv3);
+ v1.replaceRingVertex(iv2, ivMid);
+ v2.replaceRingVertex(iv1, ivMid);
+ vMidTest.tIndices_.push(iTri, iNewTri);
+ vertices.push(vMidTest);
+ }
+ else
+ {
+ var vm = vertices[ivMid];
+ vm.ringVertices_.push(iv3);
+ vm.tIndices_.push(iTri, iNewTri);
+ }
+ iTrisLeaf.push(iNewTri);
+ triangles.push(newTri);
+ };
+})();
/**
* Fill the triangles. It checks if a newly vertex has been created at the middle
* of the edge. If several split are needed, it first chooses the split that minimize
* the valence of the vertex.
*/
-Topology.prototype.fillTriangles = function (iTris)
+Topology.prototype.fillTriangles = (function ()
{
- var mesh = this.mesh_;
- var vertices = mesh.vertices_;
- var triangles = mesh.triangles_;
- var iAr = mesh.indexArray_;
-
- var nbTris = iTris.length;
- var iTrisNext = [];
- for (var i = 0; i < nbTris; ++i)
+ var key = [0, 0];
+ return function (iTris)
{
- var iTri = iTris[i];
- var j = iTri * 3;
- var iv1 = iAr[j],
- iv2 = iAr[j + 1],
- iv3 = iAr[j + 2];
-
- var vMap = this.verticesMap_;
- var val1 = vMap[[Math.min(iv1, iv2), Math.max(iv1, iv2)]],
- val2 = vMap[[Math.min(iv2, iv3), Math.max(iv2, iv3)]],
- val3 = vMap[[Math.min(iv1, iv3), Math.max(iv1, iv3)]];
-
- var num1 = vertices[iv1].ringVertices_.length,
- num2 = vertices[iv2].ringVertices_.length,
- num3 = vertices[iv3].ringVertices_.length;
- var split = 0;
- if (val1)
+ var mesh = this.mesh_;
+ var vertices = mesh.vertices_;
+ var triangles = mesh.triangles_;
+ var iAr = mesh.indexArray_;
+
+ var nbTris = iTris.length;
+ var iTrisNext = [];
+ for (var i = 0; i < nbTris; ++i)
{
- if (val2)
+ var iTri = iTris[i];
+ var j = iTri * 3;
+ var iv1 = iAr[j],
+ iv2 = iAr[j + 1],
+ iv3 = iAr[j + 2];
+
+ var vMap = this.verticesMap_;
+ if (iv1 < iv2)
+ {
+ key[0] = iv1;
+ key[1] = iv2;
+ }
+ else
+ {
+ key[0] = iv2;
+ key[1] = iv1;
+ }
+ var val1 = vMap[key];
+ if (iv2 < iv3)
+ {
+ key[0] = iv2;
+ key[1] = iv3;
+ }
+ else
+ {
+ key[0] = iv3;
+ key[1] = iv2;
+ }
+ var val2 = vMap[key];
+ if (iv1 < iv3)
+ {
+ key[0] = iv1;
+ key[1] = iv3;
+ }
+ else
{
- if (val3)
+ key[0] = iv3;
+ key[1] = iv1;
+ }
+ var val3 = vMap[key];
+
+ var num1 = vertices[iv1].ringVertices_.length,
+ num2 = vertices[iv2].ringVertices_.length,
+ num3 = vertices[iv3].ringVertices_.length;
+ var split = 0;
+ if (val1)
+ {
+ if (val2)
{
- if (num1 < num2 && num1 < num3) split = 2;
- else if (num2 < num3) split = 3;
+ if (val3)
+ {
+ if (num1 < num2 && num1 < num3) split = 2;
+ else if (num2 < num3) split = 3;
+ else split = 1;
+ }
+ else if (num1 < num3) split = 2;
else split = 1;
}
- else if (num1 < num3) split = 2;
+ else if (val3 && num2 < num3) split = 3;
else split = 1;
}
- else if (val3 && num2 < num3) split = 3;
- else split = 1;
- }
- else if (val2)
- {
- if (val3 && num2 < num1) split = 3;
- else split = 2;
+ else if (val2)
+ {
+ if (val3 && num2 < num1) split = 3;
+ else split = 2;
+ }
+ else if (val3) split = 3;
+
+ if (split === 1)
+ this.fillTriangle(iTri, iv1, iv2, iv3, val1);
+ else if (split === 2)
+ this.fillTriangle(iTri, iv2, iv3, iv1, val2);
+ else if (split === 3)
+ this.fillTriangle(iTri, iv3, iv1, iv2, val3);
+ else continue;
+ iTrisNext.push(iTri, triangles.length - 1);
}
- else if (val3) split = 3;
-
- if (split === 1)
- this.fillTriangle(iTri, iv1, iv2, iv3, val1);
- else if (split === 2)
- this.fillTriangle(iTri, iv2, iv3, iv1, val2);
- else if (split === 3)
- this.fillTriangle(iTri, iv3, iv1, iv2, val3);
- else continue;
- iTrisNext.push(iTri, triangles.length - 1);
- }
- return iTrisNext;
-};
+ return iTrisNext;
+ };
+})();
/** Fill crack on one triangle */
Topology.prototype.fillTriangle = function (iTri, iv1, iv2, iv3, ivMid)
View
11 gui/gui.js
@@ -309,14 +309,17 @@ Gui.prototype = {
mesh.render_.shader_.type_ = this.ctrlShaders_.getValue();
this.ctrlShaders_.object = mesh.render_.shader_;
mesh.render_.flatShading_ = this.ctrlFlatShading_.getValue();
- this.updateMeshInfo(mesh.vertices_.length, mesh.triangles_.length);
+ this.updateMeshInfo();
},
/** Update number of vertices and triangles */
- updateMeshInfo: function (nbVertices, nbTriangles)
+ updateMeshInfo: function ()
{
- this.ctrlNbVertices_.name('Ver : ' + nbVertices);
- this.ctrlNbTriangles_.name('Tri : ' + nbTriangles);
+ var mesh = this.sculptgl_.mesh_;
+ if (!mesh)
+ return;
+ this.ctrlNbVertices_.name('Ver : ' + mesh.vertices_.length);
+ this.ctrlNbTriangles_.name('Tri : ' + mesh.triangles_.length);
},
/** Open file */
View
28 math3d/geometry.js
@@ -20,7 +20,7 @@ Geometry.mouseOnUnitSphere = function (mouseXY)
};
/** Compute intersection vertex between a ray and a triangle. Returne false if it doesn't intersect. */
-Geometry.intersectionRayTriangle = function ()
+Geometry.intersectionRayTriangle = (function ()
{
var EPSILON = 1E-20;
var edge1 = [0.0, 0.0, 0.0];
@@ -53,7 +53,7 @@ Geometry.intersectionRayTriangle = function ()
vec3.scaleAndAdd(vertInter, orig, dir, t);
return true;
};
-}();
+})();
/** Compute the bounding box of a triangle defined by three vertices */
Geometry.computeTriangleAabb = function (aabb, v1x, v1y, v1z, v2x, v2y, v2z, v3x, v3y, v3z)
@@ -95,7 +95,7 @@ Geometry.triangleNormal = function (normal, v1x, v1y, v1z, v2x, v2y, v2z, v3x, v
};
/** If point is inside the triangle, test the sum of the areas */
-Geometry.pointInsideTriangle = function ()
+Geometry.pointInsideTriangle = (function ()
{
var vec1 = [0.0, 0.0, 0.0];
var vec2 = [0.0, 0.0, 0.0];
@@ -114,10 +114,10 @@ Geometry.pointInsideTriangle = function ()
var area3 = vec3.len(vec3.cross(temp, vecP1, vecP2));
return Math.abs(total - (area1 + area2 + area3)) < 1E-20;
};
-}();
+})();
/** If a sphere intersect a triangle */
-Geometry.sphereIntersectTriangleEdges = function (point, radiusSq, v1, v2, v3)
+Geometry.triangleInsideSphere = function (point, radiusSq, v1, v2, v3)
{
if (Geometry.distanceSqToSegment(point, v1, v2) < radiusSq) return true;
if (Geometry.distanceSqToSegment(point, v2, v3) < radiusSq) return true;
@@ -126,7 +126,7 @@ Geometry.sphereIntersectTriangleEdges = function (point, radiusSq, v1, v2, v3)
};
/** Minimum squared distance to a segment */
-Geometry.distanceSqToSegment = function ()
+Geometry.distanceSqToSegment = (function ()
{
var pt = [0.0, 0.0, 0.0];
var v2v1 = [0.0, 0.0, 0.0];
@@ -144,7 +144,7 @@ Geometry.distanceSqToSegment = function ()
pt[2] = point[2] - v1[2] - t * v2v1[2];
return vec3.sqrLen(pt);
};
-}();
+})();
/** Sign angle between two 2d vectors in radians */
Geometry.signedAngle2d = function (v1, v2)
@@ -157,27 +157,27 @@ Geometry.signedAngle2d = function (v1, v2)
};
/** Distance from a vertex and a plane */
-Geometry.pointPlaneDistance = function ()
+Geometry.pointPlaneDistance = (function ()
{
var temp = [0.0, 0.0, 0.0];
return function (v, ptPlane, nPlane)
{
return vec3.dot(vec3.sub(temp, v, ptPlane), nPlane);
};
-}();
+})();
/** Mirror a vertex according to a plane */
-Geometry.mirrorPoint = function ()
+Geometry.mirrorPoint = (function ()
{
var temp = [0.0, 0.0, 0.0];
return function (v, ptPlane, nPlane)
{
return vec3.sub(v, v, vec3.scale(temp, nPlane, Geometry.pointPlaneDistance(v, ptPlane, nPlane) * 2.0));
};
-}();
+})();
/** Compute the projection of a vertex on a line */
-Geometry.vertexOnLine = function ()
+Geometry.vertexOnLine = (function ()
{
var ab = [0.0, 0.0, 0.0];
return function (vertex, vNear, vFar)
@@ -187,13 +187,11 @@ Geometry.vertexOnLine = function ()
var dot = vec3.dot(ab, vec3.sub(proj, vertex, vNear));
return vec3.scaleAndAdd(proj, vNear, ab, dot / vec3.sqrLen(ab));
};
-}();
+})();
/** Return the intersection between a ray and a plane */
Geometry.intersectLinePlane = function (s1, s2, origin, normal, out)
{
- if (out === undefined)
- out = [0.0, 0.0, 0.0];
var dist1 = vec3.dot(vec3.sub(out, s1, origin), normal);
var dist2 = vec3.dot(vec3.sub(out, s2, origin), normal);
//ray copplanar to triangle
View
95 math3d/picking.js
@@ -34,51 +34,66 @@ Picking.prototype = {
},
/** Intersection between a ray and a mesh */
- intersectionRayMesh: function (mesh, vNear, vFar, mouseX, mouseY, pressure)
+ intersectionRayMesh: (function ()
{
- this.mesh_ = null;
- this.pickedTriangle_ = -1;
- var triangles = mesh.triangles_;
- var vAr = mesh.vertexArray_;
- var iAr = mesh.indexArray_;
+ var v1 = [0.0, 0.0, 0.0];
+ var v2 = [0.0, 0.0, 0.0];
+ var v3 = [0.0, 0.0, 0.0];
var ray = [0.0, 0.0, 0.0];
- vec3.sub(ray, vFar, vNear);
- vec3.normalize(ray, ray);
- var rayInv = [1.0 / ray[0], 1.0 / ray[1], 1.0 / ray[2]];
- var iTrisCandidates = mesh.octree_.intersectRay(vNear, rayInv);
- var distance = -1.0;
- var nbTrisCandidates = iTrisCandidates.length;
+ var rayInv = [0.0, 0.0, 0.0];
var vertInter = [0.0, 0.0, 0.0];
- for (var i = 0; i < nbTrisCandidates; ++i)
+ return function (mesh, vNear, vFar, mouseX, mouseY, pressure)
{
- var indTri = iTrisCandidates[i] * 3;
- var ind1 = iAr[indTri] * 3,
- ind2 = iAr[indTri + 1] * 3,
- ind3 = iAr[indTri + 2] * 3;
- var v1 = [vAr[ind1], vAr[ind1 + 1], vAr[ind1 + 2]],
- v2 = [vAr[ind2], vAr[ind2 + 1], vAr[ind2 + 2]],
- v3 = [vAr[ind3], vAr[ind3 + 1], vAr[ind3 + 2]];
- if (Geometry.intersectionRayTriangle(vNear, ray, v1, v2, v3, vertInter))
+ this.mesh_ = null;
+ this.pickedTriangle_ = -1;
+ var triangles = mesh.triangles_;
+ var vAr = mesh.vertexArray_;
+ var iAr = mesh.indexArray_;
+ vec3.sub(ray, vFar, vNear);
+ vec3.normalize(ray, ray);
+ rayInv[0] = 1 / ray[0];
+ rayInv[1] = 1 / ray[1];
+ rayInv[2] = 1 / ray[2];
+ var iTrisCandidates = mesh.octree_.intersectRay(vNear, rayInv);
+ var distance = -1.0;
+ var nbTrisCandidates = iTrisCandidates.length;
+ for (var i = 0; i < nbTrisCandidates; ++i)
{
- var testDistance = vec3.sqrDist(vNear, vertInter);
+ var indTri = iTrisCandidates[i] * 3;
+ var ind1 = iAr[indTri] * 3,
+ ind2 = iAr[indTri + 1] * 3,
+ ind3 = iAr[indTri + 2] * 3;
+ v1[0] = vAr[ind1];
+ v1[1] = vAr[ind1 + 1];
+ v1[2] = vAr[ind1 + 2];
+ v2[0] = vAr[ind2];
+ v2[1] = vAr[ind2 + 1];
+ v2[2] = vAr[ind2 + 2];
+ v3[0] = vAr[ind3];
+ v3[1] = vAr[ind3 + 1];
+ v3[2] = vAr[ind3 + 2];
+ if (Geometry.intersectionRayTriangle(vNear, ray, v1, v2, v3, vertInter))
{
- if (testDistance < distance || distance < 0.0)
+ var testDistance = vec3.sqrDist(vNear, vertInter);
{
- distance = testDistance;
- vec3.copy(this.interPoint_, vertInter);
- this.pickedTriangle_ = iTrisCandidates[i];
+ if (testDistance < distance || distance < 0.0)
+ {
+ distance = testDistance;
+ vec3.copy(this.interPoint_, vertInter);
+ this.pickedTriangle_ = iTrisCandidates[i];
+ }
}
}
}
- }
- if (this.pickedTriangle_ !== -1)
- {
- this.mesh_ = mesh;
- this.computeRadiusWorldSq(mouseX, mouseY, pressure);
- }
- else
- this.rWorldSqr_ = 0.0;
- },
+ if (this.pickedTriangle_ !== -1)
+ {
+ this.mesh_ = mesh;
+ this.computeRadiusWorldSq(mouseX, mouseY, pressure);
+ }
+ else
+ this.rWorldSqr_ = 0.0;
+ };
+ })(),
/** Find all the vertices inside the sphere */
pickVerticesInSphere: function (rWorldSqr)
@@ -92,15 +107,21 @@ Picking.prototype = {
var nbVerts = iVerts.length;
var vertexSculptMask = ++Vertex.sculptMask_;
var pickedVertices = this.pickedVertices_;
+ var inter = this.interPoint_;
+ var itx = inter[0],
+ ity = inter[1],
+ itz = inter[2];
var ind = 0,
j = 0;
for (var i = 0; i < nbVerts; ++i)
{
ind = iVerts[i];
var v = vertices[ind];
j = ind * 3;
- var distSqr = vec3.sqrDist([vAr[j], vAr[j + 1], vAr[j + 2]], this.interPoint_);
- if (distSqr < rWorldSqr)
+ var dx = itx - vAr[j],
+ dy = ity - vAr[j + 1],
+ dz = itz - vAr[j + 2];
+ if ((dx * dx + dy * dy + dz * dz) < rWorldSqr)
{
v.sculptFlag_ = vertexSculptMask;
pickedVertices.push(iVerts[i]);
View
49 object/aabb.js
@@ -162,32 +162,31 @@ Aabb.prototype = {
},
/** Return true if a sphere intersect with the box */
- intersectSphere: function ()
+ intersectSphere: function (vert, radiusSquared)
{
- var nearest = [0.0, 0.0, 0.0];
- return function (vert, radiusSquared)
- {
- var min = this.min_,
- max = this.max_;
- var vx = vert[0],
- vy = vert[1],
- vz = vert[2];
-
- if (min[0] > vx) nearest[0] = min[0];
- else if (max[0] < vx) nearest[0] = max[0];
- else nearest[0] = vx;
-
- if (min[1] > vy) nearest[1] = min[1];
- else if (max[1] < vy) nearest[1] = max[1];
- else nearest[1] = vy;
-
- if (min[2] > vz) nearest[2] = min[2];
- else if (max[2] < vz) nearest[2] = max[2];
- else nearest[2] = vz;
-
- return vec3.sqrDist(vert, nearest) < radiusSquared;
- };
- }(),
+ var min = this.min_,
+ max = this.max_;
+ var vx = vert[0],
+ vy = vert[1],
+ vz = vert[2];
+ var dx = 0.0,
+ dy = 0.0,
+ dz = 0.0;
+
+ if (min[0] > vx) dx = min[0] - vx;
+ else if (max[0] < vx) dx = max[0] - vx;
+ else dx = 0.0;
+
+ if (min[1] > vy) dy = min[1] - vy;
+ else if (max[1] < vy) dy = max[1] - vy;
+ else dy = 0.0;
+
+ if (min[2] > vz) dz = min[2] - vz;
+ else if (max[2] < vz) dz = max[2] - vz;
+ else dz = 0.0;
+
+ return (dx * dx + dy * dy + dz * dz) < radiusSquared;
+ },
/** Check if the aabb is a plane, if so... enlarge it */
enlargeIfFlat: function (offset)
View
12 object/mesh.js
@@ -270,11 +270,19 @@ Mesh.prototype = {
this.updateVerticesNormal();
//octree construction
+ this.computeOctree(aabb);
+ },
+
+ /** compute octree */
+ computeOctree: function (aabbSplit)
+ {
+ var triangles = this.triangles_;
+ var nbTriangles = triangles.length;
var trianglesAll = [];
- for (i = 0; i < nbTriangles; ++i)
+ for (var i = 0; i < nbTriangles; ++i)
trianglesAll.push(i);
this.octree_ = new Octree();
- this.octree_.aabbSplit_.copy(aabb);
+ this.octree_.aabbSplit_.copy(aabbSplit);
this.octree_.build(this, trianglesAll);
},
View
18 object/states.js
@@ -142,7 +142,7 @@ States.prototype = {
this.pullUndoTriangles();
this.pullUndoVertices();
- this.recomputeOctree(this.undos_[this.curUndoIndex_].aabbState_);
+ this.mesh_.computeOctree(this.undos_[this.curUndoIndex_].aabbState_);
mesh.updateBuffers();
this.redos_.push(redoState);
@@ -366,7 +366,7 @@ States.prototype = {
this.pullRedoTriangles();
this.pullRedoVertices();
- this.recomputeOctree(redoCur.aabbState_.clone());
+ this.mesh_.computeOctree(redoCur.aabbState_);
mesh.updateBuffers();
if (!this.firstState_) this.curUndoIndex_++;
@@ -443,20 +443,6 @@ States.prototype = {
}
},
- /** Recompute octree */
- recomputeOctree: function (aabbSplit)
- {
- var mesh = this.mesh_;
- var triangles = mesh.triangles_;
- var nbTriangles = triangles.length;
- var trianglesAll = [];
- for (var i = 0; i < nbTriangles; ++i)
- trianglesAll.push(i);
- mesh.octree_ = new Octree();
- mesh.octree_.aabbSplit_.copy(aabbSplit);
- mesh.octree_.build(mesh, trianglesAll);
- },
-
/** Reset */
reset: function ()
{
View
10 sculptgl.js
@@ -429,6 +429,7 @@ SculptGL.prototype = {
this.sculptTimer_ = setInterval(function ()
{
self.sculpt_.sculptStroke(self.mouseX_, self.mouseY_, self.pressureRadius_, self.pressureIntensity_, self);
+ self.gui_.updateMeshInfo();
self.render();
}, 20);
}
@@ -456,6 +457,7 @@ SculptGL.prototype = {
clearInterval(this.sculptTimer_);
this.sculptTimer_ = -1;
}
+ this.gui_.updateMeshInfo();
this.mouseButton_ = 0;
},
@@ -514,7 +516,7 @@ SculptGL.prototype = {
else
{
this.sculpt_.sculptStroke(mouseX, mouseY, pressureRadius, pressureIntensity, this);
- this.gui_.updateMeshInfo(this.mesh_.vertices_.length, this.mesh_.triangles_.length);
+ this.gui_.updateMeshInfo();
}
}
else if (button === 3 || (event.altKey && !event.shiftKey && !event.ctrlKey))
@@ -614,7 +616,7 @@ SculptGL.prototype = {
cut: function ()
{
this.sculpt_.cut(this.picking_);
- this.gui_.updateMeshInfo(this.mesh_.vertices_.length, this.mesh_.triangles_.length);
+ this.gui_.updateMeshInfo();
this.render();
},
@@ -649,14 +651,14 @@ SculptGL.prototype = {
{
this.states_.undo();
this.render();
- this.gui_.updateMeshInfo(this.mesh_.vertices_.length, this.mesh_.triangles_.length);
+ this.gui_.updateMeshInfo();
},
/** When the user redos an action */
onRedo: function ()
{
this.states_.redo();
this.render();
- this.gui_.updateMeshInfo(this.mesh_.vertices_.length, this.mesh_.triangles_.length);
+ this.gui_.updateMeshInfo();
}
};

0 comments on commit 88e996b

Please sign in to comment.
Something went wrong with that request. Please try again.