For scientific visualisation, I'm using a lot of splines which are bevelled with an object (i.e. a hexagon). I control the level of details depending on the context.
Without losing the benefits of curves, I want to assign colours to the curve points so that the generated mesh will show these colours (with interpolation).
Here's an image of what I would like to achieve. The image below is an example of the object I want to map colours to. Some splines have hundreds of points. Each point has a colour so the mesh has to show the "exact" colour at the proper location.
I browsed stack exchange for an answer and I also did try to answer my own question before posting it here, see below.
1. the naive way
I tried looping over the curve points but there's no colour property. Meh.
2. curve mesh data
So, this is about looping over generated mesh vertices and then calculating how close they are to a point in order to assign the proper vertex colour.
When I have a meshed curve in my viewport, I do a loop
for mesh in bpy.data.meshes:
print(mesh)
And I get 0 as a result. But my mesh is there, I can see it in Blender.
3. weights to colours with Cycles
So far what I did was assigning the colour value to the weight property of curve points, like this simplified code:
polyline.points.add(len(points) - 1)
for i in range(len(points)):
vertex = points[i]
# x, y, z and weight
polyline.points[i].co = (x, y, z, w)
# radius of the point (only meaningful if a tube-like volume is drawn around it)
polyline.points[i].radius = r
I thought there would be a way to then transfer the weight to vertex colouring of the curve mesh but I found none since I can't access the mesh data.
So I randomly tried to find a way to use weights with Cycles, maybe there is something that I can plug to the colour input of a standard material ? Didn't find any.
4. using BMesh ?
Bmesh doesn't support curves so it's a dead end here as well.
5. uvw mapping
As Chebhou wrote, I could use UVW mapping but I would like to see this in python. However, I'm asking for a way to match colours at every curve point. It seems that uvw mapping is non linear so how do I know to what coordinate in space (on the mesh) a color will be ?