GLTF load from string texture loading

Hello !

I have an issue when loading a gltf file as a string.

When I load it with BABYLON.SceneLoader.Append("./", "test.gltf", scene, function (scene) { // do something with the scene });, it works fine (texture are fully loaded)

However, when I pass it as a string (with embedded texture) with BABYLON.SceneLoader.Append("", "data:" + gltfString, scene, function (scene) { // do something with the scene }); it doesn’t work.

I use exactly the same file, so I guess the issue is in the gltf-loader, am I wrong ?

You would need to specify pluginExtension from the append function for the application to detect it is a gltf file in this case

I tried to specify the extension like this : loader = BABYLON.SceneLoader.Append("", "data:" + gltf, this.scene, undefined, undefined, undefined, ".gltf");

The mesh is loaded but the texture still fails to load with this error : Error: /textures/0: Error while trying to load image: data:data:{"accessors":[{"buffer... - Fallback texture was used

Can it be because the string is not well formatted and the gltf fails to parse the texture ? I don’t understand how the loader can load the gltf as a file but not as a string, even though it is exactly the same

Edit: I also tried using a base64 encoded glb, with this gltf glTF-Sample-Models/2.0/Avocado at master · KhronosGroup/glTF-Sample-Models · GitHub , and the same error is returned : Error: /textures/2: Error while trying to load image: data:data:application/octet-stre... - Fallback texture was used

@bghgary might know, and a repro in the playground could help ?

1 Like

Welcome to the forums!

Are you encoding a self-contained GLB to base64 or encoding just the glTF file?

We really need a playground to help with this one.

1 Like

I had the problem with glTF as a string (without encoding), or with GLB encoded with base64.

Actually I tested to upgrade Babylon.js to version 5.0.0 and it works like a charm. Unfortunately, I can’t find a gltf who fits in a string and that can be saved in the playground.

However, I tested in the playground and with version 4.2.1, I have the error during loading of textures, and with version 5.0.0 I have no errors.

You can try yourself by using this playground and replacing the boomBox variable with the base64 encoded string of the same GLTF. You will notice that it will works with version 5.0 but not with version 4.2 !

Yup several improvments have been made regarding this in 5.0 that we can not back port to 4.2.1.

5.0 is now in RC and close to ship.

1 Like