Sub topic 8
Vertex groups and weights
This chapter assumes you can already create an armature, parent bones, and add an Armature modifier to a mesh. It covers the data that tells each bone which vertices to move: vertex groups and their weights.
What a vertex group is
A vertex group is a named list of vertices on a mesh. Each entry stores one number, the weight, between 0.0 and 1.0. A vertex can belong to many groups and has a separate weight in each one.
Vertex groups are not specific to rigging. Modifiers, particle systems, and shaders also read them. The Armature modifier uses them in one particular way. If a group has the same name as a deforming bone in the armature the modifier points to, that bone moves the vertices in the group.
The vertex group lives on the mesh object, in obj.vertex_groups. The weights are stored per vertex, in mesh.vertices[i].groups.
How weights drive deformation
For each vertex, the Armature modifier looks at every group on that vertex. It keeps the groups whose name matches a bone with the Deform option enabled. It then blends the transforms of those bones using the weights.
- A vertex with weight 1.0 in one group and nothing else follows that bone rigidly.
- A vertex with 0.5 in one group and 0.5 in another follows the average of the two bone motions. This is how elbows and knees bend smoothly.
- A vertex in no matching group does not move. It stays where it was, even if the rest of the mesh bends.
- Groups with no matching bone, or whose bone has Deform turned off, are ignored.
Blender divides by the total weight of the matching groups on each vertex. The ratio between weights therefore matters more than their absolute values. A vertex with 0.2 in one group and 0.2 in another behaves like one with 0.5 and 0.5. A vertex whose only weight is 0.2 still follows its bone completely.
Name matching and its failure modes
The link between mesh and bone is the name. This is the most common source of "my rig does nothing" bugs.
| Symptom | Likely cause |
|---|---|
| Mesh does not follow a bone at all | Group name differs from the bone name, for example `Arm.L` against `arm.L` |
| Mesh follows the wrong bone after renaming | You renamed the bone in the armature but not the group. Renaming a bone through the Outliner or Bone properties usually renames matching groups automatically. Renaming from a script does not. |
| Part of the mesh stays behind | Those vertices have no weights, or only weights on non-deforming bones |
| Mesh does not deform in the viewport | The Armature modifier has no object set, or it is disabled for the viewport |
Names are case-sensitive. The .L and .R suffixes matter for mirroring, because Blender's mirror tools use them to find the opposite side.
Weights from the interface
You can create groups in the Object Data properties of the mesh, under Vertex Groups. In Edit Mode, select vertices, choose a group, set Weight, and click Assign. In Weight Paint Mode you paint the weights directly. Automatic weights, covered in the next chapter, create the groups and fill them for you.
Two cleanup tools matter when a mesh will leave Blender, for example for a game engine:
- Normalize All scales each vertex's weights so they sum to 1.0.
- Limit Total caps the number of groups per vertex. Many engines read only four influences per vertex and drop the rest, which can cause deformation that differs from what you saw in Blender.
Weights from Python
The group API has three calls you need: add, remove, and weight.
vg.add(indices, weight, type)takes a list of vertex indices. The type is'REPLACE','ADD', or'SUBTRACT'.vg.remove(indices)takes vertices out of the group.vg.weight(index)returns the weight of one vertex. It raisesRuntimeErrorif the vertex is not in the group.
The script below builds a subdivided cube and gives it a smooth weight gradient between two groups. The weights run from the bottom of the cube to the top, so the two bones share the middle. Run it in Object Mode.
import bpy
import bmesh
# Create a cube and subdivide it so there are rows of vertices to blend
bpy.ops.mesh.primitive_cube_add(size=2, location=(0, 0, 1))
obj = bpy.context.active_object
obj.name = "Cube"
bm = bmesh.new()
bm.from_mesh(obj.data)
bmesh.ops.subdivide_edges(bm, edges=bm.edges[:], cuts=4, use_grid_fill=True)
bm.to_mesh(obj.data)
bm.free()
# Names must match the bone names in the armature
root_vg = obj.vertex_groups.new(name="root")
child_vg = obj.vertex_groups.new(name="child")
# Local z runs from -1 (bottom) to +1 (top)
for v in obj.data.vertices:
t = (v.co.z + 1.0) / 2.0 # 0.0 at the bottom, 1.0 at the top
root_vg.add([v.index], 1.0 - t, 'REPLACE')
child_vg.add([v.index], t, 'REPLACE')
# Read the weights back through the vertex data
for v in obj.data.vertices[:3]:
entries = {obj.vertex_groups[g.group].name: round(g.weight, 2)
for g in v.groups}
print(v.index, entries)Note that add with weight 0.0 still makes the vertex a member of the group. Membership and weight are separate things. If you want a vertex truly outside a group, use remove. The loop above adds a few zero-weight entries at the top and bottom rows. They are harmless, but they count as influences when you limit the total per vertex.
To bind this mesh to the rig from earlier chapters, add the Armature modifier with mod.object set to the armature object. The vertex groups named root and child then take effect.
Practical guidance
- Work on the weights of one bone at a time, and check the result by posing the rig through its extreme range of motion.
- Keep the weights smooth across joints. Abrupt jumps from 1.0 to 0.0 between neighboring vertices create creases when the bone rotates.
- Run Normalize All and Limit Total before export, then pose the rig again to confirm nothing shifted.
- If you add a bone later, create its group with the exact bone name before you start painting.
Exercise
A character's forearm follows the rig, but the hand mesh stays in place when you rotate the hand bone. The bone is named hand.R and the mesh has a vertex group named Hand.R. What is wrong, and how do you fix it?
Show answer
Vertex group names are case-sensitive, so Hand.R does not match the bone hand.R, and the Armature modifier finds no bone for that group. Rename either the group or the bone so the names are identical. Then check that the bone's Deform option is enabled and that the hand vertices have nonzero weights in the group.
Exercise
A vertex has a weight of 0.3 in group upper_arm and 0.3 in group forearm. It has no other groups. How will it move when the forearm bone rotates, compared with a vertex weighted 0.5 and 0.5 in the same groups?
Show answer
Both vertices move the same way. Blender divides by the total weight, so only the ratio between the weights matters, and both vertices split the influence 50/50 between the two bones.