简体   繁体   English

将3D网格细分为任意大小的片段

[英]Subdividing 3D mesh into arbitrarily sized pieces

I have a mesh defined by 4 points in 3D space. 我有一个在3D空间中由4个点定义的网格。 I need an algorithm which will subdivide that mesh into subdivisions of an arbitrary horizontal and vertical size. 我需要一种算法,可以将该网格细分为任意水平和垂直大小的细分。 If the subdivision size isn't an exact divisor of the mesh size, the edge pieces will be smaller. 如果细分尺寸不是网格尺寸的精确除数,则边件将更小。

All of the subdivision algorithms I've found only subdivide meshes into exact powers of 2. Does anyone know of one that can do what I want? 我发现的所有细分算法都只能将网格细分为2的精确乘方。有人知道可以实现我想要的功能的人吗?

Failing that, my thoughts about a possible implementation is to rotate the mesh so that it is flat on the Z axis, subdivide in 2D and then translate back into 3D. 失败的话,我对可能的实现方式的想法是旋转网格,使其在Z轴上平坦,细分为2D,然后再转换回3D。 That's because my mind finds 3D hard ;) Any better suggestions? 那是因为我的想法很难3D;)还有更好的建议吗?

Using C# if that makes any difference. 如果使用C#,那有什么区别。

If you only have to work with a rectangle in 3D, then you simply need to obtain the two edge vectors and then you can generate all the interior points of the subdivided rectangle. 如果只需要使用3D矩形,则只需获取两个边缘矢量,然后即可生成细分矩形的所有内部点。 For example, say your quad is defined by (x0,y0),...,(x3,y3) , in order going around the quad. 例如,假设您的四边形由(x0,y0),...,(x3,y3) ,以围绕四边形排列。 The edge vectors relative to point (x0,y0) are u = (x1-x0,y1-y0) and v = (x3-x0,y3-y0) . 相对于点(x0,y0)的边缘向量为u = (x1-x0,y1-y0)v = (x3-x0,y3-y0)

Now, you can generate all the interior points. 现在,您可以生成所有内部点。 Suppose you want M edges along the first edge, and N along the second, then the interior points are just 假设您希望第一个边沿有M条边,第二条沿边需要N条边,那么内部点就是

(x0,y0) + i/(M -1)* u + j/(N-1) * v

where i and j go from 0 .. M-1 and 0 .. N-1 , respectively. 其中ij0 .. M-10 .. N-1开始。 You can figure out which vertices need to be connected together by just working it out on paper. 只需在纸上进行计算,即可确定需要将哪些顶点连接在一起。

This kind of uniform subdivision works fine for triangular meshes as well, but each edge must have the same number of subdivided edges. 这种均匀细分也适用于三角形网格,但是每个边必须具有相同数量的细分边。

If you want to subdivide a general mesh, you can just do this to each individual triangle/quad. 如果要细分普通网格,则可以对每个单独的三角形/四边形进行细分。 This kind of uniform subdivision results in poor quality meshes since all the original flat facets remain flat. 由于所有原始平面均保持平坦,因此这种均匀的细分导致网格质量较差。 If you want something more sophisticated, you can look at Loop subidivision, Catmull-Clark, etc. Those are typically constrained to power-of-two levels, but if you research the original formulations, I think you can derive subdivision stencils for non-power-of-two divisions. 如果您想要更复杂的东西,可以查看Loop细分,Catmull-Clark等。这些通常被限制为2的幂,但如果您研究原始的公式,我认为您可以为非模板细分模板。两分制。 The theory behind that is a bit more involved than I can reasonably describe here. 其背后的理论比我在这里可以合理描述的要复杂得多。

Now that you've explained things a bit more clearly, I don't see your problem: you have a rectangle and you want to divide it up into rectangular tiles. 现在,您已经对事情进行了更清晰的解释,我看不到您的问题:您有一个矩形,并且想要将其分成矩形图块。 So the mesh points you want are regularly spaced in both orthogonal directions. 因此,所需的网格点在两个正交方向上有规律地间隔。 In 2D this is trivial, surely ? 在2D中,这肯定是微不足道的吗? In 3D it's also trivial though the maths is a little trickier. 在3D中,尽管数学有些棘手,但它也是微不足道的。

Off the top of my head I would guess that transforming from 3D to 2D (and aligning the rectangle with the coordinate axes at the same time) then calculating the mesh points, then transforming back to 3D is probably about as simple (and CPU-time consuming) as working it all out in 3D in the first place. 从我的头顶上,我想从3D转换为2D(并同时将矩形与坐标轴对齐)然后计算网格点,然后再转换回3D大概很简单(和CPU时间)消耗),因为首先要在3D环境中完成所有工作。

Yes, using C# means that I'm not able to propose a code to help you. 是的,使用C#意味着我无法提出代码来帮助您。

Comment or edit you question if I've missed the point. 如果我错过了重点,请评论或编辑您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM