Skeletal Animation
November 4, 2023About 1 min
Skeletal Animation
Keyframe animation basics
帧动画由一段时间中几个特定时间点和物体姿势组成。如下图:

其中姿势可以由位置
,缩放
,旋转
组成。在DX9中使用D3DXKEY_VECTOR3
表示位置和缩放,使用D3DXKEY_QUATERNION
表示旋转。
struct D3DXKEY_VECTOR3
{
FLOAT Time;
D3DXVECTOR3 Value;
};
struct D3DXKEY_QUATERNION
{
FLOAT Time;
D3DXQUATERNION Value;
};
使用ID3DXKeyframedAnimationSet
来表示一个帧动画,其中主要方法:
- D3DXCreateKeyframedAnimationSet 创建
- RegisterAnimationSRTKeys 添加动画帧
- GetSRT 通过时间获得SRT
Loading animation data
使用方法D3DXLoadMeshHierarchyFromX
加载x文件中的动画信息到ID3DXAnimationController
。
The ID3DXAnimationController
用来激活当前播放的动画,动画混合等。主要使用到API
- SetTrackAnimationSet 设置当前播放的动画
- AdvanceTime 采样下一个时间的动画姿势
获取动画信息示例:
void SkinnedMesh::GetAnimations(std::vector<std::string>& animations)
{
ID3DXAnimationSet* anim = NULL;
for (size_t i = 0; i < m_pAnimControl->GetMaxNumAnimationSets(); i++)
{
anim = NULL;
m_pAnimControl->GetAnimationSet(i, &anim);
if (anim != NULL)
{
animations.push_back(anim->GetName());
anim->Release();
}
}
}
Having multiple controllers affecting the same mesh
渲染多个物体,使用同一个mesh数据,但是播放不同的动画。效果如下:

这里使用CloneAnimationController
复制多份动画控制器。渲染步骤:
- Call
AdvanceTime()
for the active animation controller. - Calculate the world matrix for this character instance.
- Update the combined transformation matrices for the skinned mesh with
the world matrix. - Render the skinned mesh.
- Repeat with the next character instance.
值得注意的是这里使用的GPU
蒙皮,每个人物是分别提交的。直接使用CPU
蒙皮的话还是需要多个mesh。直接使用CPU蒙皮如下:
