the code to load the gltf file is as follows:
function loadGLTF(path, fileName) {
var loader = new THREE.GLTFLoader();
loader.load(`${path}${fileName}.gltf`, function (gltf) {
let object = gltf.scene;
object.scale.set(scale, scale, scale);
scene.add(object);
});
}
the object loaded here is a scene.
Click the code as follows:
window.addEventListener("mousedown", mousedown);
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
function mousedown() {
mouse.x = e.clientX / renderer.domElement.clientWidth * 2 - 1;
mouse.y = -(e.clientY / renderer.domElement.clientHeight * 2) + 1;
raycaster.setFromCamera(mouse, camera);
var intersects = raycaster.intersectObjects(scene.children);
if (intersects.length > 0) {
console.log(intersects[0].object);
}
}
when you click, you cannot click on the loaded gltf object, and the returned object is always empty, or other non-loaded objects.