3
$\begingroup$

I am having trouble with the python code to get the colors of vertices when using Dynamic Paint. If I try painting a cube using the Vertex Paint mode I can get the rgb values of the vertices using the following code, however If I use Dynamic Paint to color the vertices I keep getting "None" for the color layer. Sorry if this is a newbie question but what am I doing wrong here? I thought the color data would be the same whether I used Dynamic Paint or Vertex Paint mode.

import bpy
import bmesh
context = bpy.context
scene = context.scene
mesh = context.object.data
bm = bmesh.new()

meshes = [o.data for o in scene.objects if o.type == 'MESH']
for mesh in meshes:
    bm.from_mesh(mesh)
    color_layer = bm.loops.layers.color.get("Col")
    print(color_layer)
    if color_layer is None:
        color_layer = bm.loops.layers.color.new("Col")
    for face in bm.faces:
        for loop in face.loops:
            print("Vert:", loop.vert.index)
            print(loop[color_layer])
bm.to_mesh(mesh)
mesh.update()
bm.clear()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.