[B2.55] Getting fcurve index from rna path for bvh hack help needed.


The following is a script to “normalize” bvh files. Its primarily for mocaps that travel in a relatively straight path… running walking etc… although it gives a good result on a barrel role in testing.

Basically it transforms the location of the hip bone by the direction vector created by the first and last location of the hip bone. I did it by subtractiing the linear path of the translated to origin end points from the location fcurves… … When I thought about it later prob could have just used the vector maths but any way actually is giving pretty satisfactory results.

The new action created is now relative to its hip bone travelling from A to B at a constant speed … along one axis at the speed property from the magnitude of the transform vector… I have chosen to use the armature as a means to do this as no constraints or anything need to be set up… also by making the armatures object centre the floor it gives something to drive toeroll…

To my question.

How do I get the index of the location fcurves from the rna path? for example pose.bones[“hip”].location … In the script I just hardcoded them in because i checked in the console.

Still very much a novice with python lingo so hope this makes some sense.


import bpy
import mathutils

# Just hardcoding names at the moment

rigId = "BvhRig"
ActionId = "Roll.001"  
rootBoneId = "hip"

ob = bpy.data.objects["BvhRig"]

#Ok got the armature get its hip fcurve.
# Duplicate the action here i think ... use a flag.
#ob.animation_data.action #the action currently attached to the object.

action = bpy.data.actions[ActionId]

frames = action.frame_range.magnitude

# for each key in the action for the hip posebone subtract out the movement.

#  pose.bones["hip"].location   is the rnapath. i really wanna get fcurve index from the path.

transformVector = mathutils.Vector((0,0,0))

for dim in [0,1,2]:
    points = action.fcurves[dim].keyframe_points
    # going to take out the motion and take starting location to (0,0,0) if not already there.
    a = points[0].co[1]
    b = points[len(points)-1].co[1]
    transformVector[dim] = b-a
    for point in points:
        # co gives us frame in 0, value in 1.
        frame = point.co[0]
        value = point.co[1]
        #Ok subtract out the travel
        newvalue = value - frame*(b-a)/frames -a
        point.co[1] = newvalue
    #Prob put an empty at transformVector .. or a custom property for the armature named after the action with the magnitude.

Here is a file with the result of the script. hmm and I’ve mod’d it a bit to duplicate the action first and also create the linear action. I uploaded it in another forum to demonstrate two tracks in the NLA … hence don’t flame me it’s not a cycling animation.
The file is attached to this post http://blenderartists.org/forum/showthread.php?t=204323

Still stuck on getting the fcurve from the RNA path… help there would be most appreciated…