I need suggestion for a generative mesh

Hi, I’m working on 3D plants generation using L-System. I’ve recently seen this picture http://p5aholic.me/images/p5/work4/4.jpg taken from this website http://p5aholic.me/ and I was wondering how the triangles are generated. I’ve already completed the code necessary to build a tree using cylinders with L-System, but i want to use different geometries, like this.
Someone has an idea about how to generate that kind of mesh? it looks like some random triangles that follows a direction but I’m not sure about how to implement it.

It looks something like random vertices inside a bounding cylinder.

Maybe generate vertices on each end of the cylinder (not uniformly distributed of course, just use the cylinder as bound), and put in some random indices?

Do you mean to create a ofMesh with mode OF_PRIMITIVE_TRIANGLE and generate some separated triangles with vertices contained in the bounding delimited by the cylinder, right?

yep, just as a first suggestion!

sounds good, i will give a try, thank you.

Hello @Hennio, I’ve tried it out what you were suggesting yesterday and I think there is something strange, some triangles should be red but they are not.

What I think it is wrong is the normals calculation. This is a picture with only 4 triangles and without the cylinder structure, the ball on the top is the light.

The triangle A has normal direction that goes in the opposite direction of the light, that’s why I think it is right that is black. The triangle B has normal that goes in the direction of the light, and correctly it is illuminated. What I think it is wrong, is that the backface of the triangle A, not visible in this picture, is also red, as it was illuminated.

This is the code that I’m using to add the vertices and calculate the normals:

    int radius = 50;
    ofNode cylEnd;
    ofNode cylStart;
    cylEnd.setPosition(200, 0, 200);
    cylStart.setPosition(200, 0, 0);
    mesh.setMode(OF_PRIMITIVE_TRIANGLES);

    int n_triangles = 4;
    ofVec3f top = cylEnd.getGlobalPosition();
    ofVec3f bottom = cylStart.getGlobalPosition();
    float minX = bottom.x -radius;
    float minY = bottom.y-radius;
    float maxX = top.x + radius;
    float maxY = top.y +radius;
    float maxZ = top.z;
    float minZ = bottom.z;
    for (unsigned int i = 0; i< (n_triangles*3); i += 3) {
        ofVec3f firstV;
        firstV.x = ofRandom(minX,maxX);
        firstV.y = ofRandom(minY,maxY);
        firstV.z = ofRandom(minZ,maxZ);
        ofVec3f secondV;
        secondV.x = ofRandom(minX,maxX);
        secondV.y = ofRandom(minY,maxY);
        secondV.z = ofRandom(minZ,maxZ);
        ofVec3f thirdV;
        thirdV.x = ofRandom(minX,maxX);
        thirdV.y = ofRandom(minY,maxY);
        thirdV.z = ofRandom(minZ,maxZ);

        mesh.addIndex(i);
        mesh.addIndex(i+1);
        mesh.addIndex(i+2);

        //find position AND direction of 2 vertices of the triangle;
        ofVec3f e1 = firstV - secondV;
        ofVec3f e2 = thirdV - secondV;
        //Use these 2 vertices to find the normal
        ofVec3f no = e2.cross( e1 ).normalize();

        mesh.addVertex(firstV);
        mesh.addNormal(no);
        mesh.addVertex(secondV);
        mesh.addNormal(no);
        mesh.addVertex(thirdV);
        mesh.addNormal(no);
    }

Do you have any suggestion? The method that I’m using to calculate the normals comes from here Mesh lighting / normal issues via https://github.com/ofZach/ofxMeshUtils/blob/master/src/ofxMeshUtils.cpp inspired by http://www.iquilezles.org/www/articles/normals/normals.htm.