Vertex color on mesh

Hello, Mr.ale211734

I have done something similar before.
What about code like the one below?

// for (var i = 0;i <8; i++) {
const geometry = scene.children[j].geometry;
if (!geometry.attributes.color){
  const count = new BufferAttribute(new Float32Array( count * 3 ), 3);
  geometry.setAttribute("color", buffer);
}
const numVertices = geometry.attributes.color.array;
let colors = new Float32Array(numVertices);
const color1 = new Color("any1");
const color2 = new Color("any2");
const color3 = new Color("any3");
const vertex = new Vector3();
const positionArray = Array.from(geometry.attributes.position.array);
for (let i = 0; i <= positionArray.length - 3; i += 3) {
  vertex.set(positionArray[i], positionArray[i + 1], positionArray[i + 2]);
  if (i % 3 === 0) {
    colors.set(color1.toArray(), i);
  }
  else if (i % 3 === 1) {
    colors.set(color2.toArray(), i);
  }
  else if (i % 3 === 2) {
    colors.set(color3.toArray(), i);
  }
}
geometry.setAttribute("color", new BufferAttribute(colors, 3));

//}

i hope this helps you

PS: Is it possible to dynamically change only a portion of a material attached to a plane? - #5 by ShoOsaka