Game mode: PointerLockControls (PerspectiveCamera)
Ok, cameras switch normally.
But I found a problem with DragControls:
— For example, I switch to 2D mode and select the cube using the dragstart events from DragControls. Ok, everything is fine, the cube is selected.
— Now I go into 3D mode and try to select a cube. Here the cube will no longer stand out !! Selection does not work.
I understood why “dragstart” stopped working on the cube, because when switching modes, the camera position changed and therefore raycaster DragControls began to work crookedly.
What can I do with DragControls to work fine? I want the select to always work normally in any camera mode.
Everytime Raycaster is used in DragControls for intersections tests, it prepares itself via the following code:
_raycaster.setFromCamera( _mouse, _camera );
Meaning the raycaster should always reflect the latest state of your camera. So please demonstrate the issue with a live example if this is not working.
Here’s an uploaded example - http://kibbler.full-stack.kz/
At startup, 2D mode is launched. The cube in the center can be selected and moved in different directions.
let objects = [];
// Cube
let test_q = new THREE.BoxBufferGeometry(2,2,2);
let test_m = new THREE.MeshBasicMaterial({color: 0x8c170b});
let test_mesh = new THREE.Mesh(test_q, test_m);
scene.add(test_mesh);
objects.push(test_mesh);
crafter.load_id = 11;
/* --------------- Панель управление -------------- */
// Управление объектами сцены
let drag_lock = false;
let drag_objects = new Drag(objects, null, camera.camera);
drag_objects.init();