fix negative slice spans, error handling in promise chain, rebuild cleanup

This commit is contained in:
Stewart Allen 2022-01-27 12:29:48 -05:00
commit 6485e54280
4 changed files with 23 additions and 17 deletions

View file

@ -106,11 +106,6 @@
}
}
/** short-circuit for microscopic and invalid objects */
if (zMax == 0 || zSum == 0 || points.length == 0) {
return [];
}
/**
* bucket polygons into z-bounded groups (inside or crossing)
* to reduce the search space in complex models
@ -130,6 +125,11 @@
});
}
/** short-circuit for microscopic and invalid objects */
if (zSpan == 0 || zSum == 0 || points.length == 0) {
return {};
}
// create empty buckets
for (i = 0; i < bucketCount + 1; i++) {
buckets.push({ points: [], slices: [] });

View file

@ -113,7 +113,7 @@ let selection = {
selection.remove(s);
}
for (let m of api.model.list()) {
m.clearSelections()
m.clearSelections();
}
},

View file

@ -153,20 +153,26 @@ mesh.model = class MeshModel extends mesh.object {
});
}
rebuild() {
rebuild(opt = {}) {
if (this.lines) {
space.scene.remove(this.lines);
this.lines = undefined;
}
if (opt.clean) {
return;
}
worker.model_rebuild({
matrix: this.matrix,
id: this.id
}).then(data => {
console.log({rebuild: this.id, data});
let points = [];
for (let i=0; i<data.length;) {
points.push(new THREE.Vector3(data[i++], data[i++], data[i++]));
}
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);
let lines = this.lines = new THREE.LineSegments(geometry, material);
space.scene.add(lines);
});
}
@ -463,6 +469,7 @@ mesh.model = class MeshModel extends mesh.object {
// clear face selections (since they've been deleted);
this.sel.faces = [];
this.updateSelections();
this.rebuild({ clean: true });
}
deleteSelections(mode) {

View file

@ -299,15 +299,14 @@ let model = {
log(`${id} | rebuilding...`);
let points = translate_encode(id, matrix);
log(`${id} | ${points.length} points`);
let layers = [];
base.slice(points, {
autoDim: true,
flat: true,
zinc: 0,
both: true,
// debug: true,
minstep: 0.25,
}).then(output => {
let layers = [];
let { points, slices } = output;
log(`${id} | ${slices.length} slices Z`);
for (let slice of slices) {
@ -316,11 +315,9 @@ let model = {
layers.appendAll(util.extract(line.p2));
}
}
// send.done(layers);
for (let p of points) p.swapXZ();
base.slice(points, {
return base.slice(points, {
autoDim: true,
zinc: 0,
both: true,
// debug: true,
minstep: 0.25,
@ -335,9 +332,11 @@ let model = {
layers.appendAll(util.extract(line.p2));
}
}
send.done(layers);
});
});
}).finally(() => {
log(`${id} | rebuild complete`);
send.done(layers);
});;
}
};