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
|
// two with the greatest delta to pass to the earcut algorith, then returns
|
||||||
// an unwrapped array in the original dimensions
|
// an unwrapped array in the original dimensions
|
||||||
function triangulate(array, holes, dims) {
|
function triangulate(array, holes, dims) {
|
||||||
let narray, d1, d2;
|
let narray;
|
||||||
if (dims === 2) {
|
if (dims === 2) {
|
||||||
narray = array;
|
narray = array;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -482,8 +482,7 @@
|
||||||
for (let i=0; i<dims; i++) {
|
for (let i=0; i<dims; i++) {
|
||||||
delta[i] = max[i] - min[i];
|
delta[i] = max[i] - min[i];
|
||||||
}
|
}
|
||||||
console.log({delta: delta.slice()});
|
let dmax = 0, d1, d2;
|
||||||
let dmax = 0; //d1, d2, dmax = 0;
|
|
||||||
for (let i=0; i<dims; i++) {
|
for (let i=0; i<dims; i++) {
|
||||||
if (delta[i] > dmax) {
|
if (delta[i] > dmax) {
|
||||||
dmax = delta[i];
|
dmax = delta[i];
|
||||||
|
|
@ -511,7 +510,6 @@
|
||||||
oa[e++] = array[ ai + j ];
|
oa[e++] = array[ ai + j ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log({d1, d2, array, narray, ec, oa});
|
|
||||||
return oa;
|
return oa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -405,10 +405,6 @@ let tool = {
|
||||||
id: m.id, opt
|
id: m.id, opt
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
if (data) {
|
if (data) {
|
||||||
// mesh.api.group.new([new mesh.model({
|
|
||||||
// file: `healed`,
|
|
||||||
// mesh: data.vertices
|
|
||||||
// })]).floor().centerXY().setSelected();
|
|
||||||
m.reload(
|
m.reload(
|
||||||
data.vertices,
|
data.vertices,
|
||||||
data.indices,
|
data.indices,
|
||||||
|
|
|
||||||
|
|
@ -162,17 +162,27 @@ mesh.model = class MeshModel extends mesh.object {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
worker.model_rebuild({
|
worker.model_rebuild({
|
||||||
|
mode: opt.mode || 'slice',
|
||||||
matrix: this.matrix,
|
matrix: this.matrix,
|
||||||
id: this.id
|
id: this.id
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
|
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 = [];
|
let points = [];
|
||||||
for (let i=0; i<data.length;) {
|
for (let i=0; i<lines.length;) {
|
||||||
points.push(new THREE.Vector3(data[i++], data[i++], data[i++]));
|
points.push(new THREE.Vector3(lines[i++], lines[i++], lines[i++]));
|
||||||
}
|
}
|
||||||
let material = new THREE.LineBasicMaterial( { color: 0xdddddd } );
|
let material = new THREE.LineBasicMaterial( { color: 0xdddddd } );
|
||||||
let geometry = new THREE.BufferGeometry().setFromPoints(points);
|
let geometry = new THREE.BufferGeometry().setFromPoints(points);
|
||||||
let lines = this.lines = new THREE.LineSegments(geometry, material);
|
let segments = this.lines = new THREE.LineSegments(geometry, material);
|
||||||
space.scene.add(lines);
|
space.scene.add(segments);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -245,26 +245,6 @@ let model = {
|
||||||
let tool = analyze(id, opt);
|
let tool = analyze(id, opt);
|
||||||
log(`${id} | unrolling...`);
|
log(`${id} | unrolling...`);
|
||||||
let unrolled = tool.unrolled();
|
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 {
|
return {
|
||||||
vertices: unrolled.toFloat32(),
|
vertices: unrolled.toFloat32(),
|
||||||
};
|
};
|
||||||
|
|
@ -316,11 +296,30 @@ let model = {
|
||||||
},
|
},
|
||||||
|
|
||||||
rebuild(data, send) {
|
rebuild(data, send) {
|
||||||
send.async();
|
|
||||||
let { id, matrix, mode } = data;
|
let { id, matrix, mode } = 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`);
|
||||||
|
|
||||||
|
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 = [];
|
let layers = [];
|
||||||
base.slice(points, {
|
base.slice(points, {
|
||||||
autoDim: true,
|
autoDim: true,
|
||||||
|
|
@ -357,7 +356,7 @@ let model = {
|
||||||
});
|
});
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
log(`${id} | rebuild complete`);
|
log(`${id} | rebuild complete`);
|
||||||
send.done(layers);
|
send.done({ lines: layers });
|
||||||
});;
|
});;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue