Shadow for an whole building

wierd i dont get the Shadow

I am fixing (parts of your issue) just now.
Know already that there’s a good a reason why you do not get any sort of shadow.
Currently your code does not pick through the child meshes and your meshes do not cast neither receive shadows (you can check this with the inspector).
Second, as pointed by @slin you are actually (attempting to) create a shadow generator for each mesh by placing it in the ‘for’ (each) loop. You certainly don’t want that and lucky for you, your code also didn’t enable this :wink: Luckily, because there’s no chance this would work.
Already take a look at this PG that (for now) relies on a promess before creating a shadow generator and run through all child meshes to set shadow casting and receiving.
Next, I just need to adjust the light and shadow but it looks like your building is just at a tiny/mini scale (like a building for ants :wink:). Let me check on that and send you an update shortly.

Ok, so it’s what I thought (nearly). Not an ants building but a 5-stars building for bees :honeybee: :wink:.
The 3 floors hold in a box of height 10. This means your values for setting the light (position and more importantly direction) need to account this scaling. You can already remove a decimal or 2 to the direction.
Next thing, I would need to understand is what sort of shadow do you want from this generator. Is it from the sun or for interior lighting? For interior lighting, I can recommend you would rather bake your lights/shadows. It will have you master your lighting much better and have MUCH lower impact on performance. Already now, you should start merging your meshes of exterior and interior walls and other structural parts. The scene is already very slow. Too many meshes and too many transform nodes for which I do not just know exactly what they are here for. I’ll send you a new PG casting shadows from the sun shortly.

I would link to have an shadow from the sun.the Most meshes just for the building I try to merch them but when i do it the whole building got damaged ( i got the building from an friend).

You can merge them inside babylon and it shouldn’t affect anything from your UVs and materials.
By default, it will create a multimat and keep everything the same.
Just go like:

const mygroup = BABYLON.Mesh.MergeMeshes([mesh0, mesh1, mesh2], true, true, undefined, false, true);

And try to make merges of all parts that need to hold together.
Create one for exterior walls, one for interior walls and one for each structural element.
This should help already.
Do this after the promess (after the object and all submeshes are loaded).

OK, so quickly added another camera because (sry) couldn’t see what I’m doing with yours.
It allowed me to understand that you also have a basement level.
First thing I would do here is:

  1. Make the ground a ground. Isolate it from other meshes/groups, call it ‘ground’ and let it be at zero origin.
  2. Make all your floors level grounds to ground (ground0, ground1, ground2…), isolate them from other meshes and groups.
    Grounds will receive shadows casted by the sun and other structural parts.
    Walls and structural parts will also receive and cast shadows from the sun.
    For interior lighting, as I said, (ideally) walls and structural parts should have baked lighting.

Edit: Once this is done, I can help you set shadows from the sun, but as of just know I don’t even know what the ground is (and I don’t want to browse through all meshes to find it). I can already say the ground is not at zero on y (which doesn’t make it easier to set shadows).

I tried to merch the Ground, but it dint worked or it is still solo in the inspector.

I called the Floor Ground_UG, Ground_EG, Ground_1OG,Ground_2OG.
Is it possible to merge them through an For While?

Babylon.js Playground (

I still can’t find my external ground. The ground that’s outside the building. What’s the name of it?
I speak german. Although the forum is in english, you can add a small text in german when you reply to my posts if you are more confortable with it. First thing I need, is to have the ground (where the building sits) for external shadows. Next, you do not need (and preferably don’t want to) merge your floors/levels.
I just need to be able to identify them. Thanks,

Edit: Just found it. It’s ‘BodenAussen’.

So now I get the the merch different floor element.

The ground from the outside is called BodenAußen.
And the floors name are Ground_UG, Ground_EG, Ground_1OG,Ground_2OG

Babylon.js Playground (

Yes, got it. But you don’t need to merge your floors (better not) and your code for doing this is wrong by any means. I hope you’re not in a hurry. It’s soon time for me to make dinner but I will try send you an update ASAP (if not tonight then tomorrow morning, if that’s ok with you?)

ok yeah im bit stressed i need it to friday but other wise i dont got the shadow.

ok Thank you very much :smiley:

I believe we can make it so that by then (thursday at the latest), you will also have your shadows :smiley:

1 Like

Meanwhile, I would have a task for you.
It looks like everything in your scene is a mesh. I have dozen of doors meshes and it looks like they are mostly all the same. I suggest you take a look at the docs for how to create instances
Ideally, all of your windows, doors, structural elements that are the same should be instances.
It will remove a LOT of load and make the scene A LOT BETTER in terms of performance and user experience.
Why don’t you take a look at this while I will take some time to bring shadows to your scene? Deal?

I take an look on the instances but i cant create per Babylon an incstance of the window and the door because when i want to do it i need the cordinate of the original place.

So i think in this case it is the better to create the instance via 3D programm.
Or im wrong wit the cordinate part?

Ich habe mir die instances angeschaut und habe festgestellt, dass man die Fenster sowie Türen aus dem 3D Objekt löschen müsste um eine Instance zu erstellen. Diese Instance müsste dann an den selben Stellen wieder hinzugefügt werden, aber dafür bräuchte ich immer die Kordinaten was ja recht aufwändig ist. Wäre es über ein 3D Programm dann nicht einfacher?

Yes/Klar. Are you using Blender?
Wenn Ja, dann bitte schau dich dies an Instances | Babylon.js Documentation
Easiest way to replace all your duplicate meshes with instances is to do straight in Blender (or 3DS).
Versuchs mal mit nur ein Objekt (z.B. Türe oder Fenster)…

1 Like

yeah that is right what i thought ok i will try it :smiley:

1 Like

Fixed a number of things but before going further, would recommend to do some changes.

Sry, I’m mixing english and german here, because we are not supposed to exchange in foreign language in the forum :grin:

  1. Du solltest das Gebäude in einem größeren Maßstab erstellen. Kann 2 oder 4 mal größer sein. So werden die Schatten besser und auch alles mit Kamera handlung
  2. PBR Materialien müssen gearbeitet werden um das neue Environmental zu benutzen
  3. Es geht doch nicht nur um Schatten. Es gibt tonnen Einstellungen um eine total verschiede Ambiance zu kreiren. Doch diese Einscheidung gehört dir.

Do you want stronger shadows, stronger lights? More or less realistic VS sexy?

Schau dir mal diese screenshots an? Ist das etwas in der Nähe?

Let me know when you have a new version (may be with instances and a rescaled building)

Das Fenster Material mußt auch noch neu gearbeitet werden (denke ich).

In this PG, press keys 1 to 6 to change the time of day (4 is launch time, 1 is night, 2 is dawn, 3 is sunrise, 5 is sunset, 6 is dusk). I still need to make some adjustments also for the light direction but is no use doing it before the revised version model.

Thank you very much.

I think this shadow projekt will be to much for the projekt i think the building is not in perfect shape with the texture an every think.

But i will let you know then i got an net Objekt.
I think I need to lear a lot for the shadow.

Ich glaube das nimmt alles einen zu großen aufwand mit dem Schatten, aber verstehe ich langsamm wie die Schatten Funktionieren

1 Like

You know best. In case, let me know and I will try to guide you through it…
Meanwhile, have a great day,


I LOVE YOU! Your help here solved my issue in How to add shadows to imported child meshes? - Questions - Babylon.js (

These lines solved my issues:

let parent = scene.getMeshByName(“_ root _”);

// shadows handling
var shadowGenerator = new BABYLON.ShadowGenerator(2048, light);

let mymesh = parent.getChildMeshes();
for (var i = 0; i < mymesh.length; i++) {
mymesh[i].receiveShadows = true;