Through the user interface, you paint a vertex by hitting V in 3D View, and clicking on a vertex.
How can this be achieved in Python?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityThis function should do the trick:
import bpy
def color_vertex(obj, vert, color):
"""Paints a single vertex where vert is the index of the vertex
and color is a tuple with the RGB values."""
mesh = obj.data
scn = bpy.context.scene
#check if our mesh already has Vertex Colors, and if not add some... (first we need to make sure it's the active object)
scn.objects.active = obj
obj.select = True
if mesh.vertex_colors:
vcol_layer = mesh.vertex_colors.active
else:
vcol_layer = mesh.vertex_colors.new()
for poly in mesh.polygons:
for loop_index in poly.loop_indices:
loop_vert_index = mesh.loops[loop_index].vertex_index
if vert == loop_vert_index:
vcol_layer.data[loop_index].color = color
#example usage
color = (1.0, 0.0, 1.0) # pink
color_vertex(bpy.context.scene.objects['Cube'], 1, color)
If you have more than 15 reputation and already know the answer, click the checkbox that says "Answer your own question" at the bottom of the Ask Question page. Type in your answer, then submit both question and answer together.
$\endgroup$To be crystal clear, it is not merely OK to ask and answer your own question, it is explicitly encouraged.
" $\endgroup$