I am trying to add custom-data layers to mesh vertices so that I may use the values to generate a colorramp on the surface during rendering.
Currently, I first map the data to RGBA values and then add vertex color groups...see code below assuming I have a mesh called surface with 100 vertices:
mesh = surface.data
bm = bmesh.new() # Create new bmesh object
bm.from_mesh(mesh) # Init the bmesh with the current mesh
#random colors atm, but would be mapped to RGBA from the values
scalars = {
'Velocity': # vertex color layer name 2
[(random(), random(), random(), 1) for _ in bm.verts],
'Salinity': # vertex color layer name 3
[(random(), random(), random(), 1) for _ in bm.verts],
}
layers = {}
for key in scalars:
layers[key] = bm.loops.layers.color.new(key)
for key, val in layers.items():
for vert in bm.verts:
for loop in vert.link_loops:
loop[val] = scalars[key][vert.index]
bm.to_mesh(mesh)
This allows me to color the surface via the vertex colors using this node setup:
What I would like to do is just assign custom-data layers using the actual float values, so instead of mapping to RGBA then coloring the surface, I could pass the data into a colorramp node to generate the colors for me, something like this:
I tried to achieve this by generating some random data to use:
scalars = {'v':np.random.rand(100),
's':np.random.rand(100)}
and modifying the above line from:
layers[key] = bm.loops.layers.color.new(key)
to:
layers[key] = bm.loops.layers.float.new(key)
which ran without error, but I do not see anything listed in my object data properties nor can I access this data from the attribute node or any other that I can see.
Do these custom-data layers get updated to the bpy mesh? If so, how can I use them in shading nodes?
Honestly a bit lost trying to follow the API docs for this one.
Thanks, Derek

