0

我正在尝试使用 Assimp 加载一个简单的八面体。这就是模型应该看起来的样子:

在此处输入图像描述

但是,这是我的代码呈现的内容:

在此处输入图像描述

显然,这是不正确的。我不确定我的代码哪里出了问题,尽管我怀疑是 OpenGL 而不是 Assimp 代码。

这是我的代码:

    auto scene = scoped!AssimpScene(assimp,"octahedron.obj",aiProcessPreset_TargetRealtime_Fast);
auto mesh = scene.scene().mMeshes[0]; 

auto vertex = new float[mesh.mNumFaces*3*3];
auto normal = new float[mesh.mNumFaces*3*3];
int b = 0;
for(int i = 0; i < mesh.mNumFaces;i++)
{
    auto face = mesh.mFaces[i];
    for(int j = 0; j < 3; j++)
    {

         auto va  = cast(float[3])mesh.mVertices[face.mIndices[j]];
         vertex[b..b+3] = va;


         auto n  = cast(float[3])mesh.mNormals[face.mIndices[j]];
         normal[b..b+3] = n;
         b+=3;
    }
}
while(!sdl2.keyboard().isPressed(SDLK_ESCAPE))
{
    sdl2.processEvents(); 
    //clear screen
    glViewport(0, 0, width,height);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);

    glVertexPointer(3,GL_FLOAT,0,cast(const(void*))vertex);
    glNormalPointer(GL_FLOAT,0,cast(const(void*))normal);


    glDrawArrays(GL_TRIANGLES,0,mesh.mNumFaces*3);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    window.swapBuffers();

}
scene.close();
assimp.close();
}

代码断断续续,可以大大改进,虽然我对 OpenGL 很陌生,所以我不确定到底如何。在这方面的任何建议将不胜感激!

以下是运行时产生的日志供参考:

2014-10-14T17:19:26.0681112:assimp.d:loggingCallbackAssimp:149 
info: assimp: Info,  T0: Load octahedron.obj

2014-10-14T17:19:26.0681631:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: Assimp 3.0.1262 amd64 gcc debug shared singlethreaded

2014-10-14T17:19:26.0681916:assimp.d:loggingCallbackAssimp:149 
info: assimp: Info,  T0: Found a matching importer for this file format

2014-10-14T17:19:26.0682121:assimp.d:loggingCallbackAssimp:149 
info: assimp: Info,  T0: Import root directory is './'

2014-10-14T17:19:26.0682681:assimp.d:loggingCallbackAssimp:149 
info: assimp: Info,  T0: Entering post processing pipeline

2014-10-14T17:19:26.0682903:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: GenUVCoordsProcess begin

2014-10-14T17:19:26.0683055:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: GenUVCoordsProcess finished

2014-10-14T17:19:26.0683206:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: TriangulateProcess begin

2014-10-14T17:19:26.0683351:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: TriangulateProcess finished. There was nothing to be done.

2014-10-14T17:19:26.0683503:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: SortByPTypeProcess begin

2014-10-14T17:19:26.0683655:assimp.d:loggingCallbackAssimp:149 
info: assimp: Info,  T0: Points: 0, Lines: 0, Triangles: 1, Polygons: 0 (Meshes, X = removed)

2014-10-14T17:19:26.0683812:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: SortByPTypeProcess finished

2014-10-14T17:19:26.0683975:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: GenFaceNormalsProcess begin

2014-10-14T17:19:26.0684129:assimp.d:loggingCallbackAssimp:149 
info: assimp: Info,  T0: GenFaceNormalsProcess finished. Face normals have been calculated

2014-10-14T17:19:26.0684297:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: Generate spatially-sorted vertex cache

2014-10-14T17:19:26.0684487:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: CalcTangentsProcess begin

2014-10-14T17:19:26.068466:assimp.d:loggingCallbackAssimp:149 
info: assimp: Error, T0: Failed to compute tangents; need UV data in channel0

2014-10-14T17:19:26.0684825:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: CalcTangentsProcess finished

2014-10-14T17:19:26.0684983:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: JoinVerticesProcess begin

2014-10-14T17:19:26.0685253:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: Mesh 0 (unnamed) | Verts in: 24 out: 24 | ~0%

2014-10-14T17:19:26.0685428:assimp.d:loggingCallbackAssimp:149 
info: assimp: Debug, T0: JoinVerticesProcess finished 

2014-10-14T17:19:26.0685593:assimp.d:loggingCallbackAssimp:149 
info: assimp: Info,  T0: Leaving post processing pipeline
4

2 回答 2

1

你没有做很多事情,openGL 比你想象的要低得多,即使使用传统的 GL,你也必须指定矩阵和光照等。

在http://www.arcsynthesis.org/gltut/index.html推荐教程

于 2014-10-15T01:39:08.590 回答
0

您不进行任何相机转换。如果您想要快速修复,您可以使用 gluLookAt,但我建议不要使用已弃用的 OpenGL。这是一个很好的教程:https ://open.gl/

于 2014-10-18T19:11:20.823 回答