[RESOLVED] LineSegs issues

Hi, I’m trying to create a generic 2D graph widget for multiple curve visualization. I’m using “LineSegs” for this.

The problem is I don’t understand why I can’t render more than one curve at a time…

This is the code snippet for the widget update method:

class GraphFrame(DirectFrame):

    ...

    def update(self):
        for ls in self.__line_segs:
            ls.detachNode()
            
        self.__line_segs = []
        
        for name, points in self.__curves.items():
            ls = LineSegs()
            ls.setColor(self.__config[name]['color'])
            ls.setThickness(self.__config[name]['thickness'])
            pos = self.__config[name]['pos']
            scale = self.__config[name]['scale']
            keys = sorted(points.keys())
            ls.moveTo((keys[0] - keys[-1]) * scale.getX() + pos.getX(), 0, points[keys[0]] * scale.getZ() + pos.getZ())
            for p in range(1, len(keys)):
                x = (keys[p] - keys[-1]) * scale.getX() + pos.getX()
                z = points[keys[p]] * scale.getZ() + pos.getZ()
                ls.drawTo(x, 0, z)
            node = render2d.attachNewNode(ls.create())
            self.__line_segs.append(node)

Each curve is identified by a unique name and it’s saved in two dicts: one for points and one for config options (color, thickness, offset, ecc.).

With this code Panda draws only the last curve :frowning:

Looks OK to me. Are you sure that your dictionaries are set up correctly, and that your other curves are in fact valid?

David

Mmm…probably you’re right because now it works: I think it was only a scale issue on the second curve. Sorry for this.

Thanks! I’ll post it soon.

Now I need to put all line segs on the top (in the z-order) of a DirectFrame (which has a background image).

How can I do that?

take a look at the manual here:
www.panda3d.org/manual/index.php/H … nder_Order

Simply set the bin to fixed and supply a sufficiently high number to the order.
Or you can create your own fixed bin on top of the existing bins and have your own complete order system.

Also, if the DirectFrame in question is in the 2-d scene graph, simply parenting the linesegs to the frame should be sufficient to make it appear on top. For objects under aspect2d, if they don’t specify any other bin, the default bin will render things in top-to-bottom, left-to-right scene graph order, which means that children will be drawn on top of their parents.

David

Thanks, it works! :slight_smile: