Showing posts with label quaternion. Show all posts
Showing posts with label quaternion. Show all posts

Wednesday, 9 March 2011

Quaternion Beziers in the 3D View

Quaternions might have great benefits for key-framing rotation (no gimbal lock and so on) , but I have to admit that when it comes to the 2D graph editor I don't stand a change of working out what effect of grabbing the handle of a key on a Quat's W channel will have on my animation.  Generally I'll adjust the key in the 3D view and leave the bezier handles well alone set to auto (or vector if I want a snap) because independently changing any of the W, X, Y, or Z channels is unlikely to yield any great improvements for my animation!


Today I expanded my add-on to draw the handles for Quaternion and Euler rotations, and to show the path of the tail of the bone (which is probably what we want to track when we're adjusting rotations).  The timeslide tool still works but I need to do a little more coding (and get my head around what a normalized quat is) before grabbing the bezier handles in the 3D view is possible.

EDIT: http://www.pasteall.org/19807/python - now with quaternion and euler editing!  Editing preview shown below.  At 1500 lines it outweighs the mushroomer, the crowd sim and the autowalker as my new biggest project... not bad for 3 days coding!


Thursday, 16 December 2010

Controllers Implemented in Pythonic Boids for Blender

While college was on I hardly had any time at all to work on this.  I found a spare three hours this morning and implemented 'controllers'.  Currently you can instruct the boids to follow or to be attracted/repelled/directed by controllers.  I also implemented a way of detecting the orientation of the ground plane from the cross product of the last two direction vectors (with necessary error checking, direction flipping etc) and replaced all of the orientation interpolation code with quaternion slerp.  This will obviously need some more careful coding to make sure that the boids don't suffer from quaternion flip - hopefully I can get the smooth interpolations of quats with the twistability of eulers (i.e. >360 degree angles).



I've also been messing with low-poly stuff seeing as that seems to be in vogue this year what with 'Between Bears' rocketing up the vimeo charts.  After walking in the woods this evening in low light I was trying to work out how to get the sense of a curved ground plane from only the striation of the tree trunks.  Kept running into anti-aliasing issues though - the opposite type from usual - smooth fades from black to white wasn't quite what I had in mind.


 

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.