【问题标题】:How to get vertex data in OpenGL from an OBJ file using a GLM object loader?如何使用 GLM 对象加载器从 OBJ 文件中获取 OpenGL 中的顶点数据?
【发布时间】:2014-04-21 10:41:30
【问题描述】:

我正在使用以下教程在 OpenGL 中绘制网格: https://www.d.umn.edu/~ddunham/cs5721f07/schedule/resources/lab_opengl07.html

在那个站点,有指向 GLM 源文件的链接,这些文件用于加载 OBJ 网格。 我能够使用这种技术成功绘制网格。但是,我需要能够获取网格的顶点(例如在矢量中)以进行分析和操作。如何做到这一点?

【问题讨论】:

    标签: opengl mesh wavefront


    【解决方案1】:

    这应该会有所帮助(请参阅提供的标题/来源):

    GLMmodel* model = glmReadOBJ(...);
    
    int vertex_count = model->numvertices; // # of vertices in the mesh
    float x0 = model->vertices[3 * 0 + 0]; // x coordinates of the 1st vertex 
    float y0 = model->vertices[3 * 0 + 1]; // y coordinates of the 1st vertex
    float z0 = model->vertices[3 * 0 + 2]; // z coordinates of the 1st vertex
    
    float x1 = model->vertices[3 * 1 + 1]; // x coordinates of the 2nd vertex
    ...
    
    int triangle_count = obj_model->numtriangles; // # of triangles in the mesh
    const GLMtriangle& triangle0 = model->triangles[0]; // 1st triangle
    int index0 = triangle0.vindices[0]; // index of the 1st vertex of the 1st triangle
    ...
    const GLMtriangle& triangle1 = model->triangles[1]; // 2nd triangle
    ...
    

    【讨论】:

      猜你喜欢
      • 2012-12-18
      • 2011-06-30
      • 1970-01-01
      • 2015-10-29
      • 1970-01-01
      • 2023-04-04
      • 2013-05-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多