0
$\begingroup$

I have been trying to import a .gltf file into belnder via python script using bpy.

bpy.ops.import_scene.gltf(filepath)

I ran the script using the next command:

blender -b --factory-startup -P import_into_blender.py

But blender crashes and exits due to an invalid vertex/mesh data in .gltf file with the next error:

RuntimeError: Error: Python: Traceback (most recent call last):
  File "/Applications/Blender.app/Contents/Resources/4.1/scripts/addons/io_scene_gltf2/__init__.py", line 2060, in unit_import
    BlenderGlTF.create(gltf_importer)
  File "/Applications/Blender.app/Contents/Resources/4.1/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py", line 35, in create
    BlenderGlTF._create(gltf)
  File "/Applications/Blender.app/Contents/Resources/4.1/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py", line 42, in _create
    BlenderScene.create(gltf)
  File "/Applications/Blender.app/Contents/Resources/4.1/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_scene.py", line 35, in create
    BlenderNode.create_vnode(gltf, 'root')
  File "/Applications/Blender.app/Contents/Resources/4.1/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py", line 46, in create_vnode
    BlenderNode.create_vnode(gltf, child)
  File "/Applications/Blender.app/Contents/Resources/4.1/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py", line 46, in create_vnode
    BlenderNode.create_vnode(gltf, child)
  File "/Applications/Blender.app/Contents/Resources/4.1/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py", line 46, in create_vnode
    BlenderNode.create_vnode(gltf, child)
  File "/Applications/Blender.app/Contents/Resources/4.1/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py", line 32, in create_vnode
    obj = BlenderNode.create_object(gltf, vnode_id)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/Blender.app/Contents/Resources/4.1/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py", line 53, in create_object
    obj = BlenderNode.create_mesh_object(gltf, vnode)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/Blender.app/Contents/Resources/4.1/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py", line 273, in create_mesh_object
    mesh = BlenderMesh.create(gltf, pynode.mesh, pynode.skin)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/Blender.app/Contents/Resources/4.1/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py", line 26, in create
    return create_mesh(gltf, mesh_idx, skin_idx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/Blender.app/Contents/Resources/4.1/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py", line 47, in create_mesh
    do_primitives(gltf, mesh_idx, skin_idx, mesh, tmp_ob)
  File "/Applications/Blender.app/Contents/Resources/4.1/scripts/addons/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py", line 185, in do_primitives
    vert_locs = np.concatenate((vert_locs, vs[unique_indices]))
                                           ~~^^^^^^^^^^^^^^^^
IndexError: index 16036 is out of bounds for axis 0 with size 496
Location: /Applications/Blender.app/Contents/Resources/4.1/scripts/modules/bpy/ops.py:109

... truncated
Blender quit

My question is related to a difference in behaviour when importing same file via UI. Why does Blender import file successfully compared to bpy and python script even though it still throws the same error?

  • Blender version: Blender 4.1.1 (hash e1743a0317bc built 2024-04-16 00:06:22)
  • OS: macOS 14.1 (23B74)
  • GLTF is generated via Autodesk Platform Service.
$\endgroup$

0

You must log in to answer this question.

Browse other questions tagged .