Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

threejs disable orbit camera while using transform control

I have a scene with multiple meshes, each one of them associated to a different transformControl; in order to select different objects, I'm using raycasting techniques. I'm also using an orbit camera in order to navigate the scene.

Whenever I modify the position/rotation/scale of the selected object using transform control, I want to disable orbit camera, because sometimes while I'm clicking on a picker, I'm also picking on the background of the scene, so the orbit camera moves.

I'd like to stop this behavior and I've already tried to handle it with raycasting techniques, but it doesn't work.

like image 887
rastafermo Avatar asked Nov 18 '13 21:11

rastafermo


2 Answers

Stumbled over this and thought it would be helpful to see the answer (credits to BuildingJarl):

// if youre definition is like
var controls = new THREE.OrbitControls( camera );

// you can easily disable it by using
controls.enabled = false;

In my case I was using a UI overlay and I got issues with getting the focus to it. Disabling the controls solved my problems.

Greetings Mat

like image 96
schlenger Avatar answered Oct 26 '22 11:10

schlenger


Taken from three.js editor's code:

var orbitControls= new THREE.EditorControls(camera, renderer.domElement);
orbitControls.addEventListener('change', render);

var transformControls = new THREE.TransformControls(camera, renderer.domElement);    
transformControls.addEventListener('change', render);
transformControls.attach(mesh);
transformControls.addEventListener('mouseDown', function () {
    orbitControls.enabled = false;
});
transformControls.addEventListener('mouseUp', function () {
    orbitControls.enabled = true;
});
like image 29
Stranger in the Q Avatar answered Oct 26 '22 10:10

Stranger in the Q