fix pocket
This commit is contained in:
parent
e13c1e7430
commit
83a4bdebfd
7 changed files with 128 additions and 122 deletions
|
|
@ -212,7 +212,7 @@ export async function cam_slice(settings, widget, onupdate, ondone) {
|
|||
minZabove = zkey;
|
||||
}
|
||||
}
|
||||
let shadow = shadowAt(widget, z, minZabove);
|
||||
let shadow = computeShadowAt(widget, z, minZabove);
|
||||
if (minZabove) {
|
||||
// const merge = shadow.length;
|
||||
// const plus = shadows[minZabove].length;
|
||||
|
|
@ -737,3 +737,92 @@ function healPolys(noff) {
|
|||
}
|
||||
return noff;
|
||||
}
|
||||
|
||||
// union triangles > z (opt cap < ztop) into polygon(s)
|
||||
export function computeShadowAt(widget, z, ztop) {
|
||||
const geo = widget.cache.geo;
|
||||
const length = geo.length;
|
||||
// cache faces with normals up
|
||||
if (!widget.cache.shadow) {
|
||||
const faces = [];
|
||||
for (let i=0, ip=0; i<length; i += 3) {
|
||||
const a = new THREE.Vector3(geo[ip++], geo[ip++], geo[ip++]);
|
||||
const b = new THREE.Vector3(geo[ip++], geo[ip++], geo[ip++]);
|
||||
const c = new THREE.Vector3(geo[ip++], geo[ip++], geo[ip++]);
|
||||
const n = THREE.computeFaceNormal(a,b,c);
|
||||
if (n.z > 0.001) {
|
||||
faces.push(a,b,c);
|
||||
// faces.push(newPoint(...a), newPoint(...b), newPoint(...c));
|
||||
}
|
||||
}
|
||||
widget.cache.shadow = faces;
|
||||
}
|
||||
const found = [];
|
||||
const faces = widget.cache.shadow;
|
||||
const { checkOverUnderOn, intersectPoints } = cam_slicer;
|
||||
for (let i=0; i<faces.length; ) {
|
||||
const a = faces[i++];
|
||||
const b = faces[i++];
|
||||
const c = faces[i++];
|
||||
let where = undefined;
|
||||
if (ztop && a.z > ztop && b.z > ztop && c.z > ztop) {
|
||||
// skip faces over top threshold
|
||||
continue;
|
||||
}
|
||||
if (a.z < z && b.z < z && c.z < z) {
|
||||
// skip faces under threshold
|
||||
continue;
|
||||
} else if (a.z > z && b.z > z && c.z > z) {
|
||||
found.push([a,b,c]);
|
||||
} else {
|
||||
// check faces straddling threshold
|
||||
const where = { under: [], over: [], on: [] };
|
||||
checkOverUnderOn(newPoint(a.x, a.y, a.z), z, where);
|
||||
checkOverUnderOn(newPoint(b.x, b.y, b.z), z, where);
|
||||
checkOverUnderOn(newPoint(c.x, c.y, c.z), z, where);
|
||||
if (where.on.length === 0 && (where.over.length === 2 || where.under.length === 2)) {
|
||||
// compute two point intersections and construct line
|
||||
let line = intersectPoints(where.over, where.under, z);
|
||||
if (line.length === 2) {
|
||||
if (where.over.length === 2) {
|
||||
found.push([where.over[1], line[0], line[1]]);
|
||||
found.push([where.over[0], where.over[1], line[0]]);
|
||||
} else {
|
||||
found.push([where.over[0], line[0], line[1]]);
|
||||
}
|
||||
} else {
|
||||
console.log({msg: "invalid ips", line: line, where: where});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// const lines = {};
|
||||
// function addline(p1, p2) {
|
||||
// let key = p1.key < p2.key ? p1.key + ',' + p2.key : p2.key + ',' + p1.key;
|
||||
// let rec = lines[key];
|
||||
// if (rec) {
|
||||
// rec.count++;
|
||||
// } else {
|
||||
// lines[key] = { p1, p2, count: 1 };
|
||||
// }
|
||||
// }
|
||||
// for (let face of found) {
|
||||
// addline(face[0], face[1]);
|
||||
// addline(face[1], face[2]);
|
||||
// addline(face[2], face[0]);
|
||||
// }
|
||||
// const singles = Object.entries(lines).filter(a => a[1].count === 1).map(a => a[1]);
|
||||
// const loops = POLY.nest(sliceConnect(singles, z));
|
||||
|
||||
let polys = found.map(a => {
|
||||
return newPolygon()
|
||||
.add(a[0].x,a[0].y,a[0].z)
|
||||
.add(a[1].x,a[1].y,a[1].z)
|
||||
.add(a[2].x,a[2].y,a[2].z);
|
||||
});
|
||||
polys = POLY.union(polys, 0.001, true);
|
||||
// console.log({z, loops, polys});
|
||||
// return loops;
|
||||
return polys;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue