From 2a64dee448d4b5dbb813dbb068f91ec13c8c1623 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 13 Jan 2022 00:45:20 -0500 Subject: [PATCH] translate point into mesh geometry space --- src/main/mesh.js | 1 + src/mesh/work.js | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/mesh.js b/src/main/mesh.js index 16be54df..a2ff4ef1 100644 --- a/src/main/mesh.js +++ b/src/main/mesh.js @@ -260,6 +260,7 @@ function space_init(data) { if (shiftKey && metaKey) { // find faces adjacent to point/line clicked model.select(int.point, int.face); + // console.log(int); } else if (metaKey) { // set focus on intersected face let { x, y, z } = int.point; diff --git a/src/mesh/work.js b/src/mesh/work.js index 3bff726d..55830674 100644 --- a/src/mesh/work.js +++ b/src/mesh/work.js @@ -103,28 +103,41 @@ let model = { // given model and point, locate matching vertices, lines, and faces select(data) { let { id, x, y, z, a, b, c, matrix } = data; - let arr = translate_encode(id, matrix); - let eps = 2; + // translate point into mesh matrix space + let v3 = new Vector3(x,y,z).applyMatrix4( + core_matrix.clone().multiply(new Matrix4().fromArray(matrix)).invert() + ); + x = v3.x; y = v3.y; z = v3.z; + let arr = cache[id].geo.attributes.position.array; + // distance tolerance for click to vertex (rough distance) + let eps = 1; + let faces = []; for (let i=0, l=arr.length; i