Exemple #1
0
 def addLine(self, points):
     """
 Adds a line to class GeomNode from a pair of points
 """
     #Creates objects needed to draw a geometry on the HUD
     #The vertex data which will define the rendered geometry
     vertex_data = GeomVertexData("graph", GeomVertexFormat.getV3(),
                                  Geom.UHStatic)
     #The object that writes vertexes the vertex data
     writer = GeomVertexWriter(vertex_data, "vertex")
     for point in points:
         writer.add_data3f(point[0], 0, point[1])
     #Defines that this geometry represents a polyline
     primitive = GeomLinestrips(Geom.UHStatic)
     #Tells geometry how many verticies will be added(?)
     primitive.add_consecutive_vertices(0, 2)
     primitive.close_primitive()
     geometry = Geom(vertex_data)
     geometry.add_primitive(primitive)
     #Draws a graph on the HUD
     self.geom_node.add_geom(geometry)
def createCircle(color_vec4=Vec4(1., 1., 1., 1.), with_hole=False, num_of_verts=10, radius=1.):
    # Own Geometry
    format = GeomVertexFormat.getV3c4()
    vdata = GeomVertexData("colored_circle", format, Geom.UHStatic)
    vdata.setNumRows(4)

    vertexPosWriter = GeomVertexWriter(vdata, "vertex")

    # generates circles in x-y plane
    circle_points = math_utils.get_circle_vertices(num_of_verts=num_of_verts, radius=radius)

    for p in circle_points:
        vertexPosWriter.addData3f(p[0], p[1], p[2])

    # let's also add color to each vertex
    colorWriter = GeomVertexWriter(vdata, "color")

    for i in range(num_of_verts):
        colorWriter.addData4f(color_vec4)

    # make primitives and assign vertices to them (primitives and primitive
    # groups can be made independently from vdata, and are later assigned
    # to vdata)
    line = GeomLinestrips(Geom.UHStatic)

    line.add_consecutive_vertices(0, num_of_verts)

    if with_hole != True:
        line.add_vertex(0)  # connect it up at the end

    line.closePrimitive()  # the 1st primitive is finished

    # make a Geom object to hold the primitives
    geom = Geom(vdata)
    geom.addPrimitive(line)

    geom_node = GeomNode("colored_circle_node")
    geom_node.addGeom(geom)

    return geom_node
def create_GeomNode_Simple_Polygon_with_Hole_LineStrips(symbol_geometries):
    color_vec4 = Vec4(1., 1., 1., 1.)

    outerpolygon_contour_points = 0.1 * symbol_geometries[0][0]
    inner_hole_contour_points = 0.1 * symbol_geometries[0][1]

    # outerpolygon_contour_points = (
    #     np.array([[0, 1], [-1, 0], [0, -1], [1, 0]], dtype=np.float64))

    # inner_hole_contour_points = (
    #     0.5 * np.array([[0, 1], [-1, 0], [0, -1], [1, 0]], dtype=np.float64))


    from panda3d.core import Triangulator, LPoint2d
    
    # tr = Triangulator()

    # for vertex in outerpolygon_contour_points: 
    #     vi = tr.addVertex(vertex[0], vertex[1])
    #     tr.addPolygonVertex(vi)

    # tr.beginHole()
    # for vertex in inner_hole_contour_points:
    #     vi = tr.addVertex(vertex[0], vertex[1])
    #     tr.addHoleVertex(vi)

    # tr.triangulate()
    
    # vertices = tr.getVertices()

    # indices = []
    # num_triangles = tr.getNumTriangles()
    # for i in range(num_triangles):
    #     indices.append([tr.getTriangleV0(i), tr.getTriangleV1(i), tr.getTriangleV2(i)])

    # Own Geometry

    # format = GeomVertexFormat.getV3c4t2()
    format = GeomVertexFormat.getV3c4()
    vdata = GeomVertexData("colored_polygon", format, Geom.UHStatic)
    vdata.setNumRows(4)

    # let's also add color to each vertex
    colorWriter = GeomVertexWriter(vdata, "color")
    vertexPosWriter = GeomVertexWriter(vdata, "vertex")

    for v in outerpolygon_contour_points: 
        vertexPosWriter.addData3f(v[0], 0, v[1])
        colorWriter.addData4f(color_vec4)
    
    for v in inner_hole_contour_points: 
        vertexPosWriter.addData3f(v[0], 0, v[1])
        colorWriter.addData4f(color_vec4)

    # make primitives and assign vertices to them (primitives and primitive
    # groups can be made independently from vdata, and are later assigned
    # to vdata)
    # tris = GeomTriangles(Geom.UHStatic) 

    tris = GeomLinestrips(Geom.UHStatic)

    # for index_triple in indices: 
    #     tris.addVertices(index_triple[0], index_triple[1], index_triple[2])
    tris.add_consecutive_vertices(0, len(outerpolygon_contour_points))
    tris.closePrimitive()

    tris.add_consecutive_vertices(len(outerpolygon_contour_points), len(inner_hole_contour_points))
    tris.closePrimitive()

    # make a Geom object to hold the primitives
    polygonGeom = Geom(vdata)  # vdata contains the vertex position/color/... buffers
    polygonGeom.addPrimitive(tris)  # tris contains the index buffer

    # now put quadGeom in a GeomNode. You can now position your geometry
    # in the scene graph.
    polygonGeomNode = GeomNode("colored_polygon_node")
    polygonGeomNode.addGeom(polygonGeom)

    return polygonGeomNode