Quoted from the BufferGeometry documentation:
index (itemSize: 3)
Enables the re-usage of vertices in multiple triangles through "indexed triangles," functioning similarly to Geometry. Each triangle corresponds to the index of three vertices, with this attribute storing the vertex index for each triangular face. If not set, the renderer assumes that each consecutive set of three positions forms a single triangle.
In "indexed triangles," the "position" array consists of numbers where every triplet represents a vertex (x, y, z). The "index" array comprises triplets where each set pertains to one face by referencing indices of vertices in the "position" array.
For instance, a vertex array might look like this:
var vertices = [0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0];
This can be interpreted as XYZ coordinate sets:
var vertices = [
0, 0, 0, // vertex index 0
1, 0, 0, // vertex index 1
1, 1, 0, // vertex index 2
0, 1, 0 // vertex index 3
];
Then, an index array such as:
var indices = [0, 1, 2, 1, 2, 3];
Represents two triangles:
var indices = [
0, 1, 2, // face with vertices at indices 0, 1, 2
1, 2, 3 // face with vertices at indices 1, 2, 3
];
Hence, triangle #1 comprises vertices at (0, 0, 0), (1, 0, 0), (1, 1, 0) while triangle #2 has vertices at (1, 0, 0), (1, 1, 0), (0, 1, 0).
An alternative method involves defining vertices without indexing. Indexing allows for efficient vertex reuse instead of redundant listings for each triangle appearance in the array. For every triangle defined in a single array, the 'vertices' array organizes sets of 9 numbers as one triangle (with consecutive vertices having XYZ values).
To address your query on adding triangles to BufferedGeometry, consider these options:
- Incorporate triangles into the initial 'oldGeom' object before conversion. It is simpler to add triangles to Geometry compared to BufferGeometry and makes use of '.fromGeometry()' as the new faces are already specified in 'oldGeom.'
- Create an oversized 'indices' array beyond the original indices and manually outline triangles there. New vertices absent in the 'vertices' array need addition. This process may prove cumbersome.