I’ve been trying to apply a shadow to objects I import using the Assets Manager, but keep running into errors. I assumed that I’d want to push the loaded meshes to my getShadowMap().renderList
after the asset manager task was complete, but I am met with this error below. Am I perhaps pushing the wrong meshes to the renderList? For reference I am using .glTF files for this project if that makes a difference.
This is my code for when the asset manager task is complete:
meshTask1.onSuccess = (task) => {
const exterior = new TransformNode('exterior');
task.loadedMeshes.forEach((mesh) => {
if (!mesh.parent) {
mesh.parent = exterior;
}
mesh.isPickable = false;
});
(this.shadowGenerator as any)
.getShadowMap()
.renderList.push(task.loadedMeshes);
};
Apologies, here’s the link:
https://playground.babylonjs.com/#BHJ58I#5
If you comment out line 64 you will see the issue appear
OH! I think I’m starting to see what the problem is.
Note your model is really big so I substituted it for a different one to make the debugging faster.
https://playground.babylonjs.com/#BHJ58I#9
Now what I think you want to do instead is move the non working line up a tad and add them one at a time. Now after doing that I got it to run, but no shadows showing up. So I looked at our example in the documentation and was like “hmmm what’s the difference”
Taking a look at this demo: https://playground.babylonjs.com/#B48X7G#2
receiveShadows = true;
2 Likes
The renderList.push
method is expecting a single mesh. You can pass something like ...arrayOfMesh
to avoid looping over all the meshes of the array.
You also need to enable the ground to receive shadows:
https://playground.babylonjs.com/#BHJ58I#10
3 Likes
Ah I didn’t realize it would only take a single mesh. Thank you for the quick answer!