LODs and Create Instance

Are Mesh Instances supposed to automatically handle LOD that are on the source mesh or do i have to re-setup LOD on the mesh instance returned from createInstance call ??

Yo @bghgary … If the answer is yes, they are automatically copied/used for mesh instances and should be setup prior to call to createInstance… Then i have to setup my LOD in _LoadMeshPrimitiveAsync … Right??? Or is there some lazy load lod that mesh instances will update from… or whats the deal with the order Mesh primitives are created and lod levels assign and finally createInstance ???


Yo @Deltakosh and Maybe Gary @bghgary can tell what to do with this one.

GLTF vs Babylon Instance Meshes In Scene Files.

Using native babylon scene files, instacnes are serialized as an array of AbtractMeshes on the the BabylonMesh entity. This mode DOES NOT actually create node that get represented in the SCENE hierarchy. When the loader create the the babylon mesh… it will iterate all the mesh.instances and create the an INSTANCE of the mesh at the serialized abstract mesh location. So when setting up the original master mesh… everything gets setup first… submeshes, LODs, etc… then when the loader creates all the instances (WHICH DOES NOT EXIST IN SCENE YET, NOT UNITIL WE CREATE THE INSTANCE) … The instances will have everything the MASTER mesh did.

Well GLTF handles instances a bit different… There is an ACTUAL node that gets serialized in the GLTF Node hierarchy… And the babylon GLTF importer does some MAGIC to detect that a node is an instance and creates and instance mesh to use CreateInstance instead of actually creating a new Babylon.Mesh for that GLTF Node… The point is everything is always represented in the scene… even the LOD and Instance Meshes

I have setup a sample TestTrees.glb scene in the playground to show this problem.

You will notice there are TWO trees



So in gltf all this created because that is what in scene files… So there will be a problem when trying yo create attach LODs using InstancedMesh. The second tree and its LOD’s are really the same meshes as TREE1 so TREE2 ends up as InstancedMesh for the whole TREE2 hierarchy.

How would handle this situation… I have two trees… each of which has lods and one of them will be made purely of instance meshes…

Here is the test playground with a TWO test trees common for a UnityGLTF export:


can you please try and get LODs going on both trees… Please :slight_smile:

Yo @Deltakosh … I created another playground that uses GLTF extension to assign the LOD levels at geometry creation BEFORE instances are created. Also the export checks if meshed are LOD Levels and Instanced Meshes… If so it just exports a empty transform and the loader later discards those empty transforms… The LODS come over on the instance mesh so DON’T NEED another mesh of the instanced lod… Please look at tree hierarchy in the inspector.



1… The instanced mesh billboard does not work (just like before you fixed billboard as LOD level). The master mesh billboard works fine. Seems like the billboard mesh does not like being an InstancedMesh :frowning:

2… There is a distance back your camera can be… Like 5 or so units… Just scroll in and out while rotating around. The second instanced tree will disappear completely for a second. Just keep moving the camera slightly… it will re-appear… It does not look like it is the LOD switch over either… Must be because the second tree is an InstancedMesh or something :frowning:

@Deltakosh or @bghgary … Will you please take a look at the scene in play ground :slight_smile:

So to your initial question: You have to set them up one by one as instances are regular meshes.

So to your questions:

  1. How do you set up the billboard when creating the instance meshes? can you repro without your extension (like a simple playground with no glb loading) or is it somehow linked to the way you create them?
  2. I feel this is linked to the way you create the instance and set the LOD. Also same thing, to investigate I would like a scene with no external code

If i dont do it in the extension then it too late for the instanced mesh. If i create the lods when the geometry is applied then those lods exists for the next call to createInstance.

I dont know how to re-produce the situation without the GLTF loader assigning the LOD.

I will see what i can make up in the playground

1 Like

But if you do it by manually creating a plane for instance but reproducing the same command ordering, do you repro the issue?

Yo @Deltakosh … I re-produced in play ground with regular primitive meshes


First shot with both balls (left one master and right one instanced mesh)
looks good:

Now if i back the camera out a little. just till green ball (second lod) and rotate around… the second ball disappears:

If i rotate a bit more it comes back:

And last the second billboard does not follow camera:

Can you take a look at it please :slight_smile:

on it

Ok the ball that disappears is fixed. But the billboard with instances and LOD is kind of REALLY tricky. Not sure I will be able to support it

My recommendation is to not use instances with LOD as they are not fully supported (and instead use clones)

Scratch that! I made it work :slight_smile:
Will be in next nightly!!

Thank you so much @Deltakosh

I needed lod and instances … especially for painting trees :evergreen_tree: on your terrain… could have hundred trees … if no instance for lod would cost 100 draw calls or more

But you did it … sweet :blush:

1 Like

Yo @Deltakosh … Thanks again bro… I noticed one SMALL issue… The position of the second instanced billboard is a little LOWER than the master:



Yo @Deltakosh … What was the issue with that little SWEET SPOT where the green ball disappeared. I think there is still a slight issue in that SWEET SPOT where is does not take into
account the SUB MESHES.

Here is a shot with actual Tree Geometry that has sub meshes and multi materials:


And when i hit that same SWEET SPOT with tree:


This will be a hard one to re produce in the play ground, but i will try. If you can just look at that sweet spot and sub meshes that would be awesome.

Looks freakin great though :slight_smile:

1 Like

This is a really COMPLICATED one where LOD and billboards and isntances are mixed up and I cannot fix anything without a simple repro unfortunately

I’ll check the position issue you mentioned

Ok the billboard position bug is fixed and will be in next nightly:)
I changed the way I was dealing with this issue so this could also have fixed the other problem :slight_smile:

Thanks @Deltakosh … I’ll check it out after nightly build

it is on master if you want to test it

I check the latest version… Billboards are fixed… Still that sweet spot issue…

I think is an issue where the master mesh is a LOD0 and the instance mesh is at LOD1 then its like its ignoring the sub meshes and multi materials.

But your right… it complicated… Since GLTF does not support sub meshes and multi materials YOU HAVE TO USE MY EXTENSION to even see the problem.

I made a test tree scene as simple as i can: Please take a look at if anything just to see what im
talking about :slight_smile:

Tree Tester

So: are all the LOD level having the same number of submshes?