We are trying to build "edit handles" that allow the user to resize a (projected) plane by dragging at one of 8 places (4 corners + 4 edges). This resizing is supposed to only scale/stretch the surface in the direction of the dragging, so the default scale mechanism of three.js won't do, as it scales in two opposite directions at the same time like seen in this example.
I've read and tried a lot, especially these two posts:
- Scaling a Three.js geometry only up
- Scaling a geometry in one direction with top as reference in threejs
Following those I ended up with this
// preparing to resize into -x direction aka "left edge"
// moving the geometry center to the right edge
mesh.geometry.translate(width/2, 0, 0);
mesh.geometry.scale(scaleX, 1, 1);
// moving the geometry center back to the middle
// as more resizing might happen, into another direction, as per comment here:
// https://stackoverflow.com/questions/26817717#comment74469004_26818522
mesh.geometry.translate(-(width/2 * scaleX), 0, 0);
The result is not what I would expect: The scaling happens in the two opposite directions again, so the translations cancel each other out - so either the scaling does not happen while the center/point of origin is placed on the right edge or there is a misconception on my end.
This on the other hand works fine
mesh.scale.set(scaleX, 1, 1);
mesh.position.x = (-width / 2);
But it really feels hacky to reset the position of the mesh over and over again - also I thought I have read that scaling the mesh is less performant as this transformation is reapplied for every frame (might have gotten this wrong though: Three.js - Scale model with scale.set() or increase model size?), while a transformation of the underlying geometry is baked into the data.
I also had a look at the sources of the TransformControls, but as it doesn't work the way we want and as I haven't fully grasped the concept of quaternions its lost on me.
So my question is this: Is there a way to do inplace unidirectional resizing without correcting the position of the mesh?