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.
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.
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: BABYLON.SceneLoader.ImportMeshAsync("","",filename,_scene,onProgress,".glb")
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.
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.
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")) {
alert(url);
return "/assets/3d/"+url;
}
return url;
}