TriangleMesh JavaFX中的getNormals()方法有什么用 [英] What is use of getNormals() method in TriangleMesh JavaFX

查看:186
本文介绍了TriangleMesh JavaFX中的getNormals()方法有什么用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用JavaFX 3D应用程序,并在TriangleMesh类中遇到了getNormals()方法.

I am currently working of JavaFX 3D application and come across getNormals() method in TriangleMesh class.

就像在TriangleMesh中一样,类用于创建用户定义的Java FX 3D对象,并且
getPoints()用于添加点
getFaces()用于添加面孔
getTexCoords( )用于管理3D对象的纹理,
但我不确定TriangleMesh类中的getNormals()方法是什么.

As in TriangleMesh class is used to create user defined Java FX 3D obejct and in that
getPoints() is used to add Points
getFaces() is used to add Faces
getTexCoords() is used to manage Texture of 3D Object,
but I am not sure what is use of getNormals() method in TriangleMesh class.

在TriangleMesh类中,我们可以将顶点格式设置为VertexFormat.POINT_TEXCOORD和VertexFormat.POINT_NORMAL_TEXCOORD.
但是,如果将vertexFormat设置为"VertexFormat.POINT_NORMAL_TEXCOORD",则需要将法线索引添加到如下面中:
[ p0,n0,t0,p1,n1,t1,p3,n3,t3,//纹理矩形的第一个三角形

In TriangleMesh class, we can set vertex format to VertexFormat.POINT_TEXCOORD and VertexFormat.POINT_NORMAL_TEXCOORD.
But if we set vertexFormat as "VertexFormat.POINT_NORMAL_TEXCOORD", then we need to add indices of normals into the Faces like below :
[ p0, n0, t0, p1, n1, t1, p3, n3, t3, // First triangle of a textured rectangle

p1,n1,t1,p2,n2,t2,p3,n3,t3//纹理矩形的第二个三角形 ]

p1, n1, t1, p2, n2, t2, p3, n3, t3 // Second triangle of a textured rectangle ]

https://docs中所述.oracle.com/javase/8/javafx/api/javafx/scene/shape/TriangleMesh.html

如果我将vertexFormat用作POINT_TEXCOORD或POINT_NORMAL_TEXCOORD,我在3D形状上没有发现任何差异.

I didn't find any difference in 3D shape, if I used vertexFormat as POINT_TEXCOORD or POINT_NORMAL_TEXCOORD.

那么TriangleMesh JavaFX中的getNormals()方法有什么用?

So what is the use of getNormals() method in TriangleMesh JavaFX?

先谢谢了.

推荐答案

在计算机图形学:

在计算机图形学中通常使用法线来确定平面朝向光源进行平面着色的方向,或者确定每个角(顶点)的方向以模拟带有Phong着色的曲面.

The normal is often used in computer graphics to determine a surface's orientation toward a light source for flat shading, or the orientation of each of the corners (vertices) to mimic a curved surface with Phong shading.


法线会影响应用于脸部的阴影.


The normals effect the shading applied to a face.

JavaFX 8的标准着色机制是 Phong着色法线向量将被计算为垂直于面部.

The standard shading mechanism for JavaFX 8 is Phong Shading and a Phong Reflection Model. By default, Phong Shading assumes a smoothly varying (linearly interpolated) surface normal vector. This allows you to have a sphere rendered by shading with limited vertex geometry supplied. By default the normal vectors will be calculated as being perpendicular to the faces.

JavaFX允许您提供自己的法线,而不是依靠默认的计算法线.然后,JavaFX中的Phong阴影算法实现将在您提供的法线之间进行插值,而不是在其计算的法线之间进行插值.更改表面法线的方向将通过更改模型表示从其弹起的光的方式来更改着色模型,本质上,在修改后的法线下,光将沿不同的方向反弹.

What JavaFX allows is for you to supply your own normals rather than rely on the default calculated ones. The Phong shading algorithm implementation in JavaFX will then interpolate between the normals that you supply rather than the normals it calculates. Changing the direction of surface normals will change the shading model by altering how the model represents light bouncing off of it, essentially the light will bounce in a different direction with a modified normal.

这个来自Wikipedia的示例在右侧显示了一个phong阴影球体.两个球实际上具有相同的几何形状.默认情况下,对phong着色方程式起作用的法线的分布是默认值,它是根据每个面的标准法线计算平滑地插值的(因此,不提供用户法线). PhongMaterial javadoc,您可以在其中看到漫反射颜色的正常贡献,无论是漫反射颜色的计算还是镜面高光.

This example from Wikipedia shows a phong shaded sphere on the right. Both spheres actually have the same geometry. The distribution of the normals which contribute towards the phong shading equation is the default, smoothly interpolated one based upon a standard normal calculation for each face (so no user normals supplied). The equation used for calculating the shading is described in the PhongMaterial javadoc, and you can see there the normal contribution to the shading algorithm, in terms of the both the calculations of diffuse color and the specular highlights.

标准3D模型,例如 obj文件可以选择允许提供法线:

Standard 3D models, such as obj files can optionally allow for providing normals:

vn i j k

vn i j k

多边形和自由形式的几何声明.

Polygonal and free-form geometry statement.

指定具有分量i,j和k的法线向量.

Specifies a normal vector with components i, j, and k.

顶点法线会影响几何图形的平滑着色和渲染. 对于多边形,使用顶点法线代替实际的构面 常态.对于曲面,将顶点法线插值到 整个表面并替换实际的分析表面法线.

Vertex normals affect the smooth-shading and rendering of geometry. For polygons, vertex normals are used in place of the actual facet normals. For surfaces, vertex normals are interpolated over the entire surface and replace the actual analytic surface normal.

存在顶点法线时,它们将取代平滑组.

When vertex normals are present, they supersede smoothing groups.

i j k是顶点法线的i,j和k坐标.他们 是浮点数

i j k are the i, j, and k coordinates for the vertex normal. They are floating point numbers


那么,为什么要呢?

最简单的解释方法可能是查看称为平滑组(请单击链接,由于版权原因,我不会在此处嵌入).从链接的图像可以看出,当将平滑组应用于面的集合时,可以在分组的面之间获得清晰的轮廓(例如折痕或拐角).指定法线使您可以完成与平滑组相似的操作,但需要更多的控制权,因为您可以为每个顶点指定单独的法线,而不是为一组相关的面指定法线.注意JavaFX允许您通过

The easiest way to explain might be to look at something known as smoothing groups (please click on the link, I won't embed here due to copyright). As can be seen by the linked image, when the smoothing group is applied to a collection of faces it is possible to get a sharp delineation (e.g. a crease or a corner) between the grouped faces. Specifying normals allows you to accomplish a similar thing to a smoothing group, just with more control because you can specify individual normals for each vertex rather than an overall group of related faces. Note JavaFX allows you to specify smoothing groups via getFaceSmoothingGroups() for instances where you don't want to go to the trouble of defining full normal geometry via getNormals().

另一个类似的想法是法线地图(或

Another, similar idea is a normal map (or bump map). Such a map stores normal information in an image rather than as vector information, such as the getNormals() method, so it is a slightly different thing. But you can see a similar interaction with the reflection model algorithm:

背景知识-如何理解Phong材料(和其他东西)

这篇关于TriangleMesh JavaFX中的getNormals()方法有什么用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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