Assimp Faces的都有指标(0,1,2) [英] Assimp Faces all have indices (0,1,2)

查看:187
本文介绍了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;
    }
}

或本(我已经试过了,是的非常的错误):

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.

推荐答案

我觉得你的code只是加载在网格(aiMesh)的第一个三角形(面)的指数。

mesh-&GT; MFACE 是一个指针,它指向第一的数组元素 aiFace 秒。

你的(第一)code不考虑变量 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天全站免登陆