Drawing and updating lines between ofNodes

Hello,

I’m attempting to draw an animated tree that consists of branching ofNodes. As the nodes move (grow) and branch (adding children nodes) I’d like to draw lines between the parent and child nodes and update the lines as the nodes move in 3D space, but I’m seeing major performance issues once I get passed a couple levels of branching (because of the exponential increase in nodes and lines).

Are there better (more performant) objects that I should be using instead of ofNode(s) and ofPolyline(s) for this task? Any suggestions would be really appreciated.

Thanks!

hi,
I would suggest to use a single instance ofMesh instead of polylines.
set the ofMesh mode to use lines

ofMesh mesh;
mesh.setMode(OF_PRIMITIVE_LINES);

on each draw you traverse the ofNode tree and add two vertices for each node, one at its parent position and one at the nodes position. Then draw.
I would guess that you are holding all the ofNodes inside a vector<ofNode>


vector<ofNode> nodes;

for(auto& n: nodes)
{
if(n.getParent()){
mesh.addVertex(n.getParent()->getGlobalPosition());
mesh.addVertex(n.getGlobalPosition());
} 
}
mesh.draw();

Thanks @roymacdonald! I’ll give that a shot.