Convert 3D pose sequences to bvh file format

How to Convert 3D Positions into a BVH File

I need to convert a sequence of 3D positions of human joints (mocap data) into a BVH file that can be loaded into blender.

The data I have is a numpy array of size TxJx3, where T is the number of frames, J is the number of joints (21 in my case), and 3 represents the 3 co-ordinate values. I have managed to visualize the sequence using python, as I have shown in this video.

import numpy as np

# TxJx3 numpy array
mocap_data = np.array([[[x1, y1, z1], [x2, y2, z2], ..., [x21, y21, z21]],
                       [[x1, y1, z1], [x2, y2, z2], ..., [x21, y21, z21]],
                       [[x1, y1, z1], [x2, y2, z2], ..., [x21, y21, z21]]])

My question is, how can I convert these 3D positions into a BVH file, that I can load into blender? Or convert them to any other format so that I can load these data in blender?

You can use the BVHTools addon in Blender to import your mocap data as a BVH file. Here are the steps to do this:

  1. Install the BVHTools addon in Blender. You can download it from here:

  2. Open Blender and go to Edit > Preferences > Add-ons. Click on the Install button and select the BVHTools addon zip file that you downloaded in step 1.

  3. Enable the BVHTools addon by checking the box next to it in the Add-ons list.

  4. Go to File > Import > BVH and select your mocap data file.

  5. In the BVH importer options, make sure to set the Joint Hierarchy to match your mocap data. You can do this by selecting the first joint in your data and then clicking the “Select Root” button in the importer options. Then select the child joints in order and click the “Add Joint” button for each one.

  6. Click the Import BVH button to import your mocap data as a BVH file.

Your mocap data should now be loaded into Blender as a skeleton that you can animate and manipulate.