diff --git a/core/common.py b/core/common.py index f26dd6c..de56360 100644 --- a/core/common.py +++ b/core/common.py @@ -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""" diff --git a/functions/tools/bone_tools.py b/functions/tools/bone_tools.py index 966fe84..ff420e9 100644 --- a/functions/tools/bone_tools.py +++ b/functions/tools/bone_tools.py @@ -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'} diff --git a/resources/translations/en_US.json b/resources/translations/en_US.json index 39b1183..80a6e93 100644 --- a/resources/translations/en_US.json +++ b/resources/translations/en_US.json @@ -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", diff --git a/ui/tools_panel.py b/ui/tools_panel.py index 2d2b625..a819ed3 100644 --- a/ui/tools_panel.py +++ b/ui/tools_panel.py @@ -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()