Recursive building with box and ofMesh

#1

I am working on a recursive 3D structure in OF. I can build it easily with for loops, pushMatrixes and ofDrawBox, but it quickly becomes too slow since I am redrawing everything every frame. The beauty of it is that each recursion builds into the previous transformation matrix…
I want to shift to making ofMesh::box and then appending them to a single ofMesh, but the box has no way to set the position and rotation derived from the pushMatrixes?

Right now I am calling this every frame in draw(), but I would like to call it in setup() or when the user hits a button to make a new mesh (eventually I want a GUI to let you adjust parameters…)

My current code looks like this:

void ofApp::recurse(){
    depth++;
    ofPushMatrix();
    ofScale(.5);
    for (int x = 0; x<6; x++) {
        ofPushMatrix();
        ofRotateDeg(x*30);
        ofTranslate(300, 0, -200 + x*-50);
        //ofMesh tempMesh = ofMesh::box(100, 100, 100);
        //how do I apply the current global position, rotation, and scale to this mesh before appending?
        //mesh.append(tempMesh);
        ofDrawBox(0,0,0,200); //this works fine but  has to be drawn every frame
        currObjects++;
        if(currObjects<maxObjects) {
            if(depth<4){
                recurse();
            }
        }
        ofPopMatrix();
    }
    ofPopMatrix();
    depth--;
}
#2

Use ofNode to do the transformations instead of push/pop translate… and then multiply all the vertices of each mesh by the node global transformation. If you are doing a recursive structure you might want to use several parented nodes