Cloning with AssetsManager

Hi all.
Wondering what the best practice/technique is for using AssetsManager with clones. In short: setting up a bunch of GLB load tasks… but for any load where the filepath is identical, cloning instead of loading a-fresh.

Is it an either/or thing?

  • If file not already loaded: use the AssetsManager OR
  • If file already loaded: run a separate cloning function (don’t use AssetsManager)

I’ve tried some cloning logic within my addMeshTask function, but it’s getting spaghetti… and doesn’t work with more than 1 file being loaded at a time, since the mesh is only available to be cloned after the batch of load tasks have been run.

What I’m looking for is a setting on AssetsManager that’s like “useClones = true.” Or am I just over-doing this? If the file is saved in browser cache, is there any performance benefit to cloning in the first place? (noting that I can’t use a Mesh Instance or SPS since materials are different per clone).

Thanks for any tips!

In your case, I would probably try to rely on an asset container as it could provide you with the extra flexibility you require: Use an AssetContainer - Babylon.js Documentation

Asset Manager will not clone automatically if same url as it has no idea what could have happened to the assets before the second call.

Hm. I did read that documentation (a few times) but don’t understand its benefit. Seems more like a way to turn on/off a set of assets at one time? If it’s a “pool of entities” … the pool can either be all-on or all-off?

From the docs, what does this mean? This assets are still linked to a scene but are not taken in account.

It means they can only work in this scene but they are not visible or used in the rendering.

so you could use .instantiateModelsToScene(); to create several copies as it will create all the required clones for you.

Does cloning confer any performance benefits (if browser is already caching file)?

Preventing some parsing and so on I would think it is more efficient but if your looking for keeping all the clones the same on screen you should think about instancing which would reduce your draw calls number.

Problem is that each clone may have a different material… (which is why i chose cloning versus instancing)

Although, am thinking about writing a method to find clones that happen to share the same material (if there are any) and instancing them… Lot of work though. But at 300 assets, I’m at sub 15 fps… so gotta do something…

1 Like