# 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 & 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)

• my fault was, i overlooked / did not realize, that i can assign each face-vertex an other vertex-color. in vertex-paint-mode that behavior is not/hard to see. so it is like, at the coordinates of one vertex, each face that is using that same vertex can have different vertex-colors. i thought that the vertex-color is stored to a vertex, so that each face, that is using the same vertex would get the same color at that coordinate. – beta-tester Jan 10 '14 at 10:57
• Hmmm, looping thru all polys and then looping thru all their loops really doesn't scale well... So there's really no way around it? I could write vertex color to an obj and import it, but I kinda like the concept of face-vertex, as it sorta gives smooth colors. – Sibbs Gambling Jul 31 '17 at 3:43