一致地确定面部法线的方向? [英] Determing the direction of face normals consistently?

查看:26
本文介绍了一致地确定面部法线的方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是计算机图形学的新手,如果我的某些语言不准确或问题遗漏了一些基本内容,我深表歉意.

I'm a newbie to computer graphics so I apologize if some of my language is inexact or the question misses something basic.

是否有可能正确计算面法线,给定一个顶点列表和一个像这样的面列表:

Is it possible to calculate face normals correctly, given a list of vertices, and a list of faces like this:

v1: x_1, y_1, z_1
v2: x_2, y_2, z_2
...
v_n: x_n, y_n, z_n
f1: v1,v2,v3
f2: v4,v2,v5
...
f_m: v_j, v_k, v_l

每个 x_i, y_i , z_i 指定顶点在 3d 空间中的位置(但不一定是向量)

Each x_i, y_i , z_i specifies the vertices position in 3d space (but isn't neccesarily a vector)

每个 f_i 包含指定它的三个顶点的索引.

Each f_i contains the indices of the three vertices specifying it.

我知道您可以使用面的两侧的叉积来获得法线,但该法线的方向取决于边的顺序和选择(据我所知).

I understand that you can use the cross product of two sides of a face to get a normal, but the direction of that normal depends on the order and choice of sides (from what I understand).

鉴于这是我拥有的唯一数据,是否可以正确确定法线的方向?或者是否有可能至少始终如一地确定它们?(所有法线可能都指向错误的方向?)

Given this is the only data I have is it possible to correctly determine the direction of the normals? or is it possible to determine them consistently atleast? (all normals may be pointing in the wrong direction?)

推荐答案

在 CG 中它是由多边形缠绕规则完成的.这意味着所有面都已定义,因此当直接在面上查看时,点按 CW(或 CCW)顺序排列.然后使用叉积将导致一致的法线.

In CG its done by polygon winding rule. That means all the faces are defined so the points are in CW (or CCW) order when looked on the face directly. Then using cross product will lead to consistent normals.

然而,有许多网格不符合缠绕规则(有些面是 CW,有些面是 CCW 不完全相同),对于那些,这是一个问题.我知道有两种方法:

However many meshes out there does not comply the winding rule (some faces are CW others CCW not all the same) and for those its a problem. There are two approaches I know of:

  1. 对于简单的形状(不要太凹)

face_normalface_center-cube_center 的点积符号会告诉你法线是指向对象内部还是外部.

the sign of dot product of your face_normal and face_center-cube_center will tell you if the normal points inside or outside of the object.

if ( dot( face_normal , face_center-cube_center ) >= 0.0 ) normal_points_out

您甚至可以使用面部的任何点代替面部中心.无论如何,对于更复杂的凹面形状,这将无法正常工作.

You can even use any point of face instead of the face center too. Anyway for more complex concave shapes this will not work correctly.

测试面上方的点是否在里面

简单地将面中心沿法线方向移动一些小距离(不要太大),然后测试该点是否在多边形网格内:

simply displace center of face by some small distance (not too big) in normal direction and then test if the point is inside polygonal mesh or not:

if ( !inside( face_center+0.001*face_normal ) ) normal_points_out

要检查点是否在内部,您可以使用命中测试.

to check if point is inside or not you can use hit test.

然而,如果法线仅用于照明计算,那么它的用法通常在点积内.所以我们可以改用它的 abs 值,这将解决所有光照问题,而不管正常的一面.例如:

However if the normal is used just for lighting computations then its usage is usually inside a dot product. So we can use its abs value instead and that will solve all lighting problems regardless of the normal side. For example:

output_color = face_color * abs(dot(face_normal,light_direction))

一些 gfx api 已经实现了这个(寻找双面材质或法线,打开它们通常使用 abs 值......)例如在 OpenGL 中:

some gfx apis have implemented this already (look for double sided materials or normals, turning them on usually use the abs value ...) For example in OpenGL:

glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

这篇关于一致地确定面部法线的方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆