Skip to content

Commit

Permalink
Fix failure to join models with material morphs
Browse files Browse the repository at this point in the history
  • Loading branch information
UuuNyaa committed Sep 21, 2023
1 parent b55b2c1 commit 4e538c7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mmd_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
bl_info = {
"name": "mmd_tools",
"author": "sugiany",
"version": (2, 9, 1),
"version": (2, 9, 2),
"blender": (2, 93, 0),
"location": "View3D > Sidebar > MMD Tools Panel",
"description": "Utility tools for MMD model editing. (UuuNyaa's forked version)",
Expand Down
28 changes: 21 additions & 7 deletions mmd_tools/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

if TYPE_CHECKING:
from properties.rigid_body import MMDRigidBody
from properties.morph import MaterialMorphData


class InvalidRigidSettingException(ValueError):
Expand Down Expand Up @@ -212,13 +213,26 @@ def join_models(parent_root_object: bpy.types.Object, child_root_objects: List[b
'selected_editable_objects': [child_armature_object],
}, location=True, rotation=True, scale=True)

# replace mesh armature modifier.object
mesh: bpy.types.Object
for mesh in FnModel.child_meshes(child_armature_object):
bpy.ops.object.transform_apply({
'active_object': mesh,
'selected_editable_objects': [mesh],
}, location=True, rotation=True, scale=True)
# Disconnect mesh dependencies because transform_apply fails when mesh data are multiple used.
related_meshes: Dict[MaterialMorphData, bpy.types.Mesh] = {}
for material_morph in child_root_object.mmd_root.material_morphs:
for material_morph_data in material_morph.data:
if material_morph_data.related_mesh_data is not None:
related_meshes[material_morph_data] = material_morph_data.related_mesh_data
material_morph_data.related_mesh_data = None
try:
# replace mesh armature modifier.object
mesh: bpy.types.Object
for mesh in FnModel.child_meshes(child_armature_object):
bpy.ops.object.transform_apply({
'active_object': mesh,
'selected_editable_objects': [mesh],
}, location=True, rotation=True, scale=True)
finally:
# Restore mesh dependencies
for material_morph in child_root_object.mmd_root.material_morphs:
for material_morph_data in material_morph.data:
material_morph_data.related_mesh_data = related_meshes.get(material_morph_data, None)

# join armatures
bpy.ops.object.join({
Expand Down

0 comments on commit 4e538c7

Please sign in to comment.