gpu蒙皮的矩阵计算

时间:2023-05-10
本文介绍了gpu蒙皮的矩阵计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试在 OpenGL 中使用 Assimp 作为我的模型导入库来制作骨骼动画.

I'm trying to do skeletal animation in OpenGL using Assimp as my model import library.

对于骨骼的 offsetMatrix 变量,我到底需要什么?我需要乘以什么?

What exactly do I need to the with the bones' offsetMatrix variable? What do I need to multiply it by?

推荐答案

让我们以这段代码为例,我用它来为我工作的游戏中的角色设置动画.我也使用 Assimp 来加载骨骼信息,并且我自己阅读了 Nico 已经指出的 OGL 教程.

Let's take for instance this code, which I used to animate characters in a game I worked. I used Assimp too, to load bone information and I read myself the OGL tutorial already pointed out by Nico.

glm::mat4 getParentTransform()
{
    if (this->parent)
        return parent->nodeTransform;
    else 
        return glm::mat4(1.0f);
}

void updateSkeleton(Bone* bone = NULL)
{ 
    bone->nodeTransform =  bone->getParentTransform() // This retrieve the transformation one level above in the tree
    * bone->transform //bone->transform is the assimp matrix assimp_node->mTransformation
    * bone->localTransform;  //this is your T * R matrix

    bone->finalTransform = inverseGlobal // which is scene->mRootNode->mTransformation from assimp
        * bone->nodeTransform  //defined above
        * bone->boneOffset;  //which is ai_mesh->mBones[i]->mOffsetMatrix


    for (int i = 0; i < bone->children.size(); i++) {
        updateSkeleton (&bone->children[i]);
    }
}

本质上是教程 GlobalTransform>带有Assimp的骨骼动画或正确的根节点变换scene->mRootNode->mTransformation是从局部空间到全局空间的变换.举个例子,当在 3D 建模器中(例如让我们选择 Blender)创建网格或加载角色时,它通常(默认情况下)位于笛卡尔平面的原点,其旋转设置为身份四元数.

Essentially the GlobalTransform as it is referred in the tutorial Skeletal Animation with Assimp or properly the transform of the root node scene->mRootNode->mTransformation is the transformation from local space to global space. To give you an example, when in a 3D modeler (let's pick Blender for instance) you create your mesh or you load your character, it is usually positioned (by default) at the origin of the Cartesian plane and its rotation is set to the identity quaternion.

但是,您可以将网格/角色从原点 (0,0,0) 平移/旋转到其他位置,并在单个场景中甚至具有不同位置的多个网格.当你加载它们时,特别是如果你做骨骼动画,必须将它们转换回本地空间(即回到原点 0,0,0 ),这就是你必须这样做的原因将所有内容乘以 InverseGlobal(将您的网格带回本地空间).

However you can translate/rotate your mesh/character from the origin (0,0,0) to somewhere else and have in a single scene even multiple meshes with different positions. When you load them, especially if you do skeletal animation, it is mandatory to translate them back in local space (i.e. back at the origin 0,0,0 ) and this is the reason why you have to multiply everything by the InverseGlobal (which brings back your mesh to local space).

之后,您需要将其乘以节点变换,即parentTransform(树中的上一级变换,这是整体变换)transform(以前是 assimp_node->mTransformation,它只是骨骼相对于节点父级的变换)和您想要应用的本地变换(任何 T * R):forward运动学、反向运动学或关键帧插值.

After that you need to multiply it by the node transform which is the multiplication of the parentTransform (the transformation one level up in the tree, this is the overall transform) the transform (formerly the assimp_node->mTransformation which is just the transformation of the bone relative to the node's parent) and your local transformation (any T * R) you want to apply to do: forward kinematic, inverse kinematic or key-frame interpolation.

最终有boneOffset(ai_mesh->mBones[i]->mOffsetMatrix),它从网格空间转换到绑定姿势的骨骼空间,如文档中所述.

Eventually there is the boneOffset (ai_mesh->mBones[i]->mOffsetMatrix) that transforms from mesh space to bone space in bind pose as stated in the documentation.

这里有一个指向 GitHub 的链接,如果您想查看我的 Skeleton 类的完整代码.

Here there is a link to GitHub if you want to look at the whole code for my Skeleton class.

希望有帮助.

这篇关于gpu蒙皮的矩阵计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:glReadPixels() “数据"参数用法? 下一篇:#error gl.h 包含在 glew.h 之前

相关文章