2
$\begingroup$

We are doing research on monitor human activities to avoid adverse events. In part of it, we did an experiment in our MoCap lap to detect the human motion to monitor his activities. We have f-curves from that motion. But we need all the xyz coordinates values for that motion for that given time (just say about 2-3 minutes) to do a scientific analysis of the data.

Do anyone have an idea how to get xyz values from f-curves?

$\endgroup$
  • $\begingroup$ What format did you save the mocap data as, bvh, c3d?. Have you imported it into blender? (btw assuming in your "lab" rather than "lap") $\endgroup$ – batFINGER Mar 19 '17 at 16:22
  • $\begingroup$ thank you for that- it's in the fbx format. I've already imported it to Blender $\endgroup$ – Ra Ca Mar 21 '17 at 11:43
  • $\begingroup$ Suggest you could get the location and rotation vectors directly from the pose bones, rather than from the fcurves. $\endgroup$ – batFINGER Mar 21 '17 at 12:17
  • $\begingroup$ So, how can I print or save all location vectors of the given animation? is it possible me to filter all location vectors(xyz values) for the given animation of the object in a separate file such as excel or notepad? $\endgroup$ – Ra Ca Mar 23 '17 at 11:46
1
$\begingroup$

This question is similar to this one answered by christopheS.

So in the same principle, I just add some more information.

  • An object has animation data
  • This data contains curves
  • A curve is defined by an 'action type' (which is defined in 'data_path') and an 'array index'
  • Action type and array index will give about what the curve is. For instance an action type equal to 'location' with an array index of 1 is a curve about the Y location of the object
  • The curve contains keyframe points. Each as a 'co'(ordinate) vector where co[ 0 ] is the frame and co[ 1 ] the value

Additionally you can ask the curve value using 'value = curve.evaluate( frame )'.

The code here is commented, so please tell if it is enough explanation or not.

import bpy

print( '---------' )

# Action types, in order to filter the wanted curves if needed
actionTypes = ('location','rotation_euler','rotation_quaternion','scale')

# Get the object from which we want the animation data
obj = bpy.data.objects['Cube']

# If it has some animation
if obj.animation_data:
    # Iterates over the wanted curves
    # The data_path gives the action's type
    for curve in [c for c in obj.animation_data.action.fcurves if c.data_path.endswith( actionTypes )]:
        # The array_index give the corresponding X, Y or Z index of the curve
        print( curve.data_path, curve.array_index )
        for key in curve.keyframe_points:
            # The curve's points has a 'co' vector giving the frame and the value
            print( 'frame: ', key.co[0], ' value: ', key.co[1] )
    pass
else:
    print("no data")
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you for that python codings. I applied it to my problem. I get some output, I think it is a part of xyz coordinates. but I need full of xyz values for the given f-curve. Please note that I am new to python programming. $\endgroup$ – user37066 Mar 19 '17 at 7:12
  • $\begingroup$ @user37066, each curve is dedicate to an axis (so a curve for X, another one for Y, etc.). To combine them all, go through the coordinates of each/one and if no coordinate corresponds for the others, call "evaluate(frame)" on them... Short comment, this is the principle, and the rest is Python coding... $\endgroup$ – lemon Mar 19 '17 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.