[Bf-python] Mesh.Face.MCol

Campbell Barton cbarton at metavr.com
Fri Jan 13 17:12:14 CET 2006


Hi Ken
Was just making some face functions- subdivide edge and triangulate face 
(Avoids an editmode cycle)

And found that dealing with face vertex colour to be a bit painfull. 
because you cant assign Col's like you can Uv's. wich has made it 
necessary to write a VertCol copy function.

Heres a simple function that triangulates a quad into 2 tri's... see how 
the colour us handeled,
__________________________________________

def copyCol(fromCol, toCol):
        toCol.r = fromCol.r
        toCol.g = fromCol.g
        toCol.b = fromCol.b


def triangulate(mesh, faceIndex):
    f = mesh.faces[faceIndex]
    if len(f.v) != 4:
        return
   
    # Add faces
    mesh.faces.extend( (f.v[0], f.v[1], f.v[2]), (f.v[0], f.v[2], f.v[3]) )
    f1 = mesh.faces[-2]
    f2 = mesh.faces[-1]
   
    f1.mat = f2.mat = f.mat
   
    if mesh.faceUV:
        if f.image:
            f1.mode = f2.mode = f.mode
            f1.image = f2.image = f.image
            f1.uv = (f.uv[0], f.uv[1], f.uv[2])
            f2.uv = (f.uv[0], f.uv[2], f.uv[3])
           
            #f1.col = (f.col[0], f.col[1], f.col2]) # IDEAL
            copyCol(f.col[0], f1.col[0])
            copyCol(f.col[1], f1.col[1])
            copyCol(f.col[2], f1.col[2])
           
            copyCol(f.col[0], f2.col[0])
            copyCol(f.col[2], f2.col[1])
            copyCol(f.col[3], f2.col[2])           
    # Remove the face, may want to save up and batch face removel for 
faster operation.
    mesh.faces.delete(0, (faceIndex,))



More information about the Bf-python mailing list