I'm having trouble applying vertex colors through Python to a mesh. The mesh is imported from a file which has vertex info, face info (vertex indices), and a list of colors that corresponds to each vertex.
Creating the Bmesh mesh is fine:
bm = bmesh.new()
[bm.verts.new(v) for v in verts]
bm.verts.ensure_lookup_table()
[bm.faces.new([bm.verts[f[0]], bm.verts[f[1]], bm.verts[f[2]]]) for f in faces]
bm.faces.ensure_lookup_table()
However, I can't seem to find a way to apply colors to each vertex. Doing
color_layer = bm.loops.layers.color.new("color")
...
bm.faces[i].loops['color'].vert
just yields a Bmesh vertex with an index of -1...
Is there anyway to get back the correct vertex indices in this way?