When using the raycaster to detect mouse intersection with a cube, everything works perfectly:
raycaster.setFromCamera(mouse, camera)
const intersects = raycaster.intersectObject(cubeMesh)
if(intersects.length > 0)
console.log('intersecting')
However, when I have a .gltf object positioned exactly like the cubeMesh
, and I check if it's loaded first in an "update" function (called every frame), the intersection with the .gltf is not detected:
const Update = () => {
renderer.render(scene, camera)
raycaster.setFromCamera(mouse, camera)
if(gltfObj){
const intersects = raycaster.intersectObject(gltfObj)
if(intersects.length > 0)
console.log('intersecting')
}
requestAnimationFrame(Update);
};