我在 Android 的 OpenGLES 应用程序中实现骨骼动画时遇到问题。 对于模型,我使用 assimp 转换一个用 3ds max 导出的 FBX 文件并将其转换为文本文件。该文件加载骨骼数据(顶点、权重、偏移矩阵、层次结构等)
如果我将骨骼矩阵作为单位矩阵发送,我可以获得绑定(bind)姿势:
然后我存储每个节点的子节点,并使用此代码递归地将节点转换矩阵乘以它们的父节点
public void setBoneHeirarchy()
{
for (Bone b : mRootBones)
{
setBoneTransformations(b, mRootTransform);//From assimp aiScene->mRootNode->mTransformation
}
}
private void setBoneTransformations(Bone b, Matrix4 parent)
{
Matrix4 globalTransform = new Matrix4();
globalTransform.multMatrix(parent); //[this].multMatrix([arg]) multiplies the matrix like [this] = [this] * [arg]
globalTransform.multMatrix(b.nodeTransformation); //loaded from assimp as aiNode->mTransformation
b.transformation.loadIdentity(); //the final transformation to return
b.transformation.multMatrix(mRootTransformInverse); //Inverse of mRootNode->mTransformation
b.transformation.multMatrix(globalTransform); //calculated above
b.transformation.multMatrix(b.offsetMatrix); //read from text file (converted with assimp)
for (Bone child: b.children)
setBoneTransformations(child, globalTransform);
}
这个 blob 是结果:
我认为我的骨骼重量和 ID 是正确的,因为我得到了这个: i.stack.imgur.com/fcTro.png 当我翻译其中一个转换矩阵时
我试图遵循 ogldev.org/www/tutorial38/tutorial38.html 教程
现在我不知道去哪里找错误
是读取矩阵有问题还是计算有问题?
最佳答案
我尝试了多种矩阵乘法组合后解决了它
- 首先我从 FBX 切换到 Collada 文件格式,然后将其转换成我自己的格式
- 从 assimp 加载矩阵后立即转置它(我在将它加载到着色器中时转置它)
- 我没有乘以从 assimp 加载的节点变换,而是根据动画节点的平移、旋转和缩放 vector 创建了一个矩阵
我不完全明白将其更改为 Collada 是否有帮助,但谷歌搜索表明人们对 FBX 格式有疑问。
关于java - Android OpenGLES 骨骼动画问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43740035/