diff --git a/src/geo/slicer.js b/src/geo/slicer.js index 28187953..1e02a6ce 100644 --- a/src/geo/slicer.js +++ b/src/geo/slicer.js @@ -76,7 +76,7 @@ } if (zInc) { - for (i = zMin; i < zMax; i += zInc) { + for (i = zMin; i <= zMax; i += zInc) { zIndexes.push(i); } } else { @@ -97,7 +97,7 @@ zScale = 1 / (zMax / bucketCount); - console.log({zMin, zMax, zIndexes, points, bucketCount, zScale, zSum}); + // console.log({zMin, zMax, zIndexes, points, bucketCount, zScale, zSum}); if (bucketCount > 1) { // create empty buckets @@ -127,11 +127,6 @@ // create buckets data structure for (let i = 0; i < zIndexes.length; i++) { - let ik = zIndexes[i].toFixed(5); - // ensure no slice through horizontal lines or planes - if (zFlat[ik]) { - zIndexes[i] -= -0.001; - } bucketZ(i, zIndexes[i]); onupdate((i / zIndexes.length) * 0.1); } @@ -145,13 +140,11 @@ async function sliceBuckets() { let output = []; let count = 0; + let opt = { ...options, zmin: zMin }; for (let bucket of buckets) { - for (let params of bucket.slices) { - output.push({ - slice: sliceZ(params.z, bucket.points, options, params), - params, - options - }); + let { points, slices } = bucket; + for (let params of slices) { + output.push(sliceZ(params.z, points, opt)); onupdate(0.1 + (count++ / zIndexes.length) * 0.9); } } @@ -244,7 +237,8 @@ function sliceZ(z, points, options = {}) { let phash = {}, lines = [], - p1, p2, p3; + p1, p2, p3, + zmin = options.zmin; // iterate over matching buckets for this z offset for (let i = 0; i < points.length; ) { @@ -261,7 +255,7 @@ // one side of triangle is on the Z plane and 3rd is below // drop lines with 3rd above because that leads to ambiguities // with complex nested polygons on flat surface - if (where.under.length === 1) { + if (where.under.length === 1 || z === zmin) { lines.push(makeZLine(phash, where.on[0], where.on[1], false, true)); } } else if (where.on.length === 3) { @@ -290,14 +284,9 @@ // de-dup and group lines lines = removeDuplicateLines(lines); - let groups = connectLines(lines, z, { - debug: options.debug, - }); + let groups = connectLines(lines, z, { debug: options.debug }); - let tops = polygons.nest(groups); - let data = { lines, groups, tops }; - - return data; + return { lines, groups }; } /** @@ -597,24 +586,18 @@ for (let array of connect) { if (array.delete) continue; - let first = array[0]; - let last = array.peek(); - let dist = first.distToSq2D(last); - - if (debug) console.log({ - dist: dist.round(4), - merged: array.merged || false, - array - }); - if (dist <= bridge) { - // tail meets head (close) - emit(newPolygon().addPoints(array)); - } else { - // tail meets head (far) - emit(newPolygon().addPoints(array) - // .setOpen() - ); + if (debug) { + let first = array[0]; + let last = array.peek(); + let dist = first.distToSq2D(last); + console.log({ + dist: dist.round(4), + merged: array.merged || false, + array + }); } + + emit(newPolygon().addPoints(array)); } if (debug) console.log({ emitted }); diff --git a/src/main/mesh.js b/src/main/mesh.js index 138be903..58018194 100644 --- a/src/main/mesh.js +++ b/src/main/mesh.js @@ -286,6 +286,7 @@ function space_init(data) { case 'KeyA': return api.tool.analyze(); case 'KeyR': + if (shiftKey) return api.tool.rebuild(); return api.tool.repair(); case 'KeyE': return api.tool.clean(); diff --git a/src/mesh/build.js b/src/mesh/build.js index f2120661..bc5dae63 100644 --- a/src/mesh/build.js +++ b/src/mesh/build.js @@ -299,7 +299,7 @@ function ui_build() { // h.div({ class: "vsep" }), h.button({ _: 'automatic', onclick: tool.repair }), h.button({ _: 'analyze', onclick: tool.analyze }), - h.button({ _: 'rebuild', onclick: tool.rebuild }), + // h.button({ _: 'rebuild', onclick: tool.rebuild }), h.button({ _: 'clean', onclick: tool.clean }), ]), ]); diff --git a/src/mesh/model.js b/src/mesh/model.js index c7051542..0d41df30 100644 --- a/src/mesh/model.js +++ b/src/mesh/model.js @@ -158,7 +158,21 @@ mesh.model = class MeshModel extends mesh.object { matrix: this.matrix, id: this.id }).then(data => { - console.log({rebuild: this.od, data}); + console.log({rebuild: this.id, data}); + let points = []; + for (let arr of data) { + arr.push(arr[0]); + for (let i=0; i { - console.log({sliced}); - log(`${id} | ${sliced.length} slices`); - }); - return []; + base.slice(points, { flat: true, autoDim: true, zinc: 0 }) + .then(sliced => { + let layers = []; + log(`${id} | ${sliced.length} slices`); + for (let slice of sliced) { + for (let poly of slice.groups) { + layers.push(poly.points.map(p => [ p.x, p.y, p.z ])); + } + } + send.done(layers); + }); } };