Skip to content

Instantly share code, notes, and snippets.

Created April 5, 2013 14:23
Show Gist options
  • Save anonymous/5319655 to your computer and use it in GitHub Desktop.
Save anonymous/5319655 to your computer and use it in GitHub Desktop.
import bpy
def gump(color_choice):
"""
go to vertex paint or edit mode and select a few faces
then run this script
"""
print('_'*80)
# find object
my_object = bpy.context.active_object.data
# find color map
if not my_object.vertex_colors:
my_object.vertex_colors.new()
color_map = my_object.vertex_colors.active
# find selected faces
bpy.ops.object.mode_set(mode='OBJECT')
faces = [f.index for f in my_object.polygons if f.select]
print("selected faces: ", faces)
# make_paint_list:
paint_list = []
i = 0
for poly in my_object.polygons:
face_is_selected = poly.index in faces
for idx in poly.loop_indices:
if face_is_selected:
paint_list.append(i)
i += 1
return color_map, paint_list[:]
def color_vcm(color_map, paint_list):
print("vertex color indices: ", paint_list)
# paint vertex colormap indices using paint_list
for i in paint_list:
color_map.data[i].color = color_choice
bpy.ops.object.mode_set(mode='VERTEX_PAINT')
ob = bpy.context.active_object
def vertex_paint_mode():
return (bpy.context.active_object.mode == 'VERTEX_PAINT')
def face_masking():
return ob.data.use_paint_mask
if vertex_paint_mode() and face_masking():
color_choice = (0.2, 0.3, 0.7)
map_and_paint_list = gump(color_choice)
color_vcm(* map_and_paint_list)
else:
print("Use face masking mode, while in Vertex Paint mode")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment