How to limit theTransformControl move space

Hello, everybody.
Now I am facing in transformcontrol move space limiting problem.
So I want to limit transformcontrol’s space by x,y,z coordinate.
Is there any solution?

A simple approach is to define the minimum and maximum allowed translation like so:

var min = new THREE.Vector3( - 100, - 100, - 100 );
var max = new THREE.Vector3( 100, 100, 100 );

When your scene is static (so when there are no animations), it’s sufficient to render the scene only when something has changed e.g. the user has interacted with an object. To do so, you often register an event listener to the controls like so:

control.addEventListener( 'change', render );

In the render function, you can now clamp the position like so:

var object = control.object; // control is an instance of TransformControls
object.position.clamp( min, max );
11 Likes

Thank you very much Mr @Mugen87.
I fixed it with my own way.
So my method is to track the object position(the object that attached to control), so if the position of this object is gone out of limit value, then I set the value of the object to limit value.
Of course, this process has to be performed in update() or animate() function.
My method is too manual?
So I am gonna try your method. It looks more professional.
Thank you very much.
:+1::+1::+1:

1 Like

solution

This link can also be used as a reference, hopefully to help others with this problem

This works to clamp the object inside restraints - however, for me at least, the transform controls continue to move past the limits, and only snaps back after the user lifts the mouse. Is there a solution to this?