add remove zero weight vertex groups to panel

This commit is contained in:
989onan
2025-04-02 20:45:32 -04:00
parent 5cad28a41b
commit 199551a505
4 changed files with 13 additions and 3 deletions
+5 -1
View File
@@ -495,8 +495,9 @@ def fix_zero_length_bones(armature: Object) -> None:
bone.length = 0.001
bpy.ops.object.mode_set(mode='OBJECT')
def remove_unused_vertex_groups(mesh: Object) -> None:
def remove_unused_vertex_groups(mesh: Object) -> int:
"""Remove vertex groups with no weights"""
removed: int = 0
for vg in mesh.vertex_groups:
has_weights: bool = False
for vert in mesh.data.vertices:
@@ -508,6 +509,9 @@ def remove_unused_vertex_groups(mesh: Object) -> None:
break
if not has_weights:
mesh.vertex_groups.remove(vg)
removed = removed+1
return removed
def calculate_bone_orientation(mesh: Object, vertices: List[Any]) -> Tuple[Vector, float]:
"""Calculate optimal bone orientation based on mesh geometry"""
+3 -2
View File
@@ -272,10 +272,11 @@ class AvatarToolKit_OT_RemoveZeroWeightVertexGroups(Operator):
def execute(self, context: Context) -> set[str]:
meshes: list[bpy.types.Object] = get_all_meshes(context)
removed: int = 0
for mesh_obj in meshes:
remove_unused_vertex_groups(mesh_obj)
removed = removed+remove_unused_vertex_groups(mesh_obj)
self.report({'INFO'}, t("Tools.vertex_groups_removed", count=removed))
return {'FINISHED'}
+3
View File
@@ -191,6 +191,8 @@
"Tools.merge_twist_bones_desc": "When checked, twist bones will be kept, even if there are zero-weight",
"Tools.clean_weights": "Remove Zero Weight Bones",
"Tools.clean_weights_desc": "Remove bones with no vertex weights",
"Tools.clean_vertex_groups": "Remove Unused Vertex Groups",
"Tools.clean_vertex_groups_desc": "Remove vertex groups on meshes assigned to no vertices.",
"Tools.preserve_parent_bones": "Preserve Parent Bones",
"Tools.preserve_parent_bones_desc": "Keep bones that have children even if they have no weights",
"Tools.target_bone_type": "Target Bone Type",
@@ -204,6 +206,7 @@
"Tools.remove_selected_bones": "Remove Selected Bones",
"Tools.remove_selected_bones_desc": "Remove selected zero weight bones from armature",
"Tools.bones_removed": "Removed {count} bones",
"Tools.vertex_groups_removed": "Removed {count} vertex groups.",
"Tools.clean_constraints": "Delete Bone Constraints",
"Tools.clean_constraints_desc": "Remove all bone constraints from armature",
"Tools.clean_constraints_success": "Removed {count} bone constraints",
+2
View File
@@ -93,6 +93,8 @@ class AvatarToolKit_PT_ToolsPanel(Panel):
row = col.row(align=True)
row.operator(AvatarToolKit_OT_RemoveZeroWeightBones.bl_idname, text=t("Tools.clean_weights"), icon='GROUP_BONE')
row.operator(AvatarToolKit_OT_DeleteBoneConstraints.bl_idname, text=t("Tools.clean_constraints"), icon='CONSTRAINT_BONE')
row = col.row(align=True)
row.operator(AvatarToolKit_OT_RemoveZeroWeightVertexGroups.bl_idname, text=t("Tools.clean_vertex_groups"), icon='CONSTRAINT_BONE')
# Merge Tools
merge_box: UILayout = layout.box()