레퍼런스 computeFaces()

computeFaces()

Computes the geometry's faces using its vertices.

All 3D shapes are made by connecting sets of points called vertices. A geometry's surface is formed by connecting vertices to form triangles that are stitched together. Each triangular patch on the geometry's surface is called a face. myGeometry.computeFaces() performs the math needed to define each face based on the distances between vertices.

The geometry's vertices are stored as p5.Vector objects in the myGeometry.vertices array. The geometry's first vertex is the p5.Vector object at myGeometry.vertices[0], its second vertex is myGeometry.vertices[1], its third vertex is myGeometry.vertices[2], and so on.

Calling myGeometry.computeFaces() fills the myGeometry.faces array with three-element arrays that list the vertices that form each face. For example, a geometry made from a rectangle has two faces because a rectangle is made by joining two triangles. myGeometry.faces for a rectangle would be the two-dimensional array [[0, 1, 2], [2, 1, 3]]. The first face, myGeometry.faces[0], is the array [0, 1, 2] because it's formed by connecting myGeometry.vertices[0], myGeometry.vertices[1],and myGeometry.vertices[2]. The second face, myGeometry.faces[1], is the array [2, 1, 3] because it's formed by connecting myGeometry.vertices[2], myGeometry.vertices[1], and myGeometry.vertices[3].

Note: myGeometry.computeFaces() only works when geometries have four or more vertices.

예제

Notice any errors or typos? Please let us know. Please feel free to edit src/webgl/p5.Geometry.js and open a pull request!

관련 레퍼런스