LODs and Create Instance

Yes… SAme number of submeshes and exact same multi materials…

NOTE: Even thow the InstancedMesh ONLY says 1 submesh in the inspector… it is actually showing and using ALL 5 submeshes and materials… I am making another Test Tree Scene with mutiple trees spread a little apart from each other… Go to scroll in to LOD0… then back the camera out to right BEFORE it switched to LOD1… now with them all on LOD0 (and the camera right on the edge of LOD0…before it switches to LOD1)… Then just rotate the camera around so that SOME trees are still far enough away to show LOD0 but the trees on the edge will switch to LOD1…

https://www.babylonjs-playground.com/index.html#DI1URI#3

That when is looses the sub mesh info:
Playground shot 1: camera rotated and front left tree looses sub mesh info:

Rotate a little to the right then the right tree goes screwy and left tree and all other are looking good:

But we are almost there… Will be so sweet for Terrains and Painting Complex trees right from Unity Terrain Builder :slight_smile:

I could fix it but I need your help to repro in the playground without your extension

I will try and re create with .babylon scene files so I can use native submeshes and multi materiel for the row tree geometry. Then I make play ground to setup LODs and instances

1 Like

Yo @Deltakosh … Well i had to add support for the new toolkit to generate native .babylon scene files as well as .gltf and.glb (So i had to actually support BOTH file systems).

Anyways… Here is a Test Trees using Raw .babylon scene files (NO Mackey Extensions):

https://www.babylonjs-playground.com/index.html#DI1URI#4

The ONLY problem is with the billboard… If ANY of the LOD levels show a BILLBOARD. The Master tree billboard ALSO shows even though it SHOULD NOT because of its LOD level.

The submesh issue is NOT an issue when using babylon scene files. I also noticed the Instanced Meshes actually show 5 submeshes in the inspector and they render correctly…

But the GLTF version only shows 1 submesh in the inspector (Even though it actually renders as if it had all 5 submeshes)

So the issues has to be with HOW/WHEN i am creating the submeshes for the master tree:

In the GLTF exporter (Right after the geometry data is assigned to the babylonMesh) is where and when i create the sub meshes like this:

            // Setup Sub Meshes
            if (primitive.extras != null && primitive.extras.metadata != null && primitive.extras.metadata.multimaterial != null && primitive.extras.metadata.submeshes != null) {
                const submeshes:any = primitive.extras.metadata.submeshes;
                babylonMesh.subMeshes = [];
                for (let subIndex = 0; subIndex < submeshes.length; subIndex++) {
                    const parsedSubMesh = submeshes[subIndex];
                    BABYLON.SubMesh.AddToMesh(parsedSubMesh.materialIndex, parsedSubMesh.verticesStart, parsedSubMesh.verticesCount, parsedSubMesh.indexStart, parsedSubMesh.indexCount, <BABYLON.AbstractMesh>babylonMesh);
                }
            }

I am using metadata to define the sub meshes index values and then calling: BABYLON.SubMesh.AddToMesh

Should i be creating/defining the SUB MESHES a different way ???

Is there some kind of MARK DIRTY or SOMETHING else i need to do to make the instance ACTUALLY recognize all five submeshes… so they show as 5 submeshes in the inpsector???

As A Reference… The GLTF Version that show the submeshes INCORRECTLY in inspector:

https://www.babylonjs-playground.com/index.html#DI1URI#2

So… Its gotta be HOW or WHEN i am crating the sub meshes for the GLTF Version ???

And of course that FINAL BILLBOARD issue where the MASTER BILLBOARD is rendering on the MASTER tree if ANY of the instances are showing the BILLBOARD for its final LOD Level…

Thats is what i can come up with so far… If you can lend your expertise … I know we can fix this issue :slight_smile:

Did you solve that “Sweet Spot” Issue?

Not quite… Narrowed it down to creating sub meshes with GLTF Extension that is probably the culprit.

Still trying to figure it out… Hopefully @Deltakosh has some insight on how i should be creating the sub meshes

I do not repro (Or I think I don’t :D)

I guess the master mesh is the one closer to the camera and you can see that there is on billboard and the master mesh is not billboard

Wait I may have found something. Can you try the enxt nightly (in a hour or so)

ok… But yeah the image you made sow the billboard and lod0 at the same time:

Tell me if the new version is better

Well if the newer version is on the playground… then not better,

https://www.babylonjs-playground.com/index.html#DI1URI#4

this playground of raw babylon meshes still show the master billboard as well as the LODX mesh if showing any instanced meshed billboard… It like if it has to show a billboard… the mastre mesh billboard is ALWAYS visible.

Yeah now I see it. I will find a way
Stay tuned

Yo @Deltakosh … I need to add LOD support to Babylon Entities and BABYLON.Mesh.Parse

I propose we add to BabylonMesh.cs (Borrowed from MSFT_lod style of LOD encoding) with future support for coverages when we get that working:

        [DataMember]
        public string[] lodMeshIds { get; set; }

        [DataMember]
        public float[] lodCoverages { get; set; }

        [DataMember]
        public int[] lodDistances { get; set; }

Then in BABYLON.Mesh.Parse … We WIRE UP the lod mesh ids and distances … What do you think ???

I can’t recreate…

Re create what … the LOD issue ?

Ok I have a fix!!! This was a really complicated one to fix
Will be on nightly in a couple of hours
Please keep me posted

And obviously ok to add support for LOD in bjs format

Holy Crap @Deltakosh … You FIXED A COUPLE Of Things… Now is perfect… Even now can ADD LEVELS after the createInstance… So will now work prefect in .babylon files.

Check this one out: https://www.babylonjs-playground.com/index.html#DI1URI#5

Now you made it possible to use the babylonFileLoader.ts waiting feature for importMesh and loadAssetContainer

Thanks you soo much @Deltakosh… You are da shit !!!

1 Like

Thanks again @Deltakosh

Terrains with COMPLEX TRESS

  • Multi Complex Materials (Some have MASK using alpha cutoffs and some do not… leaves looks sweet)
  • Multi Complex LOD including BILLBOARD and Final Culling

and to top all that off… ** CAN ALL BE INSTANCED **

can have a terrain with hundreds of trees and still cost only a FEW draw calls (Depending on how many materials your master tree is made from)

UPDATE
Yo @Deltakosh … Found ONE SMALL ISSUE. When your up close like in center of scene and simply rotate camera around the tree disappears… Kinda like before… But if zoomed out enough everything shows ok… here is a playground using just the free camera that starts in center of scene. Just rotate around and see the tree disappears but then comes back

https://www.babylonjs-playground.com/index.html#DI1URI#6

But Still … Freaking sweet :slight_smile:

Yo @Deltakosh … Maybe the up close issue… is some kind of camera near clip plane issue… could that be it ???

nope sounds like a bug again…
Will take care of that