Skip to content

Instantly share code, notes, and snippets.

@zeffii
Last active August 29, 2015 14:26
Show Gist options
  • Save zeffii/86fdbec4e58d5cf86fd1 to your computer and use it in GitHub Desktop.
Save zeffii/86fdbec4e58d5cf86fd1 to your computer and use it in GitHub Desktop.
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
@zeffii
Copy link
Author

zeffii commented Jul 28, 2015

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