wire up basic slicing visualization
This commit is contained in:
parent
5f11231e9e
commit
96f50d36a7
5 changed files with 52 additions and 47 deletions
|
|
@ -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 });
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 }),
|
||||
]),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -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<arr.length-1; i++) {
|
||||
let p1 = arr[i];
|
||||
let p2 = arr[i+1];
|
||||
points.push(new THREE.Vector3().fromArray(p1));
|
||||
points.push(new THREE.Vector3().fromArray(p2));
|
||||
}
|
||||
}
|
||||
let material = new THREE.LineBasicMaterial( { color: 0xdddddd } );
|
||||
let geometry = new THREE.BufferGeometry().setFromPoints(points);
|
||||
let line = new THREE.LineSegments(geometry, material);
|
||||
space.scene.add(line);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -291,16 +291,23 @@ let model = {
|
|||
return { faces, edges, verts, point };
|
||||
},
|
||||
|
||||
rebuild(data) {
|
||||
rebuild(data, send) {
|
||||
send.async();
|
||||
let { id, matrix } = data;
|
||||
log(`${id} | rebuilding...`);
|
||||
let points = translate_encode(id, matrix);
|
||||
log(`${id} | ${points.length} points`);
|
||||
base.slice(points, { flat: true, autoDim: true }).then(sliced => {
|
||||
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);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue