From 43914a027f1de0572ea3584e2b4dce118848bd7b Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 13 Aug 2024 15:38:41 -0400 Subject: [PATCH] abstraction to allow extrude face and sketch on face --- src/mesh/model.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/mesh/model.js b/src/mesh/model.js index 2d422389..0ff370f3 100644 --- a/src/mesh/model.js +++ b/src/mesh/model.js @@ -637,7 +637,7 @@ mesh.model = class MeshModel extends mesh.object { this.updateSelections(); } - triangulateSelections() { + selectionToRotationPolys() { let selverts = this.collectFacesByMaterialIndex(1); if (selverts?.length) { let points = [...selverts].group(3).map(a => new Vector3().fromArray(a)); @@ -651,11 +651,19 @@ mesh.model = class MeshModel extends mesh.object { // union and earcut the result let polys = tris.map(t => newPolygon().fromVectors([ t.a, t.b, t.c ])); let union = polygons.union(polys,0,true); - let ears = union.map(p => p.earcut()).flat(); - // unrotate using the same quaternion - rotato.invert(); + return { polys: union, normal: targetNorm, quaternion: rotato }; + } else { + return {}; + } + } + + triangulateSelections() { + let { polys, quaternion } = this.selectionToRotationPolys(); + if (polys) { + let ears = polys.map(p => p.earcut()).flat(); let nupoints = ears.map(p => p.points).flat().map(p => p.toVector3()); - nupoints.forEach(p => p.applyQuaternion(rotato)); + // invert quaternion to restore points alignment to original face + nupoints.forEach(p => p.applyQuaternion(quaternion.invert())); let nuverts = nupoints.map(p => p.toArray()).flat().toFloat32(); // remove selection and append nuverts this.deleteSelections(nuverts);