Currently, I am experimenting with ThreeJS to generate a point cloud. My goal is to assign a distinct color to each individual point within the cloud based on its position. How can I go about setting specific colors for each vertex in the geometry and subsequently changing those colors as needed?
geometry = new THREE.Geometry();
for (i = 0; i < particleCount; i++) {
var vertex = new THREE.Vector3();
vertex.x = Math.random() * 2000 - 1000;
vertex.y = Math.random() * 2000 - 1000;
vertex.z = Math.random() * 2000 - 1000;
geometry.vertices.push(vertex);
}
colors = [0xff0000, 0x0000FF, 0x00FF00, 0x000000]
size = 0.5
material = new THREE.PointsMaterial({
size: size,
color: colors[0]
});
particles = new THREE.Points(geometry, material);
scene.add(particles);