I’m adding a mesh to an existing light’s shadow generator. But the returned object type (IShadowGenerator) doesn’t implement the addShadowCaster method. We can get around this by casting, but it feels like a hack… Maybe IShadowGenerator should have the addShadowCaster method?
// we have to upcast, because the method actually returns an IShadowGenerator,
// which doesn't implement `addShadowCaster`
let sg = light.getShadowGenerator() as ShadowGenerator | null
if (!sg)
sg = new ShadowGenerator(1024, light)
sg.addShadowCaster(mesh)
I am wondering: the docs mention “addShadowCaster” in this context: Introduced with Babylon.js v3.1, there are two new helper functions to deal with shadow casters:
So maybe when they added the helpers they forgot to update the interface?
Oh, speaking of docs. This should work without typecasting: