Itβs better to check this using the point product of the direction of the beam and the normal face
tested on three.js (r103)
const point = new THREE.Vector3(2, 2, 2) // Your point const direction = new THREE.Vector3(1, 1, 1); const geometry = new THREE.BoxGeometry(5, 5, 5) const material = new THREE.MeshBasicMaterial({ color: 0xffff00, side: THREE.DoubleSide }); const mesh = new THREE.Mesh(geometry, material) const raycaster = new THREE.Raycaster() raycaster.set(point, direction) const intersects = raycaster.intersectObject(mesh); if (intersects.length && direction.dot(intersects[0].face.normal) > 0) { console.log('Point is in object'); } else { console.log('Point is out of object'); }
In rare cases, you can get an even number of interactions with a point located inside the grid
(try point = new THREE.Vector3(0, 0, 0) , which should give 4 intersections)
source share