Hello.
I know that this problem has already been solved on the forum, but I haven’t found the right answer for me.
I’m trying to display the points after passing the cursor over the object. It works with “cube”, but didnt work with my object.
Can you help me? Thank you.
const raycaster = new THREE.Raycaster();
// create cube
const cube = new THREE.Mesh(
new THREE.BoxGeometry(10,10,10),
blueMaterial
);
scene.add(cube);
// load model
const gltfLoader3 = new GLTFLoader();
gltfLoader3.load(
"./static/rektorat.glb",
(gltf3) => {
scene.add(gltf3.scene);
}
);
function tick() {
controls.update();
for (let point of points) {
const screenPosition = point.position.clone();
screenPosition.project(camera);
const x = screenPosition.x * window.innerWidth * 0.5;
const y = -screenPosition.y * window.innerHeight * 0.5;
point.element.style.transform = `translate(${x}px, ${y}px)`;
renderer.domElement.addEventListener("mousemove", (e) => {
const x = (e.clientX / window.innerWidth) * 2 - 1;
const y = -(e.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(
new THREE.Vector2(x, y),
camera
);
});
point.element.style.display = "none";
var intersections = raycaster.intersectObjects([cube]);
if(intersections.length > 0)
point.element.style.display = "block";
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(tick);
I have tried
var intersections = raycaster.intersectObjects(gltfLoader3);
or
var intersections = raycaster.intersectObjects(gltf3.scene);
nothing worked