How to access vertex_color layer directly from inside BMVert I want to access vertex colors directly from inside BMVerts, but I don't know how.
I am able to access vertex colors indirect for inside BMFaces:


import bpy
import bmesh
obj = bpy.context.active_object
mesh = obj.data
bm = bmesh.new()
bm.from_mesh(mesh)
layer_color = bm.loops.layers.color.get("col_test")
for bmf in bm.faces:
    #bmf.loops[0][layer_color] = new_color
    for loop in bmf.loops:
        color = loop[layer_color]
        print(color)
        loop[layer_color] = new_color
bm.to_mesh(mesh)
bm.free()

But this way I loop multiple times through the same vertex colors, because a face vertex is owned by multiple faces.
I don't want to loop through all faces only to get access to the vertex colors.

I am looking for something more direct, like:


import bpy
import bmesh
obj = bpy.context.active_object
mesh = obj.data
bm = bmesh.new()
bm.from_mesh(mesh)
layer_color = bm.loops.layers.color.get("col_test")
for bmv in bm.verts:
    color = bmv.????[layer_color]
    print(color)
    bmv.????[layer_color] = new_color
bm.to_mesh(mesh)
bm.free()

It seems there is no "interface" to access the vertex color from insider a BMVert directly, or am I doing something completely wrong?
Vertex colors are stored in face loops, you can't ignore/overlook this.

However its reasonable that you might want to generate vertex colors per vertex and not have to deal with looping on vertex-loops while generating/manipulating the colors.

Your best options would be to have 2 functions for converting colors between loops and verts. This could take &amp; return array of Color objects. Then at least you can keep the conversion isolated and not complicate your color calculation logic. (If your generating new colors you only need one function to go from vertices to loops of course)