add union op

This commit is contained in:
Stewart Allen 2022-01-30 21:56:53 -05:00
commit d64000aafb
3 changed files with 21 additions and 2 deletions

View file

@ -284,6 +284,8 @@ function space_init(data) {
case 'KeyM':
if (shiftKey) return api.tool.merge();
return api.tool.mirror();
case 'KeyU':
return shiftKey && api.tool.union();
case 'KeyA':
return shiftKey ? api.tool.analyze() : undefined;
case 'KeyR':

View file

@ -312,6 +312,22 @@ let tool = {
});
},
union(models) {
models = fallback(models);
api.log.emit(`union ${models.length} model(s)`).pin();
worker.model_union(models.map(m => {
return { id: m.id, matrix: m.matrix }
}))
.then(data => {
let group = api.group.new([new mesh.model({
file: `unioned`,
mesh: data
})]).promote();
api.selection.set([group]);
api.log.emit('union complete').unpin();
});
},
duplicate() {
for (let m of selection.models()) {
m.duplicate();

View file

@ -281,8 +281,8 @@ function ui_build() {
h.button({ _: 'visible', onclick() { selection.visible({ toggle: true }) } }),
h.button({ _: 'bounds', onclick() { selection.boundsBox({ toggle: true }) } }),
h.button({ _: 'gridlines', onclick() { api.grid() } }),
h.button({ _: 'wireframe', onclick() { api.wireframe() } }),
h.button({ _: 'normals', onclick() { api.normals() } }),
h.button({ _: 'wireframe', onclick() { api.wireframe() } }),
]),
h.div([
h.div({ _: "edit", class: "head" }),
@ -291,8 +291,8 @@ function ui_build() {
h.button({ _: 'regroup', onclick: tool.regroup }),
h.button({ _: 'merge', onclick: tool.merge }),
h.button({ _: 'mirror', onclick: tool.mirror }),
h.button({ _: 'union', onclick: tool.union }),
h.button({ _: 'split', onclick: call.edit_split }),
h.button({ _: 'invert', onclick: tool.invert }),
]),
h.div([
h.div({ _: "fix", class: "head" }),
@ -300,6 +300,7 @@ function ui_build() {
h.button({ _: 'automatic', onclick: tool.repair }),
h.button({ _: 'analyze', onclick: tool.analyze }),
// h.button({ _: 'rebuild', onclick: tool.rebuild }),
h.button({ _: 'invert', onclick: tool.invert }),
h.button({ _: 'clean', onclick: tool.clean }),
]),
]);