Loading objects as blobs

Hello all,
I searched for a solution but I havent found anything.
I have a problem regarding loading objects.
My project requires a small babylon previewer for the newly uploaded objects.
We support obj with mtl, textures,
gltf either with embedded textures or not
and glb.
The user can either provide a URL for the object which works as expected, or he can provide a local object with its textures

I dont have access neither to the original object, nor to the uploader.
I get the resulted files data which I can create a new blob from.
The problem is that when I try to load an obj with mtl, the loader reads obj without an issue but then it tries to load the mtl using its original name and not the blob.

Do you have any ideas?
The only thing that comes to mind and I want to avoid is editing the loaded obj or gltf to change the uri of the rest of the objects.

The OBJ file contains the line that references the .mtl file (the URL to load). You will need to change the content of this file with the new (blobl) URL instead of the URL referenced there.

But maybe someone else had a better solution?

Thank you Raanan for the fast answer.
That is what I try to avoid. I will wait if someone else has a better idea

You can try to override the FileTools.RequestFile function to intercept the request for the mtl file:



You can use Tools.PreprocessUrl instead of overriding FileTools.RequestFile. All url requests should go through that function. That should be a bit cleaner.

This function is typically used when you need to pass authentication tokens as parameters to the URL, but in this case you can use it to redirect to blobs.

1 Like

thank you all for your answers. I will try them and gine feedback

Hi there, @bghgary:

Any PG, sample code, or this forum thread about how to use this functionality? I can only find the API doc.

I am trying to get rid of this same problem when I use a GLB streamed as a blob.

The loader (SceneLoader) can’t find the textures, as they are set with no path at all before de filename (I want them in the same folder as the GLB) and that is misunderstood by the importer (ImportMeshAsync) as being the server root.

I’m loading the “blobed” GLB this way:
where filename is in fact a ObjectURL created from the blob.

Of course, all run flawless when I use a GLB with all the textures embedded, but I prefer to have the textures in their own files as they are shared between several 3d models.

Any help or direction with this?

Thanks for your time!

Hi there, @GkAdam:

Replying to a long time ago question but, did you find any solution to your problem? I’m facing a very similar one with a blob of GLB + External Textures.

Thanks for your time!

Hi there, @bghgary :

Ok, I’ve managed to find that, in order to fulfill the whole path of my (PBR) textures, the intended use for PreprocessUrl would be something like this:

BABYLON.Tools.PreprocessUrl = function (url) {
    if (url.endsWith("png")) {
        return "/assets/3d/"+url;

    return url;

Thanks for your help and clues!