Created
April 5, 2013 08:50
-
-
Save anonymous/5317702 to your computer and use it in GitHub Desktop.
blender material from vertex color map
This file contains hidden or 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 | |
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