示例#1
0
 def center(self):
     bbox = boundingBox(self.vertices)
     dx = bbox[3] - bbox[0]
     dy = bbox[4] - bbox[1]
     dz = bbox[5] - bbox[2]
     self.translateX(-bbox[3] + dx * 0.5)
     self.translateY(-bbox[4] + dy * 0.5)
     self.translateZ(-bbox[5] + dy * 0.5)
示例#2
0
def tessPolygon(mesh,
                positions,
                z,
                color=None,
                flipped=False,
                texture_boundingBox=None):
    offset = len(mesh.vertices)

    n = [0., 0., 1.]

    # Get rid of begining/ending duplicate
    if positions[0][0] == positions[-1][0] and positions[0][1] == positions[
            -1][1]:
        positions.pop()

    rotY = []
    if flipped:
        n = [0., 0., -1.]
        rotY = quat_from_axis(np.radians(180), (0, 1, 0))

    if texture_boundingBox == None:
        texture_boundingBox = boundingBox(positions)

    points = []
    for point in positions:
        v = np.array([point[0], point[1], z])
        if flipped:
            v = quat_mult(rotY, (v[0], v[1], v[2]))

        points.append([point[0], point[1]])

        mesh.addTexCoord([
            remap(point[0], texture_boundingBox[0], texture_boundingBox[2],
                  0.0, 1.0),
            remap(point[1], texture_boundingBox[1], texture_boundingBox[3],
                  0.0, 1.0)
        ])

        mesh.addVertex(v)
        mesh.addNormal(n)
        if color:
            mesh.addColor(color)

    segments = []
    for i in range(len(positions)):
        segments.append([i, (i + 1) % len(positions)])

    cndt = triangulate(dict(vertices=points, segments=segments), 'p')

    for face in cndt['triangles']:
        mesh.addTriangle(offset + (face[0] % len(points)),
                         offset + (face[1] % len(points)),
                         offset + (face[2] % len(points)))

    # offset += len(positions)

    return mesh