I have the following two functions:
def get_random_color():
''' generate rgb using a list comprehension '''
r, g, b = [random.random() for i in range(3)]
return r, g, b, 1
def createMeshFromData(name, origin, verts, faces):
# Create mesh and object
me = bpy.data.meshes.new(name + 'Mesh')
ob = bpy.data.objects.new(name, me)
ob.location = origin
ob.show_name = True
# Link object to scene and make active
scn = bpy.context.scene
scn.objects.link(ob)
scn.objects.active = ob
ob.select = True
ob.color = get_random_color()
# Create mesh from given verts, faces.
me.from_pydata(verts, [], faces)
# Update mesh with new data
me.update()
return ob
createMeshFromData gets its data from a database for verts and faces. Later on it will also get a color value.
So far I am trying to assign a random color using the function get_random_color. I assign this color with ob.color = get_random_color() but this does not seem to work once I press F12 to render.
How to assign a color value to an object?
I am not familiar with blender (coming from matplotlib) and I would apprecite your help.