I need this vertex group:
additively merged with this vertex group:
into a third new vertex group like this:
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityYou can do this using the 'Vertex Weight Mix' modifier.
Here, I have an object with two vertex groups I would like to mix, one is a patch on the left and the other contains a patch on the right of the object:
'Vertex Group A' is set to the left patch (the vertex group I want to effect) and 'Vertex Group B' is the right patch (the vertex group I want to add into the other one). I then set the 'Mix Mode' to add and the vertex groups are mixed:
Applying the modifier will cause these mixed weights to be permanently written to the 'Left' vertex group.
If you want to preserve the contents of the 'Left' vertex group then you can make a copy of it before applying the modifier:
Fill in the required vertex group names, it will merge them into a 3rd new group:
import bpy
# EDIT THIS
vgroup_A_name = ""
vgroup_B_name = ""
# Get both groups and add them into third
ob = bpy.context.active_object
if (vgroup_A_name in ob.vertex_groups and
vgroup_B_name in ob.vertex_groups):
vgroup = ob.vertex_groups.new(name=vgroup_A_name+"+"+vgroup_B_name)
for id, vert in enumerate(ob.data.vertices):
available_groups = [v_group_elem.group for v_group_elem in vert.groups]
A = B = 0
if ob.vertex_groups[vgroup_A_name].index in available_groups:
A = ob.vertex_groups[vgroup_A_name].weight(id)
if ob.vertex_groups[vgroup_B_name].index in available_groups:
B = ob.vertex_groups[vgroup_B_name].weight(id)
# only add to vertex group is weight is > 0
sum = A + B
if sum > 0:
vgroup.add([id], sum ,'REPLACE')
0
, is only a partial solution. In case there is a vertex which belongs to both original groups, but also has a weight value of 0
, the current approach obviously won't add it to the new group properly so I think the better approach is to test if MeshVertex.groups collection
is not empty as well as checking whether the correspondig vertex is part of "Group" and "Group.001" before adding the vertex to the new group. I adapted your code here to reflect that.
$\endgroup$
When copying vertices into another group, it doesn't preserve the vertex weights and it assigns the value set in the Weight slider:
(thanks to @Jerryno)
In Edit Mode, you can combine the vertices by pressing Select for each group.
Select the first group then press Select in the Vertex Groups Panel.
Repeat the selection with the second group to combine the vertices.
Create a new Vertex Group, then press Assign.