add gbr to loader classes

This commit is contained in:
Stewart Allen 2024-06-29 19:21:22 -04:00
commit fdfea41a48
8 changed files with 179 additions and 129 deletions

View file

@ -1851,8 +1851,8 @@ class Polygon {
return this;
}
// turn 2d polygon into closed 3d mesh faces
extrude(z = 1) {
// turn 2d polygon into a 2.5D ribbon extruded in Z
ribbonZ(z = 1) {
let poly = this.clone().setClockwise();
let faces = [];
let points = poly.points;
@ -1870,6 +1870,25 @@ class Polygon {
return faces;
}
// extrude poly (with inner voids) into 3d mesh
extrude(z = 1) {
let obj = [];
let earcut = this.earcut();
for (let poly of earcut) {
for (let point of poly.points) {
obj.push(point.x, point.y, z);
}
for (let point of poly.points.reverse()) {
obj.push(point.x, point.y, 0);
}
}
obj.appendAll(this.ribbonZ(z));
for (let inner of this.inner || []) {
obj.appendAll(inner.ribbonZ(z));
}
return obj;
}
// split long straight lines into segments no longer than max
// and return a new polygon
segment(max = 1) {