Last active
August 29, 2015 14:26
-
-
Save zeffii/86fdbec4e58d5cf86fd1 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 | |
obj = bpy.context.active_object | |
mesh = obj.data | |
if not mesh.vertex_colors: | |
mesh.vertex_colors.new() # creates the map called 'Col' | |
# color_layer = mesh.vertex_colors.active | |
color_layer = mesh.vertex_colors['Col'] # must exist first | |
face_colours = [ | |
(0, 0.5, 0.5), | |
(0.5, 0.5, 0), | |
(0.5, 0, 0.5), | |
(.4, 0.4, 0.2), | |
(0.8, 0.1, 0.8), | |
(0.2, 0.2, 0.1) | |
] | |
i = 0 | |
for poly in mesh.polygons: | |
for idx in poly.loop_indices: | |
color_layer.data[i].color = face_colours[poly.index] | |
i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have more examples here: http://blenderscripting.blogspot.nl/search/label/Vertex%20Color