Sub topic 13
Cleaning, decimating and baking curves
Animation data grows noisy. Motion capture writes a key on every frame. Hand animation leaves keys that repeat the same value. A Noise modifier is cheap to author but hard to export. This chapter covers three ways to control that density in the Graph Editor. Clean removes redundant keys. Decimate reduces keys while approximating the curve. Baking converts a result, including modifiers, constraints and drivers, into plain keys.
You should already be comfortable selecting channels and keys in the Graph Editor, know the interpolation modes, and understand that modifiers change a curve's evaluated value without changing its keys. Menu names and locations differ slightly between Blender versions, so check the operator names given here if a menu entry looks different.
Why reduce or bake at all
Dense keys make a curve hard to edit. If a curve has a key on every frame, moving one key creates a visible kink, and smoothing the motion means editing dozens of handles. Fewer keys with good handles give smoother, more editable motion.
Baking solves a different problem. A curve with a Noise modifier looks right in Blender, but a game engine or another exporter often ignores modifiers. Baking samples the evaluated result and writes it as keys, so every consumer sees the same motion.
| Tool | What it does | Typical use |
|---|---|---|
| Clean Keyframes | Removes keys that do not change the curve's shape | Tidying after retiming, imports, or accidental keying |
| Clean Channels | Clean Keyframes, plus removing channels left with no real animation | Removing unused channels from an imported action |
| Decimate | Removes keys while approximating the curve | Simplifying motion capture or baked curves |
| Convert Keys to Samples | Replaces keys with one value per frame, with no handles | Storing dense data compactly, read-only style |
| Bake (Graph Editor and Bake Action) | Writes evaluated results as keys | Exporting, or freezing modifiers, constraints and drivers |
Cleaning keyframes
Clean Keyframes (Key menu, or graph.clean) deletes a key when removing it leaves the curve essentially unchanged. It compares each key with its neighbors. A key counts as redundant when its value is within the Threshold of the value you would get by skipping it. The default threshold is 0.001, which is small and conservative.
A typical case is a held pose. If you keyed a value on frames 10, 20 and 30 and all three are identical, the key on frame 20 adds nothing, so Clean removes it. The first and last key of a curve are kept.
The Clean Channels variant goes further. After cleaning, if a curve is left with a single key whose value equals the property's default (for example, scale 1.0 or location 0.0), Blender removes the whole F-curve. This is useful on imported actions that key every property whether or not it moves. It can also remove a channel you deliberately keyed as a "reset to default" pose, so use it with care.
Raise the threshold only as far as the motion tolerates. A threshold of 0.01 on a location curve measured in meters ignores changes of one centimeter, which is invisible in a large scene and obvious in a close-up. The threshold is in the property's own units, so the right value for rotation (radians in the data, degrees in the UI) differs from the right value for location.
Decimating curves
Decimate is for curves where every key carries some information but there are simply too many. It has two modes.
- Ratio keeps a fraction of the keys. A ratio of 0.5 aims to keep about half. Blender removes the keys whose removal changes the curve least.
- Error Margin (the "Allowed Change" variant) removes keys as long as the curve stays within a maximum deviation of the original. You set the tolerance, and Blender decides how many keys that allows.
Use Error Margin when you care about fidelity and Ratio when you need a specific budget, such as a maximum key count. Both work on the selected keys of the selected curves, so you can leave the first and last keys alone, or decimate only a noisy section, by selecting a range of keys with box select.
Decimation works best on curves sampled densely and smoothly, such as motion capture. After decimating, the remaining keys keep their interpolation and handles are recalculated, so Auto Clamped handles produce a smooth curve through what remains. On curves with sharp intentional features, such as a bounce impact, Ratio can remove the sharp key that defines the feature. Use Error Margin there, or deselect the important keys first.
A common workflow for motion capture cleanup is: Decimate with a small error margin, review the curve, then manually edit the few keys that matter.
Baking curves
Baking turns computed motion into stored keys. There are three places you will meet it.
Bake in the Graph Editor
The Graph Editor can bake the selected F-curves: it evaluates each curve at regular frame intervals and writes keys at those frames. The operators differ by version. Older versions have Key > Bake Keys or Convert Keys to Samples. Newer versions add a Bake Channels operator with a frame range, a step, and an option to include modifiers. Because evaluation includes modifiers, baking a curve with a Noise modifier gives you the noise as keys, which you can then edit directly.
Convert Keys to Samples (graph.keys_to_samples) is related but not identical. It replaces keys with a sampled curve that has a value per frame and no handles or per-key interpolation. This is compact, but you cannot edit it like a normal curve until you run Convert Samples to Keys (graph.samples_to_keys).
Bake Action
Bake Action (Object > Animation > Bake Action, or nla.bake) is the tool for baking constraints, parents and drivers, which a Graph Editor bake does not capture because they are not on the F-curve. Its key options:
- Start/End Frame and Frame Step. A step of 2 writes a key every second frame.
- Only Selected Bones / Only Selected Objects. Limits the bake to your selection.
- Visual Keying. Records the final, constraint-affected transform instead of the property's own value. Turn it on when constraints drive the motion.
- Clear Constraints and Clear Parents. Removes them after baking, so they do not apply on top of the baked motion a second time.
- Overwrite Current Action. Writes into the existing action instead of creating a new one.
- Clean Curves. Runs Clean on the result, which is often enough to remove the redundancy that baking every frame creates.
A step of 1 gives exact results but the most keys. Bake with a coarser step only when the motion is smooth, then check the result.
Baking an F-curve from Python
The next script shows what baking does at the data level. It builds a cube with an X location curve and a Noise modifier, samples the evaluated curve every second frame, removes the modifier and old keys, and writes the samples back as keys. It uses action.fcurves, which applies to Blender versions before the slotted-actions change, so check the API docs for your version.
import bpy
bpy.ops.mesh.primitive_cube_add()
obj = bpy.context.object
obj.location = (0.0, 0.0, 0.0)
obj.keyframe_insert(data_path="location", frame=1)
obj.location = (4.0, 0.0, 0.0)
obj.keyframe_insert(data_path="location", frame=24)
fcurve = obj.animation_data.action.fcurves.find("location", index=0)
noise = fcurve.modifiers.new(type='NOISE')
noise.scale = 5.0
noise.strength = 0.2
start, end, step = 1, 24, 2
frames = list(range(start, end + 1, step))
if frames[-1] != end:
frames.append(end)
# evaluate() includes modifiers, so the noise is captured here.
values = [fcurve.evaluate(f) for f in frames]
print("keys before:", len(fcurve.keyframe_points))
for m in list(fcurve.modifiers):
fcurve.modifiers.remove(m)
while len(fcurve.keyframe_points) > 0:
fcurve.keyframe_points.remove(fcurve.keyframe_points[0])
for f, v in zip(frames, values):
kp = fcurve.keyframe_points.insert(f, v, options={'FAST'})
kp.interpolation = 'LINEAR'
fcurve.update()
print("keys after:", len(fcurve.keyframe_points))Samples are taken before the modifier is removed, which is the order that matters. If you removed the modifier first, you would bake the clean curve and lose the noise. Linear interpolation between keys two frames apart reproduces the sampled shape closely. Use Bezier with Auto Clamped handles if you want smoother results from a coarser step.
Common problems
- Motion changes after Clean. The threshold is too high for the property's units. Undo and lower it.
- Baked motion looks doubled. Constraints or parents were left in place after a Visual Keying bake. Re-bake with Clear Constraints and Clear Parents enabled.
- Decimate removes an important pose. Use Error Margin, or deselect the key before running it.
- Baked curve is huge. Increase the frame step, or run Clean or Decimate on the result.
- Modifiers still apply after baking. A Graph Editor bake does not remove the modifier by itself. Delete it from the Modifiers tab, or the baked keys will be modified again.
Exercise
A motion capture curve has a key on every frame and you want it light enough to edit by hand without visibly changing the motion. Which tool do you choose, and which mode, and why? Separately, a character's hand follows a Copy Location constraint, and you want that motion as plain keys for export. Which tool, and which option must be on?
Show answer
For the dense mocap curve, use Decimate in Error Margin mode, because every key carries some information, so Clean would remove too little, and Error Margin lets you set the maximum visible deviation instead of guessing a key count. For the constrained hand, use Bake Action (nla.bake) with Visual Keying enabled, because the constraint result is not stored on the F-curve and only Visual Keying records the final transform. Also enable Clear Constraints so the constraint does not apply again on top of the baked keys.