I am playing with three JS and want to determine if a mesh is fully inside another mesh. I wrote a little robot which should run into a home box navigated by the player. I know how to detect collision, but is there an easy way to detect if an object is inside another object?
I could calculate center Position of the homebox and compare to robot Position, but maybe there is something build in to threejs.
If you make a boundingBox (
THREE.Box3) for both the 'robot' and the 'home' you can use the
containsBox method. So something like this:
var robotBB = new THREE.Box3().setFromObject(robot); var homeBB = new THREE.Box3().setFromObject(home)
robot are your objects. Now you can do:
var robotIsHome = homeBB.containsBox(robotBB);
robotIsHome will be true if the
robotBB is completely inside
©2020 All rights reserved.