add surface normal filtering for upward faces (cnc)

This commit is contained in:
Stewart Allen 2022-04-04 19:17:13 -04:00
commit 594a1daa07
3 changed files with 16 additions and 8 deletions

View file

@ -589,8 +589,7 @@ mesh.model = class MeshModel extends mesh.object {
}
// find adjacent faces to clicked point/line on a face
find(int, action, opt) {
let { radians, radius } = opt;
find(int, action, surface) {
let { point, face } = int;
let { x, y, z } = point;
let { a, b, c } = face;
@ -599,7 +598,7 @@ mesh.model = class MeshModel extends mesh.object {
mesh.api.log.emit("matching surface").pin();
}, 150);
worker.model_select({
id: this.id, x, y:-z, z:y, a, b, c, matrix: this.matrix, radians, radius
id: this.id, x, y:-z, z:y, a, b, c, matrix: this.matrix, surface
}).then(data => {
if (timer) {
clearTimeout(timer);

View file

@ -158,8 +158,12 @@ mesh.tool = class MeshTool {
return sides.map(side => this.side2face[side].filter(v => v != face)).flat();
}
findConnectedSurface(faces, radians) {
findConnectedSurface(faces, radians, filterZ) {
const found = {};
const norms = this.normals;
if (filterZ) {
faces = faces.filter(f => norms[f][2] >= filterZ);
}
const check = faces.slice();
for (let face of faces) {
found[face] = 1;
@ -168,7 +172,10 @@ mesh.tool = class MeshTool {
// const _v2 = new Vector3();
while (check.length) {
const face = check.shift();
const norm = this.normals[face];
const norm = norms[face];
if (filterZ !== undefined && norm[2] < filterZ) {
continue;
}
const fadj = this.getAdjacentFaces(face).filter(f => !found[f]);
for (let f of fadj) {
// #1 most accurate
@ -182,7 +189,7 @@ mesh.tool = class MeshTool {
// .map((v,i) => Math.pow(norm[i] - v, 2))
// .reduce((a,v) => a + v)));
// #3 fastest, still good
const fn = Math.sqrt(this.normals[f]
const fn = Math.sqrt(norms[f]
.map((v,i) => Math.pow(norm[i] - v, 2))
.reduce((a,v) => a + v));
if (fn <= radians) {

View file

@ -282,7 +282,8 @@ let model = {
// given model and point, locate matching vertices, lines, and faces
select(data) {
let { id, x, y, z, a, b, c, matrix, radians, radius } = data;
let { id, x, y, z, a, b, c, matrix, surface } = data;
let { radians, radius, filterZ } = surface;
// translate point into mesh matrix space
let v3 = new Vector3(x,y,z).applyMatrix4(
core_matrix.clone().multiply(new Matrix4().fromArray(matrix)).invert()
@ -327,7 +328,8 @@ let model = {
// if the geometry has indexed faces and radians are set, find surface
const tool = rec.tool;
if (tool && tool.sides && radians) {
tool.findConnectedSurface(faces, radians);
const match = tool.findConnectedSurface(faces, radians, filterZ);
return { faces: match, edges, verts, point };
}
return { faces, edges, verts, point };
},