提交 71f07b91 编写于 作者: Z zz85

Playing with holes.. Need a clear mind to write this cleanly

上级 8be77c88
......@@ -38,8 +38,19 @@ THREE.ExtrudeGeometry = function( shape, options ) {
reverse = false;
}
//var faces = THREE.Shape.Utils.triangulate2(vertices);
var faces = THREE.FontUtils.Triangulate( vertices, true );
var holes = shape.getHoles();
var faces = THREE.Shape.Utils.triangulate2(vertices, holes);
console.log(faces);
//var faces = THREE.FontUtils.Triangulate( vertices, true );
var ahole ;
for (var h in holes) {
ahole = holes[h];
vertices = vertices.concat(ahole);
}
var contour = vertices;
......
......@@ -27,29 +27,49 @@ THREE.Shape.prototype.extrude = function( options ) {
};
THREE.Shape.prototype.getHoles = function() {
var holesPts = [];
var i=0, il= this.holes.length;
for (; i<il; i++ ) {
holesPts[i] = this.holes[i].getSpacedPoints();
}
return holesPts;
};
THREE.Shape.Utils = {
triangulate2 : function(pts) {
triangulate2 : function(pts, holes) {
// For use Poly2Tri.js
//var pts = this.getPoints();
var allpts = pts.concat();
var shape = [];
for (var p in pts) {
shape.push(new js.poly2tri.Point(pts[p].x, pts[p].y))
shape.push(new js.poly2tri.Point(pts[p].x, pts[p].y));
}
var swctx = new js.poly2tri.SweepContext(shape);
/*
for (var idx in holes)
{
swctx.AddHole(holes[idx]);
for (var h in holes) {
var aHole = holes[h];
var newHole = []
for (i in aHole) {
newHole.push(new js.poly2tri.Point(aHole[i].x, aHole[i].y));
allpts.push(aHole[i]);
}
*/
swctx.AddHole(newHole);
}
var find;
var findIndexForPt = function (pt) {
find = new THREE.Vector2(pt.x, pt.y);
var p;
for (p=0, pl = pts.length; p<pl; p++) {
if (pts[p].equals(find)) return p;
for (p=0, pl = allpts.length; p<pl; p++) {
if (allpts[p].equals(find)) return p;
}
return -1;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册