Sorry for the basic question, but I’m using LineSeg to have my object trace out a line as it moves. I’d like the line to fade away after a certain amount of time, so I figured I would change the alpha value, but I can’t seem to write something that works. GeomNode doesn’t have a setColor function, and when I try to call setColor on the NodePath containing that GeomNode, nothing happens. Incidentally, when I try to call getColor on that NodePath, I get an error message “:pgraph(warning): get_color() called on render/path which has no color set.”
I tried looking deep into GeomNode and I see that it stores the color in VertexData, but a) I couldn’t get a modifiable reference to the VertexData and b) it feels way too low level to have to modify VertexData to get the color I want. Surely there’s a better way?
Thanks @eldee, between this and your help on the floating point issue I ought to pay you
@Thaumaturge it turns out that setColorScale doesn’t work because it multiplies the color in the GeomNode with the value supplied. I guess I could make the base color 1,1,1,1 and then use colorscale to set it and change it.
Although I never use LineSegs, I do see it has a set_vertex_color method, so you could iterate over the created vertices and change their colors individually.
There is also a set_color method, but it only sets the color for vertices that will be created afterwards, not for existing vertices.
Of course, both these methods set specific vertex colors, while what you want is to set the general “scenegraph” color. The reason that calling set_color on your NodePath doesn’t work, is that the RenderState associated with the LineSegs Geom itself contains a ColorAttrib whose color type is explicitly set to vertex. You can see this by printing the RenderState:
The easy solution that you are looking for is to simply pass a priority value bigger than zero into the set_color call on your NodePath:
This will override the vertex colors when rendering your lines geometry, so you don’t even need to mess with those.