Syncing up mesh rotation with light direction

Hi there. Am wondering how to sync mesh rotation with light direction. Lights don’t seem to have same rotation properties of meshes? Have a playground here:

On line 79, I’m trying to match the rotation of a mesh - with the rotation of a light. I’ve got position working just fine - but rotation has been giving me grief for the better part of a couple days. Any tips would be much appreciated! thx. I’m trying to wrap a SpotLight light with a mesh that looks like a spotlight.

Technically you should be able to make the light a child of the mesh

Cool! I’m pretty sure that worked:

I added a huge cylinder to show orientation better.
One funny thing is that the light gizmo stops working… even though the light continues to rotate. So it’s a bit hard to tell if it’s aligning correctly…

Image here showing gizmo no longer moving…

Nope, didn’t work, but is probably not the parenting that’s not working… is probably how i’m rotating the cylinder.

Attached a mesh gizmo to the parented glb. Same results as before… but now i’m thinking maybe it is working correctly… but just hard to tell b/c the light gizmo remains stationary.

Hm, maybe also confusing is that meshes don’t light up. Did a search and found that i’d posted many moons about the same issue. Imported GLB model won't light up. But i gotta imagine that these meshes should light up with a spotlight pointing right at them??

This can’t be right, right?

1 Like

Just to simplify, I made the world comprise of just one cube - showing normals:

Still doesn’t illuminate (but does show shadows)

It does work with a directional light:
It seems to work with point light also:

Is this a bug with Spotlight?

deleting b/c makes more confusing.

Ok! Think i got the rotation sorted out (with help of the pilot):

However, found 2 things that I think are bugs

  1. think I found a bug with the light Gizmo, as noted above. Once you start moving the light with Dat.gui, it is no longer responsive.

  2. And also found a bug(?) with imported GLBs not receiving light in the playground, as noted above.

Well. Using

materialOfTheCube.usePhysicalLightFalloff = false

seems to enables lighting on the mesh. But for some reason it is inversed and I am not sure why. So basically when you open the scene if you check the bottom of the cube it is lighten up, and if you rotate light 180 degrees, top is lighten up. (lines 94-95).

Oh hey! Didn’t know about that toggle. That seems to make everything work a bit better. Here’s a simpler PG:

But like you said - it’s like the lighting is inverted - illuminating the wrong sides of the box. But everything else is right - like shadows and light pattern on ground.


Add cubeMat.backFaceCulling = true

How or why this works I do not know.

Another way to do it is using #102 open the Inspector, go to properties of Material and change Orientation to CounterClockwise. How you change this property in code I do not know.


Note that this playground does work “as is” in my local repository:

So it must be a later change that makes it fail in the public playground.

1 Like

Cool workarounds guys! @johnk, you ever try “Replay Code” in the inspector? It tells you what the code is for a change you make in inspector. Love that feature. Apparently, changing orientation of that Material is:

// Code generated by babylon.js Inspector
// Please keep in mind to define the 'scene' variable before using that code
scene.getMaterialByID("Material").sideOrientation = 1;

That made me wonder if it’s a Blender GLB export setting… but i didn’t see anything that looked suspicious. Hm.

Also funny that it works locally without modifications. Something new perhaps that’s only in the PG engine? Maybe @Deltakosh could opine? Seems like it might be a bug.

I’ll have a look!

Ok I finally found the issue: it is related to a faulty gltf extension. I pinged @MackeyK24 who is owning this extension.

So far the extension is turned off on the PG so it should be back to normal


I fixed the issues with a Scene Manager 4.1.0 Beta 1 Update :slight_smile:


One other thing i notice (bug?) is that when the light is pointing straight down with no rotation, the spotlight is slightly askew (distance from center point to edge of circle are not equal). That’s not right is it?

34%20PM 48%20PM 11%20PM

This is actually a bug…in the inspector:

I will fix it for next nightly

Cool. Maybe related to the light-icon (gizmo) not updating?
That would be a great fix too… hard to tell what’s going on with rotation in particular.
You can see this bug by turning on the light-icon and then moving the DAT.gui sliders that i have in the playground. You’ll see that the light-icon doesn’t move/rotate.