Assume: two surface point: a ,b ,center of a and b: cab, face normal :fn ,vector a-b :vab, box position (0,0,0) , no roation, box z length same as distance a and b, place box along box z axis.
my code not working as i thought
function placeBoxToFace(obj, cab, fn, vab) {
//clone and normalize
const upCopy = new THREE.Vector3();
const fnCopy= new THREE.Vector3();
const vabCopy= new THREE.Vector3();
const boxYDirection= new THREE.Vector3(0,1,0);
const boxZDirection= new THREE.Vector3(0,0,-1);
upCopy.copy(box.up).normalize();
fnCopy.copy(fn).normalize();
vabCopy.copy(vab).normalize();
//get thickness as y
const objBox = new THREE.Box3();
const objSize = new THREE.Vector3();
objBox.setFromObject(obj);
objBox.getSize(objSize);
const thickness = objSize.y;
//rotate box to face
obj.quaternion.setFromUnitVectors(boxYDirection, fnCopy);
//set object postion
obj.position.copy(cab).add(fnCopy);
obj.position.add(fnCopy.multiplyScalar(thickness / 2));
//rotate box to vab (not working as i thought)
const quaternion = new THREE.Quaternion();
quaternion.setFromUnitVectors(boxYDirection, fnCopy);
boxYDirection.applyQuaternion(quaternion).normalize();
obj.quaternion.setFromUnitVectors(boxYDirection, vab);
}
}
did i do something wrong? please help.