Calculates the normal vector for each vertex on the geometry.
All 3D shapes are made by connecting sets of points called vertices. A geometry's surface is formed by connecting vertices to create triangles that are stitched together. Each triangular patch on the geometry's surface is called a face. myGeometry.computeNormals()
performs the math needed to orient each face. Orientation is important for lighting and other effects.
A face's orientation is defined by its normal vector which points out of the face and is normal (perpendicular) to the surface. Calling myGeometry.computeNormals()
first calculates each face's normal vector. Then it calculates the normal vector for each vertex by averaging the normal vectors of the faces surrounding the vertex. The vertex normals are stored as p5.Vector objects in the myGeometry.vertexNormals array.
The first parameter, shadingType
, is optional. Passing the constant FLAT
, as in myGeometry.computeNormals(FLAT)
, provides neighboring faces with their own copies of the vertices they share. Surfaces appear tiled with flat shading. Passing the constant SMOOTH
, as in myGeometry.computeNormals(SMOOTH)
, makes neighboring faces reuse their shared vertices. Surfaces appear smoother with smooth shading. By default, shadingType
is FLAT
.
The second parameter, options
, is also optional. If an object with a roundToPrecision
property is passed, as in myGeometry.computeNormals(SMOOTH, { roundToPrecision: 5 })
, it sets the number of decimal places to use for calculations. By default, roundToPrecision
uses 3 decimal places.
예제
구문
computeNormals([shadingType], [options])
매개변수
shading type. either FLAT or SMOOTH. Defaults to FLAT
.
shading options.