Пример #1
0
def createTriangleTextureNormal(image_filename, p1, p2, p3, nx=1, ny=1):
    """
    Creates a triangle with textures.

    :param image_filename: Image
    :param p1: Vertex (x,y,z)
    :param p2: Vertex (x,y,z)
    :param p3: Vertex (x,y,z)
    :param nx: Texture coord pos
    :param ny: Texture coord pos
    :return:
    """
    # Dissamble vertices
    x1, y1, z1 = p1
    x2, y2, z2 = p2
    x3, y3, z3 = p3

    # Calculate the normal
    normal = _normal3(p3, p2, p1)

    # Defining locations and texture coordinates for each vertex of the shape
    vertices = [
        # X, Y,  Z,   U,   V
        x1,
        y1,
        z1,
        (nx + ny) / 2,
        nx,
        normal.get_x(),
        normal.get_y(),
        normal.get_z(),
        x2,
        y2,
        z2,
        0.0,
        0.0,
        normal.get_x(),
        normal.get_y(),
        normal.get_z(),
        x3,
        y3,
        z3,
        ny,
        0.0,
        normal.get_x(),
        normal.get_y(),
        normal.get_z()
    ]

    # Defining connections among vertices
    # We have a triangle every 3 indices specified
    indices = [0, 1, 2]

    return _Shape(vertices, indices, image_filename)
Пример #2
0
def create4VertexTextureNormal(image_filename, p1, p2, p3, p4, nx=1, ny=1):
    """
    Creates a 4-vertex poly with texture.

    :param image_filename: Image
    :param p1: Vertex (x,y,z)
    :param p2: Vertex (x,y,z)
    :param p3: Vertex (x,y,z)
    :param p4: Vertex (x,y,z)
    :param nx: Texture coord pos
    :param ny: Texture coord pos
    :return:
    """
    # Extend
    p1 = __vertexUnpack3(p1)
    p2 = __vertexUnpack3(p2)
    p3 = __vertexUnpack3(p3)
    p4 = __vertexUnpack3(p4)

    # Dissamble vertices
    x1, y1, z1 = p1
    x2, y2, z2 = p2
    x3, y3, z3 = p3
    x4, y4, z4 = p4

    # Calculate the normal
    normal = _normal3(p3, p2, p1)

    # Defining locations and texture coordinates for each vertex of the shape
    vertices = [
        x1, y1, z1, 0, 0,
        normal.get_x(),
        normal.get_y(),
        normal.get_z(), x2, y2, z2, nx, 0,
        normal.get_x(),
        normal.get_y(),
        normal.get_z(), x3, y3, z3, nx, ny,
        normal.get_x(),
        normal.get_y(),
        normal.get_z(), x4, y4, z4, 0, ny,
        normal.get_x(),
        normal.get_y(),
        normal.get_z()
    ]

    # Defining connections among vertices
    # We have a triangle every 3 indices specified
    indices = [0, 1, 2, 2, 3, 0]

    return _Shape(vertices, indices, image_filename)
Пример #3
0
def createTriangleColorNormal(p1, p2, p3, r, g, b):
    """
    Creates a triangle with color.

    :param p1: Vertex (x,y,z)
    :param p2: Vertex (x,y,z)
    :param p3: Vertex (x,y,z)
    :param r: Red color
    :param g: Green color
    :param b: Blue color
    :return:
    """
    # Extend
    p1 = __vertexUnpack3(p1)
    p2 = __vertexUnpack3(p2)
    p3 = __vertexUnpack3(p3)

    # Dissamble vertices
    x1, y1, z1 = p1
    x2, y2, z2 = p2
    x3, y3, z3 = p3

    # Calculate the normal
    normal = _normal3(p3, p2, p1)

    # Defining locations and color
    vertices = [
        # X, Y,  Z, R, G, B,
        x1,
        y1,
        z1,
        r,
        g,
        b,
        normal.get_x(),
        normal.get_y(),
        normal.get_z(),
        x2,
        y2,
        z2,
        r,
        g,
        b,
        normal.get_x(),
        normal.get_y(),
        normal.get_z(),
        x3,
        y3,
        z3,
        r,
        g,
        b,
        normal.get_x(),
        normal.get_y(),
        normal.get_z()
    ]

    # Defining connections among vertices
    # We have a triangle every 3 indices specified
    indices = [0, 1, 2]

    return _Shape(vertices, indices)