Re-do 3rd attempt I hate MMD stuff
This commit is contained in:
@@ -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']
|
||||
|
||||
+13
-35
@@ -87,53 +87,31 @@ class AvatarToolkitSceneProperties(PropertyGroup):
|
||||
)
|
||||
|
||||
merge_twist_bones: BoolProperty(
|
||||
name=t("Tools.merge_twist_bones"),
|
||||
description=t("Tools.merge_twist_bones_desc"),
|
||||
name=t("MMD.merge_twist_bones"),
|
||||
description=t("MMD.merge_twist_bones_desc"),
|
||||
default=True
|
||||
)
|
||||
|
||||
clean_weights_threshold: FloatProperty(
|
||||
name=t("Tools.clean_weights_threshold"),
|
||||
description=t("Tools.clean_weights_threshold_desc"),
|
||||
default=0.01,
|
||||
min=0.0000001,
|
||||
max=0.9999999
|
||||
keep_twist_bones: BoolProperty(
|
||||
name=t("MMD.keep_twist_bones"),
|
||||
description=t("MMD.keep_twist_bones_desc"),
|
||||
default=False
|
||||
)
|
||||
|
||||
connect_bones_min_distance: FloatProperty(
|
||||
name=t("Tools.connect_bones_min_distance"),
|
||||
description=t("Tools.connect_bones_min_distance_desc"),
|
||||
default=0.005,
|
||||
min=0.001,
|
||||
max=0.1
|
||||
keep_upper_chest: BoolProperty(
|
||||
name=t("MMD.keep_upper_chest"),
|
||||
description=t("MMD.keep_upper_chest_desc"),
|
||||
default=True
|
||||
)
|
||||
|
||||
merge_weights_threshold: FloatProperty(
|
||||
name=t("Tools.merge_weights_threshold"),
|
||||
description=t("Tools.merge_weights_threshold_desc"),
|
||||
name=t("MMD.merge_weights_threshold"),
|
||||
description=t("MMD.merge_weights_threshold_desc"),
|
||||
default=0.01,
|
||||
min=0.0001,
|
||||
min=0.0,
|
||||
max=1.0
|
||||
)
|
||||
|
||||
mmd_process_twist_bones: BoolProperty(
|
||||
name=t("MMD.process_twist_bones"),
|
||||
description=t("MMD.process_twist_bones_desc"),
|
||||
default=True
|
||||
)
|
||||
|
||||
mmd_connect_bones: BoolProperty(
|
||||
name=t("MMD.connect_bones"),
|
||||
description=t("MMD.connect_bones_desc"),
|
||||
default=True
|
||||
)
|
||||
|
||||
save_backup_state: BoolProperty(
|
||||
name="Save Backup State",
|
||||
description="Save the initial state of the armature before standardizing bones",
|
||||
default=False
|
||||
)
|
||||
|
||||
def register() -> None:
|
||||
"""Register the Avatar Toolkit property group"""
|
||||
logger.info("Registering Avatar Toolkit properties")
|
||||
|
||||
Reference in New Issue
Block a user