Beispiel #1
0
def createColoredUnitDisk(color_vec4=Vec4(0., 0., 1., 1.), num_of_verts=10, origin_point=Vec3(0., 0., 0.), radius=1.):
    # Own Geometry
    # format = GeomVertexFormat.getV3c4t2()
    format = GeomVertexFormat.getV3c4()
    vdata = GeomVertexData("colored_circle", format, Geom.UHStatic)
    vdata.setNumRows(4)

    vertexPosWriter = GeomVertexWriter(vdata, "vertex")

    # num_of_verts = 10

    # phi = 0.
    r = radius

    # origin_point_x = 0.
    # origin_point_z = 0.
    vertexPosWriter.addData3f(origin_point[0], origin_point[1], origin_point[2])

    circle_points = math_utils.get_circle_vertices(num_of_verts=num_of_verts, radius=r)

    circle_points[:,0] += origin_point[0]
    circle_points[:,1] += origin_point[1]
    circle_points[:,2] += origin_point[2]

    _normal_vector_info = Vec3(0., 1., 0.)      # this is returned just as info about the normal vector of the generated geometry
    for p in circle_points:
        vertexPosWriter.addData3f(p[0], 0, p[1])

    # for i in range(num_of_verts):
    #     phi += 2. * np.pi / num_of_verts
    #     x = r * np.cos(phi)
    #     z = r * np.sin(phi)
    #     vertexPosWriter.addData3f(x, 0, z)

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

    colorWriter.addData4f(color_vec4)  # origin point

    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)
    tris = GeomTrifans(Geom.UHStatic)  # the first vertex is a vertex that all triangles share

    tris.add_consecutive_vertices(0, num_of_verts+1)
    tris.addVertex(1)

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

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

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

    return geom_node, _normal_vector_info
Beispiel #2
0
def create_GeomNode_Cone(color_vec4=Vec4(1., 1., 1., 1.)):
    # a cone that points into the y direction
    # and the center of it's base is at the origin

    # ---- step 1: create circle with trifans in the x-y plane and close the primitive

    format = GeomVertexFormat.getV3c4()
    vdata = GeomVertexData("colored_quad", format, Geom.UHStatic)
    vdata.setNumRows(4)

    # add color to each vertex
    colorWriter = GeomVertexWriter(vdata, "color")

    # add a vertex position to each vertex
    vertexPosWriter = GeomVertexWriter(vdata, "vertex")

    # first the circle vertices
    num_of_circle_vertices = 10
    circle_verts = math_utils.get_circle_vertices(num_of_verts=num_of_circle_vertices)

    # then the origin point vertex
    vertexPosWriter.addData3f(0., 0., 0.)
    colorWriter.addData4f(color_vec4)

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

    # build the primitive (base of cone)
    tris = GeomTrifans(Geom.UHStatic) # the first vertex is a vertex that all triangles share

    tris.add_consecutive_vertices(0, num_of_circle_vertices+1)  # add all vertices

    # close up the circle (the last triangle involves the first
    # point of the circle base, i.e. point with index 1)
    tris.addVertex(1)

    tris.closePrimitive()  # this resets all the data contained in the vertexPosWriter and colorWriter

    # ---- step 2: create tip vertex and make a trifans primitive
    #      with the vertices of the cone base outer circle

    # first the tip point vertex
    vertexPosWriter.addData3f(0., 0., cos(pi / 6.))
    colorWriter.addData4f(color_vec4)

    tris.addVertex(num_of_circle_vertices+1)
    tris.add_consecutive_vertices(0, num_of_circle_vertices+1)  # add all circle vertices

    # close up the circle (the last triangle involves the first
    # point of the circle base, i.e. point with index 1)
    tris.addVertex(0)

    tris.closePrimitive()  # this resets all the data contained in the vertexPosWriter and colorWriter

    # ----- step 3: make a GeomNode out of the Geom (to which the Primitives have been added)

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

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

    return geom_node