Facing polyhedra mesh face to the camera

How would I go about facing a polyhedron mesh’s face in front of the camera, for example, in this playground:

Making it possible so when I click and / or choose a number from 1 to 12 for example in which the number represents a face of the dodecahedron, this mesh will rotate or the camera will move so the camera will be facing the mesh’s face forming a 90 degrees angle?

You just need to get a normal for a flat face and then determine a rotation quaternion to rotate it to align with the camera look direction. To get you started, this snippet of code aligns a facet normal with the +Y axis.

var q = new BABYLON.Quaternion();
BABYLON.Quaternion.FromUnitVectorsToRef(facetNormalWorld, diceYWorld, q);
q.multiplyInPlace(diceRoot.rotationQuaternion);
targetQuaternion = q;

To determine a flat face, you need to find a facet where all three vertex normals are the same (if the face wasn’t flat, than the vertex that is shared with the next face would have an averaged normal which would be different than the other vertex normals). I’m trying to figure out if the vertices for a facet are available from the facet index or if I would need to get them directly from the vertex data.

1 Like

Maybe that can help:

2 Likes