动态生成复杂 3D 网格的三角形列表
在我的应用程序中,我具有复杂 3D 实体的形状和尺寸(例如 圆柱体 )取自用户输入。我需要为其构造顶点和索引缓冲区。
由于尺寸取自用户输入,因此我无法使用 Blender 或 3D Max 手动创建模型。动态生成这样的网格的教科书方法是什么?
我正在寻找能够根据顶点、边和孔生成三角形的东西。类似于 TetGen,尽管 TetGen 无法排除落在实体/网格内部的三角形。
In my application, I have the shape and dimensions of a complex 3D solid (say a Cylinder Block) taken from user input. I need to construct vertex and index buffers for it.
Since the dimensions are taken from user input, I cannot user Blender or 3D Max to manually create my model. What is the textbook method to dynamically generate such a mesh?
I am looking for something that will generate the triangles given the vertices, edges and holes. Something like TetGen, though TetGen has no way of excluding the triangles which fall on the interior of the solid/mesh.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来您需要创建一个顶点数组和一个三角形列表,每个三角形都包含顶点数组中的 3 个索引列表。没有简单的方法可以做到这一点。要绘制一个盒子,您需要 8 个向量和 12 个三角形(每边 2 个)。一些表示也会使用显式边缘表示。我怀疑这比您想要做的工作要多得多……
您需要的是一个可以执行 CSG(复合实体几何)的网格库。这样,您应该能够指定块的尺寸,然后指定圆柱体的尺寸,并告诉它为您切割它们(CSG 差异)。所有顶点和三角形管理都应该为您完成。最后,这样的库应该能够将网格导出为一些常见的格式。这里唯一的问题是我不知道这样一个库的名称。有些事情告诉我,如果你知道如何编写脚本,Blender 实际上可以完成所有这些工作。我还怀疑那里有 1 或 2 个相当好的库。
Google 实际上让我回到了 StackOverflow:
一个好的 3D 网格库
你最终可能会如果它们不提供创建网格的函数(它们都谈论操作网格或执行 CSG),则需要以编程方式生成简单的网格并使用库对其进行操作。
Sounds like you need to create an array of verticies, and a list of triangles each of which contains a list of 3 indicies into the vertex array. There is no easy way to do this. To draw a box, you need 8 veticies and 12 triangles (2 per side). Some representations will use explicit edge representations too. I suspect this is way more work than you want to do so.....
What you need is a mesh library that can do CSG (composite solid geometry). This way you should be able to specify the dimensions of the block, and then the dimensions of the cylinders and tell it to cut them out for you (CSG difference). All the vertex and triangle management should be done for you. In the end, such a library should be able to export the mesh to some common formats. Only problem here is that I don't know the name of such a library. Something tells me that Blender can actually do all of this if you know how to script it. I also suspect there are 1 or 2 fairly good libraries out there.
Google actually brought me back to StackOverflow with this:
A Good 3D mesh library
You may ultimately need to generate simple meshes programatically and manipulate them with a library if they don't provide functions for creating meshes (they all talk about manipulating a mesh or doing CSG).
这有点取决于您的要求。
如果生成后不需要访问网格,而只需要渲染它,最快的选择是使用
glGenBuffers
创建顶点缓冲区,使用glMapBuffer
将其映射到内存中code>,将数据写入缓冲区,然后使用glUnmapBuffer
取消映射。绘图速度会非常快,因为所有数据都可以上传到显卡内存。如果您确实需要在生成网格数据后访问它,或者如果您希望定期修改它,那么最好在常规数组中构建顶点数据,并将顶点数组与
glVertexPointer
和朋友一起使用。您还可以使用组合:在主内存中生成网格数据,然后使用
memcpy()
将其放入映射的顶点缓冲区中。最后,如果“尺寸”指的是缩放整个物体,则可以在任何 3D 建模程序中离线创建它,并使用 OpenGL 转换(例如
glScale
),将尺寸应用到网格,同时渲染。It depends a bit on your requirements.
If you don't need to access the mesh after generating, but only need to render it, the fastest option is to create a vertex buffer with
glGenBuffers
, map it into memory withglMapBuffer
, write your data into the buffer, then unmap it withglUnmapBuffer
. Drawing will be very fast because all data can be uploaded to video card memory.If you do need to access the mesh data after generating it, or if you expect to modify it regularly, you might be better off building your vertex data in a regular array and using vertex arrays with
glVertexPointer
and friends.You can also use a combination: generate the mesh data in main memory, then
memcpy()
it into a mapped vertex buffer.Finally, if by "dimensions" you mean just scaling the entire thing, you can create it offline in any 3D modelling program and use the OpenGL transformations, for example
glScale
, to apply the dimensions to the mesh while rendering.我不确定 Marching Cube 算法 是否有任何帮助?
I'm not sure if the Marching Cube algorithm would be any help?.