# Customize File Loader Best Practice

**URL:** <https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112>\
**Category:** Questions\
**Created:** [August 30, 2024, 12:53pm UTC](https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112 "2024-08-30T12:53:20Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason-wangting](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jason-wangting/32/42037_2.png) [@jason-wangting](https://forum.babylonjs.com/u/jason-wangting)\
**Post date:** [August 30, 2024, 12:53pm UTC](https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112/1 "2024-08-30T12:53:20Z")

</div>

Hi Babylon Experts, I got a question about customizing URDF loader.  
As we all know, the importMeshAsync function needs to return the array of loaded mesh. Visual properties of URDF could refer to another model which type could be DAE. My question is that weather the loaded meshes of DAE file need to be included in the loaded meshes of URDF file?  
Below is example code:

```auto
{
     async importMeshAsync(meshesNames: string | readonly string[] | null | undefined, scene: Scene, data: unknown, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<ISceneLoaderAsyncResult> {
        const loadedMeshes = [];
        const robot = new Robot();
        await deserializeUrdfToRobot(data as string, robot);
        // robot.visual is another model, so need to import the model using importMesh
        SceneLoader.ImportMesh(null, base, filename, scene, (daeFileLoadedMeshes,) => {
            // weather the loaded meshes of DAE file need to be included in the loaded meshes of URDF file?
             loadedMeshes.push([...daeFileLoadedMeshes]);
        });
        robot.create(scene);
        return {
            meshes: loadedMeshes,
            particleSystems: [],
            skeletons: [],
            animationGroups: [],
            transformNodes: [],
            geometries: [],
            lights: [],
            spriteManagers: [],
        };
    }
}

```

Thanks  
BR

---

<div class="post-metadata">

**Author:** ![HiGreg](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@HiGreg](https://forum.babylonjs.com/u/HiGreg)\
**Post date:** [August 30, 2024, 4:10pm UTC](https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112/2 "2024-08-30T16:10:21Z")

</div>

Not an expert. It seems to me that you’re generally doing it right.

The URDF format can reference 3d files in a variety of formats, not just dae, (including from a brief search: dae, obj, .mesh, stl). Loading those referenced meshes with subsequent calls. Unfortunately, URDF files do not require a “name,” so the standard method of selecting which meshes to load (with name parameter) won’t work.

Note also the newer method of loading using [appendSceneAsync](https://forum.babylonjs.com/t/sceneloader-and-gltf-options/52853) but I’m not sure how flushed out it is (the examples are primarily using gltf format).

One thing you might have to work out is how to specify any options for the subsequent loads. Or just try the defaults and see how well it works!

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [August 30, 2024, 8:20pm UTC](https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112/3 "2024-08-30T20:20:41Z")

</div>

I think this seems pretty reasonable, but as @HiGreg mentioned it would be better to use the new module level functions as they are better for tree shaking and allow options to be passed through. For the module level functions, we did not include `importMeshAsync` because we believed that `loadAssetContainerAsync` can do all the same things, but this case is interesting since `ISceneLoaderPluginAsync` requires you to implement `importMeshAsync`. We could definitely include it if it is needed for scenarios like this.

Also just FYI, we are doing work right now to make it possible to have loaders by created through async factories, which makes it possible to do dynamic imports for the loaders, which I think is especially good for this kind of scenario, where your URDF may reference various other formats. In that case, you would only have to pay the download cost of a DAE loader (for example) when loading a specific URDF that references a DAE.

---

<div class="post-metadata">

**Author:** ![jason-wangting](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jason-wangting/32/42037_2.png) [@jason-wangting](https://forum.babylonjs.com/u/jason-wangting)\
**Post date:** [August 31, 2024, 2:35am UTC](https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112/4 "2024-08-31T02:35:15Z")

</div>

Wow，I’ve always heard that Babylon.js has a fantastic community, and today I experienced it.  
Thank you very much for your reply. It’s very useful for me.

Besides, I find that [appendSceneAsync](https://doc.babylonjs.com/features/featuresDeepDive/importers/loadingFileTypes#appendsceneasync) will invoke the [`load`](https://github.com/BabylonJS/Babylon.js/blob/4c490583f33116b044f3db8f60da918710ccd495/packages/dev/core/src/Loading/sceneLoader.ts#L1042) or [`loadAsync`](https://github.com/BabylonJS/Babylon.js/blob/4c490583f33116b044f3db8f60da918710ccd495/packages/dev/core/src/Loading/sceneLoader.ts#L1051) provided by customized plugin. So I think `appendSceneAsync` method is suitable for other formats. For reference only.

I think registering other loaders(eg: DAE loader) to Babylon.js in the URDF loaders is one option. My implement is that just invoking `appendSceneAsync` method when load those referenced mesh, developers need to register other loaders in their app instead of registering in the URDF Loader. Maybe I need to find a way to overwrite the subsequent loader’s configuration temporarily if necessary. I will try it to see how it works.

---

<div class="post-metadata">

**Author:** ![jason-wangting](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jason-wangting/32/42037_2.png) [@jason-wangting](https://forum.babylonjs.com/u/jason-wangting)\
**Post date:** [August 31, 2024, 2:51am UTC](https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112/5 "2024-08-31T02:51:00Z")

</div>

Thank you for your reply.

Yes, I find the [createPlugin factory method](https://github.com/BabylonJS/Babylon.js/blob/4c490583f33116b044f3db8f60da918710ccd495/packages/dev/core/src/Loading/sceneLoader.ts#L583) in the code. It’s pretty good. I will try it when most of loader plugins have already implemented this factory method in the URDF loader.

---

<div class="post-metadata">

**Author:** ![jason-wangting](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jason-wangting/32/42037_2.png) [@jason-wangting](https://forum.babylonjs.com/u/jason-wangting)\
**Post date:** [August 31, 2024, 2:52am UTC](https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112/6 "2024-08-31T02:52:53Z")

</div>

You can find the [Babylon-URDF-Loader here.](https://www.npmjs.com/package/babylon-urdf-loader) if you need.

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [August 31, 2024, 5:45am UTC](https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112/7 "2024-08-31T05:45:01Z")

</div>

Cool! I was curious to see the source but it looks like maybe the repo is private.

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [August 31, 2024, 10:02am UTC](https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112/8 "2024-08-31T10:02:41Z")

</div>

> [@ryantrem](#):
>
> I was curious to see the source

I believe it is here - [GitHub - polyhobbyist/babylon\_ros](https://github.com/polyhobbyist/babylon_ros)

---

<div class="post-metadata">

**Author:** ![jason-wangting](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jason-wangting/32/42037_2.png) [@jason-wangting](https://forum.babylonjs.com/u/jason-wangting)\
**Post date:** [September 2, 2024, 5:14am UTC](https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112/9 "2024-09-02T05:14:37Z")

</div>

😀 I forgot to set it as public~ I will make it public when I finish most of functions recently.

---

<div class="post-metadata">

**Author:** ![jason-wangting](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jason-wangting/32/42037_2.png) [@jason-wangting](https://forum.babylonjs.com/u/jason-wangting)\
**Post date:** [September 2, 2024, 5:15am UTC](https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112/10 "2024-09-02T05:15:51Z")

</div>

Yes, This project builds upon the work done in [GitHub - polyhobbyist/babylon\_ros](https://github.com/polyhobbyist/babylon_ros), with additional configurations and integration with the standard loader interface designed by Babylon.js.

---

<div class="post-metadata">

**Author:** ![jason-wangting](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jason-wangting/32/42037_2.png) [@jason-wangting](https://forum.babylonjs.com/u/jason-wangting)\
**Post date:** [September 2, 2024, 3:08pm UTC](https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112/11 "2024-09-02T15:08:26Z")

</div>

Hi, I have made it public, you can find it here [GitHub - babylon-ros](https://github.com/jason-wangting/babylon-ros), for your reference.

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [September 14, 2024, 1:16am UTC](https://forum.babylonjs.com/t/customize-file-loader-best-practice/53112/12 "2024-09-14T01:16:33Z")

</div>

@jason-wangting the async factories I mentioned for dynamically importing (lazily downloading) loader plugins is now live. If you are still working on your custom loader, check it out! [Dynamically imported scene loader plugins and glTF extensions](https://forum.babylonjs.com/t/dynamically-imported-scene-loader-plugins-and-gltf-extensions/53438)
