Problem generating mesh

Hello, for a project I need to generate custom cylinder (i can not use ofCylinderPrimitive). The method that I’m using to draw a single cylinder (using OF_PRIMITIVE_TRIANGLE_STRIP) is explained here How to draw a cylinder starting from 2 ofNode.

In my mesh, i need to put together different cylinders, the problem is that sometimes there are surfaces between cylinder that should not be there. For example, this picture should compose a “Y”.

I’ve also tried to create the cylinders using OF_PRIMITIVE_TRIANGLES and specifying the indexes as follow, but I’ve the same problem.

//App.h
    ofVboMesh mesh;
    ofNode start;
    ofNode end;
    int resolution = 18;
    float radius = 100.00;
// App.cpp

    mesh.setMode(OF_PRIMITIVE_TRIANGLES);
    for (int i = 0; i <= resolution; i++){
        //calculate x and y component
        float theta = 2.0f * 3.1415926f * float(i) / float(resolution);
        float x = radius * cosf(theta);
        float y = radius * sinf(theta);
        ofVec3f circleTemp = ofVec3f(x, y, 0.0);
        ofVec3f direction = (ofVec3f() + circleTemp).getNormalized();
        
        // bottom
        mesh.addVertex(circleTemp * start.getGlobalTransformMatrix());
        mesh.addNormal(direction * start.getGlobalTransformMatrix());
        //top
        mesh.addVertex(circleTemp * end.getGlobalTransformMatrix());
        mesh.addNormal(direction * end.getGlobalTransformMatrix());
    }

    int currentIndeces = mesh.getNumIndices();
    for (int i = 0; i < resolution; i++){
        int first = currentIndeces + i*2;
        mesh.addIndex(first+1);
        mesh.addIndex(first);
        mesh.addIndex(first+2);
            
        mesh.addIndex(first+2);
        mesh.addIndex(first+3);
        mesh.addIndex(first+1);
    }

Does someone have an idea? Do i need to “close” the cylinders putting a cap on it?

I still didn’t have find a solution to this problem. What I’ve tired until now is to use the OF_PRIMITIVE_TRIANGLE_STRIP mode, as I’ve seen that is also used in the ofCylinferPrimitive. This is the code used to draw the picture in the previous post:

    // SET THE POSITIONS
    ofNode end;
    ofNode start;
    start.setPosition(-200, 0, 0);
    end.setPosition(-200, 0, 200);
    
    ofNode secondEnd;
    secondEnd.setParent(end);
    secondEnd.move(0, 200, 200);
    
    ofNode thirdEnd;
    thirdEnd.setParent(end);
    thirdEnd.move(0, -200, 200);


    mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
    // FIRST BRANCH
    for (int i = 0; i <= resolution; i++){
        //calculate x and y component
        float theta = 2.0f * 3.1415926f * float(i) / float(resolution);
        float x = radius * cosf(theta);
        float y = radius * sinf(theta);
        ofVec3f circleTemp = ofVec3f(x, y, 0.0);
        ofVec3f direction = (ofVec3f() + circleTemp).getNormalized();
        
        // bottom
        mesh.addVertex(circleTemp * start.getGlobalTransformMatrix());
        mesh.addNormal(direction * start.getGlobalTransformMatrix().getRotate());
        //top
        mesh.addVertex(circleTemp * end.getGlobalTransformMatrix());
        mesh.addNormal(direction * end.getGlobalTransformMatrix().getRotate());
    }

    // SECOND BRANCH
    for (int i = 0; i <= resolution; i++){
        //calculate x and y component
        float theta = 2.0f * 3.1415926f * float(i) / float(resolution);
        float x = radius * cosf(theta);
        float y = radius * sinf(theta);
        ofVec3f circleTemp = ofVec3f(x, y, 0.0);
        ofVec3f direction = (ofVec3f() + circleTemp).getNormalized();
        
        // bottom
        mesh.addVertex(circleTemp * end.getGlobalTransformMatrix());
        mesh.addNormal(direction * end.getGlobalTransformMatrix().getRotate());
        //top
        mesh.addVertex(circleTemp * secondEnd.getGlobalTransformMatrix());
        mesh.addNormal(direction * secondEnd.getGlobalTransformMatrix().getRotate());
    }
    
    // THIRD BRANCH
    for (int i = 0; i <= resolution; i++){
        //calculate x and y component
        float theta = 2.0f * 3.1415926f * float(i) / float(resolution);
        float x = radius * cosf(theta);
        float y = radius * sinf(theta);
        ofVec3f circleTemp = ofVec3f(x, y, 0.0);
        ofVec3f direction = (ofVec3f() + circleTemp).getNormalized();
        
        // bottom
        mesh.addVertex(circleTemp * end.getGlobalTransformMatrix());
        mesh.addNormal(direction * end.getGlobalTransformMatrix().getRotate());
        //top
        mesh.addVertex(circleTemp * thirdEnd.getGlobalTransformMatrix());
        mesh.addNormal(direction * thirdEnd.getGlobalTransformMatrix().getRotate());
    }

The code for each cylinder is always the same. I think the problem is happening at the end, where the last vertices of the mesh get connected. If I draw all the cylinder in a separate mesh, it is not a problem. But I’ve to build structure compose by a lot of cylinder, and it will be an overkill to have a separate mesh for each cylinder. Any suggestion is more than appreciated.

Solved. I’ve used OF_PRIMITIVE_TRIANGLE and I’ve specified the indexes that compose each face of the triangle. I don’t know if it is less performant than triangle strip(http://hacksoflife.blogspot.de/2010/01/to-strip-or-not-to-strip.html), but I don’t care, it is working fine in my case. I will post some code as reference here tomorrow.