[译]如何统一多边形顶点排列顺序

3.3.1 Consistent Vertex Winding

Some 3D models come with polygons that are not all wound in a clockwise or counterclockwise direction, but are a mixture of both. Those polygons that are wound inconsistently should have the vertex order reversed. A good way to accomplish this is to find all common edges and verify that neighboring polygon edges are drawn in the opposite order (see Figure 6 ).

有些3D模型中的多边形顶点不是都按顺时针或都按逆时针排列,而是两种排列方式都有。(译者,平面有分正面和反面,现实中如果一个平面的顶点从正面 看是顺时针排列,那么从背面看就是逆时针,法向量判别可见面就是用了这个原理。如果规定一个平面的顶点从正面看是用顺时针,而实际模型却用了逆时针,这就 是排列不一致,用法向量进行可见面判别就不准确了。)要对这些顶点排列顺序不一致的多边形顶点进行反向排列。有一个方法,找出所有公共边,验证邻接多边形的边界是否是反向排列(Figure 6)

 

% latex2html id marker 1408
/fbox{/begin{tabular}{c}
/vrule width 0pt height 0.1...
...hefigure . Proper Winding for Shared Edge of Adjoining Facets}//
/end{tabular}}

 

To begin rewinding polygons, one polygon must be chosen as ``correct.'' All neighboring polygons must then be found and made consistent with the ``correct'' polygon. This repeats recursively for each new ``correct'' polygon until no more neighboring polygons can be found. If the model is a single closed object, all polygons will now be consistent. However, if the model has multiple unconnected pieces, another polygon that has not yet been tested must be found and the process must be repeated until all polygons have been tested and made consistent.

在修改多边形之前,要确定一个顶点排列“正确”的多边形。找到所有与它邻接的多边形,使他们的顶点排列顺序与该“正确”多边形一致。对每个处理后的多边形递归执行这个步骤,直到没有邻接多边形。如果模型是一个封闭物体,那所有多边形顶点的排序顺序已经一致。然而,如果模型由多个互相不相连的物体组成,就要找出还没有处理的多边形重复这个操作,直到所有多边形都测试通过。

The above method still leaves a 50-50 chance that the entire object is now wound backwards (assuming an object with half of the facets wound clockwise and half wound counterclockwise). Short of getting a human involved to look at the model, there are ways to check that the normals are pointing outwards. One way is to find the geometric center of the object by computing the object bounding box by finding the maximum and minimum X, Y and Z values, then computing the mid-point of the bounding box. Next, select a vertex that is the maximum distance from this center point and compute the (normalized) vector from the center point to this vertex. Then take the normal of one of the facets that shares the distant vertex and compute the dot product of the two vectors. A positive result indicates that the normals are all correct while a negative result indicates that the normals are all backwards. If the normals are backwards, negate them all and reverse the windings of all facets.

上面的方法有50%的概率使物体正反面颠倒。除了让人来分辨这个模型的正误外,还有另外一种方法判断平面的法向量是否朝向外面。先找到物体包围盒的中心,找到物体最大和最小的X, Y, Z坐标,两个坐标中点就是物体包围盒的中心。然后选择距离这个中心最远的点,并算出从中心到这个点的向量。计算共享这个最远点的某个面的法向量,如果这两个向量的点乘值大于0,就说明所有面的法向量都已经正确。如果点乘值小于0,说明所有面的法向量都颠倒了,这时遍历所有平面,把顶点顺序反转。

There are still a few pathological cases that may not come out right, such as a model of a room where it is desirable to view the inside walls, but the above method works for most cases.

虽然上述方法不适用于个别情况(比如一个房间的模型,要求墙壁内侧必须可见),大多数情况还是适用的。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值