Jump to content

Is there a built in "plug-in" loader?


Recommended Posts

Specifically, I'm wanting to add the babylon.objFileLoader plugin so I can use .obj/.mtl assets (dynamically, and only if needed). Is there a built-in way to delay the renderLoop until the plugin and assets to import are loaded in?




To expand, I'm hoping there's a built-in way that will prevent me from having to wrap the renderLoop in a "success" function completed after the loads, or from using a timer to check for a ready state until it is true.


One such (ideal) solution would be to import the babylon.objFileLoader via the AssetsManager, but does it do this?


Final edit: I've done this through a bit elaborate 'require', but I'm still interested if there is a built-in way of including JS and delaying the renderLoop.

Link to comment
Share on other sites

The loaders are registered using the SceneLoader (for example - https://github.com/BabylonJS/Babylon.js/blob/master/loaders/OBJ/babylon.objFileLoader.js#L728 ) .

You could use the (private) static method _getPluginForFilename of the scene loader to make sure the plugin is there. Maybe a public method "isRegistered(extension)" can be added, but - if you add the js file in your head there is no reason it won't be loaded and ready to be used.

Link to comment
Share on other sites

Adding it in the head is pretty much what I'm trying to avoid. I'm using RequireJS module loading, and I have no guarantee that Babylon.js will be loaded before the plugin, which causes problems.


Really, I'm trying to make it where when I'm adding a mesh task, it says - "oh hey, you want to load an .obj file - let me grab this plug in for your first". A native way to import js via the AssetsManager would be swell :)

Link to comment
Share on other sites

Yep, understood.

The loader-concept is rather new. The babylon loader is integrated in the system, the rest can be added as plugins, but it would be nice to be able to use the assets manager to do that. Using the Mesh Task the loaders could be loaded dynamically.

There are a few problems with that, let me think of a nice way to solve them. One of them is the location of the loaders. As far as I know (and correct me if I am wrong) the loaders are not on the CDN. 

Brain is working. And always open for suggestions :-)

Link to comment
Share on other sites

Nope, for now the external loaders are not on the CDN, but it would be usefull to also have them there.

One difficulty if you address them directly in the babylon loader system, to upload one if needed, is that it should be relative to the actual path of the BJS file (because for a BJS file loaded from a SSL server, the files uploaded afterwhile should also come from SSL, but the BJS CDN is not SSL - that's why I systematicaly port each BJS release in a second CDN which support SSL). Maybe we can define a "global depency path", to define the server where to search for those dependencies, and then we keep the same file structure on every CDN.

What do you think ?

Link to comment
Share on other sites

I made a first draft of the changes, I think this will work - https://github.com/RaananW/Babylon.js/commit/6bdaf8c73f31568303703e1d6fd23e37e82a4aed

This is locally on my repo, PR was not sent yet as I need to fully test it.


In general - a new variable was added : SceneLoader.LoadersLocation, which is the global location of the loaders (and is mutable! so should be changed according to your needs).

When trying to load a file, the extension will be tested. If a plugin was found, it will run the code normally. If not, it will try loading the js file and will wait for an event that is triggered after the plugin is registered.


It will then execute the success function, which will load the object using the plugin.


Already fixed a small bug (i forgot the "document.head.appendChild(script);" to actually load the script). Still need to test it. You are more than welcomed to try as well! 


Of course, we need to think if it makes sense to have it in the framework...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...