Collision issue between Box3 that have undergone rotations along x, y, or z

Hello,
I have a problem and I would like you to help me solve it. Currently, I am working on a project that requires an update regarding box collisions. Initially, I used the intersect function of Box3 . Now, they want the boxes to undergo rotations, and collisions should occur on the actual box, not the bounding box of Box3 . I thought about transforming my Box3 into an OBB (Oriented Bounding Box) and trying to use the intersect function, but it doesn’t seem to work.

image
export function isCollided(component: Component, components: Component){
return components.some((otherComponent: any) => {
const otherComponent3DObject = get3DComponentById(otherComponent.id);
const movedComponent3DObject = get3DComponentById(component.id);

if (otherComponent3DObject) {
  const otherBoundingBox = new Box3().setFromObject(otherComponent3DObject)
  const boundingBox = new Box3().setFromObject(movedComponent3DObject)
  const OBBother = new OBB().fromBox3(otherBoundingBox)
  const OBBFromMovedComponent = new OBB().fromBox3(boundingBox)
  return OBBother.intersectsOBB(OBBFromMovedComponent)
}

return false;

});
}

I used OBB like this, updating the OBB every frame (to account for a moving box).

Your base box size should be the size or your non-rotated box, and then you can apply the rotation after.

let obb = new OBB()
 
obb.center.set(0, 0, 0)
obb.rotation.identity()
obb.applyMatrix4(mesh.matrixWorld)

let other = { 
   obb: new OBB()
}
 
if (other.obb.intersectsOBB(obb)) {
   // do someting
} 

Three’s own documentation only mentions 2D rotations, though.

You may try Yuka
Yuka | Bounding Volumes
Yuka | Documentation

OBB.

Oriented Bounding Box : three.js docs

Example : Collision Detection using OBB - Three.js Tutorials

1 Like