Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

threejs How to rotate transformcontrol itself

I'd like to rotate transformcontrol itself when object which attach to transformcontrol is rotate.

Before rotate

enter image description here

After rotate

enter image description here

As image shown, before rotate, cylinder's top direction is z-axis of transformcontrol, however after rotate is not.

I'd like that the transformcontrol's z axis to be always in the upward direction of the cylinder.

like image 488
takeyourcode Avatar asked Sep 03 '25 05:09

takeyourcode


1 Answers

TransformControls returns an object that you can modify directly.

const controls = new TransformControls(camera, renderer.domElement);
controls.setSpace('local');
controls.rotation.x = Math.PI / -2;

If you want to sync its rotation with your mesh, you can add it as a child of that mesh or use Euler#copy.

mesh.add(controls);

// or manually in a render loop, for example

scene.add(controls);

renderer.setAnimationLoop(() => {
  controls.rotation.copy(mesh.rotation);

  renderer.render(scene, camera);
});
like image 126
Cody Bennett Avatar answered Sep 04 '25 19:09

Cody Bennett