From e009cf5af9688b4affe4e41c0429e1e66ced5501 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sat, 15 Jan 2022 15:04:53 -0500 Subject: [PATCH] implement crude/inaccruate/test split --- src/main/mesh.js | 15 ++++++++------- src/mesh/model.js | 25 +++++++++++++++++++++++-- src/mesh/work.js | 19 +++++++++++++++++++ 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/main/mesh.js b/src/main/mesh.js index ec8f9e05..cb177aaf 100644 --- a/src/main/mesh.js +++ b/src/main/mesh.js @@ -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() { diff --git a/src/mesh/model.js b/src/mesh/model.js index 4c6d75e0..464314d5 100644 --- a/src/mesh/model.js +++ b/src/mesh/model.js @@ -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) { diff --git a/src/mesh/work.js b/src/mesh/work.js index 4b2993c2..9b30819a 100644 --- a/src/mesh/work.js +++ b/src/mesh/work.js @@ -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