add boolean intersect
This commit is contained in:
parent
df3d3941c8
commit
275666459e
3 changed files with 27 additions and 3 deletions
|
|
@ -79,7 +79,7 @@ const selection = {
|
||||||
// if model, remove selcted group
|
// if model, remove selcted group
|
||||||
if (selected.contains(object.group)) {
|
if (selected.contains(object.group)) {
|
||||||
selection.remove(object.group);
|
selection.remove(object.group);
|
||||||
tools.remove(objec.group);
|
tools.remove(object.group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selected.addOnce(object);
|
selected.addOnce(object);
|
||||||
|
|
@ -369,7 +369,7 @@ const tool = {
|
||||||
}))
|
}))
|
||||||
.then(data => {
|
.then(data => {
|
||||||
let group = api.group.new([new mesh.model({
|
let group = api.group.new([new mesh.model({
|
||||||
file: `unioned`,
|
file: `union`,
|
||||||
mesh: data
|
mesh: data
|
||||||
})]).promote();
|
})]).promote();
|
||||||
api.selection.set([group]);
|
api.selection.set([group]);
|
||||||
|
|
@ -377,6 +377,22 @@ const tool = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
intersect(models) {
|
||||||
|
models = fallback(models);
|
||||||
|
api.log.emit(`intersect ${models.length} model(s)`).pin();
|
||||||
|
worker.model_intersect(models.map(m => {
|
||||||
|
return { id: m.id, matrix: m.matrix }
|
||||||
|
}))
|
||||||
|
.then(data => {
|
||||||
|
let group = api.group.new([new mesh.model({
|
||||||
|
file: `intersect`,
|
||||||
|
mesh: data
|
||||||
|
})]).promote();
|
||||||
|
api.selection.set([group]);
|
||||||
|
api.log.emit('intersect complete').unpin();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
subtract(models) {
|
subtract(models) {
|
||||||
models = fallback(models);
|
models = fallback(models);
|
||||||
api.log.emit(`subtract ${models.length} model(s)`).pin();
|
api.log.emit(`subtract ${models.length} model(s)`).pin();
|
||||||
|
|
@ -385,7 +401,7 @@ const tool = {
|
||||||
}))
|
}))
|
||||||
.then(data => {
|
.then(data => {
|
||||||
let group = api.group.new([new mesh.model({
|
let group = api.group.new([new mesh.model({
|
||||||
file: `subtracted`,
|
file: `subtract`,
|
||||||
mesh: data
|
mesh: data
|
||||||
})]).promote();
|
})]).promote();
|
||||||
api.selection.set([group]);
|
api.selection.set([group]);
|
||||||
|
|
|
||||||
|
|
@ -382,6 +382,7 @@ function ui_build() {
|
||||||
h.div({ _: "bool", class: "head" }),
|
h.div({ _: "bool", class: "head" }),
|
||||||
h.button({ _: 'union', onclick: tool.union }),
|
h.button({ _: 'union', onclick: tool.union }),
|
||||||
h.button({ _: 'subtract', onclick: tool.subtract }),
|
h.button({ _: 'subtract', onclick: tool.subtract }),
|
||||||
|
h.button({ _: 'intersect', onclick: tool.intersect }),
|
||||||
]),
|
]),
|
||||||
h.div([
|
h.div([
|
||||||
h.div({ _: "normal", class: "head" }),
|
h.div({ _: "normal", class: "head" }),
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,13 @@ let model = {
|
||||||
return base.CSG.toPositionArray(union);
|
return base.CSG.toPositionArray(union);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
intersect(recs) {
|
||||||
|
let arrays = recs.map(rec => translate_encode(rec.id, rec.matrix));
|
||||||
|
let solids = arrays.map(a => base.CSG.fromPositionArray(a));
|
||||||
|
let union = base.CSG.intersect(...solids);
|
||||||
|
return base.CSG.toPositionArray(union);
|
||||||
|
},
|
||||||
|
|
||||||
subtract(recs) {
|
subtract(recs) {
|
||||||
let bases = recs.filter(rec => !rec.tool)
|
let bases = recs.filter(rec => !rec.tool)
|
||||||
.map(rec => translate_encode(rec.id, rec.matrix))
|
.map(rec => translate_encode(rec.id, rec.matrix))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue