Best way to trigger an event based on what direction a mesh is facing


I have imported a mesh and have added some events to allow the user to change the rotation of the mesh with the cursor. The mesh is a bit like a 6 sided die. I ideally want to trigger an event based on what side of the ‘die’ is facing the camera. The camera is just a static universal camera that points at the die.

I have thought of using getDirection or rays or even checking if the rotation was between certain values but that seems like a hacky way of doing things.

Ideally I’d want to trigger the event based on which face of the die is the closest to facing the camera if that makes sense.

EDIT: Sorry, have been busy with other bits so not had chance to update this post. I have linked the playground below with the code I am using to handle the rotations.

Any help would be appreciated thank you.

Would be great if you could share the start of your code so that we can help troubleshooting it in the community.

Something like the dot product of both directions might do ?

Hey, I have updated the post with a playground with my code rotation code

I am still not sure to understand exactly what you are trying to achieve as I am not seeing any code in the playground regarding the event ?

if your camera is static why not simply checking the cube rotation ?

When the user moves the cube around, depending on which face of the cube is facing the camera, I want to display different HTML. What I am struggling to get started on is how to determine which face of the cube is facing the camera at any which time.

I was thinkiing I could check the rotation of the camera for example if X is between -45 deg and 45 deg show face 1, between 45 and 90 face 2 etc but how would I get the rotation in terms of degrees?

“box.absoluteRotationQuaternion.toEulerAngles()” should provide you with the rotation in radians arount x y and z