KhronosGroup / glTF-Blender-IO

Blender glTF 2.0 importer and exporter
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
Apache License 2.0
1.48k stars 317 forks source link

Exporter crashes when exporting an armature-deformed mesh with apply modifiers enabled #2231

Closed SolarLune closed 4 months ago

SolarLune commented 4 months ago

Describe the bug The GLTF exporter crashes when exporting a scene that contains the following setup:

To Reproduce Steps to reproduce the behavior:

  1. Create an armature.
  2. Parent the default cube to it, selecting the option to deform the mesh using the armature, with automatic weights, for example.
  3. In the material for the cube, set the base color to use an image - it can be external or internal.
  4. Go to export a GLTF file and enable "Apply Modifiers".
  5. Export.

The export will fail. The message I received is as follows:

Python: Traceback (most recent call last):
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/__init__.py", line 1227, in execute
    res = gltf2_blender_export.save(context, export_settings)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 37, in save
    json, buffer = __export(export_settings)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 55, in __export
    __gather_gltf(exporter, export_settings)
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 196, in __gather_gltf
    active_scene_idx, scenes, animations = gltf2_blender_gather.gather_gltf2(export_settings)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather.py", line 30, in gather_gltf2
    scenes.append(__gather_scene(blender_scene, export_settings))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py", line 36, in wrapper_cached
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather.py", line 89, in __gather_scene
    node = gltf2_blender_gather_nodes.gather_node(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py", line 47, in gather_node
    children=__gather_children(vnode, export_settings),
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py", line 103, in __gather_children
    node = gather_node(c, export_settings)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py", line 41, in gather_node
    mesh = __gather_mesh(vnode, blender_object, export_settings)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py", line 331, in __gather_mesh
    result = gltf2_blender_gather_mesh.gather_mesh(blender_mesh,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py", line 36, in wrapper_cached
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_mesh.py", line 57, in gather_mesh
    primitives=__gather_primitives(blender_mesh, uuid_for_skined_data, vertex_groups, modifiers, materials, export_settings),
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_mesh.py", line 135, in __gather_primitives
    return gltf2_blender_gather_primitives.gather_primitives(blender_mesh,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py", line 36, in wrapper_cached
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py", line 56, in gather_primitives
    blender_primitives, addional_materials_udim = __gather_cache_primitives(materials, blender_mesh, uuid_for_skined_data,
                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py", line 36, in wrapper_cached
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py", line 124, in __gather_cache_primitives
    blender_primitives, additional_materials_udim, shared_attributes = gltf2_blender_gather_primitives_extract.extract_primitives(
                                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives_extract.py", line 29, in extract_primitives
    primitive_creator.manage_material_info() # UVMap & Vertex Color
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives_extract.py", line 401, in manage_material_info
    base_material, material_info = get_base_material(material_idx, self.materials, self.export_settings)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/material/gltf2_blender_gather_materials.py", line 629, in get_base_material
    material, material_info = gather_material(
                              ^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py", line 36, in wrapper_cached
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/material/gltf2_blender_gather_materials.py", line 80, in gather_material
    pbr_metallic_roughness, uvmap_info_pbr_metallic_roughness, vc_info, udim_info_prb_mr = __gather_pbr_metallic_roughness(blender_material, orm_texture, export_settings)
                                                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/material/gltf2_blender_gather_materials.py", line 433, in __gather_pbr_metallic_roughness
    return gltf2_blender_gather_materials_pbr_metallic_roughness.gather_material_pbr_metallic_roughness(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py", line 36, in wrapper_cached
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/material/gltf2_blender_gather_materials_pbr_metallic_roughness.py", line 27, in gather_material_pbr_metallic_roughness
    base_color_texture, uvmap_info, udim_info_bc, _ = __gather_base_color_texture(blender_material, export_settings)
                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/material/gltf2_blender_gather_materials_pbr_metallic_roughness.py", line 130, in __gather_base_color_texture
    tex, uvmap_info, udim_info, factor = gather_texture_info(inputs[0], inputs, export_settings)
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/material/gltf2_blender_gather_texture_info.py", line 29, in gather_texture_info
    return __gather_texture_info_helper(primary_socket, blender_shader_sockets, 'DEFAULT', filter_type, export_settings)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py", line 36, in wrapper_cached
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/material/gltf2_blender_gather_texture_info.py", line 54, in __gather_texture_info_helper
    index, factor, udim_image = __gather_index(blender_shader_sockets, None, export_settings)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/material/gltf2_blender_gather_texture_info.py", line 208, in __gather_index
    return gltf2_blender_gather_texture.gather_texture(blender_shader_sockets, use_tile, export_settings)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py", line 36, in wrapper_cached
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/material/gltf2_blender_gather_texture.py", line 44, in gather_texture
    sampler=__gather_sampler(blender_shader_sockets, export_settings),
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/material/gltf2_blender_gather_texture.py", line 198, in __gather_sampler
    return gather_sampler(
           ^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py", line 36, in wrapper_cached
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/solarlune/Applications/blender/4.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_sampler.py", line 21, in gather_sampler
    group_path.append(bpy.data.materials[tab[0]])
                      ~~~~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 'bpy_prop_collection[key]: key "" not found'

Expected behavior It should simply export the GLTF successfully.

.blend file/ .gltf (mandatory) applyModifiersArmatureBug.zip

Version

Note that I don't believe the last stable version had this issue.

julienduroure commented 4 months ago

Hello, I can confirm the crash