Determine if a mesh is inside another mesh in thre

2019-07-18 12:33发布

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.

1条回答
我命由我不由天
2楼-- · 2019-07-18 12:44

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.

查看更多
登录 后发表回答