3
$\begingroup$

I am very new to animation and rendering softwares, so please let me know if I need to provide more information about this. I have a sequence of 3D positions of human joints (basically mocap data), representing different kinds of walking. I have managed to visualize the sequence using python, as I have shown in this video. Each 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. So 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?

$\endgroup$
4
  • $\begingroup$ Consult the code of the bvh importer / exporter. $\endgroup$
    – batFINGER
    Commented Jan 1, 2020 at 13:59
  • $\begingroup$ Do you happen to know where I can find the code? $\endgroup$
    – mauve127
    Commented Jan 1, 2020 at 16:05
  • $\begingroup$ Is it this one? github.com/20tab/bvh-python $\endgroup$
    – mauve127
    Commented Jan 1, 2020 at 16:07
  • $\begingroup$ I went through the repo, but I didn't find a way to compute the 3D positions of the joints. For reference, I want to know how to recover the 'head' attribute of the PoseBone data structure in this link docs.blender.org/api/blender_python_api_2_77_1/… $\endgroup$
    – mauve127
    Commented Jan 1, 2020 at 16:24

1 Answer 1

3
$\begingroup$

OK, found the solution myself. Posting here in case anyone else finds this useful. In the BVH format, the following relationship holds between the joints:

$$pos_j = R_{P(j)}offset_j + pos_{P(j)}$$

where $pos_j$ indicates the 3D position of joint $j$, $P(j)$ returns the parent of joint $j$ in whatever DAG the positions are modeled in (generally the DAG starts at the root and points towards the end-effectors) $offset_j$ indicates the offset of joint $j$ relative to its parent $P(j)$ (aka the connecting limb), and $R_{P(j)}$ is the 3D rotation that determines how much should $offset_j$ be rotated from an initial pose (generally a T-pose). In the BVH format, for each parent $P(j)$, we need to store $R_{P(j)}^{-1}R_j$.

The main trouble I had then was working with joints that had multiple children, for example, the root joint, which has connections to both legs as well as the spine. I eventually came across this repo and digging through their function forward_kinematics inside skeleton.py, realized what to do. Basically, for joints with multiple children, I had to make copies with $offset=0$, and assign those as parents of the corresponding chains. Thus I made 3 copies of the root: one became the parent for the left leg chain, one for the right leg chain, and one for the spine. And similarly for the other parents with multiple children. And yes, the visualization works great!

$\endgroup$
2
  • $\begingroup$ How to calculate the rotation matrix? $\endgroup$ Commented Jan 20, 2022 at 2:51
  • $\begingroup$ Since I assumed the forward kinematics setup, the rotation matrix is part of my input, i.e., known apriori. $\endgroup$
    – mauve127
    Commented Jan 21, 2022 at 7:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .