Understand how we place the value

Hi everyone

I want understand the logic behind how we choice the value in this table ?

thanks

x,y,z,x,y,z,x,y,z

Example,

4 Likes

Just a small node: you’ll see not that much with this data, as the triangle is degenerated (two vertices have the same coordinates (0, 1, 0) :thinking:

1 Like

These two very simple examples show you the meaning of the values.

BufferGeometryNonIndexed
BufferGeometryIndexed

rom the Collection of examples from discourse.threejs.org

1 Like

I like to use the built-in three.js math classes to read from and write to typed arrays.

THREE.Vector2 for an itemSize of 2
THREE.Vector3 for an itemSize of 3
THREE.Vector4 for an itemSize of 4
THREE.Color for colors, THREE.Euler and THREE.Quaternion for rotation.

const _vec3 = new THREE.Vector3();

const array = new FLoat32Array([
   0,1,0,
   0,1,0,
   0,1,1
])

// Read item 0 from the array
let offset = 0;
_vec3.fromArray(array, offset);

// Update the vector (e.g. scale it)
_vec3.multiplyScalar(2);

// Write it back to the array
_vec3.toArray(array, offset);

console.log(array);
// Output: [0, 2, 0, 0, 1, 0, 0, 1, 1]

Or in a loop

const itemSize = 3; // for Vector3
for (let i = 0; i < array.length; i += itemSize) {
	_vec3
		.fromArray(array, i); // Read
	    .multiplyScalar(2);  // Update
	    //... other operations
	    .toArray(array, i); // Write
}

console.log(array);
// Output: [0, 2, 0, 0, 2, 0, 0, 2, 2]