Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/pre_cleanup.py
Last active December 15, 2015 20:40
Show Gist options
  • Save zeffii/5319796 to your computer and use it in GitHub Desktop.
Save zeffii/5319796 to your computer and use it in GitHub Desktop.
import bpy
# instructions:
# "Use face masking mode, while in Vertex Paint mode"
def make_paint_list(my_object, faces):
# paint_list will contain all vertex color map indices to
# be used for overpainting.
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 paint_list
def do_painting(color_map, paint_list):
print("vertex color indices: ", paint_list)
for i in paint_list:
color_map.data[i].color = color_choice
bpy.ops.object.mode_set(mode='VERTEX_PAINT')
def find_and_paint(color_choice):
my_object = bpy.context.active_object.data
# use active color map, create one if none available
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)
paint_list = make_paint_list(my_object, faces)
do_painting(color_map, paint_list)
def vertex_paint_mode():
return (bpy.context.active_object.mode == 'VERTEX_PAINT')
def face_masking():
return bpy.context.active_object.data.use_paint_mask
if vertex_paint_mode() and face_masking():
color_choice = (0.2, 0.3, 0.7)
find_and_paint(color_choice)
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