Check if point is inside a custom mesh geometry

If your mesh is close-up. You can use the THREE.js built-in ray-caster. Sample code is as

const point = new THREE.Vector3(2,2,2) // Your point
const geometry = new THREE.BoxBufferGeometry( 5, 5, 5 )
const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } )
const mesh = new THREE.Mesh( geometry, material )
const raycaster = new THREE.Raycaster()
raycaster.set(point, new THREE.Vector3(1,1,1))
const intersects = raycaster.intersectObject(mesh)
if( intersects.length %2 === 1) { // Points is in objet
   console.log(`Point is in object`)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/89/three.js"></script>


Just raycast once from the point to any direction, then check the intersects num, if is odd, the point is in the geometry, here is the demo


This is a computational geometry problem. You can look at Finding if point is inside geometry. Since your geometry is irregular the problem is much harder.

But if precision is not too important you can check if the point is inside the bounding box of the geometry.

Tags:

Three.Js