From 8cd2a22a5444e72ade17bea69f991616a406a842 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sat, 1 Jan 2022 10:44:06 -0500 Subject: [PATCH] explore rotation and bounds --- src/main/mesh.js | 5 +++++ src/mesh/api.js | 14 ++++++++++++-- src/mesh/object.js | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/mesh.js b/src/main/mesh.js index aa6939c1..bc38b458 100644 --- a/src/main/mesh.js +++ b/src/main/mesh.js @@ -127,7 +127,12 @@ broker.subscribe('space_init', data => { let q = new THREE.Quaternion(); // find intersecting point, look "up" on Z and rotate to face that q.setFromUnitVectors(int.face.normal, new THREE.Vector3(0,0,-1)); + // let e = new THREE.Euler().setFromQuaternion(q); + // let n = int.face.normal; + // console.log({n,q,e}); + // group.rotation(e.x, e.y, e.z); group.qrotate(q); + group.floor(); } else { api.selection.toggle(model.group); } diff --git a/src/mesh/api.js b/src/mesh/api.js index 71a8fd1d..d7bc6888 100644 --- a/src/mesh/api.js +++ b/src/mesh/api.js @@ -78,6 +78,13 @@ let selection = { return selection; }, + qrotate(q) { + for (let s of selected) { + s.qrotate(q); + } + return selection; + }, + scale(dx = 0, dy = 0, dz = 0) { for (let s of selected) { let { x, y, z } = s.scale(); @@ -192,9 +199,12 @@ let util = mesh.util = { let box = new THREE.Box3(); if (Array.isArray(object)) { for (let o of object) { - box.union(new THREE.Box3().setFromObject( + box.expandByObject( o instanceof mesh.object ? o.object() : o - )); + ); + // box.union(new THREE.Box3().setFromObject( + // o instanceof mesh.object ? o.object() : o + // )); } } else if (object) { box.setFromObject( diff --git a/src/mesh/object.js b/src/mesh/object.js index 29d113d5..ab87d49a 100644 --- a/src/mesh/object.js +++ b/src/mesh/object.js @@ -69,16 +69,21 @@ mesh.object = class MeshObject { } rot.set(...arguments); moto.Space.update(); + return this; } rotate(x = 0, y = 0, z = 0) { if (x) this.object().rotateOnWorldAxis(new THREE.Vector3(1,0,0), x); if (y) this.object().rotateOnWorldAxis(new THREE.Vector3(0,1,0), y); if (z) this.object().rotateOnWorldAxis(new THREE.Vector3(0,0,1), z); + moto.Space.update(); + return this; } qrotate(quaternion) { this.object().setRotationFromQuaternion(quaternion); + moto.Space.update(); + return this; } position() {