Exporting to GLTF in new version causing an error on importing from Blender

After updating Babylon.js from 8.12.1 to 8.44.0, I’m experiencing a problem importing GLTF files exported by Babylon.js into Blender:

WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/__init__.py", line 2013, in execute
WARN   | return self.import_gltf2(context)
WARN   | ~~~~~~~~~~~~~~~~~^^^^^^^^^
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/__init__.py", line 2045, in import_gltf2
WARN   | return self.unit_import(self.filepath, import_settings)
WARN   | ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/__init__.py", line 2060, in unit_import
WARN   | BlenderGlTF.create(gltf_importer)
WARN   | ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/blender/imp/blender_gltf.py", line 40, in create
WARN   | BlenderGlTF._create(gltf)
WARN   | ~~~~~~~~~~~~~~~~~~~^^^^^^
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/blender/imp/blender_gltf.py", line 47, in _create
WARN   | BlenderScene.create(gltf)
WARN   | ~~~~~~~~~~~~~~~~~~~^^^^^^
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/blender/imp/scene.py", line 39, in create
WARN   | BlenderNode.create_vnode(gltf, 'root')
WARN   | ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/blender/imp/node.py", line 47, in create_vnode
WARN   | BlenderNode.create_vnode(gltf, child)
WARN   | ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/blender/imp/node.py", line 33, in create_vnode
WARN   | obj = BlenderNode.create_object(gltf, vnode_id)
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/blender/imp/node.py", line 54, in create_object
WARN   | obj = BlenderNode.create_mesh_object(gltf, vnode)
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/blender/imp/node.py", line 304, in create_mesh_object
WARN   | mesh = BlenderMesh.create(gltf, pynode.mesh, pynode.skin)
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/blender/imp/mesh.py", line 26, in create
WARN   | return create_mesh(gltf, mesh_idx, skin_idx)
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/blender/imp/mesh.py", line 47, in create_mesh
WARN   | do_primitives(gltf, mesh_idx, skin_idx, mesh, tmp_ob)
WARN   | ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/blender/imp/mesh.py", line 177, in do_primitives
WARN   | indices = BinaryData.decode_accessor(gltf, prim.indices)
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/io/imp/gltf2_io_binary.py", line 72, in decode_accessor
WARN   | array = BinaryData.decode_accessor_obj(gltf, accessor)
WARN   | File "/usr/share/blender/5.0/scripts/addons_core/io_scene_gltf2/io/imp/gltf2_io_binary.py", line 130, in decode_accessor_obj
WARN   | array = np.frombuffer(
WARN   | buffer_data,
WARN   | dtype=np.dtype(dtype).newbyteorder('<'),
WARN   | count=accessor.count * component_nb,
WARN   | )
WARN   | ValueError: buffer is smaller than requested size

I haven’t had time to delve into the issue yet, but I’m pretty sure the update caused the problem.

I attached a GLTF file that can reproduce the problem (on the Blender’s side). I’ll update the thread if I find anything new.

Thanks!

import problem.zip (4.7 MB)

Would you happen to have the source scene you used to generate the file ?

cc @alexchuber to have a look

it looks like the bin name is wrong for some reasons. Also what did you use to export ? (javascript, max, maya.,) ?

It’s a bit complicated. I use GLTF2Export.GLTFAsync to export a Babylon scene to GLTF first, then reconstruct it after modifying things like texture paths before sending it to a rendering server (which runs a Blender headless instance).

From what I can see, the final .gltf file references the .bin file with its correct name and size, so I don’t know about a potential mismatch in that part:
```json

“buffers” : [ {
“uri” : “design.bin”,
“byteLength” : 20320
} ],
```

As for the test case, I can create a minimal test case in my app and export it as a .babylon file. However, the Babylon sandbox failed to load it, complaining about missing materials. I’ll attach the exported file, just in case:

scene.babylon.zip (14.6 KB)

Yes, could you send a playground of the original scene? I see the binary has a ton of glTF validation errors, but it’s hard to tell where they’re coming from. TY!

EDIT: My bad, I missed the latest response. Can you try exporting the .babylon file with Texture.ForceSerializeBuffers = true so it can be loaded in the Sandbox?

2 Likes

I added this on top of the component that initialises the engine, but the exported file still shows the same errors when I try to import it into the Sandbox:

import * as B from "@babylonjs/core"
...
B.Texture.ForceSerializeBuffers = true

Am I missing something?

Huh, odd. The original issue with the load was that it tried to fetch from an invalid path,


which happens because the .babylon loader uses the serialized texture’s name for the source URL (legacy behavior, I think.) It’s surprising that Texture.ForceSerializeBuffers didn’t work around that. Could you share the new file? Also, any chance you renamed some textures before exporting the scene to .babylon?

Sorry, I know this isn’t the issue you came for! :laughing:

Ah, nevermind. It wasn’t the invalid URLs preventing the load, but this:

Can investigate the export issue now.

(Though I am still curious about how the invalid URLs came to be… don’t want to miss a bug!)

2 Likes

This should fix the glTF export:

4 Likes

I just tested it with 8.45.5 and can confirm the PR fixed that issue.

Thanks much for the support, as always! :slightly_smiling_face:

3 Likes