fix box array for union/intersect
This commit is contained in:
parent
78a2e0a35e
commit
8e731a01ef
4 changed files with 40 additions and 37 deletions
|
|
@ -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<dims; i++) {
|
||||
delta[i] = max[i] - min[i];
|
||||
}
|
||||
console.log({delta: delta.slice()});
|
||||
let dmax = 0; //d1, d2, dmax = 0;
|
||||
let dmax = 0, d1, d2;
|
||||
for (let i=0; i<dims; i++) {
|
||||
if (delta[i] > dmax) {
|
||||
dmax = delta[i];
|
||||
|
|
@ -511,7 +510,6 @@
|
|||
oa[e++] = array[ ai + j ];
|
||||
}
|
||||
}
|
||||
console.log({d1, d2, array, narray, ec, oa});
|
||||
return oa;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<data.length;) {
|
||||
points.push(new THREE.Vector3(data[i++], data[i++], data[i++]));
|
||||
let { vertices, lines } = data;
|
||||
if (vertices) {
|
||||
mesh.api.group.new([new mesh.model({
|
||||
file: `healed`,
|
||||
mesh: data.vertices
|
||||
})]).floor().centerXY().setSelected();
|
||||
}
|
||||
if (lines) {
|
||||
let points = [];
|
||||
for (let i=0; i<lines.length;) {
|
||||
points.push(new THREE.Vector3(lines[i++], lines[i++], lines[i++]));
|
||||
}
|
||||
let material = new THREE.LineBasicMaterial( { color: 0xdddddd } );
|
||||
let geometry = new THREE.BufferGeometry().setFromPoints(points);
|
||||
let segments = this.lines = new THREE.LineSegments(geometry, material);
|
||||
space.scene.add(segments);
|
||||
}
|
||||
let material = new THREE.LineBasicMaterial( { color: 0xdddddd } );
|
||||
let geometry = new THREE.BufferGeometry().setFromPoints(points);
|
||||
let lines = this.lines = new THREE.LineSegments(geometry, material);
|
||||
space.scene.add(lines);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -245,26 +245,6 @@ let model = {
|
|||
let tool = analyze(id, opt);
|
||||
log(`${id} | unrolling...`);
|
||||
let unrolled = tool.unrolled();
|
||||
|
||||
// log(`${id} | intersecting...`);
|
||||
// let box = new THREE.BoxGeometry(10000, 10000, 10000).attributes.position.array;
|
||||
// box = base.CSG.Solid.fromPositionArray(box);
|
||||
//
|
||||
// let solid = base.CSG.Solid.fromPositionArray(unrolled);
|
||||
// // let inter = box.intersect(solid);
|
||||
// let inter = solid.union(solid.clone());
|
||||
// let ears = inter.polygons
|
||||
// .map(p => 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 });
|
||||
});;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue