Hi!
Pass vertex data in buffer attributes.
For example, here: Project MONOLITH
There is setAttributes()
function, that has that code:
let pos = g.attributes.position;
let faces = pos.count / 3;
let faceVerts = [
new THREE.Vector3(),
new THREE.Vector3(),
new THREE.Vector3()
];
let position2 = [];
let position3 = [];
for (let i = 0; i < faces; i++) {
faceVerts[0].fromBufferAttribute(pos, i * 3 + 0);
faceVerts[1].fromBufferAttribute(pos, i * 3 + 1);
faceVerts[2].fromBufferAttribute(pos, i * 3 + 2);
for (let v = 0; v < 3; v++) {
let v2 = faceVerts[(v + 1) % 3];
let v3 = faceVerts[(v + 2) % 3];
position2.push(v2.x, v2.y, v2.z);
position3.push(v3.x, v3.y, v3.z);
}
}
g.setAttribute("position2", new THREE.Float32BufferAttribute(position2, 3));
g.setAttribute("position3", new THREE.Float32BufferAttribute(position3, 3));
(lines 426-449 in JS section)
and in the vertex shader I simply do this:
attribute vec3 position2;
attribute vec3 position3;
(lines 71-72 in JS section)