我正在做一个骨骼动画渲染器,但遇到了一些问题。我编写了自己的 Collada Loader,一切正常(我已经检查了多次),我为绘图准备了蒙皮和骨架数据。
我理解它的方式你必须首先将你的关节乘以反向绑定变换,以使它们位于你的世界坐标系的中心,然后根据动画乘以关节动画矩阵(关节层次结构的连接本地关节变换)将关节变换到正确的世界位置。
我将粘贴下面的代码,不处理帧的插值我尝试渲染每个关节动画的第一帧,这样我就可以只专注于蒙皮。
static void
update_animator(Animator* animator)
{
if (animator->anim == NULL)return;
increase_animation_time(animator);
//this is the array holding the animated local bind transforms for each joint,
//if there is no animation in a certain joint its simply m4d(1.f)
mat4 *local_animated_transforms= (mat4*)malloc(sizeof(mat4) *joints_count);
for (i32 i = 0; i < 44; ++i)
{
local_animated_transforms[i] = m4d(1.f);
}
for (u32 i = 0; i < animator->anim->joint_anims_count; ++i)
{
JointKeyFrame current_pose = animator->anim->joint_animations[i].keyframes[0];
u32 animation_index = current_pose.joint_index;
mat4 local_animated_transform = translate_mat4(current_pose.transform.position) * quat_to_mat4(current_pose.transform.rotation);
local_animated_transforms[animation_index] = local_animated_transform;
}
for (u32 i = 0; i < joints_count;++i)
calc_animated_transform(animator, animator->model.joints, local_animated_transforms, i);
}
static void
calc_animated_transform(Animator *animator, Joint *joints, mat4 *local_transforms, u32 index)
{
//here we get the animated joint transform meaning the world pos of the joint in the animation
mat4 animated_joint_transform = concat_local_transforms(joints, local_transforms, index);
//here we multiply by inv bind transform to get the world pos relative to the original bone transforms
joints[index].animated_transform =animated_joint_transform * joints[index].inv_bind_transform;
}
任何帮助表示赞赏!