create body isolation function

This commit is contained in:
bakedpotatolord 2025-07-19 17:50:13 -06:00
commit 0ffe2ba461
4 changed files with 38 additions and 0 deletions

View file

@ -1775,6 +1775,7 @@ function init_two() {
$('mesh-export-stl').onclick = () => { objectsExport('stl') };
$('mesh-export-obj').onclick = () => { objectsExport('obj') };
$('mesh-merge').onclick = selection.merge;
$('mesh-split').onclick = selection.isolateBodies;
$('context-duplicate').onclick = duplicateSelection;
$('context-mirror').onclick = mirrorSelection;
$('context-layflat').onclick = () => { api.event.emit("tool.mesh.lay-flat") };

View file

@ -3,6 +3,7 @@
import { api } from './api.js';
import { space } from '../../moto/space.js';
import { THREE } from '../../ext/three.js';
import { tool as MeshTool } from '../../mesh/tool.js';
const selectedMeshes = [];
@ -206,6 +207,39 @@ function merge() {
api.platform.select(w);
}
/**
* Isolates the bodies within the selected widgets. If no widgets are selected,
* it processes all available widgets. For each widget, it checks if a tool is
* associated; if not, it creates a new MeshTool and indexes the vertices.
* The function identifies isolated bodies within each widget. If a widget has
* a single body, it remains selected. Otherwise, it creates new widgets for
* each isolated body and selects them while deleting the original widget.
*/
function isolateBodies(){
let sel = widgets();
console.log('isolate', sel);
if (sel.length === 0) {
sel = api.widgets.all();
}
for(let widget of sel){
if (!widget.tool) {
let tool = widget.tool = new MeshTool();
tool.index(widget.getGeoVertices({ unroll: true, translate:true }));
}
let bodies = widget.tool.isolateBodies()
if(bodies.length ==1){
api.platform.select(widget);
}else{
console.log(bodies,Array.from(bodies.entries()))
for(let [i,verts] of bodies.entries()){
let w = api.platform.load_verts([], verts, `isolate ${i} of ${ widget.anno.file}`);
api.platform.select(w)
}
api.platform.delete(widget);
}
}
}
function exportWidgets(format = "stl") {
let sel = widgets();
if (sel.length === 0) {
@ -291,6 +325,7 @@ function setDisabled(bool) {
export const selection = {
move,
merge,
isolateBodies,
scale,
rotate,
mirror,

View file

@ -286,6 +286,7 @@
<div id="ft-mesh" class="grow f-col pop">
<div id="ft-mesh-btn">
<div><button id="mesh-merge" lk="rc_merg">Merge</button></div>
<div><button id="mesh-split" lk="rc_splt">Isolate Bodies</button></div>
<div><button id="mesh-export-obj" lk="rc_xobj">export OBJ</button></div>
<div><button id="mesh-export-stl" lk="rc_xstl">export STL</button></div>
</div>

View file

@ -78,6 +78,7 @@ self.lang['en-us'] = {
rc_xstl: "export STL",
sb_info: ["print speed","in mm/s"],
rc_merg: "merge object meshes",
rc_splt: "isolate bodies",
// DEVICE MENU and related dialogs
dm_sldt: "select a device type",