Skip to content

Archive

Tag: Pose

Bones

For games, exporting bone transforms is often more efficient than exporting animation curves.

Most animation data is modeled using Actions; however, data related to the current pose (for an Object using an Armature) is exposed via Object :

x = D.objects['armature']

bone = x.pose.bones['root']

bone.matrix # transform
bone.location # just the location.

(‘D’ is a shortcut for bpy.data).

Actions

In Blender 2.63, retrieve actions using:

anAction = D.actions[name]

Action.fcurves contains animation data per channel. The grouping of fcurves (in the blender UI) is cosmetic.

  • FCurve.data_path refers the data being animated using a given animation curve. This could be something like ‘pose.bones["neck"].scale’. Several curves may use the same name (e.g. scale has 3 components so there may be 3 curves with the same data-path)
  • FCurve.keyframe_points refers keyframes for a given curve. The main property of a Keyframe is co, which includes the time offset co.x (the frame) and property value co.y
data_path does not fully identify which property of the object is being animated (e.g. for location, X, Y or Z?). for vector properties, it appears that FCurve.array_index identifies the component ( x <=> 0, y <=> 1, z <=> 2)

References (Blender API docs)

This article may be useful to both wannabe Blender animators and game developers wishing to export animations from Blender (better know what we’re trying to export). To follow, it would be nice if you know a little (a fair bit?) about how blender works and how to pose armatures. This is explained quite well in the Blender Noob to Pro wikibook.

I had to work out this stuff myself, not because nobody knows about it but because apparently it’s hard to explain (or according to some, not really worth it, although frankly, I doubt…).

So this could be interesting to other intermediate level Blender users that know enough about bones animation in blender that they’re puzzled, baffled and about to give up :)

I expect this article may be inaccurate in some places. But overall I tried to explain something that seems fairly confusing to me, and tried to make sure that if you’re confused as well, reading and trying things out patiently will get you out of the ditch.

And finally, before we start – although the Blender interface is somehow obscure when it comes to bones and other things, I think it’s worth learning, because it’s fast and productive, which is why I love Blender.

In a nutshell

  • Blender actions are sequences of poses typically associated with an armature. A walk cycle can be an action, a kick or a punch can be an action. Bowing can be an action.
  • Actions are reusable. You can use the same action several times in your animation.
  • An armature is a bunch of bones. Bones are like magnets used to move the geometry that makes up a model.
  • A pose is a way to arrange the bones that make up an armature – a pose is a kind of ‘key frame’.
  • NLA (non linear animation) is a process that consists in blending actions together. For example you can combine a waving action with a walking action. That’s obviously easier if we key frame leg bones and arm bones separately (armatures, however, are not limited to human shape).
  • Blender has an integrated NLA editor. this is a bit like Final Cut Pro, but for continuous animation, e.g a character doing varied things like walking, kicking, jumping…
  • A strip, is just a name for an action added to the NLA editor. A strip is attached to an armature and an action, and has a starting point in time. So the strip ‘makes the armature move’, and along with it a 3D model also attached to the armature. So several strips can refer the same action and several strips can be used to animate a character over time by picking previously created actions.

Outline for Character animation using bones.

As far as I have understood and tested, bone animation in blender works in two steps – creating actions, and using actions in your animation. Bone animation is somehow confusing, because the system does not let you create actions ‘on a separate timeline’. Actions can be stored on a separate timeline, but all the editing done happens on the main timeline. Another way to say this is that you can’t edit a library item as such. Blender definitely has a kind of library for assets, but we rarely get to see it, if ever.

If you hate theory, you might want to skip the next sections (not recommended though) and just ‘work it out’ using the test setup (see below)

Creating an action the first time(!).

  1. You create an armature. An armature is ‘just bones sticking together’. It is not rendered on the screen.
  2. You attach a model to this armature. The model becomes a child of the armature.
  3. You start creating poses for the first action that you wish to define. When you create the first pose, two important, easy to miss things happen:
    1. An action is created. An action is a sequence of poses.
    2. The created action is attached to the armature.
  4. You name the action that you have created.
  5. You detach the action from the armature. You typically do this because you want to create a ‘library’ of actions that you can reuse throughout your animation (or export to a game if it’s what you’re after. At this point, as far as I know, there is not a single window in the blender interface that can tell you that this action exists.

Using an action

  1. You add a strip to your armature. Adding a strip is a way to tell blender that we want the armature (and beyond, the model(s) attached to it) to perform an action at a given time. Maybe unfortunately, whenever you create a strip this causes the underlying action to be re-attached to the armature.

Creating an action the second time.

The second time you want to create an action for the same armature, assuming you are already using a strip referring an action you previously created, you may find that you can create key frames (poses) but when browsing the animation your key frames are ignored.

In this case, what works:

  1. Create the action explicitly.
  2. Generate a strip for this action
  3. Create poses for this action
  4. When you are done, you can both delete the strip and detach the action.

As far as I could work out, what happens is:

  • When you have no strip defined, you can create as many actions as you want and everything renders to the main time line.
  • As soon as you have defined at least one strip, actions are never rendered unless they are attached to strips.

Test Setup

By default, blender only shows three ‘editors’ (each in a separate frame). To see what’s going on, you need to create several more frames and toggle them to varied editors. Each frame has a button in the bottom left corner (or sometimes top left) that lets you choose a different editor. To work things out, you need 5 editors open, which is OK on say, a small widescreen monitor:

  • Outliner – this shows you the structure of your scene as a tree.
  • 3D view (showing on startup by default)
  • The NLA editor – this is the Final Cut Pro – like thingy that lets you do the overall layout of your animation.
  • The buttons window (showing by default)
  • The action view – this lets you create new actions and select an action to edit it. A tricky bit is that sometimes it lets you try to edit something that won’t show on the screen – when you are using strips, you can only edit an action that’s currently attached to a strip.

Then you can try things like:

  • Creating an armature. press [space] > add > armature in the 3D view
  • Posing an armature. Look at the bottom of the 3D view and click the button that says [object mode]. You can change that to pose mode. You can also click the smiley icon in the outliner, next to the name of your armature.
  • Inserting key frames while posing using the [i] key and [arrow-left], [arrow-right] to browse the timeline (move back and forth in time).
  • Observing that when you insert the first key frame while posing, a new action is created, and the keyframes show in the action editor as well as in the NLA editor. The action itself also appears as a child of the armature in the outliner. Also, a default name for this action appears in the action editor and you can edit the name. At this point, even though no strip is defined in the NLA, your action can play back on the main timeline.
  • Observing that pressing the [x] key in the action editor hides the current action (it doesn’t delete it, it just ‘detaches it’ from your scene, keeping it somewhere in memory).
  • Observing that, in the NLA editor, you can choose strip > add action strip, and that will let you select the action that you previously detached to combine it with the new strip. Also the action will become current in the action editor. You can detach the action again (press [x] in the action editor) and the strip will still cause the action to playback.
  • Observing that, if you already have a strip in the NLA editor, just detaching the current action, if any, and trying to set new key-frames for posing will be ineffective.
  • Observing that actions can be created from the action editor. If you have an armature selected and no current action there’s an ‘up arrow down arrow’ button that gives this option once clicked. It also lets you make any existing action (including actions incompatible with the current armature) current for your current armature at any time – sometimes allowing you to make an action current and apparently editable, but without any effect on your animation (not until you attach to the armature a strip using that action.

OK, next time, I’ll be back on my turf, and look into ways that can be used to export animations from Blender and getting them into a game :)