LightGizmo messes up DirectionalLights rotation

Playground link: Babylon.js Playground
(comment line 20 on and off and rotate, then notice directional light’s rotation)

Hello!

I’m trying to let the user rotate a directional light using the rotationGizmo that the GizmoManager sets up. Currently, I cannot add the DirectionalLight to the rotationGizmo, because it is not a mesh.

I’m relatively new to BabylonJS so maybe there is a simple solution to the above problem I cannot grasp at the moment.

However, the solution I’ve come up with is to add a mesh to the GizmoManager and parent the Directional Light to it, then rotate the mesh. That seems to work great! Until I want to show the LightGizmo visualization. Then the rotations are seemingly doubling from the parent.

To see this weird behavior, go to the playground and uncomment line 20. When you rotate the sphere, you’ll notice the LightGizmo shows the correct light rotation, but the actual light is double the parent’s rotation.

Thanks!

Tom

cc @Cedric

Let me take a look.

1 Like

I’m busy today. I’ll check the issue monday. Sorry for that.

Hi @tfmertz sorry for the delay

I fixed your PG:

The rotation was applied twice because light transformedDirection was transformed by lightgizmo attached mesh and sphere.
Just attaching the rotation gizmo to the lightGizmo fixes the issue.

4 Likes

No worries, thanks for the clarifications!

This actually unlocked another realization for me, I don’t actually need the light to be parented to the sphere anymore. You can see it work in this PG: https://playground.babylonjs.com/#XFGJCL#3

Which confuses me a bit because in gizmo.attachMesh(lightGizmo.attachedMesh) I thought that lightGizmo.attachedMesh had to be a mesh, but it seems like it’s taking the light and rotating it without a mesh just fine! Unless there’s some magic where the lightGizmo’s attachedMesh is the visualization for the lightGizmo?

Either way, it’s exactly what I wanted! :raised_hands:

1 Like