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) {
|
if (zInc) {
|
||||||
for (i = zMin; i < zMax; i += zInc) {
|
for (i = zMin; i <= zMax; i += zInc) {
|
||||||
zIndexes.push(i);
|
zIndexes.push(i);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -97,7 +97,7 @@
|
||||||
|
|
||||||
zScale = 1 / (zMax / bucketCount);
|
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) {
|
if (bucketCount > 1) {
|
||||||
// create empty buckets
|
// create empty buckets
|
||||||
|
|
@ -127,11 +127,6 @@
|
||||||
|
|
||||||
// create buckets data structure
|
// create buckets data structure
|
||||||
for (let i = 0; i < zIndexes.length; i++) {
|
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]);
|
bucketZ(i, zIndexes[i]);
|
||||||
onupdate((i / zIndexes.length) * 0.1);
|
onupdate((i / zIndexes.length) * 0.1);
|
||||||
}
|
}
|
||||||
|
|
@ -145,13 +140,11 @@
|
||||||
async function sliceBuckets() {
|
async function sliceBuckets() {
|
||||||
let output = [];
|
let output = [];
|
||||||
let count = 0;
|
let count = 0;
|
||||||
|
let opt = { ...options, zmin: zMin };
|
||||||
for (let bucket of buckets) {
|
for (let bucket of buckets) {
|
||||||
for (let params of bucket.slices) {
|
let { points, slices } = bucket;
|
||||||
output.push({
|
for (let params of slices) {
|
||||||
slice: sliceZ(params.z, bucket.points, options, params),
|
output.push(sliceZ(params.z, points, opt));
|
||||||
params,
|
|
||||||
options
|
|
||||||
});
|
|
||||||
onupdate(0.1 + (count++ / zIndexes.length) * 0.9);
|
onupdate(0.1 + (count++ / zIndexes.length) * 0.9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -244,7 +237,8 @@
|
||||||
function sliceZ(z, points, options = {}) {
|
function sliceZ(z, points, options = {}) {
|
||||||
let phash = {},
|
let phash = {},
|
||||||
lines = [],
|
lines = [],
|
||||||
p1, p2, p3;
|
p1, p2, p3,
|
||||||
|
zmin = options.zmin;
|
||||||
|
|
||||||
// iterate over matching buckets for this z offset
|
// iterate over matching buckets for this z offset
|
||||||
for (let i = 0; i < points.length; ) {
|
for (let i = 0; i < points.length; ) {
|
||||||
|
|
@ -261,7 +255,7 @@
|
||||||
// one side of triangle is on the Z plane and 3rd is below
|
// one side of triangle is on the Z plane and 3rd is below
|
||||||
// drop lines with 3rd above because that leads to ambiguities
|
// drop lines with 3rd above because that leads to ambiguities
|
||||||
// with complex nested polygons on flat surface
|
// 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));
|
lines.push(makeZLine(phash, where.on[0], where.on[1], false, true));
|
||||||
}
|
}
|
||||||
} else if (where.on.length === 3) {
|
} else if (where.on.length === 3) {
|
||||||
|
|
@ -290,14 +284,9 @@
|
||||||
|
|
||||||
// de-dup and group lines
|
// de-dup and group lines
|
||||||
lines = removeDuplicateLines(lines);
|
lines = removeDuplicateLines(lines);
|
||||||
let groups = connectLines(lines, z, {
|
let groups = connectLines(lines, z, { debug: options.debug });
|
||||||
debug: options.debug,
|
|
||||||
});
|
|
||||||
|
|
||||||
let tops = polygons.nest(groups);
|
return { lines, groups };
|
||||||
let data = { lines, groups, tops };
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -597,24 +586,18 @@
|
||||||
for (let array of connect) {
|
for (let array of connect) {
|
||||||
if (array.delete) continue;
|
if (array.delete) continue;
|
||||||
|
|
||||||
let first = array[0];
|
if (debug) {
|
||||||
let last = array.peek();
|
let first = array[0];
|
||||||
let dist = first.distToSq2D(last);
|
let last = array.peek();
|
||||||
|
let dist = first.distToSq2D(last);
|
||||||
if (debug) console.log({
|
console.log({
|
||||||
dist: dist.round(4),
|
dist: dist.round(4),
|
||||||
merged: array.merged || false,
|
merged: array.merged || false,
|
||||||
array
|
array
|
||||||
});
|
});
|
||||||
if (dist <= bridge) {
|
|
||||||
// tail meets head (close)
|
|
||||||
emit(newPolygon().addPoints(array));
|
|
||||||
} else {
|
|
||||||
// tail meets head (far)
|
|
||||||
emit(newPolygon().addPoints(array)
|
|
||||||
// .setOpen()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit(newPolygon().addPoints(array));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) console.log({ emitted });
|
if (debug) console.log({ emitted });
|
||||||
|
|
|
||||||
|
|
@ -286,6 +286,7 @@ function space_init(data) {
|
||||||
case 'KeyA':
|
case 'KeyA':
|
||||||
return api.tool.analyze();
|
return api.tool.analyze();
|
||||||
case 'KeyR':
|
case 'KeyR':
|
||||||
|
if (shiftKey) return api.tool.rebuild();
|
||||||
return api.tool.repair();
|
return api.tool.repair();
|
||||||
case 'KeyE':
|
case 'KeyE':
|
||||||
return api.tool.clean();
|
return api.tool.clean();
|
||||||
|
|
|
||||||
|
|
@ -299,7 +299,7 @@ function ui_build() {
|
||||||
// h.div({ class: "vsep" }),
|
// h.div({ class: "vsep" }),
|
||||||
h.button({ _: 'automatic', onclick: tool.repair }),
|
h.button({ _: 'automatic', onclick: tool.repair }),
|
||||||
h.button({ _: 'analyze', onclick: tool.analyze }),
|
h.button({ _: 'analyze', onclick: tool.analyze }),
|
||||||
h.button({ _: 'rebuild', onclick: tool.rebuild }),
|
// h.button({ _: 'rebuild', onclick: tool.rebuild }),
|
||||||
h.button({ _: 'clean', onclick: tool.clean }),
|
h.button({ _: 'clean', onclick: tool.clean }),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,21 @@ mesh.model = class MeshModel extends mesh.object {
|
||||||
matrix: this.matrix,
|
matrix: this.matrix,
|
||||||
id: this.id
|
id: this.id
|
||||||
}).then(data => {
|
}).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 };
|
return { faces, edges, verts, point };
|
||||||
},
|
},
|
||||||
|
|
||||||
rebuild(data) {
|
rebuild(data, send) {
|
||||||
|
send.async();
|
||||||
let { id, matrix } = data;
|
let { id, matrix } = data;
|
||||||
log(`${id} | rebuilding...`);
|
log(`${id} | rebuilding...`);
|
||||||
let points = translate_encode(id, matrix);
|
let points = translate_encode(id, matrix);
|
||||||
log(`${id} | ${points.length} points`);
|
log(`${id} | ${points.length} points`);
|
||||||
base.slice(points, { flat: true, autoDim: true }).then(sliced => {
|
base.slice(points, { flat: true, autoDim: true, zinc: 0 })
|
||||||
console.log({sliced});
|
.then(sliced => {
|
||||||
log(`${id} | ${sliced.length} slices`);
|
let layers = [];
|
||||||
});
|
log(`${id} | ${sliced.length} slices`);
|
||||||
return [];
|
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