Threejs, Understanding Raycaster's Intersectd Object Coordinates
Hello, I have one doubt: I have implemented a raycaster and I have been testing it manually, however I do not know why on most of the clicks which I made on the 3D model, it did no
Solution 1:
Raycarster.setFromCamera(NDC, camera)
takes as first parameter the normalized device coordinates. That is a value between -1 and 1. But you are giving the actual coordinates. That is why it doesn't intersect. Try this:
const screenPosition = {
x: event.clientX - canvas.offsetLeft,
y: event.clientY - canvas.offsetHeight
};
const widthHalf = canvas.clientWidth * 0.5;
const heightHalf = canvas.clientHeight * 0.5;
const mouse = {
x: (screenPosition.x - widthHalf) / widthHalf ,
y: - (screenPosition.y - heightHalf) / heightHalf,
};
Also try to set recursive to true
in intersectObject()
.
Post a Comment for "Threejs, Understanding Raycaster's Intersectd Object Coordinates"