我一直在尝试使用Assimp在OpenGl中为模型制作动画。我尝试的结果是这。
加载骨骼:
List<Bone> getBones(AIMesh mesh) {
List<Bone> bones = new ArrayList<>();
for (int i = 0; i < mesh.mNumBones(); i++) {
AIBone aiBone = AIBone.create(mesh.mBones().get(i));
Bone bone = new Bone(aiBone.mName().dataString());
bone.setOffset(aiMatrixToMatrix(aiBone.mOffsetMatrix()).transpose());
bones.add(bone);
}
return bones;
}
加载顶点:
VertexData processVertices(AIMesh mesh) {
float[] weights = null;
int[] boneIds = null;
float[] vertices = new float[mesh.mNumVertices() * 3];
boolean calculateBones = mesh.mNumBones() != 0;
if (calculateBones) {
weights = new float[mesh.mNumVertices() * 4];
boneIds = new int[mesh.mNumVertices() * 4];
}
int i = 0;
int k = 0;
for (AIVector3D vertex : mesh.mVertices()) {
vertices[i++] = vertex.x();
vertices[i++] = vertex.y();
vertices[i++] = vertex.z();
//bone data if any
if (calculateBones) {
for (int j = 0; j < mesh.mNumBones(); j++) {
AIBone bone = AIBone.create(mesh.mBones().get(j));
for (AIVertexWeight weight : bone.mWeights()) {
if (weight.mVertexId() == i - 3) {
k++;
boneIds[k] = j;
weights[k] = weight.mWeight();
}
}
}
}
}
我做错了什么。绑定姿势是否需要所有矩阵,或者我可以仅使用偏移量进行测试吗?
如果我让你的代码正确,你就不会从脸上得到 inidecs,对吧?您需要遍历网格的面以获得正确的inidic,如果我正确理解了您正在使用的概念。