Game animation workflow improvements
Open, NormalPublic

Description

This patch drastically improves workflow for game animators using Blender (but not necessarily BGE) by:

* Allowing a library of Actions to be associated with an ID
* Locking the preview frame range to the length of the active object's action

== Action Library ==

This is a feature that game animators have long needed. They typically author large numbers of separate actions, but up until now have had no way to manage or easily switch between them.

An Action Library is similar to material or texture slots and is exposed to the user through a new panel in Object Properties (see attached image). It has three unique behaviours:

* It is not possible to have the same Action in a library twice. If the user selects an Action which is already in the library, the active slot is changed to it.
* The Library can be "locked" to prevent changes to its contents. The object's active action can still be changed, but only to one already in the library. Locking also filters the template_ID search results, providing a good way to navigate large libraries.
* Actions can be added in bulk with ops.action.library_add_by_name().

This feature is completely backwards-compatible, and if not used (i.e. no library slots created) does not impact existing program behaviour.

== Lock Preview Range to Action ==

This is a new button in the Timeline, placed next to the existing Preview Range button, which locks the preview frame range to the length of the active object's action.

This facilitates switching between Action Library slots, particularly if the animation is a looping one. Previously the frame range had to be manually adjusted every time.

== Other changes ==

* Fixed nla.add_tracks() being impossible to call without the user adding an action then manually clicking the unfreeze button in the NLA editor first.
* Extended the PointerRNA::poll API to support polling for unlink/new/open operations. (Implemented in the patch by template_ID.)
* Fixed a bug in BLI_strescape() that added junk to the end of the result.
* Made the "search for unknown operator" message less confusing when the operator name is blank.

Details

Type
Patch

It's been a while, so I've synced the patch with SVN.

Replied to Tom by mail, request this patch is remade and split into 2-3 parts, splitting various useful improvements from larger features and fixes.

* Removed the nla.add_tracks() change, I'll submit that one after this patch is in
* Removed the BLI_strescape() fix, Campbell has committed his own version of it
* Removed "unknown operator" change, split into a new patch

The PointerRNA::poll() change remains as it's required for the patch to function.

Some quick general comments. I haven't gone over the specifics of the action setting stuff yet, which looks like it'll need some careful checking...

== Action Libraries ==
* I'm really not a fan of the whole "array of pointers" style of doing things (which you've used to store this info). In general, it's quite a hairy way of doing things, for fairly minimal gains. Better would be to just use a ListBase to store the list of actions, at storing the pointers to each action using a LinkData (or perhaps a specialised struct to be more future-proof), and doing away with the "count" var.

* From the looks of things, you're practically assuming that actions can only exist at object level. Perhaps from the perspective of just pure GE character animators, this is sufficient. However, a large part of the animation system design revolves around the idea that AnimData represents a unit/point of animation evaluation and storage, which does its magic on whichever ID block it lives on (regardless of type of ID block). I'm not too sure what the current state of GE animation+actions stands at, but IIRC it is now possible to set up and link various actions for materials, lights, etc. too. So, I think it would pay to not make this too heavily "object only" stuff once again, as we used to have in the past.

== Lock Preview Range ==
I've seen the requests on this for a while, so I guess this functionality+approach is ok.

* I think it might be better to not assume start=0. While the files you may have come across use start=0 as convention, something out there may be using 1. Also, this might get used by normal animators too...
* The recalculation of action ranges on each frame/update change is a bit worrying, although I'll let this go here, since IIRC it's done in a few places anyway when updating ;)

Thanks for the review! Action setting is indeed quite fiddly, but I'm confident that I've handled all the scenarios.

1) I looked at material/texture slots and copied what I saw there. ListBase was actually recommended to me while I was coding, but I didn't know about LinkData so concluded that the system was only suitable for lists of all possible IDs. My vote is for leaving this as-is now, then refactoring it together with material/texture/etc slots later on.

2) The only place this is really assumed is in the UI and associated operators. Everything else is directly on AnimationData. I agree that more _could_ be done, but I'm not sure if it's worth the extra complexity: I very much doubt that any game engine exporter will ever look at non-object animations, and anyone working on a movie or BGE game already has systems to handle multiple actions.

3) Agreed. The start value can be left active in the UI to achieve this.

4) Also agreed, but like you say that's just how things are done right now.

Submitting patch version 4. I've changed the preview lock feature to allow the start and/or end of the frame range to be locked separately. This isn't as intuitive as the original design, but offers total flexibility.

The drop-down menu button is rendered incorrectly at the moment. I've opened a bug for that: http://projects.blender.org/tracker/index.php?func=detail&aid=28742&group_id=9&atid=498

Checking this again after being quite busy for a while. As we've now moved into bcon3, this will have to wait till the next dev cycle before being included.

In response to reply @ 2011-09-25 03:13:
1) -1 on that idea. For new code, we should not be accepting code which borrows from some of the uglier stuff that used to lurk around on the presumption that at some point it can get refactored along with said bad code.

Patch 4 Comments:
- Separate locking is overkill IMO. Just a single lock or no lock for preview range which deals with both at the same time should be sufficient IMO
- Popup menus with options isn't that nice, especially from headers

Attaching patch v5! :)

* Updated to r44717
* Switched from an array of pointers to ListBase+LinkData
* Reverted to the one-button preview range lock
* Fixed incorrect Outliner action selection when there are empty slots
* Added 'add()' and 'remove()' Python funcs to the ActLib collection
* Moved 'active' and 'locked' Python vars from AnimData to the ActLib collection

Joshua, last year you were concerned that the UI only applied to objects. I could adjust things so that Actions have their own top-row category like Textures. It's cramped up there though, and I for one really dislike the way you have to switch context with that set-up. Textures are only on Materials, Worlds, or Brushes but Actions can be almost anywhere...

(Attaching updated screenshot)

(Attaching annotated screenshot)

v6 fixes a memory leak when freeing AnimData and moves the new operators from the "action" category to "object".

I've tried making a unified set of operators and UI (with the goal of mimicking the way Custom Properties works) but I've run into a showstopper: poll functions don't take any parameters so you can't tell them where in context to look. There would need to be a different set of operators for each context location. :(

v7 fixes a Python error in the new panel.

Updated to r60065. I've removed library locking since the new filtering system solves the problem of browsing large lists in a much nicer way.