in my case how i use OBB
i put in a array all objet i need to manage for collision
listForCollision.push({o:scene.getObjectByName(‘nameofmyobjet1’),obb:new OBB()});
listForCollision.push({o:scene.getObjectByName(‘nameofmyobjet2’),obb:new OBB()});
listForCollision.push({o:scene.getObjectByName(‘nameofmyobjet3’),obb:new OBB()});
…
listForCollision.push({o:scene.getObjectByName(‘nameofmyobjetn’),obb:new OBB() , dx:-0.25 ,dy:-0.25 ,dz:0 });
listForCollision.push({o:scene.getObjectByName(‘nameofmyobjetm’),obb:new OBB(), dx:0 ,dy:0 ,dz:1} );
…
after i create obb for all objet in the array
for(var i=0,longueur=listForCollision.length;i<longueur;i++){
createOBB(listForCollision[i]);
}
and function is ( delta is to add or substract length to OBB )
function createOBB(monObjet){
var delta = new THREE.Vector3( 0.25 , 0.25, 0.25 ) ;
if ( monObjet.dx !== undefined ) { delta.x = monObjet.dx ;}
if ( monObjet.dy !== undefined ) { delta.y = monObjet.dy ;}
if ( monObjet.dz !== undefined ) { delta.z = monObjet.dz ;}
// get opposite of rotation objet axe Z
var monquater=new THREE.Quaternion();
monquater.set(0,0,-monObjet.o.quaternion.z,monObjet.o.quaternion.w);
//clone objet to create OBB and rotate clone around axe Z
var monObjetDouble=monObjet.o.clone(true);
monObjetDouble.applyQuaternion(monquater);
//create box and set it with clone
var monAABB = new THREE.Box3();
monAABB.setFromObject( monObjetDouble );
// add delta
monAABB.min.subVectors(monAABB.min,delta);
monAABB.max.addVectors(monAABB.max,delta);
// create helperbox to see box
var helperbox=new THREE.Box3Helper(monAABB,0xffffff);
scene.add(helperbox);
// get center and half dim of box3
var moncentre = new THREE.Vector3() ;
monAABB.getCenter(moncentre);
var mondim = new THREE.Vector3();
monAABB.getSize(mondim);
mondim.multiplyScalar(0.5);
var monAngle = 0;
var angle=Math.acos(monObjet.o.quaternion.w);
var signe=Math.asin(monObjet.o.quaternion.z);
if ( signe > 0 ) { monAngle = 2*angle ; }
else { monAngle = 2* ( 2*Math.PI - angle) }
var xxxx=Math.cos(monAngle),yyyy=Math.sin(monAngle);
// rotate helperbox
helperbox.setRotationFromAxisAngle(new THREE.Vector3(0,0,1),monAngle);
//set OBB
monObjet.obb.set(new THREE.Vector3(moncentre.x,moncentre.y,moncentre.z), new THREE.Vector3(mondim.x,mondim.y,mondim.z), new THREE.Matrix3().set(xxxx,-yyyy,0,yyyy,xxxx,0,0,0,1) ) ;
monObjet.helperBox=helperbox;
}
and result with helperbox visible .