Skip to content

Commit

Permalink
fix: remove blender 3.6 custom property cache on import
Browse files Browse the repository at this point in the history
  • Loading branch information
saturday06 committed Jun 10, 2024
1 parent 885879c commit c95aac9
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/io_scene_vrm/importer/abstract_base_vrm_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,8 +995,16 @@ def import_gltf2_with_indices(self) -> None:
edit_bone.roll = roll
edit_bones.extend(edit_bone.children)

extras_material_index_key = self.import_id + "Materials"
for material in self.context.blend_data.materials:
if self.is_temp_object_name(material.name):
continue
material_index = material.pop(extras_material_index_key, None)
if isinstance(material_index, int):
self.materials[material_index] = material

extras_mesh_index_key = self.import_id + "Meshes"
for obj in self.context.selectable_objects:
for obj in self.context.blend_data.objects:
data = obj.data
if not isinstance(data, Mesh):
continue
Expand All @@ -1011,17 +1019,28 @@ def import_gltf2_with_indices(self) -> None:
obj.pop(extras_mesh_index_key, None)
data.pop(extras_mesh_index_key, None)

# Blender 3.6ではevaluatedされたメッシュから参照されるマテリアルの
# カスタムプロパティも消さないとキャッシュとしてずっと残ることがある
restore_modifiers_names = []
for modifier in obj.modifiers:
if modifier.show_viewport:
modifier.show_viewport = False
restore_modifiers_names.append(modifier.name)
depsgraph = bpy.context.evaluated_depsgraph_get()
evaluated_mesh_owner = obj.evaluated_get(depsgraph)
evaluated_mesh = evaluated_mesh_owner.to_mesh(
preserve_all_data_layers=True, depsgraph=depsgraph
)
for evaluated_material in evaluated_mesh.materials:
if evaluated_material:
evaluated_material.pop(extras_material_index_key, None)
for modifier in obj.modifiers:
if modifier.name in restore_modifiers_names:
modifier.show_viewport = True

# ここでupdateしないとエクスポート時にCustom Propertyが復活することがある
data.update()

extras_material_index_key = self.import_id + "Materials"
for material in self.context.blend_data.materials:
if self.is_temp_object_name(material.name):
continue
material_index = material.pop(extras_material_index_key, None)
if isinstance(material_index, int):
self.materials[material_index] = material

for image in list(self.context.blend_data.images):
custom_image_index = image.get(self.import_id)
if not isinstance(custom_image_index, int) and image.name.startswith(
Expand Down

0 comments on commit c95aac9

Please sign in to comment.