在 OpenGL 中处理网格的建议方法
我正在寻找比我当前的实现更好的方法来处理网格,当前的实现基本上是类形式的 .obj 格式。
我当前的结构是
Class Vertex
{
float[3] Pos;
}
Class Face
{
Vertex[3] Verts;
float[3][3] Norm;
float[3][3] Tex;
}
Class Mesh
{
Face[] MeshData;
}
在大多数情况下我都可以很好地使用它,但我希望能够执行诸如操纵顶点并随机移动它之类的操作。我做到了,但是连接的面不会随之移动。
这可能可以通过对同一位置的顶点的所有引用(对同一顶点的引用)来解决,但我不知道如何事先做到这一点,而且我无法想象删除双顶点会是一个甚至远程快速按照我的设置进行操作。
I'm looking for better ways to handle having a mesh than my current implementation which is basically the .obj format in the form of a class.
My Current Structure is
Class Vertex
{
float[3] Pos;
}
Class Face
{
Vertex[3] Verts;
float[3][3] Norm;
float[3][3] Tex;
}
Class Mesh
{
Face[] MeshData;
}
I can use this just fine in most cases, but I'd like to be able to do things such as manipulate a vertex and move it randomly. I did it, however the connected faces wouldn't move with it.
That could probably be fixed by making all references to a vertex in the same position, a reference to the same vertex, but I don't know how to do that beforehand and I can't imagine removing double vertices would be an even remotely fast operation with my setup.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要操作网格并且渲染速度是次要的,请查看 half-edge数据结构。
如果渲染速度至关重要,请将所有内容展平为交错的顶点/纹理坐标/法线数组,以获得最大的 VA/VBO 友好性:
通常您会希望
sizeof(Vertex)
为 32 字节的倍数。If you're going to be manipulating the mesh and rendering speed is secondary look into the half-edge data structure.
If rendering speed is paramount flatten everything out into a interleaved vertex/texcoord/normal array for maximum VA/VBO-friendliness:
Generally you'll want
sizeof(Vertex)
to be a multiple of 32 bytes.