How do i set the vertex color to vertex normal for all vertices of an selected object?
My approach here somehow prints only a few vertices and spares out the rest :( How can i fix that and include ALL other planes, too? (see images below)
import bpy
current_obj = bpy.context.active_object
mesh = current_obj.data
if mesh.vertex_colors:
vcol_layer = mesh.vertex_colors.active
else:
vcol_layer = mesh.vertex_colors.new()
print("*"*40)
for poly in mesh.polygons:
for loop_index in poly.loop_indices:
loop_vert_index = mesh.loops[loop_index].vertex_index
#color = [1 , 0, 0]
#vcol_layer.data[loop_index].color = color
#vcol_layer.data[loop_index].color = mesh.vertices[loop_vert_index].normal
color = mesh.vertices[loop_vert_index].normal
vcol_layer.data[loop_vert_index].color = color
print("painting vert",loop_index, "to color ", color[0], color[1], color[2])
mesh.vertex_colors.active = vcol_layer
mesh.update()
Outcome for a sphere (paints only 1/4 of vertices??):
Outcome for a foliage-mesh (all planes are joined into one mesh)
Still paints not all vertices????
Please help me out, how to include all vertices :)