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

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

问题描述

我是计算机图形学的新手,因此如果我的某些语言不准确或该问题缺少基本知识,我深表歉意.

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天全站免登陆