track area/surface minz and re-apply for op area
This commit is contained in:
parent
a48c2891fb
commit
21dd650c1e
1 changed files with 14 additions and 9 deletions
|
|
@ -46,10 +46,11 @@ class OpArea extends CamOp {
|
||||||
|
|
||||||
// selected area polygons: surfaces and edges
|
// selected area polygons: surfaces and edges
|
||||||
let { devel, edgeangle } = settings.controller;
|
let { devel, edgeangle } = settings.controller;
|
||||||
|
let polys = [];
|
||||||
let stack = [];
|
let stack = [];
|
||||||
let surfaces = this.surfaces = [];
|
let surfaces = this.surfaces = [];
|
||||||
let areas = this.areas = [ stack ];
|
let areas = this.areas = [ stack ];
|
||||||
let polys = [];
|
let aminz = Infinity;
|
||||||
|
|
||||||
function newArea() {
|
function newArea() {
|
||||||
if (stack.length) {
|
if (stack.length) {
|
||||||
|
|
@ -65,7 +66,9 @@ class OpArea extends CamOp {
|
||||||
|
|
||||||
// gather area selections
|
// gather area selections
|
||||||
for (let arr of (op.areas[widget.id] ?? [])) {
|
for (let arr of (op.areas[widget.id] ?? [])) {
|
||||||
polys.push(newPolygon().fromArray(arr));
|
let poly = newPolygon().fromArray(arr);
|
||||||
|
aminz = Math.min(aminz, poly.minZ());
|
||||||
|
polys.push(poly);
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect open poly edge segments into closed loops (when possible)
|
// connect open poly edge segments into closed loops (when possible)
|
||||||
|
|
@ -76,24 +79,25 @@ class OpArea extends CamOp {
|
||||||
let vert = widget.getGeoVertices({ unroll: true, translate: true }).map(v => v.round(4));
|
let vert = widget.getGeoVertices({ unroll: true, translate: true }).map(v => v.round(4));
|
||||||
let faces = CAM.surface_find(widget, (op.surfaces[widget.id] ?? []), (follow ?? edgeangle ?? 5) * DEG2RAD);
|
let faces = CAM.surface_find(widget, (op.surfaces[widget.id] ?? []), (follow ?? edgeangle ?? 5) * DEG2RAD);
|
||||||
let fpoly = [];
|
let fpoly = [];
|
||||||
let fminz = Infinity;
|
|
||||||
for (let face of faces) {
|
for (let face of faces) {
|
||||||
let i = face * 9;
|
let i = face * 9;
|
||||||
fpoly.push(newPolygon()
|
fpoly.push(newPolygon()
|
||||||
.add(vert[i++], vert[i++], fminz = Math.min(fminz, vert[i++]))
|
.add(vert[i++], vert[i++], aminz = Math.min(aminz, vert[i++]))
|
||||||
.add(vert[i++], vert[i++], fminz = Math.min(fminz, vert[i++]))
|
.add(vert[i++], vert[i++], aminz = Math.min(aminz, vert[i++]))
|
||||||
.add(vert[i++], vert[i++], fminz = Math.min(fminz, vert[i++]))
|
.add(vert[i++], vert[i++], aminz = Math.min(aminz, vert[i++]))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// remove invalid edges (eg. when vertical walls are the only selection)
|
// remove invalid edges (eg. when vertical walls are the only selection)
|
||||||
fpoly = fpoly.filter(p => p.area() > 0.001);
|
fpoly = fpoly.filter(p => p.area() > 0.001);
|
||||||
|
|
||||||
// add in unioned surface areas
|
// add in unioned surface areas
|
||||||
polys.push(...POLY.setZ(POLY.union(fpoly, 0.00001, true), fminz));
|
polys.push(...POLY.setZ(POLY.union(fpoly, 0.00001, true), aminz));
|
||||||
|
|
||||||
// smoothing for jaggies usually caused by vertical walls
|
// smoothing for jaggies usually caused by vertical walls
|
||||||
if (smoothVal)
|
if (smoothVal) {
|
||||||
polys = polys.map(poly => POLY.offset(POLY.offset([ poly ], smoothVal), -smoothVal)).flat();
|
polys = polys.map(poly => POLY.offset(POLY.offset([ poly ], smoothVal), -smoothVal)).flat();
|
||||||
|
POLY.setZ(polys, aminz);
|
||||||
|
}
|
||||||
|
|
||||||
// expand selections (flattens z variable polys)
|
// expand selections (flattens z variable polys)
|
||||||
if (Math.abs(expand) > 0) {
|
if (Math.abs(expand) > 0) {
|
||||||
|
|
@ -144,6 +148,7 @@ class OpArea extends CamOp {
|
||||||
let zroc = 0;
|
let zroc = 0;
|
||||||
let zinc = 1 / zs.length;
|
let zinc = 1 / zs.length;
|
||||||
let lzo;
|
let lzo;
|
||||||
|
|
||||||
outer: for (;;)
|
outer: for (;;)
|
||||||
for (let z of zs) {
|
for (let z of zs) {
|
||||||
let slice = newLayer(z);
|
let slice = newLayer(z);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue