如何将bvh文件解析为OpenGL中制作的骨架模型? [英] How to parse a bvh file to a skeleton model made in OpenGL?

查看:257
本文介绍了如何将bvh文件解析为OpenGL中制作的骨架模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将bvh数据解析为我已经使用OpenGL开发的骨骼.关于数据解析,有一件事我很好奇.

I'm trying to parse the bvh data to my skeleton I already developed with OpenGL. There is one thing regarding data parsing I got curious about though.

Bvh数据有两个部分,分别是HIERARCHY和MOTION. HIERARCHY指定树结构和OFFSET数据,该数据用于推断父骨骼的长度. MOTION指定了根骨头的位置以及每个骨头的关节配置.

Bvh data has two parts, which are HIERARCHY and MOTION. HIERARCHY specifies the tree structure and the OFFSET data, which is used to infer the length of the parent bone. MOTION specifies the position of the root bone and the joint configurations of every bone.

我已经用在HIERARCHY中提到的骨头制作了模型.我也使用HIERARCHY中提到的相同树结构制作了模型. (当然,由于模型是在解析文件数据之前创建的,因此骨骼之间的长度由我任意设置.因此,建模骨骼的长度实际上与OFFSET数据有所不同.)

I already made my model with the bones that were mentioned in HIERARCHY. I made my model under the same tree structure mentioned in HIERARCHY as well. (Of course the length between the bones is arbitrarily set by me since the model is made before parsing the file data. So the modeled bone's length is actually a bit different from the OFFSET data.)

既然我已经制作了要动画的模型,那是否意味着我可以忽略HIERARCHY(= OFFSET)部分,而只需读取MOTION数据部分以获得每个关节的关节配置?

Since I already made the model that I want to be animated, does that mean I can ignore the HIERARCHY(=OFFSET) part, and just read the MOTION data part for obtaining each joint's joint configuration?

我觉得这是一个非常明显的问题,但是有些感觉不对劲,因为那仅意味着我可以忽略文件的前半部分(HIERARCHY),而仅对其后半部分进行解析即可.

I feel like this is a really obvious question, but something just feels wrong because that just means I can ignore the first half(HIERARCHY) of the file, and just make a parser for the second half of it.

文件的前半部分可能缺少任何细节吗?

Is there any detail that I am possibly missing from the first half of the file?

推荐答案

BVH HIERARCHY包含骨骼的初始姿态(不包含任何MOTION数据).因此OFFSET实际上也定义了每个骨骼的初始方向.如果忽略它,则BVH和网格之间将失去同步.您需要做的是:

BVH HIERARCHY contains initial pose of the skeleton (without any MOTION data). So the OFFSET actually define the initial orientation of each bone too. If you ignore it you will lose sync between BVH and your mesh. What you need to do is:

  1. 解析整个HIERARCHY结构
  2. 针对每个缩放比例的骨骼计算变换,将您的网格与BVH初始位置对齐

这听起来并不容易,因为BVH中每个骨骼都有两个端点.但是对于正确的网格位置来说,这是不够的,因为它缺少围绕骨骼轴的旋转.比例是BVH骨与网状骨大小之间的简单比率.

this is not as easy as it sounds as you got two endpoints for each bone in BVH. But for correct position of mesh is that not enough as its missing the rotation around bone axis. Scale is simple ratio between BVH bone and mesh bone size.

您需要构造4x4均匀矩阵.这里有一些想法:

What you need is to construct 4x4 homogenuous matrices. Here some ideas on how:

  • Understanding 4x4 homogenous transform
  • How to find rotation matrix between two vectors in THREE.js
  • Problem superimposing and aligning 3D triangles

解析整个MOTION数据

parse whole MOTION data

每帧

计算到达骨骼的变换矩阵并将其应用于您的网格(连同初始位置矩阵).

compute transform matrices of reach bone and apply it on your mesh (together with the initial position matrices).

我强烈建议在不使用任何网格的情况下仅使用线条来解析/播放BVH.并且仅在其正常工作时才移至下一个级别.因为根据所使用的符号矩阵乘法顺序和坐标系,您可能已经损坏了输出.这将使您难以调试最上面的内容.

I strongly suggest parse/play BVH without any mesh using just lines. And move to the next level only if it is working correctly. Because depending on used notations matrix multiplication order and coordinate systems you might have corrupted output. Which would give you hard time debugging the stuff on top of it.

请注意,旋转必须按定义的顺序进行且没有任何偏移!!!

Beware the rotations must be done in defined order and without any offset !!!

[edit1]

下面是一些BVH的小例子:

Here some small BVH example:

HIERARCHY
ROOT Hips
{
    OFFSET  0.00    0.00    0.00
    CHANNELS 6 Xposition Yposition Zposition Zrotation Xrotation Yrotation
    JOINT Chest
    {
        OFFSET   0.00    5.21    0.00
        CHANNELS 3 Zrotation Xrotation Yrotation
        JOINT Neck
        {
            OFFSET   0.00    18.65   0.00
            CHANNELS 3 Zrotation Xrotation Yrotation
            JOINT Head
            {
                OFFSET   0.00    5.45    0.00
                CHANNELS 3 Zrotation Xrotation Yrotation
                End Site 
                {
                    OFFSET   0.00    3.87    0.00
                }
            }
        }
        JOINT LeftCollar
        {
            OFFSET   1.12    16.23   1.87
            CHANNELS 3 Zrotation Xrotation Yrotation
            JOINT LeftUpArm
            {
                OFFSET   5.54    0.00    0.00
                CHANNELS 3 Zrotation Xrotation Yrotation
                JOINT LeftLowArm
                {
                    OFFSET   0.00   -11.96   0.00
                    CHANNELS 3 Zrotation Xrotation Yrotation
                    JOINT LeftHand
                    {
                        OFFSET   0.00   -9.93    0.00
                        CHANNELS 3 Zrotation Xrotation Yrotation
                        End Site 
                        {
                            OFFSET   0.00   -7.00    0.00
                        }
                    }
                }
            }
        }
        JOINT RightCollar
        {
            OFFSET  -1.12    16.23   1.87
            CHANNELS 3 Zrotation Xrotation Yrotation
            JOINT RightUpArm
            {
                OFFSET  -6.07    0.00    0.00
                CHANNELS 3 Zrotation Xrotation Yrotation
                JOINT RightLowArm
                {
                    OFFSET   0.00   -11.82   0.00
                    CHANNELS 3 Zrotation Xrotation Yrotation
                    JOINT RightHand
                    {
                        OFFSET   0.00   -10.65   0.00
                        CHANNELS 3 Zrotation Xrotation Yrotation
                        End Site 
                        {
                            OFFSET   0.00   -7.00    0.00
                        }
                    }
                }
            }
        }
    }
    JOINT LeftUpLeg
    {
        OFFSET   3.91    0.00    0.00
        CHANNELS 3 Zrotation Xrotation Yrotation
        JOINT LeftLowLeg
        {
            OFFSET   0.00   -18.34   0.00
            CHANNELS 3 Zrotation Xrotation Yrotation
            JOINT LeftFoot
            {
                OFFSET   0.00   -17.37   0.00
                CHANNELS 3 Zrotation Xrotation Yrotation
                End Site 
                {
                    OFFSET   0.00   -3.46    0.00
                }
            }
        }
    }
    JOINT RightUpLeg
    {
        OFFSET  -3.91    0.00    0.00
        CHANNELS 3 Zrotation Xrotation Yrotation
        JOINT RightLowLeg
        {
            OFFSET   0.00   -17.63   0.00
            CHANNELS 3 Zrotation Xrotation Yrotation
            JOINT RightFoot
            {
                OFFSET   0.00   -17.14   0.00
                CHANNELS 3 Zrotation Xrotation Yrotation
                End Site 
                {
                    OFFSET   0.00   -3.75    0.00
                }
            }
        }
    }
}
MOTION
Frames:    2
Frame Time: 0.033333
 8.03    35.01   88.36  -3.41    14.78  -164.35  13.09   40.30  -24.60   7.88    43.80   0.00   -3.61   -41.45   5.82    10.08   0.00    10.21   97.95  -23.53  -2.14   -101.86 -80.77  -98.91   0.69    0.03    0.00   -14.04   0.00   -10.50  -85.52  -13.72  -102.93  61.91  -61.18   65.18  -1.57    0.69    0.02    15.00   22.78  -5.92    14.93   49.99   6.60    0.00   -1.14    0.00   -16.58  -10.51  -3.11    15.38   52.66  -21.80   0.00   -23.95   0.00   
 7.81    35.10   86.47  -3.78    12.94  -166.97  12.64   42.57  -22.34   7.67    43.61   0.00   -4.23   -41.41   4.89    19.10   0.00    4.16    93.12  -9.69   -9.43    132.67 -81.86   136.80  0.70    0.37    0.00   -8.62    0.00   -21.82  -87.31  -27.57  -100.09  56.17  -61.56   58.72  -1.63    0.95    0.03    13.16   15.44  -3.56    7.97    59.29   4.97    0.00    1.64    0.00   -17.18  -10.02  -3.08    13.56   53.38  -18.07   0.00   -25.93   0.00    

这里是预览:

是骨骼,没有应用MOTION数据(纯偏移量),因为您可以看到骨骼未对齐(但距骨骼不远),骨骼不在同一平面内并且旋转了一点.但是您需要考虑到初始配置和姿势可以是任何东西.

on the left is skelet without applying MOTION data (pure offsets) as you can see its not axis aligned (but its not far from it) the bones are not in the same plane and are rotated a bit. But you need to take into account that the initial configuration and pose can be anything.

右侧是预览,其中预览了来自MOTION数据的第一帧转换.

On the right is preview with applied first frame transforms from MOTION data.

另请参阅:

这篇关于如何将bvh文件解析为OpenGL中制作的骨架模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆