From 5f001f30502da5bd24210fe3bee2ff07f565df05 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 25 Jul 2024 16:03:51 -0400 Subject: [PATCH] add sketch poly group and ungroup --- src/mesh/build.js | 4 ++-- src/mesh/sketch.js | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/mesh/build.js b/src/mesh/build.js index 964a9a82..828cb2e9 100644 --- a/src/mesh/build.js +++ b/src/mesh/build.js @@ -433,8 +433,8 @@ function ui_build() { h.button({ _: 'intersect', onclick: sketch.boolean.intersect }), h.button({ _: 'difference', onclick: sketch.boolean.difference }), h.hr(), - h.button({ _: 'group', onclick: sketch.boolean.union }), - h.button({ _: 'ungroup', onclick: sketch.boolean.union }), + h.button({ _: 'group', onclick: sketch.boolean.group }), + h.button({ _: 'ungroup', onclick: sketch.boolean.ungroup }), ]) ]), h.div({ class: "sketch-off" }, [ diff --git a/src/mesh/sketch.js b/src/mesh/sketch.js index fc1a5d66..7a86a7d5 100644 --- a/src/mesh/sketch.js +++ b/src/mesh/sketch.js @@ -170,11 +170,30 @@ mesh.sketch = class MeshSketch extends mesh.object { let items = sketch.selection.mesh_items(); let polys = items.map(i => i.sketch_item.poly); let union = POLYS.union(polys, 0, true); - console.log('sketch union', union); sketch.selection.delete(); for (let poly of union) { sketch.add_polygon({ poly }); } + }, + + group() { + let items = sketch.selection.mesh_items(); + let polys = items.map(i => i.sketch_item.poly).clone(true); + let union = POLYS.nest(POLYS.flatten(polys, [], true)); + sketch.selection.delete(); + for (let poly of union) { + sketch.add_polygon({ poly }); + } + }, + + ungroup() { + let items = sketch.selection.mesh_items(); + let polys = items.map(i => i.sketch_item.poly).clone(true); + let flat = POLYS.flatten(polys, [], true); + sketch.selection.delete(); + for (let poly of flat) { + sketch.add_polygon({ poly }); + } } } } @@ -287,7 +306,7 @@ mesh.sketch = class MeshSketch extends mesh.object { } add_polygon(opt = {}) { - log(this.file || this.id, '| add polygon'); + // log(this.file || this.id, '| add polygon'); Object.assign(opt, { center: {x:0, y:0, z:0} }, opt); this.items.push({ type: "polygon", ...opt, ...opt.poly.toObject() }); this.render();