Maniphest T99969

bpy.ops.object.vertex_weight_copy() fails in multi edit mode
Needs Information from Developers, Normal

Assigned To
None
Authored By
Mark Edwards (mark__e)
Jul 25 2022, 5:12 PM
Tags
  • BF Blender
  • Modeling
  • Animation & Rigging
Subscribers
Germano Cavalcante (mano-wii)
Mark Edwards (mark__e)
Philipp Oeser (lichtwerk)

Description

System Information
Operating system: windows 10 amd ryzen 9 5950x 2 x 3090 (not in nvlink)
Graphics card:

Blender Version
Broken: 3.12
Worked: don't think it ever has

in multi edit copy vertex to selected fails and does not create new groups or copy the weights, you have to join the mesh first then do copy to selected then separate the mesh again which is problematic in more complex rigging scenarios with shape keys etc.

Exact steps for others to reproduce the error
included example blend file with both meshes selected tab into edit mode highlight 1 vertex on the cylinder and then select all the verts on the ico sphere and select copy, the copy fails. If you join the ico sphere to the cylinder mesh and do the same it works as expected.

going to write a script as a workaround but I think it's really a bug ? (all be it a small one :-) )

Event Timeline

Mark Edwards (mark__e) created this task.Jul 25 2022, 5:12 PM
Mark Edwards (mark__e) added a comment.EditedJul 26 2022, 7:23 AM

Workaround if anyone else runs into this, use case is mainly for things like adding buttons to shirts / bits of hard armour etc. but keeping mesh object separate that you want to move with deformed mesh but not deform much themselves in a way that will export to game engine without additional parenting / vertex parenting. (obviously add armature to target mesh pointing to rig as well, might add that as convenience later)

import bpy

#make sure we only have 2 objects selected
if len(bpy.context.selected_objects) == 2:
    
    #get target and source objects
    first_object = bpy.context.selected_objects[0]
    second_object = bpy.context.selected_objects[1]
    
    #get target and source mesh objects
    
    has_active_target = False
    
    if first_object ==  bpy.context.view_layer.objects.active:
        target_object = first_object
        target_mesh = first_object.data
        
        source_object = second_object
        source_mesh = second_object.data
        
        has_active_target = True
    
    elif second_object == bpy.context.view_layer.objects.active:
        target_object = second_object
        target_mesh = second_object.data
        
        source_object = first_object
        source_mesh = first_object.data

        has_active_target = True
        
    else:
        print ("One object needs to be active")
        has_active_target = False
    

    if has_active_target == True:

        print ("Source : " + source_mesh.name)
        print ("Target : " + target_mesh.name)
    
        #create new list with only the selected verts from each object in it
        source_selected_verts = list(filter(lambda v: v.select, source_mesh.vertices))
        target_selected_verts = list(filter(lambda v: v.select, target_mesh.vertices))
        
        #create int list of target verts selected
        target_selected_verts_index = [i.index for i in target_selected_verts]
        
        #make sure we only have one source vert selected
        if len(source_selected_verts) == 1:
            
            #get selected single vert
            source_selected_vert = source_selected_verts[0]
            
            #get vertex index
            source_selected_verts_index = source_selected_vert.index
            
            #get all the group names in the source object
            vgroup_names = {vgroup.index: vgroup.name for vgroup in source_object.vertex_groups}
            
            #iterate through all the vertex associated with the object and create a look up list
            vgroups = {v.index: [vgroup_names[g.group] for g in v.groups] for v in source_mesh.vertices}
            

            #get count of source groups
            for i in range (len(vgroups[source_selected_verts_index])):
                
                #get group name string
                group_name = vgroups[source_selected_verts_index][i]
                
                #get weight for that group
                group_weight = source_selected_vert.groups[i].weight
                
                #remove any groups from the destination mesh
                for vgroup in target_object.vertex_groups:
                    if vgroup.name ==  group_name:   
                        target_object.vertex_groups.remove(vgroup)
                
                #create new group
                new_group = target_object.vertex_groups.new(name=group_name)
                
                #use selected target index range to add weight
                new_group.add(target_selected_verts_index,group_weight,'ADD')
        
        print ("Vertex weights copied")
    else:
        print ("Only select one source vertex to copy from")
else:
    print ("Only select 2 objects")
Germano Cavalcante (mano-wii) changed the task status from Needs Triage to Needs Information from Developers.Jul 26 2022, 8:17 PM
Germano Cavalcante (mano-wii) added projects: Modeling, Animation & Rigging.
Germano Cavalcante (mano-wii) added a subscriber: Germano Cavalcante (mano-wii).

Thank you for the report.
While this is not really a bug, it appears to be something that was missed in T54641: Multi-object mode support (parent task).
So it seems to be something for the developers to consider.

Philipp Oeser (lichtwerk) added a subscriber: Philipp Oeser (lichtwerk).Nov 7 2022, 12:07 PM

Seems like all of bpy.ops.vertex_group_XXX was not covered by multi-object-editing