示例#1
0
 def camera(self) -> np.array:
     t = 0.05 * self.t
     pan = 0.05
     target = np.array([0, 0, pan])
     up = np.array([0, 0, 1])
     r = 0.6
     eye = np.array([r * math.cos(t), r * math.sin(t), r * 0.3 + pan])
     return numgl.lookat(eye, target, up)
示例#2
0
文件: main.py 项目: vidstige/nes3d
def main():
    target = np.array([0, 0, 0])
    up = np.array([0, 1, 0])

    cube = Model.load_obj('icosaedron.obj')
    cube.compute_face_normals()

    w = 64
    h = 64

    n = 32
    tiles = []
    for i in range(n):
        a = 2 * np.pi * i / n
        eye = np.array([np.sin(a), 0, np.cos(a)])
        projection = numgl.lookat(eye, target, up)
        projection_hash = md5(projection.data.tobytes())
        cache_file = 'cache/render-{hash}.npy'.format(hash=projection_hash)
        if os.path.isfile(cache_file):
            im = np.load(cache_file)
        else:
            im = np.zeros((h, w, 4))
            render(im, cube, projection)
            os.makedirs('cache/', exist_ok=True)
            np.save(cache_file, im)

        #with open('image-{:02}.png'.format(i), 'wb') as f:
        #    f.write(png.write(image.quantize(im, bits=8).tobytes(), w, h))

        large = (8, 16)
        tiles.extend(image.tile(im, shape=large))

    lookup = make_lookup(0, len(tiles))

    replace_duplicates(tiles, lookup)
    repack(tiles, lookup)

    # downsample to 2-bits
    # write sprite sheets
    low_bank = image.quant2(image.intensity(np.vstack(tiles[0::2])), bits=2)
    with open('image-0000.chr', 'wb') as f:
        f.write(npchr.write(low_bank))

    high_bank = image.quant2(image.intensity(np.vstack(tiles[1::2])), bits=2)
    with open('image-1000.chr', 'wb') as f:
        f.write(npchr.write(high_bank))

    # write lookup tables
    with open('lookup.bin', 'wb') as f:
        f.write(pack_lookup(lookup))
示例#3
0
def main():
    eye = np.array([0, 0, -1])
    target = np.array([0, 0, 0])
    up = np.array([0, 1, 0])

    cube = Model.load_obj('icosaedron.obj')
    cube.compute_face_normals()

    w = 64
    h = 64

    os.makedirs('images', exist_ok=True)
    n = 100
    tau = 2 * math.pi
    for a in range(n):
        eye = np.array([math.sin(tau * a / n), 0, math.cos(tau * a / n)])
        im = np.zeros((h, w, 4), 'uint8')
        render(im, cube, numgl.lookat(eye, target, up))
        with open('images/{:02}.png'.format(a), 'wb') as f:
            f.write(png.write(im.tobytes(), w, h))

    out = 'out.gif'
    create_gif(sorted(glob('images/*.png')), out)
    print(out)
示例#4
0
 def pose(self):
     return numgl.lookat(self.eye, self.target, self.up)