[Python] Problem with Blender 2.5 change vertex colour script


I modified this script from tutorialsforblender3d.com to try and get it to work for 2.5, but when I try to use it on my character only some of the verts change colour. I’ve attached the blend, and here is the script:

import GameLogic as g

# get controller
cont = g.getCurrentController()

# get object controller is attached to
own = cont.owner

# get the mesh
mesh = own.meshes[0]

# get the number of materials on the mesh
mats = mesh.numMaterials

# cycle through all of the materials
for i in range(0, mats):
    # get array length of the material
    array = mesh.getVertexArrayLength(i - 1)
    # loop through array
    for vertNum in range( 0, array):
        # get vertex
        vert = mesh.getVertex(0, vertNum)
        #Change the color
        color = [0.5, 0.5, 0.5, 1.0]
        # change vertex color


Edit: It appears that most of the faces of my mesh go invisible in weight paint mode, and that only the few that are visible are the ones that get coloured in the game engine. Anyone know the cause and solution?

Edit 2: Cause: faces were on clip alpha for some reason. The faces that showed weren’t, because they were new ones as I’d redone some topology. Solution: set to opaque. I could do with that copy button right about now :slight_smile:

Edit 3: after going through all 700 or so faces and setting it to opaque… it hasn’t worked. And I have no clue why. It seemed to work on the first I tried but now even less faces are changing colour.

Edit 4:Also, all the faces are on opaque, but acting as if they’re on alpha with buggy sorting! Argh! And enabling sorting actually ‘fixes’ this…? I think I may have to try and ‘copy’ this mesh somehow and lose all the data, just start again.

Edit 5: I redownloaded the file I put up here and am working on that again. Putting faces to opaque seems to be working again. I think it didn’t work last time because I tried to use the mirror modifier to save time. Ironic.


torin.blend (603 KB)

Think I’ve found a bug in 2.53 Beta 1 on Windows 7 32-bit:

Using python to assign vertex colours during game engine only works when there is a variance of texture face modes, see attachment.

When you change the last face to opaque, as all the others are, the script stops working.

My solution is to just place a small plane with clip alpha inside the mesh, where it can’t be seen. Not happy with it though :slight_smile:


torin.blend (617 KB)