From 1958bd0c5f66503fafa1001fe53e2198c5196f35 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sat, 15 Jan 2022 16:38:50 -0500 Subject: [PATCH] complete proper split in z --- src/main/mesh.js | 1 + src/mesh/model.js | 14 +++++++---- src/mesh/object.js | 4 ++-- src/mesh/work.js | 58 ++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/src/main/mesh.js b/src/main/mesh.js index cb177aaf..9576a4c9 100644 --- a/src/main/mesh.js +++ b/src/main/mesh.js @@ -186,6 +186,7 @@ let split = { space.scene.remove(obj); space.mouse.onHover(undefined); temp_mode = split.state = undefined; + mesh.api.selection.update(); } } diff --git a/src/mesh/model.js b/src/mesh/model.js index 464314d5..74366d27 100644 --- a/src/mesh/model.js +++ b/src/mesh/model.js @@ -340,17 +340,23 @@ mesh.model = class MeshModel extends mesh.object { split(plane) { // extract axes from plane and split when present (only z for now) let { z } = plane; + let m4 = this.mesh.matrix; 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 + if (o2.length) this.group.add(new mesh.model({ file: `${this.file}-split`, - mesh: o2.toFloat32() - })).select(); + mesh: o2 + }).applyMatrix4(m4)).select(); + // this becomes bottom + if (o1.length) { + this.reload(o1); + } else { + this.remove(); + } // and we're done resolve(); }); diff --git a/src/mesh/object.js b/src/mesh/object.js index d8350979..a5ebf31e 100644 --- a/src/mesh/object.js +++ b/src/mesh/object.js @@ -61,11 +61,11 @@ mesh.object = class MeshObject { if (elements) { this.object.applyMatrix4(new Matrix4().fromArray(elements)); } - return this; + return this.matrixChanged(); } applyMatrix4(matrix) { - return this.applyMatrix(matrix.elements).matrixChanged(); + return this.applyMatrix(matrix.elements); } select() { diff --git a/src/mesh/work.js b/src/mesh/work.js index 8ae20507..c33445a6 100644 --- a/src/mesh/work.js +++ b/src/mesh/work.js @@ -37,7 +37,8 @@ function cacheUpdate(id, data) { function translate_encode(id, matrix) { let rec = cache[id]; let geo = rec.geo.clone(); - geo.applyMatrix4(core_matrix.clone().multiply( new Matrix4().fromArray(matrix) )); + let mat = core_matrix.clone().multiply(new Matrix4().fromArray(matrix)); + geo.applyMatrix4(mat); return geo.attributes.position.array; } @@ -87,16 +88,65 @@ let model = { let o1 = []; let o2 = []; let pos = translate_encode(id, matrix); + let split = []; + let on = []; + let over = []; + let under = []; + function sort(v) { + if (v.z < z) return under.push(v); + if (v.z > z) return over.push(v); + on.push(v); + } + function lerp(v1, v2) { + let zd = Math.abs(v1.z - v2.z); + let z1 = Math.abs(v1.z - z); + return v1.clone().lerp(v2, z1/zd); + } for (let i=0, l=pos.length; i