Color for NMesh or NMFace, how?

:frowning: I dont understand how to set color in the NMesh Face. I tried following options

face = NMesh.Face()
face.col = [(255,0,0),(0,255,0),(0,0,255), (0,0, 255)]
or
COL=NMesh.Col()
COL.r=140
COL.g=250
COL.b=120
COL.a=0
face.col.append(COL)

or
face.col = [(223,125, 67)]
or
COL=NMesh.Col(230, 123, 255, 0)

HOW?? :o I went through the examples…It doesnt explain(clearly) how to set color either in the Nmesh Object, vertices or Face …or how this should work?

did you call mesh.update()? mesh.hasVertexColours(1) [if mesh doesn’t already have vertex colors: you haven’t entered vertex paint or face select mode…]?

face.col = [NMesh.Col(127,255,64,0),NMesh.Col(127,255,64,0),NMesh.Col(127,255,64,0)]

#RND_COLORS.py
# set random colors to every face in a mesh
import Blender
for obj in Blender.Object.GetSelected():
	if obj.getType() != "Mesh": continue
	mesh = obj.getData()
	mesh.hasVertexColours(1)
	numfaces = len(mesh.faces)
	step = 256*256*256 / numfaces
	color = 0
	for f in mesh.faces:
		r = color / 256 / 256
		g = color / 256 - r * 256
		b = color - r*256*256 - g * 256
		#print r,g,b
		# all verticies in face get same color
		f.col = len(f.v)*[Blender.NMesh.Col(r,g,b,0)]
		color += step
	mesh.update()

:frowning: :expressionless: I am sorry, It’s still unclear. I tried …but failed
Please,can you guide me on how to get some color on this face? supposedly I want a red square(me)


import Blender
from Blender import NMesh
me = NMesh.GetRaw()
v=NMesh.Vert(1.0,0.0,0.0)
me.verts.append(v)
v=NMesh.Vert(1.0,1.0,0.0)
me.verts.append(v)
v=NMesh.Vert(0.0,1.0,0.0)
me.verts.append(v)
v=NMesh.Vert(0.0,0.0,0.0)
me.verts.append(v)
f=NMesh.Face()
f.v.append(me.verts[0 ])
f.v.append(me.verts[1 ])
f.v.append(me.verts[2 ])
f.v.append(me.verts[3 ])
me.faces.append(f)
numfaces = len(me.faces)
step = 256*256*256 / numfaces
me.hasVertexColours(1)
color = 0
for f in me.faces:
      r = color / 256 / 256
      g = color / 256 - r * 256
      b = color - r*256*256 - g * 256
      f.col = len(f.v)*[Blender.NMesh.Col(r,g,b,0)]
      color += step

me.update()
NMesh.PutRaw(me, " plane", 1)
Blender.Redraw()


THank you, so far :expressionless:

r g b were calculated to not red [that script set the different faces in a mesh to different colors]

here it is set to red manually

import Blender 
from Blender import NMesh 
me = NMesh.GetRaw() 
v=NMesh.Vert(1.0,0.0,0.0) 
me.verts.append(v) 
v=NMesh.Vert(1.0,1.0,0.0) 
me.verts.append(v) 
v=NMesh.Vert(0.0,1.0,0.0) 
me.verts.append(v) 
v=NMesh.Vert(0.0,0.0,0.0) 
me.verts.append(v) 
f=NMesh.Face() 
f.v.append(me.verts[0 ]) 
f.v.append(me.verts[1 ]) 
f.v.append(me.verts[2 ]) 
f.v.append(me.verts[3 ]) 
me.faces.append(f) 
numfaces = len(me.faces) 
me.hasVertexColours(1) 
color = 0 
for f in me.faces: 
      f.col = len(f.v)*[Blender.NMesh.Col(255,0,0,0)] 

me.update() 
NMesh.PutRaw(me, " plane", 1) 
Blender.Redraw()

:o I still see the same grey square. There is no color(red). What could be wrong now? Is there some other settings which I am missing ?? I copy exactly what u have :frowning:

Thanks

are you in textured view mode [alt+z]?

vertex colors only show up in textured mode unless you assign a material setup with vcol light [vertex colors add light] or vcol paint [vertex color is base material color]

:smiley: I see it now!! All it needed was ALT+Z (for textured view). Innitially I was expecting and hoping to see some color by pressing F12 (render) or wysiwyg (on screen)

Thanks a alot for your help and your patient z3r0 d. I am going to stick around and write more scripts to explore blender3d API