[Bf-python] Generate NLA Strips with Python
Roland Hess
rolandh at reed-witting.com
Tue Apr 6 14:52:22 CEST 2004
Hi all. In order for my BlenderPeople project to continue, I needed
to be able to generate NLA strips from existing actions via Python. I
just finished testing a compiled build with that functionality. I'll
give you an overview and post a link to the patch file. I'm not sure
what the standards/best practices are for actually writing this
stuff, so anything that's bad, well, feel free to send me back to the
drawing board.
Method of Attack:
Trying to keep the Python layer as thin as possible, I wrote the main
NLA strip creation function directly into editnla.c in the blender
/src directory. The new function is public and accepts inputs of
armature and action name, start and end frames, and a repeat value.
If the armature name and action name exist, an NLA strip is created
with the specified values. I put the functionality in the editnla.c
section so that other Blender functions can internally call it and
send it generic values for NLA creation, if they should ever need to.
The Python portion only defines the function for scripting access,
does some validity checking on user inputs, then calls the function
found in editnla.c.
As I wasn't sure if an all new Python module called NLA would
necessitate changes in the makefiles (which I have no clue about), I
rolled this into the Armature module. The function is accessed from
Python as:
Armature.AddNLA(ArmatureName,ActionName,startframe,endframe,repeat)
Things to consider:
I believe it would be beneficial to have two different functions: the
one I have written in editnla.c and a new one that accepts a link to
an armature object instead of an armature name. It might also be
useful to split off two lookup functions that return both armature
and action object pointers given the respective names.
As far as editing already existing NLA strips, this may not be
possible. NLA strips are not currently named. Within the NLA source,
they are only accessed sequentially when generating animation, and by
proximity to the mouse pointer when editing, so there is no way I can
think of to direct changes to a particular strip, unless you went
through the list of all strips, checking for armature/action name and
start/end frame characteristics. Bleh. Deleting strips also faces the
same problem.
As there is really only a single function, and it applies to armature
objects, is there any reason to split this off into its own NLA
module as opposed to piggybacking on the Armature module?
Patch:
http://66.134.133.114/patch.txt
In case you just want to look at the code, my new stuff is:
in editnla.c: add_nlablock_generic(args)
in armature.c: M_Armature_AddNLA(args)
Thoughts? Anyone else want to test/fix/beautify/advise about this code?
--
Roland Hess (harkyman)
Digital Prepress/Network Administrator
Reed & Witting Company
More information about the Bf-python
mailing list