I have these 2 events that are fired, The objects I am targetting are BufferGeometry but its not returning any intersections. The objects in the intersections array are groups, if I change this to check for my meshes it throws an error. Does anyone know what might be causing this to happen?
export class Raycaster extends THREE.Raycaster {
mouse: THREE.Vector2 = new THREE.Vector2();
constructor(camera: THREE.PerspectiveCamera, renderer: Renderer) {
super();
fromEvent(renderer.domElement, 'mousemove').subscribe((event: MouseEvent) => {
const canvasBounds = renderer.domElement.getBoundingClientRect();
this.mouse.x = ((event.clientX - canvasBounds.left) / (canvasBounds.right - canvasBounds.left)) * 2 - 1;
this.mouse.y = - ((event.clientY - canvasBounds.top) / (canvasBounds.bottom - canvasBounds.top)) * 2 + 1;
});
const click = fromEvent(renderer.domElement, 'click');
click.subscribe((event: MouseEvent) => {
this.setFromCamera(this.mouse, camera);
let arr = [];
DataController.scene.children[0].children[0].traverse((mesh) => {
if (mesh.type === "Mesh") {
arr.push(mesh);
}
});
const intersections = this.intersectObjects(arr);
if (intersections.length > 0) {
((intersections[0].object as THREE.Mesh).material as MeshStandardMaterial).color.set(0xFF0000);
}
});
}
}