Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zeffii/5317722 to your computer and use it in GitHub Desktop.
Save zeffii/5317722 to your computer and use it in GitHub Desktop.
import bpy
import random
# start in object mode
my_object = bpy.data.objects['Cube'].data
color_map_collection = my_object.vertex_colors
if len(color_map_collection) == 0:
color_map_collection.new()
"""
let us assume for sake of brevity that there is now
a vertex color map called 'Col'
"""
color_map = color_map_collection['Col']
# or you could avoid using the vertex color map name
# color_map = color_map_collection.active
i = 0
for poly in my_object.polygons:
for idx in poly.loop_indices:
rgb = [random.random() for i in range(3)]
color_map.data[i].color = rgb
i += 1
mat = bpy.data.materials.new('vertex_material')
mat.use_vertex_color_paint = True
mat.use_vertex_color_light = True # material affected by lights
my_object.materials.append(mat)
# set viewport shading to texture to view this.
@knowuh
Copy link

knowuh commented Apr 6, 2016

Trying to understand why you are not using the idx value on line 26, and instead are using i

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment