Our goal is to create "edit handles" that will enable users to resize a (projected) plane by dragging from one of 8 positions (4 corners + 4 edges). This resizing should only scale/stretch the surface in the direction of the drag. However, the default scale mechanism in three.js does not meet our requirements as it scales in two opposite directions simultaneously, similar to what can be observed in this example.
I have done extensive research and experimentation, particularly focusing on these two discussions:
- Scaling a Three.js geometry only up
- Scaling a geometry in one direction with top as reference in threejs
Following these investigations, I arrived at the following solution:
// 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);
However, the outcome was not as expected: The scaling occurs in two opposite directions again, resulting in the translations canceling each other out. It appears that either the scaling does not occur while the center/point of origin is placed on the right edge, or there may be a misconception on my part.
In contrast, the following approach yielded successful results:
mesh.scale.set(scaleX, 1, 1);
mesh.position.x = (-width / 2);
Although effective, continually resetting the mesh position feels like a hacky solution. Additionally, there are concerns about performance implications, especially regarding the frequent application of transformations during every frame, as discussed in this thread: Three.js - Scale model with scale.set() or increase model size?. It has been suggested that transforming the underlying geometry could potentially offer better performance benefits.
I also explored the source code of the TransformControls, but given its limitations and my incomplete understanding of quaternions, the concept remains elusive to me.
Thus, my inquiry is as follows: Is there a method to achieve unidirectional resizing without the need for continuously adjusting the mesh's position?