Determine if a mesh is inside another mesh in threejs

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.

Answers:

Answer

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)

Where home and robot are your objects. Now you can do:

var robotIsHome = homeBB.containsBox(robotBB);

robotIsHome will be true if the robotBB is completely inside homeBB.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.