5
$\begingroup$

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

Instances table with color values

Now I added a geometry node to display the spheres

Geometry node tree

This also works. Next, I edited the shader nodes to take the color from the attribute

Shader tree

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?

$\endgroup$

1 Answer 1

6
$\begingroup$

If you are wanting to use the color from the points that you are instancing on, you have to switch the Attribute input in the shader to Instancer rather than Geometry. This will source the attribute from the instancer object rather than the original instance (the icosphere in your case) and try to get the attribute from there.

enter image description here

If you are wanting to just have spheres with color data, I would highly, highly recommend just using the Mesh to Points and rendering with Cycles. Cycles will render points clouds extremely fast, and you can get access to the color information just as you would otherwise (and the spheres will be infinitely perfect spheres when rendered).

$\endgroup$
1
  • $\begingroup$ Thanks, that did it! Also thanks for the further recommendation, but in this case, the complex environment rather dictates the rendering engine, and there are not THAT many points.I will keep this in mind for large Point Clouds, though, which might come up. $\endgroup$
    – mcandril
    Commented Oct 8 at 7:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .