Referencing external assets in a babylon file

Is there a way to auto-load external assets with SceneLoader? I want to add a “player” mesh reference in the Editor, and have the player asset container imported automatically - without baking it into the babylon file.

The Loading Assets From Memory page describes something similar, but involves manual steps to convert assets into blobs; what I’m looking for is a mechanism to invoke the AssetsManager to load external assets on the fly.

There’s also the Incremental Loading System, which seems to do what I want, but that requires converting scenes into another format.

When you say auto-load, do you mean auto-download, or download previously and show when needed?

From what you write, I assume you mean auto-download when the asset is required?

Sorry for the lack of clarity. I am calling SceneLoader.LoadAsync, and would like it to automatically call ImportMeshAsync when it finds a reference to an external mesh.

The more I think about this, the more it sounds like a feature request, rather than something that already exists… But I was hoping to be able to write some something like this:

“meshes”: [
{“meshName”: “dummy3.babylon#YBot”,
“position”: […]}

The idea here is to import the YBot mesh from the dummy3.babylon file into the scene. This would make it possible to share assets between scenes.

I am still a bit at a loss :slight_smile:

What stops you from doing what you are describing? We don’t know when you need the mesh (other than when the mesh is in frustum but hasn’t been downloaded yet).

You can share between scenes using the assets container, and I actually assume you are referring to something very similar to the asset container - Asset Containers | Babylon.js Documentation

What stops me is that I need to modify the code of the MeshLoader, which I’m not familiar with. :slight_smile: Maybe I can add a callback, like onLoadMesh, which would be called for every “mesh” block, and expect a Mesh return value. Then the MeshLoader caller can customize the loading process.

By sharing assets, I mean at design time. I’d like to basically drag or import a mesh into the scene, without embedding it in the scene json. The assets change all the time - I don’t wan’t to have to update every “level” whenever a mesh changes.

This will require some custom implementation on your side, loading the assets you need using code (and not only using the loader, as you expect). The .babylon file was not planned with that feature in mind.

Sorry :slight_smile:

We will be happy to consider that as a feature for future versions, and I will be very happy if you submit an issue for it on github, but TBH I don’t see it happening in the near future, so I wouldn’t count on it being developed in the next major version (i.e. 6.X). And we are always happy to accept PRs with new features that we discussed here :wink:

Hello @alekop just checking in, was your question answered? :slight_smile:

Yeah, I ended up adding TransformNodes using the Editor, and then loading meshed into them, after the scene is loaded.

1 Like