|
|
发表于 2010-4-16 08:20:00
|
显示全部楼层
Re:骨骼动画的问题
骨骼动画事实上非常简单, 因为动画数据是针对骨骼空间的,所以必须要先变换到模型空间.
代码:
比如1个顶点只能受4个骨骼影响.
struct skin_info
{
uchar indices[4];
float weights[4];
}
void UpdateSkin(vec3 * pos, const vec3 * origin,
const skin_info * info, const mat4 * mats, int count)
{
mat4 blend;
for (int i = 0; i < count; ++i)
{
blend = mats[info.indices[0]] * info.weights[0] +
mats[info.indices[1]] * info.weights[1] +
mats[info.indices[2]] * info.weights[2] +
mats[info.indices[3]] * info.weights[3];
pos = origin * blend;
}
}
mats 是 offset * combient.
用GPU也很简单, 不过有限制.
cpu用simd可以快很多
|
|