动态生成复杂 3D 网格的三角形列表

发布于 2024-09-01 01:43:48 字数 357 浏览 12 评论 0原文

在我的应用程序中,我具有复杂 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 技术交流群。

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

发布评论

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

评论(3

欲拥i 2024-09-08 01:43:48

听起来您需要创建一个顶点数组和一个三角形列表,每个三角形都包含顶点数组中的 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).

风筝有风,海豚有海 2024-09-08 01:43:48

这有点取决于您的要求。

如果生成后不需要访问网格,而只需要渲染它,最快的选择是使用 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 with glMapBuffer, write your data into the buffer, then unmap it with glUnmapBuffer. 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.

夜深人未静 2024-09-08 01:43:48

我不确定 Marching Cube 算法 是否有任何帮助?

I'm not sure if the Marching Cube algorithm would be any help?.

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