LineSegs() not changing color


#1

Hi all,

I’ve tried for hours to change the color of dynamically changing LineSegs, but nothing seems to work. The lines remain black, even when I successfully set the entire RenderTree to red (using self.render.setColor).

        liftVector = LineSegs()
        liftVector.setThickness(10) # this works
        liftVector.setColor(1.0, 0.0, 0.0, 1) # this does not do anything
        for index in range(f.nelements):    # draw lines by putting pen on quarterchord
            liftVector.moveTo(f.qc[0, index], -f.qc[1, index], -f.qc[2, index])
            liftVector.drawTo(f.qc[0, index], -f.qc[1, index], -f.qc[2, index] + 1)

        lift_node = liftVector.create(True) # boolean for dynamic updating optimization, not sure if True is needed
        lift_nodepath = NodePath(lift_node)
        lift_nodepath.reparentTo(self.cog)
        lift_nodepath.setColor(1, 0, 0, 1)  # this does not do anything

#2

It works for me with the first one:

from direct.directbase import DirectStart
from panda3d.core import *

liftVector = LineSegs()
liftVector.setThickness(10)
liftVector.setColor(1.0, 0.0, 0.0, 1)
liftVector.moveTo(0, 0, 0)
liftVector.drawTo(2, 2, 2)
lift_node = liftVector.create(True)
lift_nodepath = NodePath(lift_node)
lift_nodepath.reparentTo(render)

run()

If I comment out the first setColor and change it on dynamically on the NodePath only, it works when I use an override value:

lift_nodepath.setColor((1, 0, 0, 1), 1)

Perhaps the parent node has an overriding color value in your case? That means you need to set a higher override value when specifying the color on the lower node.


#3

Hi rdb,
Thank you for the quick MWE. The code above works for me too in exactly the way you described.

However, no matter how I try, the same commands don’t work in my full code. I tried reparenting the lift_nodepaths to other nodes, using a high override value and setting the color on all nodes above in the render tree. I also removed any dynamic changes to the lines for debugging. Nothing worked, as everything but the lines turns red…

Any clues on what’s going on here? Or is there another way to use debug mode for these objects?


#4

You need to check what states are applied on the levels above. lift_nodepath.reverseLs() might give you a clue. It might be lighting, or color, or a shader, or a material, or something else; all these could be the culprit. You may need to try something like setShaderOff(10), setLightOff(10), etc. in order to ensure that these extra states on higher levels aren’t causing problems.


#5

Thanks! Just found it.
The problem is the part 100 lines later where I set “self.render.setShaderAuto()”. Apparently this shades the lines. I’ll apply the shader to a different node where I group the game 3D models and avoid it on the lines. That should work.
Thanks a lot & have a nice day


#6

Glad that you found it!

You can set setShaderOff(10) on a child node (with a higher override value) to undo the effects of a setShader*() on a higher level.


#7

Yup, beautiful red lift vectors are working thanks to setShaderOff and setLightOff now.