diff --git a/src/geo/base.js b/src/geo/base.js index 8326834e..4a19313b 100644 --- a/src/geo/base.js +++ b/src/geo/base.js @@ -465,7 +465,7 @@ // two with the greatest delta to pass to the earcut algorith, then returns // an unwrapped array in the original dimensions function triangulate(array, holes, dims) { - let narray, d1, d2; + let narray; if (dims === 2) { narray = array; } else { @@ -482,8 +482,7 @@ for (let i=0; i dmax) { dmax = delta[i]; @@ -511,7 +510,6 @@ oa[e++] = array[ ai + j ]; } } - console.log({d1, d2, array, narray, ec, oa}); return oa; } diff --git a/src/mesh/api.js b/src/mesh/api.js index df369b68..4c453e45 100644 --- a/src/mesh/api.js +++ b/src/mesh/api.js @@ -405,10 +405,6 @@ let tool = { id: m.id, opt }).then(data => { if (data) { - // mesh.api.group.new([new mesh.model({ - // file: `healed`, - // mesh: data.vertices - // })]).floor().centerXY().setSelected(); m.reload( data.vertices, data.indices, diff --git a/src/mesh/model.js b/src/mesh/model.js index e56ecf07..8855b71c 100644 --- a/src/mesh/model.js +++ b/src/mesh/model.js @@ -162,17 +162,27 @@ mesh.model = class MeshModel extends mesh.object { return; } worker.model_rebuild({ + mode: opt.mode || 'slice', matrix: this.matrix, id: this.id }).then(data => { - let points = []; - for (let i=0; i p.vertices.map(v => v.pos)) - // .map(a => { - // let pa = a.map( v => [ v.x, v.y, v.z ]).flat().map(v => v.round(2)); - // let ec = base.util.triangulate(pa, undefined, 3); - // console.log({pa, ec}); - // return ec; - // });//.flat(); - // - // console.log({solid, inter, ears, ef: ears.flat()}); - // unrolled = ears.flat(); - return { vertices: unrolled.toFloat32(), }; @@ -316,11 +296,30 @@ let model = { }, rebuild(data, send) { - send.async(); let { id, matrix, mode } = data; log(`${id} | rebuilding...`); let points = translate_encode(id, matrix); log(`${id} | ${points.length} points`); + + if (mode === 'csg') { + log(`${id} | intersecting...`); + let box = base.CSG.Solid.fromPositionArray( + new THREE.BoxGeometry(3000, 3000, 3000) + .toNonIndexed().attributes.position.array + ); + let solid = base.CSG.Solid.fromPositionArray(points); + let solution = box.intersect(solid); + let vertices = solution.polygons + .map(p => p.vertices.map(v => v.pos)) + .map(a => { + let pa = a.map( v => [ v.x, v.y, v.z ]).flat(); + let ec = base.util.triangulate(pa, undefined, 3); + return ec; + }).flat().toFloat32(); + return { vertices }; + } + + send.async(); let layers = []; base.slice(points, { autoDim: true, @@ -357,7 +356,7 @@ let model = { }); }).finally(() => { log(`${id} | rebuild complete`); - send.done(layers); + send.done({ lines: layers }); });; } };