Re-do 3rd attempt I hate MMD stuff

This commit is contained in:
Yusarina
2024-12-13 01:59:28 +00:00
parent c39f77d6d5
commit 1e0fe403aa
4 changed files with 473 additions and 577 deletions
-58
View File
@@ -485,61 +485,3 @@ def remove_unused_shapekeys(mesh_obj: Object, tolerance: float = 0.001) -> int:
removed_count += 1
return removed_count
def save_armature_state(armature: Object) -> Dict[str, Any]:
"""Save current armature state for recovery"""
state = {
'bones': {},
'pose': {},
'settings': {}
}
# Save bone data
for bone in armature.data.bones:
state['bones'][bone.name] = {
'head': bone.head_local.copy(),
'tail': bone.tail_local.copy(),
'roll': bone.roll,
'parent': bone.parent.name if bone.parent else None
}
# Save pose data if exists
if armature.pose:
for bone in armature.pose.bones:
state['pose'][bone.name] = {
'location': bone.location.copy(),
'rotation': bone.rotation_quaternion.copy(),
'scale': bone.scale.copy()
}
return state
def restore_armature_state(armature: Object, state: Dict[str, Any]) -> None:
"""Restore armature from saved state"""
bpy.ops.object.mode_set(mode='EDIT')
# Restore bones
for name, data in state['bones'].items():
if name in armature.data.edit_bones:
bone = armature.data.edit_bones[name]
bone.head = data['head']
bone.tail = data['tail']
bone.roll = data['roll']
# Restore parenting
for name, data in state['bones'].items():
if data['parent'] and name in armature.data.edit_bones:
bone = armature.data.edit_bones[name]
if data['parent'] in armature.data.edit_bones:
bone.parent = armature.data.edit_bones[data['parent']]
bpy.ops.object.mode_set(mode='POSE')
# Restore pose if exists
if 'pose' in state:
for name, data in state['pose'].items():
if name in armature.pose.bones:
bone = armature.pose.bones[name]
bone.location = data['location']
bone.rotation_quaternion = data['rotation']
bone.scale = data['scale']