fix triangulation of csg union
This commit is contained in:
parent
fb9e10eb6c
commit
563694a2f1
2 changed files with 26 additions and 8 deletions
|
|
@ -410,6 +410,7 @@ function orderClosest(array, fn, from) {
|
|||
// an unwrapped array in the original dimensions
|
||||
function triangulate(array, holes, dims) {
|
||||
let narray;
|
||||
let info;
|
||||
if (dims === 2) {
|
||||
narray = array;
|
||||
} else {
|
||||
|
|
@ -434,6 +435,7 @@ function triangulate(array, holes, dims) {
|
|||
d1 = i;
|
||||
}
|
||||
}
|
||||
info = { d1, d2, dmax, delta: delta.slice() };
|
||||
delta[d1] = dmax = 0;
|
||||
for (let i = 0; i < dims; i++) {
|
||||
if (delta[i] > dmax) {
|
||||
|
|
@ -455,6 +457,9 @@ function triangulate(array, holes, dims) {
|
|||
oa[e++] = array[ai + j];
|
||||
}
|
||||
}
|
||||
if (oa.length === 0) {
|
||||
console.log('debug_triangulate', {array, oa, info});
|
||||
}
|
||||
return oa;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,13 @@ const CSG = {
|
|||
|
||||
union() {
|
||||
if (debug) {
|
||||
for (let p of [ ...arguments ].map(a => a.polygons.map(p => p.vertices))) {
|
||||
console.log(JSON.stringify(p));
|
||||
}
|
||||
console.log(JSON.stringify([ ...arguments ]));
|
||||
}
|
||||
return jscadModeling.booleans.union(...arguments);
|
||||
let union = jscadModeling.booleans.union(...arguments);
|
||||
if (debug) {
|
||||
console.log(JSON.stringify(union));
|
||||
}
|
||||
return union;
|
||||
},
|
||||
|
||||
subtract() {
|
||||
|
|
@ -29,10 +31,21 @@ const CSG = {
|
|||
},
|
||||
|
||||
toPositionArray(geom) {
|
||||
return geom.polygons
|
||||
.map(p => p.vertices.flat())
|
||||
.map(a => base.util.triangulate(a, undefined, 3))
|
||||
.flat().toFloat32();
|
||||
const out = [];
|
||||
const poly = jscadModeling.geometries.geom3
|
||||
.toPolygons(geom)
|
||||
.map(p => p.vertices);
|
||||
for (let p of poly) {
|
||||
let p0 = p[0];
|
||||
for (let i = 0; i<p.length - 2; i++) {
|
||||
out.push(p0, p[i+1], p[i+2]);
|
||||
}
|
||||
}
|
||||
return out.flat().toFloat32();
|
||||
// return geom.polygons
|
||||
// .map(p => p.vertices.flat())
|
||||
// .map(a => base.util.triangulate(a, undefined, 3))
|
||||
// .flat().toFloat32();
|
||||
},
|
||||
|
||||
// Construct a CSG from a THREE Geometry BufferAttribute array (or similar)
|
||||
|
|
|
|||
Loading…
Reference in a new issue