Sub topic 3
Vertex groups: where weights live
This chapter assumes you can move between Object, Edit and Pose mode, select mesh elements, and have a mesh with a basic armature. It does not assume you have painted weights before.
What a vertex group is
A vertex group is a named list of vertices stored on a mesh object. Each vertex in the list carries a number called its weight. Blender uses vertex groups for several jobs: masking modifiers, driving particle density, and controlling shape keys. For skinning they hold the weights that tell each bone how strongly it pulls on each vertex.
Three facts matter for everything that follows:
- Groups belong to the mesh object, not to the armature. The armature only contains bones.
- A vertex can belong to any number of groups, each with its own weight.
- A weight is a float from 0.0 to 1.0. A weight of 0.0 is not the same as "not in the group", because membership and weight are stored separately.
The name is the link
The Armature modifier connects a vertex group to a bone by name. If the mesh has a group called Forearm.L and the armature has a deforming bone called Forearm.L, that bone moves the vertices in that group. There is no other pointer between them.
This has practical consequences:
- Names are case-sensitive.
forearm.LandForearm.Lare different names. - Renaming a bone in the armature does not rename the vertex group on the mesh. Blender renames the matching group for you only when the mesh is a child of the armature in the same scene and you rename the bone through the Outliner or Properties panel. Do not rely on it when you rename through a script or across files.
- A group with no matching bone does nothing to the deformation. It is harmless, but it can mislead you when you read the weight display.
- A bone with no matching group does not move any vertices.
Creating and editing groups in the interface
Select the mesh and open the Object Data properties tab (the green triangle icon). The Vertex Groups panel lists the groups on the object.
- Click + to add a group, then double-click its name to rename it to match a bone.
- Enter Edit Mode and select some vertices.
- Set the Weight field (default 1.0) and click Assign.
- Click Remove to take the selected vertices out of the active group.
- Use Select and Deselect to check which vertices a group holds.
Assigning in Edit Mode sets the weight to exactly the value in the Weight field, replacing any previous weight for those vertices in that group. This is a fast way to set rough regions before you refine them with brushes in a later chapter.
The dropdown menu beside the list (the down arrow) holds the group operators that later chapters use: Normalize, Normalize All, Limit Total, Clean, Mirror and others.
Locking groups
Each group has a lock icon. A locked group cannot be changed by painting, assigning or the normalize operators. Locking is useful when one bone's weights are finished and you do not want a later brush stroke or normalization to disturb them.
Weights are per-vertex, per-group
A vertex does not have one weight. It has one weight for each group it belongs to. Consider a vertex on the elbow:
| Group | Weight |
|---|---|
| `UpperArm.L` | 0.6 |
| `Forearm.L` | 0.4 |
When you pose the arm, this vertex follows a mix of both bones, leaning toward the upper arm. A vertex on the middle of the forearm might be in Forearm.L at 1.0 and in no other group, so it follows that bone alone. The smooth bend of the elbow comes from vertices that share weight between neighbouring bones.
Which groups deform
Not every vertex group is a deformation group. The Armature modifier only uses a group when a bone of the same name has its Deform option enabled (Bone properties, Deform panel). Groups named after non-deforming bones, such as control or IK target bones, are ignored for deformation. The next chapters cover this setting and how it goes wrong. For now, remember that a correctly named group is necessary but not sufficient.
Inspecting weights with Python
You can read the weight data directly. Each vertex has a groups collection. Each entry gives the group's index into obj.vertex_groups and the weight.
import bpy
obj = bpy.context.active_object
# Print each vertex's non-zero group weights.
for v in obj.data.vertices:
for g in v.groups:
name = obj.vertex_groups[g.group].name
print(v.index, name, round(g.weight, 3))This is useful for checking that a bind produced the weights you expect. The g.group value is an index, so you must look the name up in obj.vertex_groups. Do not assume the index matches the order of the bones.
Creating a group and assigning weights with Python
A group is created with vertex_groups.new, and vertices are added with add. The add method takes a list of vertex indices, a weight, and a mode.
import bpy
obj = bpy.context.active_object
# The group name must match the bone name for the Armature modifier to use it.
vg = obj.vertex_groups.new(name="Bone")
# Give every vertex a weight of 1.0 in this group.
vg.add([v.index for v in obj.data.vertices], 1.0, 'REPLACE')The third argument is the assign mode:
| Mode | Effect on a vertex already in the group |
|---|---|
| `REPLACE` | Sets the weight to the given value. |
| `ADD` | Adds the given value to the existing weight. |
| `SUBTRACT` | Subtracts the given value from the existing weight. |
A vertex that is not yet in the group is added with the given value in REPLACE and ADD modes. Blender clamps the final weight to the 0.0 to 1.0 range.
To take vertices out of a group, call vg.remove([indices]). To read one weight, call vg.weight(index). That call raises a RuntimeError if the vertex is not in the group, so wrap it in try or loop over v.groups as shown above.
import bpy
obj = bpy.context.active_object
vg = obj.vertex_groups["Bone"]
for index in (0, 1, 2):
try:
print(index, vg.weight(index))
except RuntimeError:
print(index, "not in group")Weights in Edit Mode versus Object Mode
When you change vertex groups with Python while the mesh is in Edit Mode, the edit-mesh data and the stored mesh data can disagree. Edit Mode keeps its own copy of the geometry (a BMesh). Changes made to obj.data.vertices or through vg.add may not show up until you leave Edit Mode, and changes made in Edit Mode are not written to obj.data until you toggle back to Object Mode. Switch to Object Mode before you run scripts like the ones above:
import bpy
bpy.ops.object.mode_set(mode='OBJECT')Common mistakes
- Group name typos. One wrong letter, a trailing space, or a different case leaves the bone with no weights. Check names by selecting the group in the list and comparing it with the bone name in the Outliner.
- Duplicate names from copying. When you duplicate a group, Blender appends
.001. The copy no longer matches a bone, so the original keeps working and the copy does nothing. - Weight 0.0 membership. A vertex with weight 0.0 is still in the group. It shows blue in Weight Paint mode but still counts as a member for Select and for operations like Limit Total. Use Clean (a later chapter) to remove those entries.
- Forgetting the lock. If a brush stroke seems to do nothing, check whether the active group is locked.
Key points
- A vertex group stores a weight for each member vertex. Groups live on the mesh.
- The Armature modifier matches groups to bones by exact name.
- A vertex can have several group weights. Bends come from vertices that share weight between bones.
- Assign sets a chosen weight in Edit Mode. Python's
adddoes the same withREPLACE,ADDorSUBTRACT. - Read weights through
v.groups, and use thegroupindex to find the group name.
Exercise
Your forearm vertices follow the elbow and the wrist poorly, and the Armature modifier is present. The mesh has a vertex group named forearm.L, and the armature has a deforming bone named Forearm.L. What is the likely cause, and how do you check it with Python?
Show answer
Group names are case-sensitive, so forearm.L does not match the bone Forearm.L, and the bone moves no vertices. Rename the group to Forearm.L. To check with Python, compare the sets of names: bones = {b.name for b in bpy.data.objects["Armature"].data.bones} and groups = {g.name for g in obj.vertex_groups}, then print groups - bones to see groups with no matching bone.
Exercise
You run vg.add([0, 1, 2], 0.5, 'ADD') twice on vertices that were not in the group before. What weight do vertices 0, 1 and 2 have afterwards?
Show answer
1.0. The first call adds the vertices with weight 0.5. The second call adds another 0.5 to the existing weight, giving 1.0. A third call would still give 1.0, because Blender clamps weights to the 0.0 to 1.0 range.