Wednesday, 1 December 2010

Python for Exaggerating and De-intensifying Poses

Sometimes my poses are just too strong and the animation ends up being very exaggerated and hard to follow, and sometimes they're too weak and need amplifying.  Joshua Leung's new push and relax features for pose bones in blender do a great job of handling in betweens and making them more or less similar to the neighbouring keys.  Often I find that before I even get to the inbetweening phase of animation I want to edit my key poses in a similar manner.  Especially with the spine and neck I want to be able to relax the bone's locations and rotations towards the rest pose (the same way I would smooth vertices when I'm modelling).  Here are two more python scripts I threw together this morning while working on another walk cycle...

Smooth Pose


import bpy,mathutils


amount=0.05


a=mathutils.Quaternion((1,0,0,0))
for each_bone in bpy.context.selected_pose_bones:
    each_bone.location=each_bone.location*(1-amount)
    if each_bone.rotation_mode=='QUATERNION':
        each_bone.rotation_quaternion=each_bone.rotation_quaternion*(1-amount)+(amount*a)
    elif each_bone.rotation_mode!='AXIS_ANGLE':
        each_bone.rotation_euler[0]=each_bone.rotation_euler[0]*(1-amount)
        each_bone.rotation_euler[1]=each_bone.rotation_euler[1]*(1-amount)
        each_bone.rotation_euler[2]=each_bone.rotation_euler[2]*(1-amount)

Exaggerate Pose


import bpy,mathutils


amount=0.05


a=mathutils.Quaternion((1,0,0,0))
for each_bone in bpy.context.selected_pose_bones:
    each_bone.location=each_bone.location*(1+amount)
    if each_bone.rotation_mode=='QUATERNION':
        each_bone.rotation_quaternion=each_bone.rotation_quaternion*(1-amount)-(amount*a)
    elif each_bone.rotation_mode!='AXIS_ANGLE':
        each_bone.rotation_euler[0]=each_bone.rotation_euler[0]*(1+amount)
        each_bone.rotation_euler[1]=each_bone.rotation_euler[1]*(1+amount)
        each_bone.rotation_euler[2]=each_bone.rotation_euler[2]*(1+amount)

At the moment the scripts only support quaternions and eulers as that's all I use in my rigs.  If you're an axis angle person please enlighten me as to what on earth its for!  Here's the walk cycle (crits welcome):



On another note I started hacking away at blender's source code last night trying to code smoother deforms for b-bones, which in my opinion look great until you turn on mesh display when it somehow manages to fold up the mesh in all sorts of nasty ways if you're using it for something wide (like a torso) rather than something skinny (like an arm).  While I haven't made much useful progress yet (other than beginning to understand the built in math libraries) I did stumble upon this very nice explanation of matrices, vectors and coordinate systems which I wish I'd found ages ago when I started diving into python in blender.

No comments:

Post a Comment