• 3D
  • rotation quaternions, bones, animations and importing BVH mocap data

Hi, I'm hoping some people with a bit of knowledge about how 3D animation in godot works might be able to help me.

I have a lot of motion capture data recorded in BVH format. I'd like to write a small script that converts each BVH animation into an animation to add to an AnimationPlayer.

My two problems are: 1. The Scene file format- looking for it documented somewhere, hopefully with a parser. 2. The maths involved in converting the data into the format required by godot key frames.

Each BVH frame contains data like this:

Leftleg: 'Time', 'Xposition', 'Yposition', 'Zposition', 'Yrotation', 'Xrotation', 'Zrotation'

for example:

Leftleg: 0.008, 324.790436, 86.519325, 779.784607, -109.290268, -2.373593, 12.830636

I can create a new animation and a new track and add the data like this:

var anim = Animation.new()
anim.add_track( Animation.TYPE_TRANSFORM ) 
anim.track_set_path(0, "pathSkeleton:Leftleg")
x_angle, y_angle, z_angle = covert_data_to_radians(x_angle, y_angle, z_angle)
R = euler2mat(x_angle, y_angle, z_angle, 'sxyz')
Rotation_Quaternion = mat2quat(R)
Transformation_Matrix = Vector3(0, 0, 0)
anim.transform_track_insert_key( 0, 0.008000, Transformation_Matrix, Rotation_Quaternion, Vector3(1.0, 1.0, 1.0) ) 
animplayer.add_animation("action1", anim)

It's close but it's not there yet, the bones appear to move correctly but are at weird angles. I think I'm missing a step about local transformation or that my axis maths is 90 degrees out on one or more axes.

Would love to create a small collection of tools for godot.

12 days later

Assuming your 3 functions work correctly (convert_data_to_radians(), eular2mat(), mat2quat) then I would just confirm the coordinate space of the BVH data matches the coordinate space for godot. (Y = up, Z= depth, X=left/right)