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: https://www.babylonjs-playground.com/#0AYIR5#12
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.
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…
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??
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.
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.
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.
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.
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?
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.