Hi everyone. I am very new to three.js, and I am working on a project that uses gltf models. I have a world map and 3D model pins that contain an avatar using textureLoader.load(image). When the mouse hovers over the pins, a popover appears with some information and the avatar. I wanted to make this pin clickable, so it redirects to another page and I used raycaster. However, it doesn’t behave as I would want it to. I have to click on a very specific point, where the pin meets the surface of the map, in order to be redirected to another page. Also, I want the pin model to be clickable, which is not the case right now. The globe is composed of different objects with different names and the problem is that when I click on the pin, intersects[0].object.name, does not pick up the name of the pin as if it doesn’t exist. I can’t figure out what the problem is.
Here is a screenshot of my map with markers.
const onPinClick = React.useCallback(
(event: MouseEvent) => {
event.preventDefault();
if (threeData.current === null) {
return;
}
const { scene, camera, renderer } = threeData.current;
const raycaster = new Raycaster();
const mouse = new Vector2();
if (!threeData.current) {
return;
}
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
const intersects = raycaster.intersectObjects(scene.children, true);
const pins = scene.children.find((child) => child.name === 'pins');
renderer.render(scene, camera);
if (intersects.length > 0 && pins) {
if (pins.children.find((child) => child.data.user.country.name === intersects[0].object.data.countryName)) {
router.push('/profile');
}
}
},
[router],
);
Any help is much appreciated.