implement crude/inaccruate/test split

This commit is contained in:
Stewart Allen 2022-01-15 15:04:53 -05:00
commit e009cf5af9
3 changed files with 50 additions and 9 deletions

View file

@ -155,17 +155,19 @@ let split = {
let state = split.state = { button, obj };
// for split and lay flat modes
space.mouse.onHover((int, event, ints) => {
let models = api.selection.models().map(m => m.mesh);
let models = state.models = api.selection.models();
let meshes = models.map(m => m.mesh);
if (!event) {
return models;
return meshes;
}
let { button, buttons } = event;
if (buttons) {
return;
}
let { dim, mid } = util.bounds(models);
let { dim, mid } = util.bounds(meshes);
let { x, y, z } = int.point;
state.point = { x, y, z };
// y is z in model space for the purposes of a split
state.plane = { z: y };
obj.scale.set(dim.x, dim.y, 1);
obj.position.set(mid.x, y, -mid.y);
});
@ -173,9 +175,8 @@ let split = {
},
select() {
// select plane (also exec)
console.log({select_plane: split.state});
split.end();
let { models, plane } = split.state;
Promise.all(models.map(m => m.split(plane))).then(split.end);
},
end() {

View file

@ -31,7 +31,7 @@ let materials = mesh.material = {
transparent: true,
shininess: 100,
specular: 0x202020,
color: 0xffff00,
color: 0xf0f000,
opacity: 1
}),
// model selected
@ -40,7 +40,7 @@ let materials = mesh.material = {
transparent: true,
shininess: 100,
specular: 0x202020,
color: 0x00ee00,
color: 0x00e000,
opacity: 1
}),
// face selected (for groups ranges)
@ -336,6 +336,27 @@ mesh.model = class MeshModel extends mesh.object {
if (this._norm) this._norm.update();
}
// split model along given plane
split(plane) {
// extract axes from plane and split when present (only z for now)
let { z } = plane;
return new Promise((resolve,reject) => {
let { id, matrix } = this;
worker.model_split({id, matrix, z}).then(data => {
let { o1, o2 } = data;
// this becomes bottom
this.reload(o1.toFloat32());
// new model becomes top
this.group.add(new mesh.model({
file: `${this.file}-split`,
mesh: o2.toFloat32()
})).select();
// and we're done
resolve();
});
});
}
// remove model from group and space
remove() {
if (arguments.length === 0) {

View file

@ -82,6 +82,25 @@ let model = {
return data;
},
split(data) {
let { id, matrix, z } = data;
let o1 = [];
let o2 = [];
// let pos = translate_encode(id, matrix);
let pos = cache[id].geo.attributes.position.array;
for (let i=0, l=pos.length; i<l; ) {
let v1 = new Vector3(pos[i++], pos[i++], pos[i++]);
let v2 = new Vector3(pos[i++], pos[i++], pos[i++]);
let v3 = new Vector3(pos[i++], pos[i++], pos[i++]);
if (v1.z < z && v2.z < z && v3.z < z) {
o1.appendAll([...v1, ...v2, ...v3]);
} else {
o2.appendAll([...v1, ...v2, ...v3]);
}
}
return { o1, o2 };
},
analyze(id) {
let tool = analyze(id, { mapped: true });
let { stats, mapped } = tool;