边缘折叠与assimp

时间:2016-11-30 04:29:57

标签: algorithm opengl computational-geometry mesh assimp

我正试图在我的游戏引擎中实现边缘崩溃,这是由Assimp引起的问题。从face.mNumIndices解析的索引始终是增量顺序索引。

当我检查索引列表时,该值应该是0,1,2,3,4....,999...的排序。但是我知道这是Assimp使用的某种mechanism,并且对象被渲染得很好。但Mesh Simplication还有另一个问题,我无法为这些索引生成半边结构。我坚持了几天,没有回答。我应该放弃Assimp吗?任何建议表示赞赏。

修改 我的顶点在面之间共享,我用来获取数据的代码。

BasicRenderModel* AssimpLoader::ProcessMeshBasicVersion(aiMesh * mesh, const aiScene * scene)
{
    //std::vector<Vertex> vertices;
    float *vertices = new float[mesh->mNumVertices * 3];
    int vertexLength = mesh->mNumVertices * 3;
    float *normals = new float[mesh->mNumVertices * 3];
    int normalLength = mesh->mNumVertices * 3;
    float *texCoords = new float[mesh->mNumVertices * 2];
    int texCoordLength = mesh->mNumVertices * 2;
    std::vector<int> indicesList;
    int *indices;
    int indexLength;

    //std::vector<Texture> textures;
    std::map<TextureType, std::vector<Texture>> textures;
    for (GLuint i = 0; i < mesh->mNumVertices; i++)
    {
        // Process vertex positions, normals and texture coordinates
        vertices[i * 3] = mesh->mVertices[i].x;
        vertices[i * 3 + 1] = mesh->mVertices[i].y;
        vertices[i * 3 + 2] = mesh->mVertices[i].z;
        normals[i * 3] = mesh->mNormals[i].x;
        normals[i * 3 + 1] = mesh->mNormals[i].y;
        normals[i * 3 + 2] = mesh->mNormals[i].z;
        if (mesh->mTextureCoords[0]) // Does the mesh contain texture coordinates?
        {
            texCoords[i * 2] = mesh->mTextureCoords[0][i].x;
            texCoords[i * 2 + 1] = mesh->mTextureCoords[0][i].y;
        }
        else
            texCoords[i * 2] = texCoords[i * 2 + 1] = 0.0f;
        Debug::Log("vertex: " + std::to_string(vertices[i * 3]) + "," + std::to_string(vertices[i * 3 + 1]) + "," + std::to_string(vertices[i * 3 + 2]));
    }
    // Process indices
    for (GLuint i = 0; i < mesh->mNumFaces; i++)
    {
        aiFace face = mesh->mFaces[i];
        for (GLuint j = 0; j < face.mNumIndices; j++)
            indicesList.push_back(face.mIndices[j]);
    }
    indices = new int[indicesList.size()];
    indexLength = indicesList.size();
    for (int i = 0; i < (int)indicesList.size(); i++)
        indices[i] = indicesList[i];

    return this->loader.LoadRenderModel(vertices, vertexLength, indices, indexLength, texCoords, texCoordLength, normals, normalLength);
}

this object的结果顶点和上面代码生成的索引是here

比较结果和obj文件。对于树对象,obj文件有624个顶点,但Assimp有927个顶点,obj的索引是310(行)* 3 = 930,但从Assimp读取的索引是927个索引。我认为Assimp处理后面的数据,并生成指定的索引和顶点。

如果我需要重新计算索引,那意味着我需要检查每个顶点的所有顶点以找到相同的并构造索引..?无法弄清楚如何解决这个问题..

1 个答案:

答案 0 :(得分:0)

使算法与Assimp Importer一起使用有两个重要的事项。

  1. 模型应与面共享顶点,如果模型不是,则应在3D模型软件中使用某些选项。我在问题部分提供的树对象,我需要在blender中删除双打(删除重复的顶点),而法线应该只有一个。

  2. 另一件需要注意的是带有assimp的postprocess选项。检查Assimp文档,有一个名为aiProcess_JoinIdenticalVertices的标志,如果没有启用,Assimp将为唯一顶点生成完全唯一的索引。 here上有更多信息。