ThatOpen/web-ifc-three

IFC raycaster sometimes not detecting intersections

Closed this issue · 2 comments

Hello, the raycaster takes a very long time to detect an intersection with the object. A very few clicks are detected as an intersection. Also the scene is attached to a panel on the website.


var vector = new THREE.Vector3( ( event.clientX / window.innerWidth ) * 2 - 1, - ( event.clientY / window.innerHeight ) * 2 + 1, 0.5 );
var raycaster = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );
raycaster.setFromCamera(vector, camera);
var intersected = raycaster.intersectObjects(scene.children, true);
if (intersected.length) {
      const found = intersected[0];
      const faceIndex = found.faceIndex;
      const geometry = found.object.geometry;
      const id = ifcLoader.ifcManager.getExpressId(geometry, faceIndex);
      const modelID = found.object.modelID;
      ifcLoader.ifcManager.createSubset({modelID, ids: [id], scene, removePrevious: true, material: highlightMaterial});
     const props = ifcLoader.ifcManager.getItemProperties(modelID, id, true);
     renderer.render(scene, camera);
}
thmax commented

Hey @Tamara2365 it's more a threejs issue ...
Though, i don't get why you pass an origin (camera.position) and a direction (vector.sub( camera.position ).normalize()) in your raycaster's constructor.
Because when you call setFromCamera, it "Updates the ray with a new origin and direction" (https://threejs.org/docs/#api/en/core/Raycaster).
Maybe it can help solving your issue

Hey, in case someone else has the same problem, I solved it by changing the attribute in getItemProperties from true to false: ifcLoader.ifcManager.getItemProperties(modelID, id, false);. Also I used the function getBoundingClientRect() and changed the mouse coordinates to:

raycaster = new THREE.Raycaster();
var rect = renderer.domElement.getBoundingClientRect();
mouse.x = ( ( event.clientX - rect.left ) / rect.width ) * 2 - 1;
mouse.y = - ( ( event.clientY - rect.top ) / rect.height ) * 2 + 1;

raycaster.setFromCamera(mouse, camera);

And now the intersections are detected fast.