add handles helper
This commit is contained in:
parent
c71f6099df
commit
47ea0328d0
3 changed files with 44 additions and 6 deletions
|
|
@ -135,7 +135,6 @@ const selection = {
|
||||||
for (let s of selection.list()) {
|
for (let s of selection.list()) {
|
||||||
selection.remove(s);
|
selection.remove(s);
|
||||||
tools.remove(s);
|
tools.remove(s);
|
||||||
s.showBounds(false);
|
|
||||||
s.remove();
|
s.remove();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -263,6 +263,50 @@ class TransformTool {
|
||||||
get object() {
|
get object() {
|
||||||
return this.group;
|
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
|
// Create singleton instance
|
||||||
|
|
|
||||||
|
|
@ -249,15 +249,10 @@ class MeshModel extends meshObject {
|
||||||
this.geometry.computeBoundingSphere();
|
this.geometry.computeBoundingSphere();
|
||||||
this.log('update-bounds', this.geometry.boundingBox);
|
this.log('update-bounds', this.geometry.boundingBox);
|
||||||
this.normals({ refresh: true });
|
this.normals({ refresh: true });
|
||||||
this.updateBoundsBox();
|
|
||||||
space.update();
|
space.update();
|
||||||
this.sync();
|
this.sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBoundsBox() {
|
|
||||||
this.group?.updateBoundsBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
mirror() {
|
mirror() {
|
||||||
return this.duplicate({ mirror: true });
|
return this.duplicate({ mirror: true });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue