11
$\begingroup$

I need this vertex group:

enter image description here

additively merged with this vertex group:

enter image description here

into a third new vertex group like this:

enter image description here

$\endgroup$
17
$\begingroup$

You 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:

enter image description here

'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:

enter image description here

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:

enter image description here

$\endgroup$
7
$\begingroup$

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')
$\endgroup$
  • $\begingroup$ Since you are adding each vertex to the new group, the actual vertex selection is gone. I actually need that selection in my case as well, so I've tried to improve your script to only add vertices assigned to the groups they copied from. One positive side effect is that we can merge more then 2 groups now. However I don't have that much experience in rigging like you, so what do you think about this version? $\endgroup$ – p2or Aug 23 '17 at 16:44
  • $\begingroup$ @p2or I am not sure if I understand the problem correctly or what your goal is. Vertex selection is gone? There shouldn't be such a thing. This script shouldn't alter any data, just adds extra vertex group. It could be expanded to work with any number of groups if that is your goal. Your script also works fine, I have no issue with it. As a tip you can omit the clamp part though, blender does this automatically. $\endgroup$ – Jaroslav Jerryno Novotny Aug 23 '17 at 17:44
  • $\begingroup$ Thanks for taking the time and testing the script @Jerryno. Great! No, your script appends/adds every vertex to the new group. You can check that by switching into edit mode and clicking the select button after running the thing, then the operator selects all vertices even if their weight value is 0, right? I know that you wrote this long time ago and that wasn't your actual goal, only thought we could improve your answer... Again, lack of experience here so thanks for your tip and testing the script. $\endgroup$ – p2or Aug 23 '17 at 20:30
  • 1
    $\begingroup$ @p2or Oh, this, sure, you are right. If the final weight is 0, the vertex can be omitted and not added to the group. Right. Improved :) $\endgroup$ – Jaroslav Jerryno Novotny Aug 24 '17 at 17:03
  • 1
    $\begingroup$ I just had some time to test your code. I think testing whether A+B is 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$ – p2or Aug 25 '17 at 10:46
-2
$\begingroup$

EDIT: this solution does not work

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)

enter image description here

ORIGINAL ANSWER

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.

enter image description here

Create a new Vertex Group, then press Assign.

$\endgroup$
  • 1
    $\begingroup$ This is the solution already searchable on internet but a false one: it will not preserve the vertex weights. $\endgroup$ – Jaroslav Jerryno Novotny Dec 9 '15 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.