I’m sure this is a simple question, but I’m struggling with it: how do I align a mesh (which is created with x,y,z axes parallel to the world x,y,z axes), such that the mesh’s z axis is colinear with a straight line in the z,y plane?
Thx - I’ve already looked at that and don’t understand how to apply it. The documentation is amazing, but I’m finding rotations tricky…
In layman’s terms, how do to I pick out the direction of a line, and align a mesh to it? I’ve looked at the orientation example, but what do I pick out from a line created with CreateLine, and a mesh to do mesh.rotation against?
e.g. the following attempt doesn’t work:
camAxis is a straight line constructed with CreateLines, cam is a cubic box mesh at one end of the camAxis:
const tangents = camAxis.getTangents();
const normals = camAxis.getNormals();
const binormals = camAxis.getBinormals();
var orientation = BABYLON.Vector3.RotationFromAxis(binormals[0], tangents[0], normals[0]);
cam.rotation = orientation;
The line in the zy plane will be along a vector axisZ, since it is in the zy axis the vector axisX (1, 0, 0) will be perpendicular to it. To find the axisY to complete the othagonal set of axes use
axisY = BABYLON.Vector3.Cross(axisX, axisZ)
then
rot = BABYLON.Vector3.RotationFromAxis(axisX, axisY, axisZ)