简单的Assimp程序给出错误的数据
Simple Assimp Program Giving Incorrect Data
我试图使用Assimp从obj文件加载模型,但它给出了不正确的数据。我试了几种不同的方法,但都找不到问题。
顶点位置是关闭的(稍微),但有趣的是,面部数据是畸形的。在我的OBJ文件(包括)中有20个面孔。对于这个例子,我的程序显示了20张脸,但其中一些只有2个索引!这是与三角测量标志,所以我不知道这是一个错误在assimp或与我的代码。我也尝试了其他一些标志,但似乎都不起作用。
我已经压缩了似乎导致
下面的问题的代码test.cpp
#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为基础。
相关文章:
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 使用 char* 存储数据和产生的错误
- Static_cast转换为错误的数据类型,但结果仍然正确?
- 创建服务失败0x6f7存根收到错误数据
- 通过 host() 从 af::array 检索数据会导致错误的数据
- OpenCV C++ 3 维垫数据访问错误值
- 错误: 无效使用非静态数据成员"应用程序::应用程序构造函数"
- 错误 - 自定义数据类型作为有效负载,带有提升::几何
- C 如何忽略错误数据输入
- C ++编译指示OMP分割错误(数据竞争?)与数组
- C++ mac OS X El Capitan上的openmp,Valgrind错误(数据竞赛)
- 通过结构指针访问结构变量分配错误数据
- 我该怎么做 throw 来处理 C++ 中的错误数据类型
- C++:模拟餐饮公司计费程序-无法将错误数据输出到错误文件
- 使用boost::asio套接字接收错误数据
- 读取位图图像时获取错误数据
- 来自cudaMemcpy2D的错误数据
- VS2010 x64:64位平台VS2010中包含错误数据的对象数组
- c++ fstream输出错误数据