0

For each mesh (THREE.Object3D) Three.js provide a very handy properties - boundingSphere and boundingSphere that have intersectsSphere and isIntersectionBox methods.

With all this I thought I can use it for simple collision detection but when I try it appears that collision happens all the time because (I tried boundingSphere) boundingSphere.center is always in (0, 0, 0); So If I want to check collisions between 2 meshes I should for each object - clone boundingSphere object and then get it world coordinates and only then to use intersectsSphere.

something like this:

var bs = component.object.geometry.boundingSphere.clone();
bs.center.setFromMatrixPosition(component.object.matrixWorld);
...
if (_bs.intersectsSphere(bs)){

is this how it suppose to be used or am I missing something and there are more convenient way of doing collisions detection based on boundingBox/boundingSphere?

4

1 回答 1

2

如果要使用边界框进行碰撞检测,则需要世界坐标系中的框。intersectsSphere网格的和isIntersectionBox属性中的包围体位于对象的局部坐标系中。

您可以像以前那样做:克隆卷并将它们移动到世界坐标系中的正确位置,这是一个很好的解决方案。

否则,您还可以从网格中设置一个新框并使用这些框进行碰撞。假设你有一个THREE.Mesh被叫mesh然后你可以这样做:

sphere = new THREE.Sphere.setFromPoints( mesh.vertices );

box = new THREE.Box3.setFromObject( mesh );

一个小提示。在开发过程中,很高兴看到场景中的边界框,为此您可以使用THREE.BoundingBoxHelper

var helper = new THREE.BoundingBoxHelper( mesh );
scene.add( helper );
于 2016-01-26T08:42:37.160 回答