Tracking geometry across union
and decompose
#1030
-
I have a bunch of geometries that I'm constructing, some of which overlap, which I Will this always work and is it the best approach? For context, a minimal example I was experimenting with on the ManifoldCAD. const {cube, sphere} = Manifold;
const idToIndex = {}
const boxes = [
// These two will get combined
cube([10, 2, 1]),
cube([2, 10, 1]),
// This one will be different
cube([3, 3, 1]).translate(5,5)
].map((b, idx) => {
const uniq = b.asOriginal();
idToIndex[uniq.originalID()] = idx;
return uniq;
});
const all = Manifold.union(boxes);
const parts = all.decompose();
// Maps the decomposed parts index back to the indices in the original boxes array
const mapping = new Array(parts.length);
for (let i = 0; i < parts.length; i++) {
const mesh = parts[i].getMesh();
mapping[i] = [];
for (let run = 0; run < mesh.numRun; run++) {
if (mesh.runIndex[run] !== mesh.runIndex[run+1]) {
const originalIndex = idToIndex[mesh.runOriginalID[run]];
mapping[i].push(originalIndex);
}
}
console.log(`decomposed part ${i} contains boxes: [ ${mapping[i].join(',')} ]`)
}
let result = all; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yup, that's exactly how our IDs are meant to be used. Certainly should always work - if not, please file an issue. |
Beta Was this translation helpful? Give feedback.
Yup, that's exactly how our IDs are meant to be used. Certainly should always work - if not, please file an issue.