簡體   English   中英

簡單的Assimp程序提供了不正確的數據

[英]Simple Assimp Program Giving Incorrect Data

我正在嘗試使用Assimp從obj文件加載模型,但是它提供了不正確的數據。 我嘗試了幾種不同的方法,但是找不到問題。

頂點位置關閉(略微),但有趣的是,面部數據格式不正確。 在我的OBJ文件中(包含),有20張臉。 對於此示例,我的程序顯示了20張臉,但是其中有些只有2個索引! 這是啟用了triangulation標志的,因此我不知道這是assimp還是我的代碼中的錯誤。 我也嘗試了其他一些標志,但是似乎都沒有用。

我壓縮了似乎導致以下問題的代碼

測試文件

#include <SDL2/SDL.h>
#include <GL/glew.h>
#include <SDL2/SDL_opengl.h>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#define GLM_FORCE_RADIANS
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <iostream>

using namespace std;

int main(int argc, char* args[])
{
    Assimp::Importer importer;

    const aiScene * scene = NULL;

    scene = importer.ReadFile("box.obj", aiProcess_JoinIdenticalVertices | aiProcess_Triangulate);

    if(!scene)
    {
        return -1;
    }

    for(GLuint i = 0; i < scene->mNumMeshes; i++)
    {
        const aiMesh* mesh = scene->mMeshes[i];

        //float* vertices = new float[mesh->mNumVertices * 3];
        //float* faces = new float[mesh->mNumFaces * 3];

        cout << "has positions: " << mesh->HasPositions() << " has faces: " << mesh->HasFaces() << endl;

        cout << "vertex count: " << mesh->mNumVertices << endl;
        cout << "face count: " << mesh->mNumFaces << endl;

        for(GLuint j = 0; j < mesh->mNumFaces; j++)
        {

            cout << "Face Indices: " << mesh->mFaces[j].mNumIndices << "    ";

            for(GLuint k = 0; k < mesh->mFaces[j].mNumIndices; k++)
            {
                cout << "I" << k << " V" << mesh->mFaces[j].mIndices[k] << " ";
            }

            cout << endl;

            //faces[j * 3] = mesh->mFaces[j].mIndices[0];
            //faces[j * 3 + 1] = mesh->mFaces[j].mIndices[1];
            //faces[j * 3 + 2] = mesh->mFaces[j].mIndices[2];
        }
    }

    return 0;
}

box.obj

v 0.000 0.000 1.000 
v 0.894 0.000 0.447 
v 0.276 0.851 0.447 
v -0.724 0.526 0.447 
v -0.724 -0.526 0.447 
v 0.276 -0.851 0.447 
v 0.724 0.526 -0.447 
v -0.276 0.851 -0.447 
v -0.894 0.000 -0.447 
v -0.276 -0.851 -0.447 
v 0.724 -0.526 -0.447 
v 0.000 0.000 -1.000

f 2 1 0 
f 3 2 0 
f 4 3 0 
f 5 4 0 
f 1 5 0 
f 11 6 7 
f 11 7 8 
f 11 8 9 
f 11 9 10 
f 11 10 6 
f 1 2 6 
f 2 3 7 
f 3 4 8 
f 4 5 9 
f 5 1 10 
f 2 7 6 
f 3 8 7 
f 4 9 8 
f 5 10 9 
f 1 6 10

輸出

has positions: 1 has faces: 1
vertex count: 11
face count: 20
Face Indices: 2    I0 V0 I1 V1 
Face Indices: 2    I0 V2 I1 V0 
Face Indices: 2    I0 V3 I1 V2 
Face Indices: 2    I0 V4 I1 V3 
Face Indices: 2    I0 V1 I1 V4 
Face Indices: 3    I0 V5 I1 V6 I2 V7 
Face Indices: 3    I0 V5 I1 V7 I2 V8 
Face Indices: 3    I0 V5 I1 V8 I2 V9 
Face Indices: 3    I0 V5 I1 V9 I2 V10 
Face Indices: 3    I0 V5 I1 V10 I2 V6 
Face Indices: 3    I0 V1 I1 V0 I2 V6 
Face Indices: 3    I0 V0 I1 V2 I2 V7 
Face Indices: 3    I0 V2 I1 V3 I2 V8 
Face Indices: 3    I0 V3 I1 V4 I2 V9 
Face Indices: 3    I0 V4 I1 V1 I2 V10 
Face Indices: 3    I0 V0 I1 V7 I2 V6 
Face Indices: 3    I0 V2 I1 V8 I2 V7 
Face Indices: 3    I0 V3 I1 V9 I2 V8 
Face Indices: 3    I0 V4 I1 V10 I2 V9 
Face Indices: 3    I0 V1 I1 V6 I2 V10

我知道沒有刪除操作,等等,我只是在嘗試刪除盡可能多的代碼以使問題更易於發現。

對於什么有價值的系統= Ubuntu 15.04。 昨晚進行了升級,希望這可能是系統問題

這是因為面中的頂點數應基於1,而不是基於0。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM