Instanced imported GLB mesh not casting shadows

When I try to cast shadows with instances of an imported GLB mesh the shadows don’t work but they do work for the original mesh, see …

https://playground.babylonjs.com/#MSAHKR#5

But, when I reparent the imported mesh before instancing (remove from “__root__”), then the instance does cast shadows, see …

https://playground.babylonjs.com/#MSAHKR#4

I’m not really understanding why this is the case. Can someone please enlighten me (pun intended)? :slight_smile:

I noticed that “__root__” has a scaling.z = -1 and rotation.y = 180 but I have no idea where these came from as they aren’t in the original Blender file.

So I must be misunderstanding the way GLBs are exported from Blender or imported into Babylon.js or both.

For the benefit of anyone else who stumbles onto this topic, although reparenting using mesh.parent = parent worked in my PG above I couldn’t get it to work in my application for some reason, but as soon as I changed it to mesh.setParent(parent) as per the parenting docs then shadows did start working with the instances.

It’s a mystery to me, but it works.

2 Likes

Hi inteja,

Sounds like you’ve found a solution that works! Just as a possible explanation for some of the behavior you saw, setParent() does a lot of work beyond just setting the parent, much of which involves recalculating a lot of transform internal data to make sure the internal state correctly reflects the relationship with the new parent. Also, the mysterious scaling and rotation you saw on your glTF might be one of the glTF exporters’s way to handle handedness, though I’m not super familiar with the specifics of the exporters. Glad you were able to get it working!

1 Like

You can just set scene.useRightHandedSystem = true and it will work, but you need to update the position of the instance else it is on the same spot than the master mesh:

https://playground.babylonjs.com/#MSAHKR#10

However, there’s more involved here, there’s an interaction with another late change on the shadow generator that makes it not work when in left handed system, I need to dig a bit for that one.

2 Likes

@Evgeni_Popov thanks, that might explain why I was seeing different results in my local app (4.1.0) and the PG on latest (4.2.0-beta.20)?

Absolutely.

1 Like

PR that should hopefully fix the problems:

1 Like