def main():
cont = GameLogic.getCurrentController()
own = cont.owner
mesh = own.meshes[0]
# Iterates through all vertices:
for mat in range(mesh.numMaterials):
for v_index in range(mesh.getVertexArrayLength(mat)):
vertex = mesh.getVertex(mat, v_index)
# ... eg: colour the vertex red.
vertex.colour = [1.0, 0.0, 0.0, 1.0]
main()
Ok, I have another question-> why, when I attach an object to an armature and create just one vertex group(even without assigning vertexes to it), the applied vertex color(with the above script) of the object is disabled/deleted automatically, and when I delete the created vertex group the script works again?
P.S. It actually applies the color. When I trace the “vertex.color” after applying the script, it show, that all the vertexes has the new color, but visually the color of the mesh is not changed.
There is no fix, this is a bug in 2.49.
…but, I found a workaround:
Duplicate the mesh wich color you wnat to change.
Unparent the duplicated object from the armature, but do not delete the vertex groups in it.
Apply the above script to change the color of the duplicate object.
Use instantReplaceMesh() on the original object to replace its mesh with the duplicate mesh,wich color is already changed.
In other words to workaround this bug you need to apply the color first to an unparented(from the armature) mesh, then replace the original mesh with the duplicated mesh.