简体   繁体   English

Assimp骨骼动画变换矩阵问题

[英]Assimp Skeletal Animation Transform Matrix Issues

I'm trying to work out skeletal animation using Assimp (Open Asset Import Library). 我正在尝试使用Assimp(开放资产导入库)来计算骨骼动画。 Right now I can successfully load a .dae model and render it with animation, but in the process of doing so the model gets messed up. 现在,我可以成功加载.dae模型并用动画对其进行渲染,但是在这样做的过程中,模型变得混乱了。

http://i.imgur.com/O7YzK8o.png http://i.imgur.com/O7YzK8o.png

The left model is not rigged and loaded properly. 左模型未正确装配和加载。 The model to the right is rigged and takes the correct pose from the animation but gets distorted weirdly (flat stick-figure~). 右边的模型已装配好,并从动画中获得正确的姿势,但奇怪地变形了(平坦的棍子形图〜)。

My take on it is that I probably do something wrong through the bone matrix multiplications. 我的看法是,我可能通过骨骼矩阵乘法做错了什么。

the final matrices(let's call them M) are calculated as follows: 最终矩阵(我们称它们为M)的计算如下:

M[i] = transform_matrix[i] * scene->mRootNode->mTransformation * offset_matrix[i]

where offset_matrix[i] is the combined offset matrix from the concatenation of aiBone->mOffsetMatrix , and transform_matrix[i] is the combined transform matrix from the concatenation of matrices from aiNodeAnim TRS. 其中offset_matrix[i]是来自aiBone->mOffsetMatrix的组合的组合偏移矩阵,而transform_matrix[i]是来自aiNodeAnim TRS的矩阵的组合组合变换矩阵。

Respective concatenations are done from the bottom and up to the root. 从底部到根分别进行串联。

while(node!=NULL){
    mOffset = loadRelativeOffset(node, scene) * mOffset
    node = node->mParent;
}
offset_matrix.push_back(mOffset);

loadRelativeOffset(node, scene) will loop through scene->mMeshes[0]->mNumBones and return the matrix of matched aiBone . loadRelativeOffset(node, scene)将循环遍历scene->mMeshes[0]->mNumBones并返回匹配的aiBone矩阵。 If no bone is found, the identity matrix will be returned. 如果没有找到骨头,将返回单位矩阵。 As such the end result will be a concatenation of all the bone matrices, ignoring Armature and the root node . 这样,最终结果将是所有骨骼矩阵的串联,而忽略了骨架根节点

Loading the transform matrix is done in a similar fashion but with aiNodeAnim in mNumChannels instead of aiBones in mNumBones . 加载变换矩阵的方式与aiNodeAnim类似,但是在aiNodeAnim中使用mNumChannels而不是aiBones中的mNumBones

I imagine the end result looks something like this: 我想最终结果看起来像这样:

M = Arm * Hand * Finger * RootNode * Offset_Arm * Offset_Hand * Offset_Finger;

I don't know why the RootNode matrix is there, but if it is not there everything looks like nonsense. 我不知道为什么存在RootNode矩阵,但是如果不存在,则一切看起来都是胡说八道。

Any idea what causes this, or what I can do? 知道是什么原因导致的,或者我能做什么?

I solved it. 我解决了 The problem was very simple - the bone offset matrices in aiBone are already global / combined , so there was no reason to concatenate. 问题非常简单aiBone中的骨偏移矩阵已经是全局 / 组合的 ,因此没有理由进行连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM