3D 表面法线提取器
我有一个 3D 闭合网格对象,它具有 3D 65.000 位置坐标。 出于照明目的,我需要一个 3D 表面法线提取器。
你能帮我得到它吗?
谢谢。
理查德
I have a 3D closed mesh object that has 3D 65.000 position coordinates.
For lighting purposes, I need a 3D surface normal extractor.
Could you help me to have it.
Thanks.
Richard
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好的,这里介绍了执行此任务的通用算法,与您使用的语言和图形库无关。
现在,我必须强调,这是对需要完成的工作的粗略描述,为了实现这一目标,可以省掉某些角落以提高效率。我的意思是,您不需要先计算所有三角形法线,然后计算所有顶点法线 - 这两个步骤可以混合在一起来制作更有效率。
一些伪代码可能看起来像这样
关于关于缠绕顺序的其他一些注释 - 如果你弄错了,法线将指向内,而不是向外。如上所述,这可以通过简单地更改叉积的顺序来解决。
OK, here's a stab at a general algorithm to carry out this task, independent of what language and graphics library you are using.
Now, I must stress that this is a rough description of what needs to be accomplished in order to do this there are certain corners that can be cut for efficiency. What I'm getting at is that you don't need to calculate all triangle normals first and then calculate all vertex normals - the 2 steps can be mixed in to make things more efficient.
Some pseudo code might look this
Regarding some of the other comments about winding order - if you get this wrong, the normals will point inwards, rather than outwards. This can be fixed by simply changing the order of the cross product, as noted above.
既然你有索引,我假设它是三角形列表/条带或扇形。读出每个三角形。通过叉积计算法线 2 个三角形向量。不过你有 1 个问题。如果您不知道三角形的缠绕顺序,那么您可能会得到相反的值。哪个软件创建了网格?您可以在数据文件或软件中检查缠绕顺序吗?是左手还是右手?
since you have the indices, i am assuming its either a triangle list / strip or fan. Read each triangle. Compute the normal by taking the cross product of 2 of the vectors of the triangle. You have 1 problem though. If you dont know the winding order of the triangles, then you might get the opposite value. Which software created the mesh ? Can you inspect within the data file or software what the winding order was ? is it left or right handed ?
您需要的只是构成三角形两侧的向量的叉积,并标准化为单位向量。
正如安德鲁·基思(Andrew Keith)在他的评论中所说,当您从“外部”看三角形时,您最好知道三角形是顺时针或逆时针定义的。如果你不能保证一致性,那么你的手上就会一片混乱。但可能(或者至少希望)创建该对象的代码是正常的。
What you need is simply the cross-product of the vectors that make up two sides of the triangle, normalized to a unit vector.
As Andrew Keith said in his comment, you'd better know that the triangles are defined either clockwise or counterclockwise when you look at the triangle from the "outside." If you can't guarantee consistency, you have a mess on your hands. But probably (or at least hopefully) the code that created the object is sane.
Steg 的回答指出了正确的方向。但是,如果您需要高质量的法线,请查看论文 Discrete微分几何算子
对于三角2-流形。即使对于三角形面积等估计值不合格的不规则网格,余切公式 (8) 也能提供良好的结果。
Steg's answer points into the right direction. However, if you need high-quality normals, have a look at the paper Discrete Differential-Geometry Operators
for Triangulated 2-Manifolds. The cotangent formula (8) gives you good results even for irregular meshes where estimates such as the triangle area break down.