I'm trying to change the colors of these points by randomly turning some of them white every 0.5 seconds.
this.geom = new THREE.SphereBufferGeometry(6, 350, 90);
this.colors = [];
this.color = new THREE.Color();
this.colorList = ['red','blue','pink'];
for (let i = 0; i < this.geom.attributes.position.count; i++) {
this.color.set(this.colorList[THREE.Math.randInt(0, this.colorList.length - 1)]);
this.color.toArray(this.colors, i * 3);
}
this.geom.addAttribute('color', new THREE.BufferAttribute(new Float32Array(this.colors), 3));
In order to update the colors without reloading all the points and causing the page to freeze, I am calling a function in the animate loop. I only want about 30 of the points to randomly turn white. How can I achieve this efficiently?
this.colorList = ['white', 'pink', 'blue', 'red'],
updateColor() {
for (let i = 0; i < this.geom.attributes.position.count; i++) {
this.color.set(this.colorList[THREE.Math.randInt(0, this.colorList.length - 1)]);
this.color.toArray(this.colors, i * 3);
}
this.geom.attributes.color.needsUpdate = true;
this.geom.addAttribute('color', new THREE.BufferAttribute(new Float32Array(this.colors), 3));
}