如何将人脸存储在内存中

发布于 2024-10-08 03:38:09 字数 265 浏览 1 评论 0原文

我一直在试图解决这个问题,但找不到一种看起来合理的方法,似乎没有什么可以真正解释它,我可以找到无数关于如何进行建模以及如何处理面部的东西,但没有任何关于他们可以存储在内存中以供使用。我主要关注的是 obj,剩下的很简单,主要只是用数组来存储所有内容,但是对于面,我能想到的使用它们的唯一方法是存储对象中哪些顶点的详细信息,或者每次从文件中读取它们,但这肯定是正确的吗?对每张脸都使用一个对象似乎很疯狂,但我想不出任何其他方法! 即使只是一本可以看的书或任何能指引我正确方向的东西,因为一切似乎都跳过了这些东西。谢谢。

Ive been trying to figure this out but cant find a way to do it which seems reasonable, and nothing seems to actually explain it, I can find a myriad of stuff on how to do modelling, and how to work withthe faces, but nothing on whow they can be stored in memory to work with. Ive been looking at obj mainly, and the rest is easy it's mainly just arrays to store it all, but faces, the only way Ive been able to think of to work with them is to store the details on which vertices in an object, or to read them from file each time, but that can't be right surely? It seems crazy to be using an object for every face, but I cant think of any other way!
Even just a book to look at or anything to just point me in the right direction, because everything just seems to skip over this stuff. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奈何桥上唱咆哮 2024-10-15 03:38:10

面通常由三个或更多顶点连接而成。这意味着您可以将每个面存储为其所组成的顶点(或顶点索引)列表。

f0: [v0 v1 v2]
f1: [v3 v4 v5] 
...

或者,如果每个面的顶点数量是预先确定的(我打赌这是常见的),您可以将其折叠成单个列表/向量/数组:

[/* face 1 */ v0 v1 v2 /* face 2 */ v3 v4 v5]

维基百科可能比我传达得更好。

A face is usually three or more vertices connected. This means you can store each face as a list of the vertices (or indices to the vertices) it consists of.

f0: [v0 v1 v2]
f1: [v3 v4 v5] 
...

Or if the amount of vertices for each face is predetermined (which I would wager is common), you could collapse it into a single list/vector/array:

[/* face 1 */ v0 v1 v2 /* face 2 */ v3 v4 v5]

Wikipedia may convey it better than I do.

回梦 2024-10-15 03:38:10

您正在寻找的是顶点数组。它的工作原理是每个对象都包含一组顶点和一种颜色。顶点的法线存储在同一个数组中(vertexX、vertexY、vertexZ、normalX、normalY、normalZ)。当您想要渲染对象时,您可以循环遍历对象数组并渲染每个对象,如下所示:

float plane[] = {
    10, 10, 0, 0, 0, 1,
    -10, 10, 0, 0, 0, 1,
    -10, -10, 0, 0, 0, 1,
    10, 10, 0, 0, 0, 1,
    -10, 10, 0, 0, 0, 1,
    10, -10, 0, 0, 0, 1,
};

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

glVertexPointer(3, GL_FLOAT, sizeof(plane[0])*6, &plane[0]);
glNormalPointer(3, GL_FLOAT, sizeof(plane[0])*6, &plane[3]);

glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glDrawArrays(GL_TRIANGLES, 0, (sizeof(plane) / sizeof(plane[0]))/6);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);

这应该绘制一个红色平面。唯一的区别是您希望从对象定义中向其提供数组。您还可以包含每个顶点的颜色信息,只需在上面的代码中包含一个 glColorPointer 和一个 glEnableClientState(GL_COLOR_ARRAY)。

What you are looking for is arrays of vertices. How it works is each object contains an array of vertices and a color. The normals for the vertices are stored in this same array, (vertexX, vertexY, vertexZ, normalX, normalY, normalZ). When you want to render your objects, you loop through your array of objects and render each object as shown below:

float plane[] = {
    10, 10, 0, 0, 0, 1,
    -10, 10, 0, 0, 0, 1,
    -10, -10, 0, 0, 0, 1,
    10, 10, 0, 0, 0, 1,
    -10, 10, 0, 0, 0, 1,
    10, -10, 0, 0, 0, 1,
};

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

glVertexPointer(3, GL_FLOAT, sizeof(plane[0])*6, &plane[0]);
glNormalPointer(3, GL_FLOAT, sizeof(plane[0])*6, &plane[3]);

glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glDrawArrays(GL_TRIANGLES, 0, (sizeof(plane) / sizeof(plane[0]))/6);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);

And that should draw a red plane. Only difference is you would want to feed it your array from your object definition. You can also include color information per vertex and just include a glColorPointer in the above code and a glEnableClientState(GL_COLOR_ARRAY).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文