Hi,
i’m pretty stuck with a vertex color range problem.
I’ve got a floating value between 0 and 1 which i associate with vertex of a plane
how could i make this value a color range for vertex color in rgb?
Actually accessing the r,g, and b settings of a vertex on a mesh face is okay for me, but converting those floating values into a range for each r,g,b between 0 to 255 is still hard to understand.
This is not a solution, but maybe it will help you:
There isn’t a single way to accomplish what you’re trying to do, so it depends on what’s your color repartition on [0:1].
This is an example code I made in Javascript some time ago:
It matchs this colorband (x=0 on the left and x=1 on the right)
As you can see this colorband doens’t contain all possible colors, and I don’t think you’ll be easily able to do so (you’re trying to convert a single dimensional variable to a tri-dimensional one…). Plus, my repartition doesn’t match yours (you have blue on the left and red on the right).
But maybe you can took inspiration from this one.
for face in ms.faces:
opt = 1
for i in xrange(len(face)):
points = face.v[i]
points.sel = 1
while opt == 1:
for elem in tamp:
if elem[0] == points:
if elem[4] == 0:
face.col[i].r = 0
face.col[i].g = 0
face.col[i].b = 255
elif elem[4] == 0.5:
face.col[i].r = 0
face.col[i].g = 255
face.col[i].b = 0
elif elem[4] >= 1:
face.col[i].r = 255
face.col[i].g = 0
face.col[i].b = 0
elif 0 < elem[4] < 0.5:
face.col[i].r = 0
face.col[i].g = int(elem[4]*2*255)
face.col[i].b = 255 - int(elem[4]*2*255)
elif 0.5 < elem[4] < 1:
face.col[i].r = int((elem[4]-0.5)*2*255)
face.col[i].g = 255 - int((elem[4]-0.5)*2*255)
face.col[i].b = 0
opt = 0
assuming elem[4] is a floating value between 0 and 1
it works but there is still a problem when i display it in UV face select mode some corners of the faces are in white :eek::eek::eek: