Skeletal animation of DirectX files in OpenGL

百般思念 提交于 2019-12-01 10:53:39

This post is not pretend to be a full answer, but a set of helpful links.

How to get all information needed for animation

The question is how do you import your mesh, and why do you do this. You can fight with .x meshes for a months, but this doesn't make any sense, because .x is a very basic, old and really not good enough format. You don't find many fans of .x format on StackOverflow. =)

.x file stores animation data in a tricky way. It was intended to load via set of D3DX*() functions. But, to get bones and weights from it manually, you must preprocess loaded data. Much things to code. Here is a big post, explaining how to:

Loading and displaying .X files without DirectX

Good way to do things is just switch to some mesh loading library. The most popular and universal one is Assimp. At least, look at their docs and/or source code, on how they handle loading and preprocessing, and what whey have as output. Also, here is a good explanation:

Tutorial 38 - Skeletal Animation With Assimp

So, with assimp you can stop fighting and begin animating right now. And maybe later, when you'll find idea on how it's works, you can write your own loader.

When you've got all information needed for animation

Skeletal animation is a basic topic that explained in details all around the web.

Hope it helps!

Since Drop provided links that talk about the problem, and give clues on how to solve it, but don't quite provide a simple answer, i feel obliged to leave the solution here, in case someone else stumbles on the same problem.

To get the new vertex position in "bind pose"

v'(i) = v(i)*Σ(transform(bone)*W(bone,i))

where: v'(i) - new vertex position, v(i) - old vertex position, and W(bone,i) - weight of the transformation. (and of course Σ is the sum from 0 to the amount of bones in the skeleton)

The transform(bone) is equal to sw(bone) * cM(bone), where sw is the matrix found inside the SkinWeights tag, and cM(bone) is calculated using a recursive function:

cM(bone)
{
  if(bone->parent)
    return localTransform*cM(bone->parent);
  else
    return localTransform;
}

The localTransform is the matrix located inside the FrameTransformMatrix tag.

To get the new vertex position in a certain animation frame

Do the exact same operation as mentioned above, but instead of the matrix in FrameTransformMatrix, use one of the matrices inside the appropriate AnimationKey tag. Note that when an animation is playing, the matrix inside the FrameTransformMatrix tag becomes unused. Which means, you'll probably end up ignoring it most of the time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!