Skip to content

Commit 29c5625

Browse files
committed
2.6.5
1 parent de2a1ec commit 29c5625

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

interface.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def menu_draw_mesh(layout:bpy.types.UILayout, context:bpy.types.Context):
142142
row = box.row()
143143
row.operator("objex.mesh_find_multiassigned_vertices", text="Find multiassigned vertices")
144144
row.operator("objex.mesh_find_unassigned_vertices", text="Find unassigned vertices")
145+
box.operator("objex.mesh_fix_multiassigned_vertices", text="Fix multiassigned vertices by highest weight")
145146
box.operator("objex.mesh_list_vertex_groups", text="List groups of selected vertex")
146147

147148
return

rigging_helpers.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

150189
def 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

Comments
 (0)