| 1 | import os |
| 2 | import sys |
| 3 | import time |
| 4 | |
| 5 | sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| 6 | from vox import * |
| 7 | from PIL import Image |
| 8 | |
| 9 | OUT = '/tmp/claude-1000/-home-tahinli-Documents-Code-Rust/edd994b8-9b3e-47f3-95c7-9404536bd326/scratchpad/vt' |
| 10 | |
| 11 | |
| 12 | def save_pair(name, img): |
| 13 | img.save(os.path.join(OUT, name + '.png')) |
| 14 | img.resize((img.width * 4, img.height * 4), Image.NEAREST).save(os.path.join(OUT, name + '_x4.png')) |
| 15 | |
| 16 | |
| 17 | def house(): |
| 18 | o, W, D, H = 4, 96, 64, 70 |
| 19 | fy, fx = o + D, o + W |
| 20 | t0 = time.perf_counter() |
| 21 | m = Model(W + 2 * o, D + 2 * o, 112) |
| 22 | plaster = mat(P['plaster'], noise(1, 2)) |
| 23 | wood = mat(P['wood'], noise(1, 3)) |
| 24 | pane = mat(P['window'], emissive=True) |
| 25 | door = mat(P['wood_dark'], planks(4, 2)) |
| 26 | thatch = mat(P['thatch'], noise(1, 4)) |
| 27 | brick = mat(P['brick'], bricks(4, 12)) |
| 28 | m.box(o, o, 0, fx, fy, H, plaster) |
| 29 | m.paint(lambda x, y, z: ((y > fy - 1) & (((x - o) % 24 < 2) | (z % 35 < 2)) |
| 30 | | (x > fx - 1) & (((y - o) % 24 < 2) | (z % 35 < 2))) & (z < H), wood) |
| 31 | for x0, x1 in ((o + 10, o + 20), (o + 62, o + 72)): |
| 32 | m.box(x0, fy - 2, 30, x1, fy, 44, 0) |
| 33 | m.box(x0 + 1, fy - 2, 31, x1 - 1, fy - 1, 43, pane) |
| 34 | for y0, y1 in ((o + 14, o + 24), (o + 38, o + 48)): |
| 35 | m.box(fx - 2, y0, 30, fx, y1, 44, 0) |
| 36 | m.box(fx - 2, y0 + 1, 31, fx - 1, y1 - 1, 43, pane) |
| 37 | m.box(o + 40, fy - 2, 0, o + 50, fy, 26, 0) |
| 38 | m.box(o + 40, fy - 2, 0, o + 50, fy - 1, 26, door) |
| 39 | m.gable(o, o, fx, fy, H, 100, 'x', thatch, overhang=4) |
| 40 | m.box(o + 60, o + 8, 60, o + 70, o + 14, 106, brick) |
| 41 | t1 = time.perf_counter() |
| 42 | img, em, org = render(m) |
| 43 | t2 = time.perf_counter() |
| 44 | save_pair('house', img) |
| 45 | if em is not None: |
| 46 | save_pair('house_e', em) |
| 47 | print('house grid %s build %.3fs render %.3fs origin %s' % (m.v.shape, t1 - t0, t2 - t1, org)) |
| 48 | |
| 49 | |
| 50 | def figure(): |
| 51 | t0 = time.perf_counter() |
| 52 | m = Model(40, 40, 60) |
| 53 | navy = mat(P['cloth_navy'], noise(1, 5)) |
| 54 | coat = mat(P['cloth_brown'], noise(1, 6)) |
| 55 | skin = mat(P['skin']) |
| 56 | black = mat(P['cloth_black'], noise(1, 7)) |
| 57 | m.capsule((16, 20, 22), (16, 20, 3), 2.4, navy) |
| 58 | m.capsule((24, 20, 22), (24, 20, 3), 2.4, navy) |
| 59 | m.ellipsoid(20, 20, 33, 6, 4, 10, coat) |
| 60 | m.capsule((13, 20, 40), (9, 20, 26), 2.2, coat) |
| 61 | m.capsule((27, 20, 40), (31, 20, 26), 2.2, coat) |
| 62 | m.capsule((20, 20, 40), (20, 20, 46), 1.8, skin) |
| 63 | m.ellipsoid(20, 20, 48, 4.2, 4.2, 4.6, skin) |
| 64 | m.cylinder((20, 20, 53), (20, 20, 54), 7, black) |
| 65 | m.cylinder((20, 20, 54), (20, 20, 59), 4.6, black) |
| 66 | t1 = time.perf_counter() |
| 67 | img, em, org = render(m) |
| 68 | t2 = time.perf_counter() |
| 69 | save_pair('figure', img) |
| 70 | print('figure grid %s build %.3fs render %.3fs origin %s' % (m.v.shape, t1 - t0, t2 - t1, org)) |
| 71 | |
| 72 | |
| 73 | def grass(): |
| 74 | t0 = time.perf_counter() |
| 75 | m = Model(64, 64, 2) |
| 76 | m.box(0, 0, 0, 64, 64, 2, mat(P['grass'], noise(1, 8))) |
| 77 | t1 = time.perf_counter() |
| 78 | img, em, org = render(m) |
| 79 | t2 = time.perf_counter() |
| 80 | save_pair('grass', img) |
| 81 | print('grass grid %s build %.3fs render %.3fs origin %s' % (m.v.shape, t1 - t0, t2 - t1, org)) |
| 82 | |
| 83 | |
| 84 | if __name__ == '__main__': |
| 85 | os.makedirs(OUT, exist_ok=True) |
| 86 | house() |
| 87 | figure() |
| 88 | grass() |