I use this code to paint:
import bpy
def random_color(obj):
import random
r = random.random
mesh = obj.data
scn = bpy.context.scene
#check if our mesh already has Vertex Colors, and if not add some... (first we need to make sure it's the active object)
scn.objects.active = obj
obj.select = True
if mesh.vertex_colors:
vcol_layer = mesh.vertex_colors.active
else:
vcol_layer = mesh.vertex_colors.new()
for poly in mesh.polygons:
for loop_index in poly.loop_indices:
loop_vert_index = mesh.loops[loop_index].vertex_index
random_color = [r(), r(), r()]
vcol_layer.data[loop_index].color = random_color
for obj in bpy.data.objects:
if obj.type == 'MESH':
bpy.context.scene.objects.active = obj
bpy.ops.object.mode_set(mode='VERTEX_PAINT')
in the 3D viewer, I only observe the lase part of the plane is painted.
Another problem is,when I render it, the plane is all black because I don't add a light source. But should I add light in vertex paint mode?

