How to get "cast shadow" value for a mesh in a GLTF model?

Hi guys,

I have a scene in GLTF format. I can easily get and set the “receive shadow” parameter for each mesh with a simple mesh.receiveShadows accessor. But I can’t find the same for “cast shadow” functionality. Basically I want to know if a mesh is set to cast shadows on other meshes in a scene.

Will you please suggest the option of how I can derive this information for the meshes in a GLTF scene? Is there an accessor for it or a property? I’ve tried to find it in the API doc, but no success.

Thank you!

Shadow caster meshes are stored in an array located at the shadow generator’s render list. you can check if the mesh is in this array. Maybe someone else have a nicer answer, but that will work :slight_smile:

Something along th elines of:

const isCasting = shadowGenerator.getShadowMap().renderList.indexOf(meshToCheck) !== -1;

Hi @RaananW!

Not sure if I get you correctly. From what I understand - you speak about the situation when the shadow generator’s render list is already populated. What I want to do - is exactly POPULATE the shadow generator’s render list based on the information of which meshes in the scene are set to cast shadows.

So this means, when I first read the scene, I don’t know yet which of its meshes are set to cast shadows. So I need to distinguish the meshes that are set to cast shadows from those which are not. And that’s exactly what I need that “cast shadows” information for. So any ideas how I can achieve this?

I must be missing something, but should you be the one to define which meshes are casting shadows?

1 Like

@RaananW, well yes, of course, I can define them manually in the code. But instead, I want my 3D modeler to define it, not me. And then I just want to derive this information from the scene itself. As far as I know Blender2Babylon exporter allows to set these flags for objects, here:
Screenshot_092320_035601_PM

But then, how can I read this information from the scene?

AFAIK when setting this, a shadow generator will be added to the .babylon file and will have its renderlist populated with this mesh’s id (FileFormat Map (.babylon) - Babylon.js Documentation)

Is there a shadow generator in your .babylon file?

But wait, @RaananW, AFAIK shadow generators are created for LIGHT sources, not meshes. I.e. if you would set this “Cast shadows” flag for a mesh in Blender, you would also need to define which light source this mesh should cast shadows from. And it’s obviously not like that there. So how does it work then?

Maybe we need to ping someone else to explain this?

That’s a good question :slight_smile: This could help - Blender - Babylon.js Documentation