Create Your Own File Importer
How to Create Your Own File Importer
By default, babylon.js comes with an importer for .babylon files.
You can also create your own importer by providing a specific object to the BABYLON.SceneLoader.RegisterPlugin
function.
This object must have three properties:
- A list of supported file extensions (
extensions
) - An
importMesh
function to import specific meshes - A
load
function to import complete scene - A
loadAssets
function to import all babylon elements from the file but do not add them to the scene
Here is a sample importer object:
javascript
BABYLON.SceneLoader.RegisterPlugin({ extensions: ".babylon", importMesh: function (meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons) { return true; }, load: function (scene, data, rootUrl) { return true; }, loadAssets(scene, data, rootUrl) { const container = new AssetContainer(scene); return container; },});
meshesNames
is the names of meshes to importscene
is the scene to load data intodata
is the string representation of the file to loadrootUrl
defines the root URL of your assetsmeshes
is the list of imported meshesparticleSystems
is the list of imported particle systemsskeletons
is the list of imported skeletons