SceneLoader.GetDefaultPlugin(): How to get back asynchronous loading methods?

I can get the default plugin used to load from .babylon files by:

const defaultLoaderPlugin = SceneLoader.GetDefaultPlugin();

GetDefaultPlugin() returns an IRegisteredPlugin, whose plugin property is one of these:

  • ISceneLoaderPlugin
  • ISceneLoaderPluginAsync
  • ISceneLoaderPluginFactory

However, even though the default loader plugin for .babylon files offers synchronous as well as asynchronous versions of ImportMesh, Load, and LoadAssetContainer,
with GetDefaultPlugin().plugin I only succeed in getting the synchronous versions.

What I want is an ISceneLoaderPluginAsync, that would give me the asynchronous versions.

Background: I need this for extending the functionality of the default loading behaviour of LoadAssetContainerAsync. I am registering my own ISceneLoaderPluginAsync as the new loader-plugin for .babylon files, which runs my custom behaviour, after which it registers the default plugin again, in order to import geometry the default way.

cc @bghgary

This isn’t really my area, but looking at the code, it seems the babylonFileLoader only has sync versions. Where do you see async versions?

Hey @bghgary, I am talking about SceneLoader.LoadAssetContainer() versus SceneLoader.LoadAssetContainerAsync(). I can use both to load assets from a .babylon file, however, SceneLoader.GetDefaultPlugin() returns something that only contains the synchronous method.

I am dealing with a situation where I want to extend the behaviour of a SceneLoader.LoadAssetContainerAsync() call by running my own code before loading assets from a .babylon file. To do so, I am registering my own .babylon file loader, which calls SceneLoader.LoadAssetContainerAsync() after running some extra code manipulating the incoming .babylon JSON. This works for the synchronous loading methods, however, I am unable to get access to their asynchronous versions.

1 Like

SceneLoader.LoaderAssetContainerAsync and SceneLoader.LoadAssetContainer are both “asynchronous”. The former returns a promise and the latter uses callbacks. Whether the underlying loader is actually asynchronous depends on the loader. The BabylonFileLoader is always synchronous. There is no asynchronous version. The only part that will be asynchronous is downloading the file itself which you can use Tools.LoadFile or Tools.LoadFileAsync to do if necessary, but if you are registering your own loader, you don’t need to do this part. Hope this helps.

1 Like

Hi @hschmiedhofer just checking in, did our answers help you solve your problem? Or would you like some more help? :slight_smile:

It took some time, but I think I understand now. Thanks a lot!