且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Wavefront Obj了解法线指数

更新时间:2023-11-12 23:13:58

您的问题是在数据结构中。至少在加载OBJ时,您需要将面部加载到以下内容中:

Your problem is in the data structure. At least while loading an OBJ you need to load your faces into something like:

struct Vertex
{
    unsigned int vertex;
    unsigned int normal;
    unsigned int texturecoord;
};

struct Face
{
    // not dynamic, but you get the idea.
    Vertex vertexes[N];
};

然后,如果你想要一个与顶点匹配的法线创建一个匹配的新数组。 OBJ格式针对存储进行了优化,而不是渲染。

Then you if you want an array of normals (and probably texturecoords) that matches the vertices, you need to create a new array that matches. The OBJ format is optimized for storage, not rendering.

这两步过程的另一个好处是,您可以通过将每个非三角形夹成三角形来删除同质面上的限制。

The added benefit from this two step process, is that you can remove the restriction on homogene faces, by splinting each non triangle into a triangle.