diff --git a/src2/mesh/api.js b/src2/mesh/api.js index 5faee3d4..75bc7381 100644 --- a/src2/mesh/api.js +++ b/src2/mesh/api.js @@ -135,7 +135,6 @@ const selection = { for (let s of selection.list()) { selection.remove(s); tools.remove(s); - s.showBounds(false); s.remove(); } }, diff --git a/src2/mesh/handles.js b/src2/mesh/handles.js index 66ae53cd..e9e9ee23 100644 --- a/src2/mesh/handles.js +++ b/src2/mesh/handles.js @@ -263,6 +263,50 @@ class TransformTool { get object() { return this.group; } + + activeHandles() { + if (!this.enabled) return []; + // Return an array of objects wrapping each handle + // Each object: { mesh, index, position } + return this.handles.map((mesh, index) => ({ + mesh, + index, + position: mesh.position.clone(), + })); + } + + /** + * Given a handle (from activeHandles) and a drag {delta, offset}, + * compute the new center and size for the bounding box. + * Returns: { center: Vector3, size: Vector3 } + */ + computeDelta(handleObj, { delta, offset }) { + // Get current bounds + if (!this.bounds) return null; + const { min, max } = this.bounds; + const center = min.clone().add(max).multiplyScalar(0.5); + const size = max.clone().sub(min); + + // Which handle is being dragged? + const handleIndex = handleObj.index; + // Get all corners + const corners = this.getCorners(min, max); + // Copy corners so we can mutate + const newCorners = corners.map(c => c.clone()); + // Move the dragged corner by delta + newCorners[handleIndex].add(delta); + + // Compute new min/max from moved corners + let newMin = newCorners[0].clone(); + let newMax = newCorners[0].clone(); + for (let c of newCorners) { + newMin.min(c); + newMax.max(c); + } + const newCenter = newMin.clone().add(newMax).multiplyScalar(0.5); + const newSize = newMax.clone().sub(newMin); + return { center: newCenter, size: newSize }; + } } // Create singleton instance diff --git a/src2/mesh/model.js b/src2/mesh/model.js index d0db826f..098de910 100644 --- a/src2/mesh/model.js +++ b/src2/mesh/model.js @@ -249,15 +249,10 @@ class MeshModel extends meshObject { this.geometry.computeBoundingSphere(); this.log('update-bounds', this.geometry.boundingBox); this.normals({ refresh: true }); - this.updateBoundsBox(); space.update(); this.sync(); } - updateBoundsBox() { - this.group?.updateBoundsBox(); - } - mirror() { return this.duplicate({ mirror: true }); }