边缘塌陷 [英] Edge Collapse with assimp

查看:125
本文介绍了边缘塌陷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to implement the edge collapse in my game engine, there is a problem caused by Assimp. The indices that parsed from face.mNumIndices is always the increment order indexing.

当我检查索引列表时,该值应为0,1,2,3,4....,999....但是我知道这是Assimp使用的某种机制,并且可以正确渲染该对象.但是还有另一个关于网格简化的问题,我无法为该索引生成半边结构.我坚持了几天,没有答案.我应该放弃Assimp吗?任何建议表示赞赏.

When I check the list of indices, the value should be sort of 0,1,2,3,4....,999... . But I know this is some kind of mechanism that used by Assimp, and the object are rendered all right. But there is another issue on Mesh Simplication, I could not generate the half-edge structure for this indices. I stuck on this a couple of days, and have no answer. Should I give up Assimp? Any advise is appreciated.

修改: 我的顶点在面孔之间共享,我用来在此处获取数据的代码.

My vertices are shared between faces, The code I used to get the data here.

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

此对象的结果顶点,由上面的代码生成的索引是此处

And the result vertices of this object and indices that generated by the code above is here

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

Compare the result and obj file. For the tree object, the obj file has 624 vertices, but Assimp has 927 vertices, and indices from obj are 310(lines) * 3 = 930, but the Indices read from Assimp are 927 indices. I thought Assimp process the data behind, and generate the specified indices and vertices.

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

If I need to recalculate indices, that means I need to check all vertices for each vertex to find which are the same and construct the indices..? Could not figure out how to slove this problem..

推荐答案

要使该算法与Assimp Importer一起使用,有两点重要的事情.

There has two important things to make the algorithm work with Assimp Importer.

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

  1. The model should be shared vertex with faces, If the model is not, it should be done with some options in 3D model software. The tree object that I provide in the question section, I need to remove doubles (remove duplicated vertices) in blender and the normal should be just one.

需要注意的另一件事是带有assimp的postprocess选项.检查Assimp文档,有一个名为aiProcess_JoinIdenticalVertices的标志,如果未启用,Assimp将为唯一顶点生成完全唯一的索引.在此处.

The other thing need to be noticed that the postprocess option with assimp. check the Assimp documentation, there is a flag called aiProcess_JoinIdenticalVertices, if this is not enable, Assimp would generate the totally unique Indices for unique vertices. There is more information at here.

这篇关于边缘塌陷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆