Why does bufferGeometry index have an itemSize of 1?

Why does bufferGeometry index have an itemSize of 1?

When I use setIndex on a bufferGeometry:

	geometry.setIndex([
		0,	2,	1,
		0,	3,	2, 
	]);

Shouldn’t the itemSize of the index bufferattribute be 3 instead of 1? Why is it 1?

You are thinking of a triangle. But the index refers to each of the vertices of the triangle.

Thus one value for each corner point.

For the positions you have three values. Each point has three coordinates in space x, y, z.
So in this case you actually have 3 values.

Have a look at the Beginner Example // … step 02: buildt custom geometries …
* discourse.threejs.hofk.de

:slightly_smiling_face:


const paperplaneMaterial = new THREE.MeshBasicMaterial( { color: 0xededed, side: THREE.DoubleSide, wireframe: true } );
			// 9 corner points from a sketch
const pplanePos = [
  // x    y    z      index
    0.3, 1.0, 0.0,  //  0
    0.0, 1.2, 0.0,  //  1
    0.0, 1.0, 0.0,  //  2
    0.9, 1.1, 0.1,  //  3
    0.8, 1.0, 0.0,  //  4
    0.8,-1.0, 0.0,  //  5
    0.9,-0.8, 0.1,  //  6
    0.0,-1.0, 0.0,  //  7
    0.0,-1.7,-0.0,  //  8

];

const pplaneIndices = new Uint32Array( [
    // 6 faces (triangles, counter clockwise)
    0, 1, 2,
    2, 7, 4,
    7, 5, 4,
    7, 8, 5,
    5, 3, 4,
    5, 6, 3
    
	] );

const paperplaneGeometry = new THREE.BufferGeometry( );	
paperplaneGeometry.setIndex( new THREE.BufferAttribute( pplaneIndices, 1 ) );
paperplaneGeometry.setAttribute( 'position', new THREE.BufferAttribute( new Float32Array( pplanePos ), 3 ) );
1 Like

It’s a bit confusing, because in the regular geometry from which I am migrating from, faces would be composed of a,b,c values for each triangle… If indices are always used to denote 3 values for one triangle, why not just make the itemSize 3? and have a getA, getB getC?

For LineSegments, .index denotes two points for each segment.

Or you can use .index even for Points, like in this example: three.js examples

I see, that makes sense.