Forked from anonymous/material_from_vertex_color_map.py
Last active
April 6, 2016 22:34
-
-
Save zeffii/5317722 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trying to understand why you are not using the
idx
value on line 26, and instead are usingi
…