레퍼런스 computeNormals()

computeNormals()

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. It then calculates vertex normals according to the selected shading mode. The vertex normals are stored as p5.Vector objects in the myGeometry.vertexNormals array.

The first parameter, shadingType, is optional. Passing the constant KEEP_CONNECTIONS, as in myGeometry.computeNormals(KEEP_CONNECTIONS), preserves the geometry's existing vertex connections. Each vertex normal is calculated by averaging the face normals of its connected faces. This may produce smooth transitions between connected faces rather than true flat shading.

Passing the constant SMOOTH, as in myGeometry.computeNormals(SMOOTH), calculates smooth normals by grouping vertices with approximately matching positions, without modifying the original vertices or their attributes.

Passing the constant SEGMENTED, as in myGeometry.computeNormals(SEGMENTED), produces true flat shading by assigning each triangle its own face normal. Shared vertices are duplicated as needed while preserving the original vertex indices and their connections. Associated vertex attributes, such as UV coordinates and colors, are preserved.

The constant FLAT is deprecated and behaves identically to KEEP_CONNECTIONS. It is retained for backward compatibility. By default, shadingType is KEEP_CONNECTIONS.

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])

매개변수

shadingType
KEEP_CONNECTIONS|SMOOTH|SEGMENTED: shading type. Defaults to KEEP_CONNECTIONS.
options
Object: shading options.

관련 레퍼런스