Generate a model from a set of points

Hello,

I’m trying to generate a model starting from a list of points which defines an area on the x,y plane
and extrude it along the z axis. At the moment, I’m struggling with the primitives.

Let’s suppose that I have the following situation:

        vertices = #points on the x,y plane
                        #obtained from a scipy Voronoi(using the vertices 
                        #property)
        region = #a list of indices of vertices(using the regions property)
        vdata = GeomVertexData('gdata',
                               GeomVertexFormat.getV3n3c4t2(),
                               Geom.UHStatic)
        #Number of vertices = the points on the x,y plane
        #plus the same points shifted on the z axis
        vdata.setNumRows(len(region) * 2)

        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        color = GeomVertexWriter(vdata, 'color')
        texcoord = GeomVertexWriter(vdata, 'texcoord')

        for pt in region:
            #ground level
            vertex.addData3(vertices[pt][0],
                            vertices[pt][1],
                            0)
            normal.addData3(0,0,1)
            color.addData4(255,0,0,255)
            texcoord.addData2(1,0)

            #same point shifted on the z axis
            vertex.addData3(voronoi_vertices[pt][0],
                            voronoi_vertices[pt][1],
                            20)
            normal.addData3(0,0,1)
            color.addData4(255,0,0,255)
            texcoord.addData2(1,0)

at this point I should generate the primitives. The problem is that I don’t know where to start: I cannot link random points with GeomTriangles’ addVertices method and expect to get a good result, so, how should I choose which points to connect with a triangle?

You can use the Triangulator class to calculate the triangulation of an arbitrary 2D polygon:
https://docs.panda3d.org/1.10/cpp/reference/panda3d.core.Triangulator

For a 3D polygon, use the Triangulator3 class. But in your case, Triangulator will suffice, since your points lie on the 2D plane.

Note that your colour values are incorrect, they should be in the range 0.0 through 1.0.