List vertex colors from a bmesh I'm working on a custom exporter for an external software.
I need to get a list of the vertex colors from a triangulated mesh.
To get the triangulated mesh I use this code:
bm = bmesh.new()
bm.from_mesh(SceneObj.to_mesh())
bmesh.ops.triangulate(bm, faces=bm.faces, quad_method='BEAUTY', ngon_method='BEAUTY')

With normal meshes I use this code:
#Get vertex color list without duplicates
VertexColList = []
if len(MeshObject.vertex_colors):
    if hasattr(MeshObject.vertex_colors.active, 'data'):
        for layer in MeshObject.vertex_colors:
            for vertex in layer.data:
                VertexColList.append(
                    (vertex.color[0] * .5, vertex.color[1] * .5, vertex.color[2] * .5, vertex.color[3])
                )
        VertexColList = list(dict.fromkeys(VertexColList))

But that piece of code not works in a bmesh, what should I change to make it works?
Each loop (= corner of a poly) has its own vertex color. You can print the vertex color for each corner with
# Get the first Vertex Color layer; can also use its name (eg. &quot;Col&quot;)
layer = bm.loops.layers.color[0]

for face in bm.faces:
    for loop in face.loops:
        color = loop[layer]  # gives a Vector((R, G, B, A))
        print(color)

Btw, if possible you should get the triangulation with calc_loop_triangles instead, since it gives you the triangulation that Blender actually draws.