예제 #1
0
def mesh_init(uv_steps, uv_offset, closed, lid):
    """Given number of U and V steps, generate boilerplate object with
       given texture coordinates and point indices. The initial vertex
       positions can be dummies (all 0,0,0) and will be reassigned later.
       If it's an eyelid, add an extra row with V=0.0."""
    # U steps might be determined by passing in a pointlist instead,
    # even though we're not using the coordinates yet, it'd provide some
    # consistency and avoid trouble later.
    verts = []
    tex = []
    idx = []
    norms = []
    if closed:
        uv_steps = (uv_steps[0] + 1, uv_steps[1])
    uv_div = (float(uv_steps[0] - 1), float(uv_steps[1] - 1))

    if lid: # Add extra row of vertices (with V=0) if eyelid
        for u_pos in range(uv_steps[0]):
            verts.append((0, 0, 0))
            tex.append((u_pos / uv_div[0] + uv_offset[0], uv_offset[1]))
            norms.append((0, 0, -1))
        v_range = uv_steps[1]
    else:
        v_range = uv_steps[1] - 1

    for v_pos in range(uv_steps[1]):
        v_pos_2 = (uv_offset[1] +
                   (v_pos / uv_div[1]) * (1.0 - uv_offset[1] * 2.0))
        for u_pos in range(uv_steps[0]):
            verts.append((0, 0, 0))
            tex.append((u_pos / uv_div[0] + uv_offset[0], v_pos_2))
            norms.append((0, 0, -1))

    for v_pos in range(v_range):
        for u_pos in range(uv_steps[0] - 1):
            pos = v_pos * uv_steps[0] + u_pos
            idx.append((pos + uv_steps[0], pos, pos + 1))
            idx.append((pos + 1, pos + uv_steps[0] + 1, pos + uv_steps[0]))

    shape = pi3d.Shape(None, None, "foo", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                       1.0, 1.0, 1.0, 0.0, 0.0, 0.0)
    shape.buf = [pi3d.Buffer(shape, verts, tex, idx, norms, False)]

    return shape
예제 #2
0
 def __init__(self, camera):
     vertices = [((i % 60.0) / 3.0 - 10.0, int(i / 60.0) / 3.0 - 10.0,
                  random.gauss(0.0, 10.0)) for i in range(4320)]
     normals = None
     n_v = len(vertices)
     indices = [(a, a + 1, a + 2) for a in range(0, n_v, 3)]
     tex_coords = [(v[0] / 20.0 + 0.5, v[1] / 20.0 + 0.5) for v in vertices]
     points = pi3d.Shape(camera, None, '2', 0, 0, 160.0, 0, 0, 0, 1, 1, 1,
                         0, 0, 0)
     points.buf = [
         pi3d.Buffer(points,
                     vertices,
                     tex_coords,
                     indices,
                     normals,
                     smooth=False)
     ]
     super(SimplePoints, self).__init__(camera, points)
     self.geometry.set_point_size(50)
예제 #3
0
    def __init__(self,
                 camera=None,
                 light=None,
                 inner=0.5,
                 outer=1,
                 sides=36,
                 name="",
                 start=0.0,
                 end=60,
                 x=0.0,
                 y=0.0,
                 z=0.0,
                 rx=0.0,
                 ry=0.0,
                 rz=0.0,
                 sx=1.0,
                 sy=1.0,
                 sz=1.0,
                 cx=0.0,
                 cy=0.0,
                 cz=0.0):

        super(Slice, self).__init__(camera, light, name, x, y, z, rx, ry, rz,
                                    sx, sy, sz, cx, cy, cz)

        self.inner = inner
        self.outer = outer
        self.start = start
        self.end = end
        self.n = sides + 1
        (verts, texcoords) = self.make_verts()
        norms = np.zeros_like(verts)
        norms[:, 2] = -1.0
        inds = np.array([[i + u, i + v, i + w]
                         for i in range(0, 2 * self.n, 2)
                         for (u, v, w) in [(0, 1, 3), (3, 2, 0)]],
                        dtype=float)
        self.buf = [pi3d.Buffer(self, verts, texcoords, inds, norms)]
예제 #4
0
def meshInit(uSteps, vSteps, closed, uOffset, vOffset, lid):
    verts = []
    tex = []
    idx = []
    norms = []
    if closed is True: uSteps += 1
    uDiv = float(uSteps - 1)
    vDiv = float(vSteps - 1)

    if lid is True:  # Add extra row of vertices (with V=0) if eyelid
        for u in range(uSteps):
            verts.append((0, 0, 0))
            tex.append((u / uDiv + uOffset, vOffset))
            norms.append((0, 0, -1))
        vRange = vSteps
    else:
        vRange = vSteps - 1

    for v in range(vSteps):
        v2 = vOffset + (v / vDiv) * (1.0 - vOffset * 2.0)
        for u in range(uSteps):
            verts.append((0, 0, 0))
            tex.append((u / uDiv + uOffset, v2))
            norms.append((0, 0, -1))

    for v in range(vRange):
        for u in range(uSteps - 1):
            s = v * uSteps + u
            idx.append((s + uSteps, s, s + 1))
            idx.append((s + 1, s + uSteps + 1, s + uSteps))

    shape = pi3d.Shape(None, None, "foo", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0,
                       1.0, 1.0, 0.0, 0.0, 0.0)
    shape.buf = []
    shape.buf.append(pi3d.Buffer(shape, verts, tex, idx, norms, False))

    return shape
예제 #5
0
verts[:, :, 1] = perlin.generate(xy) * HT  # y value perlin noise height
verts.shape = (IZ * IX, 3)  # pi3d uses semi-flattened arrays

s = 0
#create one long triangle_strip by alternating X directions
for z in range(0, IZ - 1):
    for x in range(0, IX - 1):
        i = (z * IX) + x
        idx.append([i, i + IX, i + IX + 1])
        idx.append([i + IX + 1, i + 1, i])
        s += 2

terrain = pi3d.Shape(None, None, "terrain", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0,
                     1.0, 1.0, 0.0, 0.0, 0.0)
terrain.buf = []
terrain.buf.append(pi3d.Buffer(terrain, verts, tex_coords, idx, None, True))
terrain.set_material((0.2, 0.3, 0.5))
terrain.set_shader(shader)

axes = pi3d.Lines(vertices=[[2.0 * W, 0.0, 0.0], [0.0, 0.0, 0.0],
                            [0.0, 2.0 * HT, 0.0], [0.0, 0.0, 0.0],
                            [0.0, 0.0, 2.0 * D]],
                  line_width=3,
                  x=-W / 2.0,
                  z=-D / 2.0)
axes.set_shader(flatsh)

mouserot = 0.0  # rotation of camera
tilt = 15.0  # tilt of camera
frame = 0
예제 #6
0
파일: text.py 프로젝트: PlagiatBros/pytaVSL
    def new_string(self):
        """
        Update string buffer. Derivated from pi3d.String
        """
        size = min(1, self.font.ratio /
                   self.length) if self.size == 'auto' else self.size
        size /= self.font.nominal_height / self.parent.height  # relative to screend height
        self.computed_size = size

        string = self.string
        font = self.font

        vertices = []
        texcoords = []
        indices = []
        tmp_vertices = []

        nlines = 0

        pos_x = 0
        pos_y = 0

        gap = self.font.line_height * self.line_height

        nlines_total = len(self.string.split('\n')) + 1
        total_height = self.font.line_height + (
            nlines_total - 1) * self.font.line_height * self.line_height

        def make_line():
            nonlocal nlines, pos_x, pos_y, tmp_vertices

            nlines += 1

            if self.h_align == 'center':
                cx = pos_x / 2.0
            elif self.h_align == 'left':
                cx = 0.0
            else:
                cx = pos_x

            if self.v_align == 'top':
                cy = gap / 2.
            elif self.v_align == 'bottom':
                cy = -gap / 2.
            else:
                cy = 0

            for vert in tmp_vertices:
                vertices.append([
                    (vert[0] - cx) * size,
                    (vert[1] + total_height / 2. - gap / 2. - pos_y + cy) *
                    size, vert[2]
                ])

            tmp_vertices = []
            pos_x = 0
            pos_y += gap

        for i, char in enumerate(string):

            if char == '\n' or (self.glitch and self.glitch_to[i] == '\n'):
                make_line()
                continue

            glyph = font.get_glyph(char)

            w, h, texc, verts = glyph[0:4]

            if self.glitch and not self.font.mono:
                # use the destination letter's width when glitching
                w = font.get_glyph(char)[0]

            for j in verts:
                glitch_offset = 0
                if self.glitch and not self.font.mono:
                    # center glitching letters
                    glitch_offset += (glyph[0] - w) / 2.0
                tmp_vertices.append(
                    (j[0] + pos_x - glitch_offset, j[1],
                     j[2] - i / 1000.))  # "-i/1000." => allow letter overlap

            pos_x += w * self.letter_spacing

            for c in texc:
                texcoords.append(c)

            # Take Into account unprinted \n characters
            stv = 4 * (i - nlines)
            indices.extend([[stv, stv + 2, stv + 1], [stv, stv + 3, stv + 2]])

        make_line()

        tex = self.buf[0].textures
        self.buf = [pi3d.Buffer(self, vertices, texcoords, indices, None)]
        self.buf[0].textures = tex

        self.height = total_height * size
        self.last_draw_align_h = self.h_align
        self.last_draw_align_v = self.h_align

        self.set_v_align(self.v_align)
        self.set_h_align(self.h_align)
        self.set_shader(self.shader)
        self.set_scale(self.sx, self.sy)
        self.set_material(self.color)
        self.set_tiles(*self.tiles)
        self.set_text_outline(self.outline)
        self.set_text_outline_color(*self.outline_color)
예제 #7
0
파일: Starfield.py 프로젝트: jmalm/pi3d
myplane.set_draw_details(flatsh, [starsimg])
"""create the shape to hold the points. This could be encapsulated in its
own class to generate the required distribution and shield the user from
having to explicitly create the Buffer object and set the Shape.buf list
"""
mystars = pi3d.Shape(None, None, "stars", 0, 0, 250, 0, 0, 0, 100, 100, 500, 0,
                     0, 0)
verts, norms, texc, faces = [], [], [], []
for i in xrange(30000):
    verts.append(
        (random.random() - 0.5, random.random() - 0.5, random.random() - 0.5))
    norms.append((0, 0, 0))
    texc.append((0, 0))
for i in xrange(10000):
    faces.append((i * 3, i * 3 + 1, i * 3 + 2))
mystars.buf = [pi3d.Buffer(mystars, verts, texc, faces, norms)]
mystars.set_point_size(50)
mystars.set_material((0.9, 0.9, 1.0))
mystars.set_shader(matsh)

# Fetch key presses
mykeys = pi3d.Keyboard()
# Display scene
while DISPLAY.loop_running():
    mysphere.rotateIncY(-0.5)
    mysphere.positionZ(mysphere.z() - 0.5)
    mystars.positionZ(mystars.z() - 0.5)
    if mystars.z() < 75:
        mystars.positionZ(250)
        mysphere.positionZ(180)
    mystars.draw()