Skip to content

Commit

Permalink
added fromPolygon2D
Browse files Browse the repository at this point in the history
  • Loading branch information
ncannasse committed Feb 25, 2021
1 parent 3f0eca8 commit a733910
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions h3d/col/Polygon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,39 @@ class Polygon implements Collider {
}
#end

public static function fromPolygon2D( p : h2d.col.Polygon, z = 0. ) {
var pout = new Polygon();
if( p.isConvex() ) {
var p0 = p[0];
for( i in 0...p.length-2 ) {
var p1 = p[i+1];
var p2 = p[i+2];
var t = new TriPlane();
t.init(
new h3d.col.Point(p0.x, p0.y, z),
new h3d.col.Point(p1.x, p1.y, z),
new h3d.col.Point(p2.x, p2.y, z)
);
t.next = pout.triPlanes;
pout.triPlanes = t;
}
} else {
var idx = p.fastTriangulate();
for( i in 0...Std.int(idx.length/3) ) {
var p0 = p[idx[i*3]];
var p1 = p[idx[i*3+1]];
var p2 = p[idx[i*3+2]];
var t = new TriPlane();
t.init(
new h3d.col.Point(p0.x, p0.y, z),
new h3d.col.Point(p1.x, p1.y, z),
new h3d.col.Point(p2.x, p2.y, z)
);
t.next = pout.triPlanes;
pout.triPlanes = t;
}
}
return pout;
}

}

0 comments on commit a733910

Please sign in to comment.