For the raycaster, it can use raycaster.setFromCamera, raycaster.intersectObjects those methods three.js docs, when the mouse picks the object, it can emits the rays and detect it. What if I don’t want to use the mouse click? My camera will be rotating, when the camera rotates to or face to the specific object, I want to receive it from raycaster.intersectObjects. How can I start with? Thanks.
To set ray by camera position (independent of mouse position), simply pass Zero-Vector2 as first parameter to setFromCamera(), or
instead use raycaster.set.
Like this:
var camDirection;
camera.getWorldDirection(camDirection);
raycaster.set(camera.position, camDirection);
To trigger intersectsObjects, you can utilize change-event of OrbitControls.
Code:
function onCameraChange(evt) {
var control = evt.target;
console.log(control);
console.log(control.target);
console.log(control.object.position);
}
controls.addEventListener('change', onCameraChange);
1 Like
Really appreaciate