I have a list of coordinates and corresponding scalar values retrieved from a Python API. I would like to place spheres on the coordinates and color them based on a color map with the scalar value.
I have imported the coordinates:
mesh = bpy.data.meshes.new(mesh_name)
obj = bpy.data.objects.new(name, mesh)
bpy.context.collection.objects.link(obj)
mesh.from_pydata(coordinates, [], [])
mesh.update()
and added the desired color
viridis = plt.get_cmap('viridis')
error_normalized = error / np.max(error) # Error is already positive starting at 0
colors = viridis(error_normalized)
color_attr = mesh.attributes.new(name="error_colors", type="FLOAT_COLOR",
color_attr.data.foreach_set("color", colors.flatten())
This seems to import correctly
Now I added a geometry node to display the spheres
This also works. Next, I edited the shader nodes to take the color from the attribute
Here, neither the Emission nor the BSDF work. If I replace the Attribute input with a color input, I can change the global color, though, so the issue seems to lie with retrieving the color value from the attribute.
The thing I notice is that FLOAT_COLOR has an alpha value which is not expected by the Color input socket of Emission. But then the Attribute Input also has a separate Alpha output socket ... Is there a way to debug what is offered by the output socket?
Any ideas?