I am struggling to move an object within a threejs scene as I am unable to select the object when clicking with the mouse. I attempted to adapt the code provided in this link (https://github.com/mrdoob/three.js/blob/master/examples/webgl_interactive_draggablecubes.html) for my own application, but unfortunately, it did not work in my specific case.
My question is: is the function provided in the code correct?
Additionally, are the camera position and rotation set correctly in the complete code provided?
function onDocumentMouseDown(event) {
console.log("function onDocumentMouseDown");
console.log(mouse.x, mouse.y);
raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( objects );
if (intersects.length > 0) {
alert("finally");
console.log(intersects[0]);
intersects[0].object.material.transparent = true;
intersects[0].object.material.opacity = 0.1;
SELECTED = intersects[0].object;
var intersects = raycaster.intersectObject( plane );
if ( intersects.length > 0 ) {
offset.copy( intersects[ 0 ].point ).sub(plane.position);
}
}
}
To access the complete code, please visit https://github.com/lohmanndouglas/Simulador.git