Hello,
I’m trying to do the following in three.js:
- we have a floor on which the cube is located,
- OrbitControls are assigned to the camera
- we have the option of switching the camera to another one
- orbitcontrols should be assigned to the new camera
- we have addEventListeners ‘mousedown’ - which after clicking on the cube should block orbitcontrols and enable the ‘mousemove’ function - which is responsible for moving the cube
- ‘mouseup’ - makes the ankle does not move and the orbits control again
How does it look in practice?
if I call the onMouseDown function at the default camera setting - orbitControls locks and unlocks as intended
if we change the camera - that’s, even though enebled is called false after calling console.log (controls) - orbit controls still work.
I do not know where I’m making a mistake.
Here are pieces of code - the function responsible for changing the camera, the onMouseDown function - to disable controls and the onMouseUp function - which should enable controls.
function choosenCamera(cameraNumber) {
var newCam;
if (cameraNumber === 0) {
newCam = cameras[0];
} else if (cameraNumber === 1) {
newCam = cameras[1];
} else if (cameraNumber === 2) {
newCam = cameras[2];
}
camera.name = newCam.label;
camera.fov = newCam.FOV;
camera.aspect = newCam.aspectRatio;
camera.position.set(newCam.position.x, newCam.position.y, newCam.position.z);
camera.rotation.set(newCam.rotation.x, newCam.rotation.y, newCam.rotation.z);
newControls = new THREE.OrbitControls(
camera,
document.getElementById('container')
);
}
function onMouseDown(e) {
controls.enabled = false;
move = true;
this.style.cursor = "all-scroll";
document
.getElementById('container')
.addEventListener("mousemove", onMouseMove, false);
}
function onMouseUp(e) {
move = false;
controls.enabled = true;
this.style.cursor = "default";
document
.getElementById(nameId)
.removeEventListener("mousemove", onMouseMove, false);
document
.getElementById('container')
.removeEventListener("mousedown", onMouseDown, false);
}