diff --git a/src/geo/base.js b/src/geo/base.js index 2e468fd1..dcace90e 100644 --- a/src/geo/base.js +++ b/src/geo/base.js @@ -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; } diff --git a/src/geo/csg.js b/src/geo/csg.js index 1c76efcf..2554e70f 100644 --- a/src/geo/csg.js +++ b/src/geo/csg.js @@ -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.vertices.flat()) + // .map(a => base.util.triangulate(a, undefined, 3)) + // .flat().toFloat32(); }, // Construct a CSG from a THREE Geometry BufferAttribute array (or similar)