abstract csg ops. add error handling in client
This commit is contained in:
parent
7daeaaba91
commit
d61600fbee
2 changed files with 26 additions and 23 deletions
|
|
@ -13,9 +13,27 @@ const CSG = {
|
|||
|
||||
// accepts 2 or more arguments with threejs vertex position arrays
|
||||
union() {
|
||||
mesh.log(`manifold.union ${arguments.length} meshes`);
|
||||
const args = [...arguments].map(a => new Module.Manifold(a));
|
||||
const result = Module.union(...args);
|
||||
return CSG.moduleOp('manifold.union', 'union', ...arguments);
|
||||
},
|
||||
|
||||
// accepts 2 or more arguments with threejs vertex position arrays
|
||||
// the fist argument is the target mesh. the rest are negatives
|
||||
subtract() {
|
||||
return CSG.moduleOp('manifold.subtract', 'difference', ...arguments);
|
||||
},
|
||||
|
||||
// accepts 2 or more arguments with threejs vertex position arrays
|
||||
intersect() {
|
||||
return CSG.moduleOp('manifold.intersect', 'intersection', ...arguments);
|
||||
},
|
||||
|
||||
moduleOp(name, op) {
|
||||
mesh.log(`${name} ${arguments.length} meshes`);
|
||||
const args = [...arguments].slice(2).map(a => new Module.Manifold(a));
|
||||
if (args.length < 2) {
|
||||
throw "missing one or more meshes";
|
||||
}
|
||||
const result = Module[op](...args);
|
||||
const output = result.getMesh({ mode: 2 });
|
||||
const errors = [ ...args, result ].map(m => m.status().value);
|
||||
for (let m of [ ...args, result ]) {
|
||||
|
|
@ -27,31 +45,6 @@ const CSG = {
|
|||
return output;
|
||||
},
|
||||
|
||||
// accepts 2 or more arguments with threejs vertex position arrays
|
||||
// the fist argument is the target mesh. the rest are negatives
|
||||
subtract() {
|
||||
mesh.log(`manifold.subtract ${arguments.length} meshes`);
|
||||
const args = [...arguments].map(a => new Module.Manifold(a));
|
||||
const result = Module.difference(...args);
|
||||
const output = result.getMesh({ mode: 2 });
|
||||
for (let m of [ ...args, result ]) {
|
||||
m.delete();
|
||||
}
|
||||
return output;
|
||||
},
|
||||
|
||||
// accepts 2 or more arguments with threejs vertex position arrays
|
||||
intersect() {
|
||||
mesh.log(`manifold.intersect ${arguments.length} meshes`);
|
||||
const args = [...arguments].map(a => new Module.Manifold(a));
|
||||
const result = Module.intersection(...args);
|
||||
const output = result.getMesh({ mode: 2 });
|
||||
for (let m of [ ...args, result ]) {
|
||||
m.delete();
|
||||
}
|
||||
return output;
|
||||
},
|
||||
|
||||
toPositionArray(mesh) {
|
||||
const { vertPos, triVerts, vertex, index } = mesh;
|
||||
if (vertex) {
|
||||
|
|
|
|||
|
|
@ -428,6 +428,11 @@ const tool = {
|
|||
mesh: data
|
||||
})]).promote();
|
||||
api.selection.set([group]);
|
||||
})
|
||||
.catch(error => {
|
||||
api.log.emit(`intersect error: ${error}`);
|
||||
})
|
||||
.finally(() => {
|
||||
api.log.emit('intersect complete').unpin();
|
||||
});
|
||||
},
|
||||
|
|
@ -447,6 +452,11 @@ const tool = {
|
|||
mesh: data
|
||||
})]).promote();
|
||||
api.selection.set([group]);
|
||||
})
|
||||
.catch(error => {
|
||||
api.log.emit(`subtract error: ${error}`);
|
||||
})
|
||||
.finally(() => {
|
||||
api.log.emit('subtract complete').unpin();
|
||||
});
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue