如何挤出平面 2D 网格并赋予其深度

发布于 2024-09-25 20:55:12 字数 300 浏览 1 评论 0原文

我有一组共面、相连的三角形,即二维网格。现在我需要将其在 z 轴上挤出几个单位。网格由一组顶点定义,渲染器通过与三角形数组匹配来理解这些顶点。

网格示例:

顶点:(0,0,0)、(10,0,0)、(10,10,0)、(0,10,0) <-- (x,y,z) 三角形:(1,2,3)& (3, 4, 1) <-- 这里的数字引用上面顶点的位置。

所以这里我们有一个二维正方形。现在我需要向该列表添加更多顶点和三角形以形成拉伸形状。三角形必须是顺时针方向,否则它们将被背面剔除。

有一个简单的算法吗?谢谢。

I have a set of co-planar, connected triangles, i.e., a 2D mesh. Now I need to extrude it out a few units in the z-axis. The mesh is defined by a set of vertices which the renderer makes sense of by matching up against an array of triangles.

Example Mesh:

Vertices: (0,0,0), (10,0,0), (10,10,0), (0,10,0) <-- (x,y,z)
Triangles: (1, 2, 3) & (3, 4, 1) <-- numbers here reference the position of a vertex above.

So here we have a 2D square. Now I need to add more vertices and triangles to that list to make an extruded shape. Triangles must be in clockwise direction, otherwise they're backface-culled.

Is there a simple algorithm for this? Thank you.

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

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

发布评论

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

评论(1

萤火眠眠 2024-10-02 20:55:12

假设您想要拉伸距离 z,则需要执行以下步骤:

0) 令 n 为原始顶点数(示例中为 4)

1) 对于顶点数组中的每个顶点,添加 (0,0,z ) ,并将结果添加到顶点数组中,总共 2*n 个顶点。因此,对于您的示例,您将把顶点 (0,0,z)、(10,0,z)、(10,10,z)、(0,10,z) 添加到顶点数组中,总计2*4=8 个顶点。

2) 为原始网格创建边界(而不是内部)边缘列表。为此,请创建所有三角形边的列表(每个三角形有 3 条边按顺时针顺序排列)。然后删除成对的相等但相反的边缘(这些是内部边缘)。对于您的示例,您将从 6 条边开始,在删除边对 (3,1) 和 (1,3) 后最终得到 4 条边。

3) 为三角形列表中的每个三角形 (a,b,c) 创建一个相应的三角形 (a+n,b+n,c+n)。这些将是挤出面

4) 最后,您要创建挤出形状的侧面。对于在步骤 2 中创建的边界边列表中的每条边 (a,b),添加三角形 (a,b,b+n) 和 (b+n,a+n,a)

即可。假设我没有错别字,你也没有错别字,你现在应该有了你想要的网格。

Assuming you want to extrude by a distance z, you need to follow these steps:

0) let n be the original number of vertices (4 in your example)

1) For each vertex in your vertex array, add (0,0,z) to it, and add the result to your vertex array, for a total of 2*n vertices. So, for your example, you will add the vertices (0,0,z), (10,0,z), (10,10,z), (0,10,z) to your vertex array, for a total of 2*4=8 vertices.

2) Create a list of boundary (as opposed to internal) edges for your original mesh. To do this, create a list of all triangle edges (3 edges going in clockwise order for each triangle). Then remove pairs of equal but opposite edges (these are the internal edges). For your example, you will start with 6 edges, and end up with 4 edges after removing the edge pair (3,1) and (1,3).

3) for each triangle (a,b,c) in your triangle list, create a corresponding triangle (a+n,b+n,c+n). These will be the extruded faces

4) Finally, you want to create the sides of your extruded shape. For each edge (a,b) in the boundary edge list you created in step 2, add the triangles (a,b,b+n) and (b+n,a+n,a)

That's it. Assuming no typos on my part, and no typos on your part, you should now have your desired mesh.

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