@@ -145,6 +145,45 @@ def execute(self, context):
145145 return {'FINISHED' }
146146
147147
148+ class OBJEX_OT_mesh_fix_multiassigned_vertices (bpy .types .Operator ):
149+
150+ bl_idname = 'objex.mesh_fix_multiassigned_vertices'
151+ bl_label = 'Fix multiassigned vertices by only keeping the group with the highest weight'
152+
153+ @classmethod
154+ def poll (self , context ):
155+ object = context .object if hasattr (context , 'object' ) else None
156+ return object and object .type == 'MESH'
157+
158+ def execute (self , context ):
159+ mesh = context .object .data
160+ was_editmode = mesh .is_editmode
161+ if was_editmode :
162+ bpy .ops .object .mode_set (mode = 'OBJECT' )
163+ obj = context .object
164+ vg_data = obj .vertex_groups
165+ if not vg_data :
166+ print ("No vertex groups found!" )
167+ return {'CANCELLED' }
168+ else :
169+ # Iterate through mesh vertices
170+ for v in obj .data .vertices :
171+ # Find the vertex group with the highest weight
172+ max_group = None
173+ max_weight = 0.0
174+
175+ for g in v .groups :
176+ group_weight = vg_data [g .group ].weight (v .index )
177+ if group_weight > max_weight :
178+ max_group = g .group
179+ max_weight = group_weight
180+
181+ # Remove the vertex from all other vertex groups
182+ for g in v .groups :
183+ if g .group != max_group :
184+ vg_data [g .group ].remove ([v .index ])
185+ return {'FINISHED' }
186+
148187# folding/unfolding
149188
150189def var_armature_rest (obj ):
@@ -665,6 +704,7 @@ def draw(self, context):
665704 OBJEX_OT_mesh_find_multiassigned_vertices ,
666705 OBJEX_OT_mesh_find_unassigned_vertices ,
667706 OBJEX_OT_mesh_list_vertex_groups ,
707+ OBJEX_OT_mesh_fix_multiassigned_vertices ,
668708 OBJEX_OT_autofold_save_pose ,
669709 OBJEX_OT_autofold_delete_pose ,
670710 OBJEX_OT_autofold_restore_pose ,
0 commit comments