Assimp Faces 都有索引 (0,1,2) [英] Assimp Faces all have indices (0,1,2)

查看:28
本文介绍了Assimp Faces 都有索引 (0,1,2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Assimp 加载 OBJ 文件,以便使用我自己的渲染管道在 OpenGL 中进行渲染.

I'm using Assimp to load in OBJ files to render in OpenGL using my own rendering pipeline.

但是当我加载文件时,每个面都有索引 (0,1,2),而不是顶点数组中的适当条目.

But when I load in a file, every face has indices (0,1,2), rather than appropriate entries into the vertex array.

我能找到的每个例子都做类似的事情(这就是我正在做的):

Every example I could find does something similar to this (which is what I'm doing):

for (size_t k = 0; k<mesh->mNumFaces; ++k)
{
    if (mesh->mFaces->mNumIndices == 3)
    {
        out.index_list.push_back(mesh->mFaces->mIndices[0]);
        out.index_list.push_back(mesh->mFaces->mIndices[1]);
        out.index_list.push_back(mesh->mFaces->mIndices[2]);
    }
    else
    {
        std::cout << "wierd number of indices to a face: " << mesh->mFaces->mNumIndices << std::endl;
    }
}

或者这个(我已经尝试过,并且非常错误):

or this (which I've tried, and is very wrong):

for (size_t k = 0; k<mesh->mNumFaces; ++k)
{
    if (mesh->mFaces->mNumIndices == 3)
    {
        out.index_list.push_back(mesh->mFaces->mIndices[0]+k*3);
        out.index_list.push_back(mesh->mFaces->mIndices[1]+k*3);
        out.index_list.push_back(mesh->mFaces->mIndices[2]+k*3);
    }
    else
    {
        std::cout << "wierd number of indices to a face: " << mesh->mFaces->mNumIndices << std::endl;
    }
}

我还根据网格中顶点和面的相对数量尝试了一些变化,猜测它应该是三角形条带等......但也不起作用.

I've also tried some variations based on the relative number of vertexes and faces in a mesh, guessing that it should be a triangle strip, etc... and that also isn't working.

示例:

if (mesh->mNumFaces == mesh->mNumVertices-2)
    for (size_t k = 0; k<mesh->mNumVertices-2; ++k)
    {
        if (k%2)
        {
            out.index_list.push_back(k+1);
            out.index_list.push_back(k+0);
            out.index_list.push_back(k+2);
        }
        else
        {
            out.index_list.push_back(k+0);
            out.index_list.push_back(k+1);
            out.index_list.push_back(k+2);
        }
    }
else if...

我显然在这里遗漏了一些非常基本和明显的东西,但我看不到它是什么.

I'm obviously missing something very basic and obvious here, but I can't see what it is.

推荐答案

我认为您的代码只是加载网格 (aiMesh) 中第一个三角形(面)的索引.

mesh->mFace 是一个指针,指向 aiFaces 数组的第一个元素.

您的(第一个)代码没有考虑变量 k,即您的面部索引.

相反,这样做:

I think your code just loads the the indices of the first triangles(faces) in the mesh(aiMesh).

mesh->mFace is a pointer which points to the first element of the array of aiFaces.

Your (first) code doesn't take into account the variable k, your face index.

Instead, do it like this:

for (size_t k = 0; k<mesh->mNumFaces; ++k)
{
    if (mesh->mFaces->mNumIndices == 3)
    {
        // kth face!
        out.index_list.push_back(mesh->mFaces[k].mIndices[0]);
        out.index_list.push_back(mesh->mFaces[k].mIndices[1]);
        out.index_list.push_back(mesh->mFaces[k].mIndices[2]);
    }
    else
    {
        std::cout << "wierd number of indices to a face: " << mesh->mFaces->mNumIndices << std::endl;
    }
}

这样您的 index_list 应该填充正确的索引.

希望这可以帮助!:)

This way your index_list should be filled with the correct indices.

Hope this helps! :)

这篇关于Assimp Faces 都有索引 (0,1,2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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