Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't recompute plane when splitting and cloning #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions csg.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ CSG.Plane.prototype = {
b.push(v.clone());
}
}
if (f.length >= 3) front.push(new CSG.Polygon(f, polygon.shared));
if (b.length >= 3) back.push(new CSG.Polygon(b, polygon.shared));
if (f.length >= 3) front.push(new CSG.Polygon(f, polygon.shared, polygon.plane));
if (b.length >= 3) back.push(new CSG.Polygon(b, polygon.shared, polygon.plane));
break;
}
}
Expand All @@ -485,16 +485,16 @@ CSG.Plane.prototype = {
// polygons that are clones of each other or were split from the same polygon.
// This can be used to define per-polygon properties (such as surface color).

CSG.Polygon = function(vertices, shared) {
CSG.Polygon = function(vertices, shared, plane) {
this.vertices = vertices;
this.shared = shared;
this.plane = CSG.Plane.fromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);
this.plane = plane ? plane.clone() : CSG.Plane.fromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);
};

CSG.Polygon.prototype = {
clone: function() {
var vertices = this.vertices.map(function(v) { return v.clone(); });
return new CSG.Polygon(vertices, this.shared);
return new CSG.Polygon(vertices, this.shared, this.plane);
},

flip: function() {
Expand Down