Permalink
Browse files

Add explodeFaces() to disconnect the faces of a shape.

  • Loading branch information...
1 parent 097ef80 commit 27ac4dcb477fa816377a996e92359d3c6c083e8d @deanm committed Jul 6, 2010
Showing with 26 additions and 0 deletions.
  1. +26 −0 pre3d_shape_utils.js
View
26 pre3d_shape_utils.js
@@ -610,6 +610,31 @@ Pre3d.ShapeUtils = (function() {
return shape;
}
+ // Detach all of the faces from each other. Basically this just duplicates
+ // all of the vertices for each face, so a vertex is not shared across faces.
+ function explodeFaces(shape) {
+ var quads = shape.quads;
+ var num_quads = quads.length;
+ var verts = shape.vertices;
+ var new_verts = [ ];
+ for (var i = 0; i < num_quads; ++i) {
+ var q = quads[i];
+ var pos = new_verts.length;
+ new_verts.push({x: verts[q.i0].x, y: verts[q.i0].y, z: verts[q.i0].z});
+ new_verts.push({x: verts[q.i1].x, y: verts[q.i1].y, z: verts[q.i1].z});
+ new_verts.push({x: verts[q.i2].x, y: verts[q.i2].y, z: verts[q.i2].z});
+ q.i0 = pos;
+ q.i1 = pos + 1;
+ q.i2 = pos + 2;
+ if (q.isTriangle() !== true) {
+ new_verts.push({x: verts[q.i3].x, y: verts[q.i3].y, z: verts[q.i3].z});
+ q.i3 = pos + 3;
+ }
+ }
+ shape.vertices = new_verts;
+ return shape;
+ }
+
// The Extruder implements extruding faces of a Shape. The class mostly
// exists as a place to hold all of the extrusion parameters. The properties
// are meant to be private, please use the getter/setter APIs.
@@ -803,6 +828,7 @@ Pre3d.ShapeUtils = (function() {
averageSmooth: averageSmooth,
linearSubdivide: linearSubdivide,
linearSubdivideTri: linearSubdivideTri,
+ explodeFaces: explodeFaces,
Extruder: Extruder
};

0 comments on commit 27ac4dc

Please sign in to comment.