Loading MTL with the OBJ from Google Storage


Let’s say I have .obj and .mtl files uploaded on Google Storage in the same bucket/folder

I can directly fetch .obj and it loads, but the .mtl doesn’t load. How do I solve this. Do I need to fetch .mtl separately and somehow connect it with the scene?

You can see in the image where it looks for the .mtl, but that path is actually not right, so it makes sense that it gives me 404 because .mtl doesn’t exist there. It is in the storage and have it’s own downloadURL. But I don’t know what to get it properly.


Oh I see some references to MTLFileLoader. I will try that out.

1 Like

Hi @Deltakosh. I’ve tried using MTLFileLoader like here.


But I am getting this error. Can I do something about it?

Did you reference the obj loader? if yes how?

Hmmm. I did not.

I used this.

import ‘babylonjs-loaders’;

Which works well when loading OBJ files. Do I need to explicitly define OBJLoader?

it should not
let me invoke @sebavan (he is off for today but should be able to help later this week)

Yup this is strange and I am not seeing any obvious reasons for the behaviour you see in the code. Could you share some code repro with us ?


If I copy this exact piece of code into my project, I get error shown above. So I am not really sure what is going on. Maybe I am missing some dependencies (i tried adding import babylon-materials, nothing happened).
I am using 4.1 version

I will try to investigate further, don’t have time today for that.

No problem, you could maybe share your github project if it is easier and I could have a look.

Assuming you get your import issues sorted…

I’m not exactly sure how Google Storage works, but the obj you are trying to load will automatically try to the load the mtl but without the extra parameters. I’m not sure if there is a way to figure that out without hard coding. One way to do this is to use the preprocessUrl function. Like this:

https://www.babylonjs-playground.com/#EMGNA0#1 (It’s currently missing the texture that the MTL is referencing. Once that’s fixed, it should load properly.)

There isn’t a need to call the MTLLoader manually.


Wow man. You have no idea how much you helped me with this.I didn’t have time to test it out earlier, but I’ve implemented it now, and managed to preprocess the urls properly. Thank you so much, I really appreciate it.

1 Like