How to add lod to loaded mesh?

Hi, I want to set up lod levels for loaded meshes (gltf), but don’t know how to properly do it.
Please have a look on not working playgound https://www.babylonjs-playground.com/#WANXPQ#2

In my mind, promise should work - but nothing is shown. What’s worse:

babylon.js:16:37009
BJS - [18:42:36]: Instances should only be created for meshes with geometry. 59

How can I fix this and get lod working?

Thanks.

Hello @franmx!

I would start with importing the mesh successfully first, then work on the LOD.

Using External Assets:
https://doc.babylonjs.com/resources/external_pg_assets

Then…

Level of Detail:
https://doc.babylonjs.com/how_to/how_to_use_lod

Hi @Anderson34, meshes actually load (I disabled them to check if isntance was being created, please see playground @ lines 24,32 ). Error is shown in browser console, so most likely it’s related to reason I can’t use lods (or so I think).

I actually haven’t worked with LOD yet, but this example seems excellent:
https://www.babylonjs-playground.com/#QE7KM

Yes, I tried to base on that one. But not working in my version, of course. :frowning:

– edit not that one, the one in documentation, thing is that they create from Babylon.Mesh which seems faster than loading external files, that’s why I’m using promise (most likely wrong)

I see :thinking: I’m relatively new to BabylonJS, so you might have to wait on the experts to help out.
Good luck!

Thanks for trying to help, hopefully some more experienced memebers will chime in.

Pinging @bghgary

You can only add lod meshes for mesh that have geometry. When you load a glTF, it will create a __root__ mesh that doesn’t have geometry.

Here is one way you can fix it:
https://www.babylonjs-playground.com/#WANXPQ#3

Thanks a lot @bghgary , I thought getMeshByName would actually get mesh geometry, so I’ll better check out indexes.

Follow ups if you don’t mind please:
a) I tried to clone / instance the object, but clones / instances don’t show up the avocado.
In clone -> boombox remains boombox
In instance -> no avocado is shown, only boombox goes to null after set distance (or so it seems).
https://www.babylonjs-playground.com/#WANXPQ#4
b) Outside of this particular promise, how can I instance or clone later on the game?
c) If I have multiple parts (lets say boombox + table) in gltf file, every part should be treated as a different object for lod, right? (table Lod 0, table Lod 1… boombox Lod 0, boombox Lod1…)

I think the negative scale is messing with things. I added scene.useRightHandedSystem=true and now it’s working. https://www.babylonjs-playground.com/#WANXPQ#5
@Deltakosh @sebavan any ideas?

I’m not exactly sure what you are asking. Wait for the promise to finish and do the same thing as you are already doing to get the main mesh and create instances from it?

I believe so, yes.

Thanks a lot. On b, like you suggested (wait the promise to finish).

How do I check promise did finish, set a boolean flag?

One way is to store the resulting promise in a variable (say loadPromise) and call .then on it. There are lots of different things you would do for this depending on how your code is set up.

Thank you very much. Hopefully some more information will be shared on if it’s possible to use the cloned objects as well (would like to change some materials on clones afterwards).

1 Like