Transparent LineSegs; setAlphaScale

I’d like to find out why any LineSegs I draw aren’t affected when I call .setAlphaScale() on a parent. Everything else fades, so afaik all transparency-related settings are fine. Even when I call .setColor() with a non-unity alpha value, the lines are always completely opaque. For reference sake, here are a few relevant sections of my code.

def draw(self):
    # ...
    self.anchor = render.attachNewNode('Actor')
    # ...
def _draw_line_segs(self, aNode, aColor, aPoints):
    Lines = LineSegs()
    Lines.setColor(aColor[0], aColor[1], aColor[2], 1)
    Lines.setThickness(1)

    if len(aPoints):
    Lines.moveTo(aPoints[0][0], aPoints[0][1], aPoints[0][2])
    for Point in aPoints[1:]:
        Lines.drawTo(Point[0], Point[1], Point[2])

    Node = Lines.create()
    NP = NodePath(Node)
    NP.reparentTo(aNode)
    return Lines
def func_x(self):
    self.anchor.setAlphaScale(0.2)
    # everything fades except lines

Note that self.anchor is passed to _draw_line_segs(). Any advice here? The goal is to make wires fade slightly along with everything else when I call .setAlphaScale() on self.anchor.

Thanks!

Have you called NP.setTransparency(TransparencyAttrib.MAlpha)? Transparency is not enabled by default, and without transparency, changing the alpha means nothing.

The fact that the rest of your model does successfully fade when you change the alpha only means that transparency is already enabled for your model, which might be due to the egg file it was loaded from. (For instance, if it has a four-channel texture applied, or any non-unity A value in , then the egg loader will enable transparency.)

David

When I try to, the wires disappear completely, although their alpha values are all 1.

self.anchor.setTransparency(TransparencyAttrib.MAlpha)

Oh, and actually the other objects fade not because they inherently have that property, but because I set it. So…that actually gives me the answer that I need to do the same for the anchor (wires’ parent), but as I mentioned in the above post I haven’t been successful with that.

Maybe it’s a sorting issue, now, with something behind the wires, that’s getting incorrectly drawn in front of them? Sorting is very important with transparency. Do the wires fade correctly when they’re the only thing in the scene?

David

Arranging for that (wires only) would be pretty difficult to do. Would it be enough to hide() everything but them? I don’t have a good understanding of pretty much anything Panda does behind the scenes.

Yes, that would be sufficient. I just want to see the wires against no background.

It would also be sufficient to put the wires in a sort bin so that they are drawn last, e.g.

NP.setBin('fixed', 0)

David

While I do that, I’d like to mention that I don’t believe LineSegs are actually NPs, since I can’t call .setTransparency() on them. And thus I don’t know what NP to call .setBin() on…

But I can .hide() everything.

You have an object called NP in the above code snippet. This is what I was referring to. It is the NodePath that contains the result of Lines.create(), which means it is the NodePath that contains your lines’ visible geometry.

David

Okay, I’ve added that line to make the nodepath draw last, but they still remain opaque. I’ve tried both of the following versions:

NP = NodePath(Node)
NP.setBin('fixed', 0)
NP.reparentTo(aNode)
NP = NodePath(Node)
NP.setTransparency(TransparencyAttrib.MAlpha)
NP.setBin('fixed', 0)
NP.reparentTo(aNode)

I could post a few dozen more relevant lines if it might help.

Here are screenshots of my gui, before and after requesting transparency. Note that I will remove both the images and the img tags in either a day or after I get another reply.

EDIT: they are now gone.

Oh, if all you want is to fade the whole screen while you put up a popup over it, wouldn’t it be easier to put a 50% transparent white card on top of the whole thing?

David

Sure :slight_smile: Although I’m less familiar with the 2D parts of Panda than in the 3D world, and hoped to save some googling by 1) using the p3doverlays project, then 2) fading the rest of the screen. Definitely not the most obvious/best but all I can manage at this point.

I would be grateful if I was shown by example how to place an object in the 2D plane, relative to the screen/window’s coordinate system.

Over

Here’s some example code that demonstrates lines successfully fading in and out along with the other geometry:

from direct.directbase.DirectStart import *
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *

# Put the camera in a convenient vantage point
base.trackball.node().setPos(0, 20, 0)

# Create a node to be the parent of smiley and the lines
root = render.attachNewNode('root')

# Load smiley
s = loader.loadModel('smiley.egg')
s.reparentTo(root)

# Create lines
ls = LineSegs()
ls.moveTo(-1.2, 0, -1.2)
ls.drawTo(1.2, 0, -1.2)
ls.drawTo(1.2, 0, 1.2)
ls.drawTo(-1.2, 0, 1.2)
ls.drawTo(-1.2, 0, -1.2)
lines = root.attachNewNode(ls.create())

# Set a looping interval to fade them both in and out together
root.setTransparency(TransparencyAttrib.MAlpha)
i = Sequence(LerpColorScaleInterval(root, 2, (1, 1, 1, 0)),
             LerpColorScaleInterval(root, 2, (1, 1, 1, 1)))
i.loop()

And here’s a very similar program that achieves a similar effect, but with a fadescreen overlayed on top instead:

from direct.directbase.DirectStart import *
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *

# Put the camera in a convenient vantage point
base.trackball.node().setPos(0, 20, 0)

# Create a node to be the parent of smiley and the lines
root = render.attachNewNode('root')

# Load smiley
s = loader.loadModel('smiley.egg')
s.reparentTo(root)

# Create lines
ls = LineSegs()
ls.moveTo(-1.2, 0, -1.2)
ls.drawTo(1.2, 0, -1.2)
ls.drawTo(1.2, 0, 1.2)
ls.drawTo(-1.2, 0, 1.2)
ls.drawTo(-1.2, 0, -1.2)
lines = root.attachNewNode(ls.create())

# Put a fade screen over the whole thing
cm = CardMaker('fade')
cm.setFrame(-1, 1, -1, 1)
fade = render2d.attachNewNode(cm.generate())
fade.setBin('fixed', 0)

# Set a looping interval to fade in and out the fade screen.
fade.setTransparency(TransparencyAttrib.MAlpha)
i = Sequence(LerpColorScaleInterval(fade, 2, (1, 1, 1, 0)),
             LerpColorScaleInterval(fade, 2, (1, 1, 1, 1)))
i.loop()

David

Wow thanks, more than I could want. I’ll post again after giving this a try :slight_smile: