Merging multiple ofPlanePrimitive on a single mesh

Hi, as the title suggest, I want to create a mesh out of different ofPlanePrimitive. After that, i want to apply a texture on it. For now I’m just debugging the mesh creation.

This is what I’m doing:

  • in my header file i’ve of3dPrimitive foliage.
  • in my App.cpp:
    //in the setup
    int n_planes = 3;
    int distance = 100;
    float rot = 0;
    for (uint i = 0; i < n_planes; i++) {
        auto p = ofPlanePrimitive(width, height, resolution, resolution);
        p.setPosition(0, 0,float(distance*i));
        // this loop is needed otherwise all the planes will be on the same z position
        for (int i=0; i<p.getMesh().getNumVertices(); i++) {
            ofVec3f actualVert =p.getMesh().getVerticesPointer()[i];
            ofVec3f newVert = actualVert * p.getGlobalTransformMatrix();
            p.getMesh().getVerticesPointer()[i] = newVert;

In the draw method there is simply a foliage.drawWireframe(). And this is the result.

As you see there are some lines that connect the last vertex of a plane mesh with the first vertex of the next plane mesh. Is there a way to avoid this?

I’ve also considered putting all the planes in a container, like std::vector<shared_ptr<ofPlanePrimitive> > planesContainer; and then iterate through them, calling mapTexCoordsFromTexture(ofTexture texture) on each of them and then draw the plane. But it is slow when the planes are more than 3, that’s why I was thinking to merge the meshes in a single of3dPrimitive, call mapTexCoordsFromTexture(ofTexture texture) on it and then draw it.

to avoid the connecting line you need to create the plane using triangles:

ofPlanePrimitive(width, height, resolution, resolution, OF_PRIMITIVE_TRIANGLES);

which allows to create separate primitives, the default triangle strip creates every triangle connected with the previous, that’s why you see the line connecting the planes

Many thanks Arturo, this fixes the first problem. The second one is that I can not have the texture displayed on the 3 planes.

In the draw method, I’m applying the texture to the of3dPrimitive like this

void ofApp::draw(){
    auto texture = pingPong.src->getTexture();
    updateRender.begin();  // updateRender is an ofShader

If I draw any other 3dPrimitive it works

you probably need to call mapTexCoordsFromTexture for every one of the original planes instead of the final mesh since that method only knows how to map the texture for the original primitive, if you change it it won’t work

I see. I wanted to skip the loop through the planes to make it faster. I will stick with the loop and a planes container. Thanks!

but you can do that in setup before putting all the planes in one primitive i think

also if the texture is continuously being updated in the update method?

as long as the size doesn’t change yes

It worked, also pretty fast, thanks!