确定一个网格是否在三个j中的另一个网格内 [英] Determine if a mesh is inside another mesh in threejs
问题描述
我正在玩三个JS,并想确定一个网格是否完全位于另一个网格内。我写了一个小机器人,该机器人应该进入由玩家导航的家庭箱子。我知道如何检测碰撞,但是有没有简单的方法来检测对象是否在另一个对象内?
我可以计算中心homebox的位置并与机器人进行比较如果你制作了一个边界框(> THREE),那么你可以使用一个边界框(
.Box3
)你可以使用'robot'和'home' containsBox
方法。所以像这样:
var robotBB = new THREE.Box3()。setFromObject(robot);
var homeBB = new THREE.Box3()。setFromObject(home)
其中 home
和 robot
是您的对象。现在你可以这样做:
var robotIsHome = homeBB.containsBox(robotBB);
robotIsHome
c $ c> robotBB 完全位于 homeBB
中。
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)
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
.
这篇关于确定一个网格是否在三个j中的另一个网格内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!