I have vertex buffer data that i want to bring into Three.js. It is a flat array that contains vertex positions and normals, like this: PX PY PZ NX NY NZ
The corresponding geometry is indexed, so i’ve tried this:
let geometry = new THREE.BufferGeometry();
geometry.setAttribute( "position", new THREE.BufferAttribute(myVertices, 6)); // 6 because there are 6 values for each vertex, but this
geometry.setIndex(new THREE.BufferAttribute(myTriangles, 1));
In your case, it will be something like this (just from the scratch, thus you’ll need to fix it, if it doesn’t work ):
let geometry = new THREE.BufferGeometry();
let buffer = new Float32Array( _your_array_of_data_for_vertices_and_normals_ );
let interleavedBuffer = new THREE.InterleavedBuffer( buffer, 6 );
geometry.setAttribute( "position", new THREE.InterleavedBufferAttribute(interleavedBuffer, 3, 0));
geometry.setAttribute( "normal", new THREE.InterleavedBufferAttribute(interleavedBuffer, 3, 3));
geometry.setIndex( myTriangles );