ofMesh copy at different position

Hello,

I am looking for a way to create same shaped ofMesh at different positions. For example, I would like to create two cubes with side 10, one positioned at 0, 0, 0 and another positioned 10, 0, 0. Then I would like to append one to another so that bar (with sides 10, 10, 20) is stored in the ofMesh. I know that I could do that by manipulating vertices, but maybe there is a helper tool? I have found ofxMesh with translation function, but it’s deprecated.

Thank you.

This thread contains the answer:


The logic is following:

  • cube is created and transformed as ofBoxPrimitive

  • getGlobalTransformationMatrix() is used to transform mesh vertices

  • cube mesh vertices are appended to the final mesh

    ofBoxPrimitive cube(10, 10, 10);
    cube.move(10, 0, 0); 
    ofMesh & cubeMesh = cube.getMesh();
    auto prevNumVertices = mesh.getNumVertices();
    for(auto & vertex : cubeMesh.getVertices())
    {   
        mesh.addVertex(vertex * cube.getGlobalTransformMatrix());
    }   
    
    for(auto i : cubeMesh.getIndices())
    {   
        mesh.addIndex(i + prevNumVertices);
    }