In this example, all lines are drawn with same color. I try to change color of every line. I made these changes.
Define attribute
const colors = new Float32Array(MAX_POINTS * 3);
geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
Change material
const material = new THREE.LineBasicMaterial({ vertexColors: true });
In the update function change colors
...
for ( let i = 0, l = MAX_POINTS; i < l; i ++ ) {
UpdateColor();
colors[Cindex++] = rgb[0];
colors[Cindex++] = rgb[1];
colors[Cindex++] = rgb[2];
positions[ index ++ ] = x;
positions[ index ++ ] = y;
positions[ index ++ ] = z;
x += ( Math.random() - 0.5 ) * 30;
y += ( Math.random() - 0.5 ) * 30;
z += ( Math.random() - 0.5 ) * 30;
}
In animate() added this line.
line.geometry.attributes.color.needsUpdate = true;
My changes is here.
Only a few line changes color. It is not working what i want. How can i do this?