【问题标题】:Assimp skeletal animation becomes a triangle messAssimp 骨骼动画变成了三角混乱
【发布时间】:2019-06-30 21:52:31
【问题描述】:

我一直在尝试使用 Assimp 在 OpenGL 中为模型制作动画。 我尝试的结果是 this.

加载骨骼:

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();
                    }
                }
            }
        }
    }

我做错了什么。 绑定姿势是否需要所有矩阵,或者我可以只使用偏移量进行测试吗?

【问题讨论】:

    标签: java opengl lwjgl assimp


    【解决方案1】:

    如果我让你的代码正确,你就不会从表面上得到 inidecs,对吧?如果我理解您使用的概念正确,您需要遍历网格的面以获得正确的索引。

    【讨论】:

      猜你喜欢
      • 2017-01-30
      • 2014-09-23
      • 2017-07-22
      • 2015-07-21
      • 2017-04-10
      • 2020-09-27
      • 2021-11-07
      • 2014-01-15
      • 1970-01-01
      相关资源
      最近更新 更多