Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / scripts / voxels / build_entity_atlas.py
build_entity_atlas.py98 lines · 4.1 KiBRaw
| 1 | #!/usr/bin/env python3 |
| 2 | """Assemble mob skins into a single entity atlas (raw RGBA, 256x256, 4x4 grid of 64px cells). |
| 3 | |
| 4 | Cell index = row*4 + col; the Rust mob renderer offsets each mob's skin-space UVs into its cell. Skins |
| 5 | that are 64x32 occupy the top half of their cell (their model UVs only touch that region). |
| 6 | """ |
| 7 | import os, sys |
| 8 | sys.path.insert(0, os.path.dirname(__file__)) |
| 9 | from build_atlas import decode_png # reuse the pure-Python PNG decoder |
| 10 | |
| 11 | ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) |
| 12 | ENT = os.path.join(ROOT, "tmp/Matcha_Flavoured/assets/minecraft/textures/entity") |
| 13 | OUT = os.path.join(ROOT, "games/voxels/src/main/rust/shaders/entity_atlas.bin") |
| 14 | |
| 15 | CELL = 64 |
| 16 | COLS = 4 |
| 17 | W = H = 256 |
| 18 | |
| 19 | # Cell index -> skin path (must match the MobKind order in entity.rs). |
| 20 | SKINS = { |
| 21 | 0: "pig/pig_temperate.png", |
| 22 | 1: "cow/cow_temperate.png", |
| 23 | 2: "sheep/sheep.png", |
| 24 | 3: "chicken/chicken_temperate.png", |
| 25 | 4: "creeper/creeper.png", |
| 26 | 5: "zombie/zombie.png", |
| 27 | 6: "zombie_villager/zombie_villager.png", # closest villager-shaped humanoid the pack ships |
| 28 | } |
| 29 | |
| 30 | |
| 31 | def main(): |
| 32 | atlas = bytearray(W * H * 4) |
| 33 | for idx, rel in SKINS.items(): |
| 34 | p = os.path.join(ENT, rel) |
| 35 | w, h, rgba = decode_png(p) |
| 36 | cx = (idx % COLS) * CELL |
| 37 | cy = (idx // COLS) * CELL |
| 38 | for y in range(min(h, CELL)): |
| 39 | for x in range(min(w, CELL)): |
| 40 | s = (y * w + x) * 4 |
| 41 | d = ((cy + y) * W + (cx + x)) * 4 |
| 42 | atlas[d:d+4] = rgba[s:s+4] |
| 43 | print("cell %d <- %s (%dx%d)" % (idx, rel, w, h)) |
| 44 | # Cell 7: procedural dark-purple Ender Dragon skin (uniform, sampled at the cell centre). |
| 45 | dx7, dy7 = (7 % COLS) * CELL, (7 // COLS) * CELL |
| 46 | for y in range(CELL): |
| 47 | for x in range(CELL): |
| 48 | n = ((x * 7 + y * 13) % 11) - 5 |
| 49 | d = ((dy7 + y) * W + (dx7 + x)) * 4 |
| 50 | atlas[d:d+4] = bytes([max(0, 34 + n), max(0, 12 + n), max(0, 48 + n), 255]) |
| 51 | # Cell 8: procedural dark Wither skin (charcoal grey). |
| 52 | dx8, dy8 = (8 % COLS) * CELL, (8 // COLS) * CELL |
| 53 | for y in range(CELL): |
| 54 | for x in range(CELL): |
| 55 | n = ((x * 5 + y * 11) % 9) - 4 |
| 56 | d = ((dy8 + y) * W + (dx8 + x)) * 4 |
| 57 | atlas[d:d+4] = bytes([max(0, 34 + n), max(0, 34 + n), max(0, 38 + n), 255]) |
| 58 | # Cell 9: procedural glowing Blaze skin (orange-yellow). |
| 59 | dx9, dy9 = (9 % COLS) * CELL, (9 // COLS) * CELL |
| 60 | for y in range(CELL): |
| 61 | for x in range(CELL): |
| 62 | n = ((x * 9 + y * 7) % 41) - 12 |
| 63 | d = ((dy9 + y) * W + (dx9 + x)) * 4 |
| 64 | atlas[d:d+4] = bytes([min(255, 236 + n // 3), max(0, 150 + n), max(0, 24 + n // 2), 255]) |
| 65 | # Cell 10: procedural Wither Skeleton skin (near-black charcoal). |
| 66 | dx10, dy10 = (10 % COLS) * CELL, (10 // COLS) * CELL |
| 67 | for y in range(CELL): |
| 68 | for x in range(CELL): |
| 69 | n = ((x * 3 + y * 13) % 7) - 3 |
| 70 | d = ((dy10 + y) * W + (dx10 + x)) * 4 |
| 71 | atlas[d:d+4] = bytes([max(0, 22 + n), max(0, 22 + n), max(0, 24 + n), 255]) |
| 72 | # Cell 11: procedural Shulker skin (muted purple, matching purpur). |
| 73 | dx11, dy11 = (11 % COLS) * CELL, (11 // COLS) * CELL |
| 74 | for y in range(CELL): |
| 75 | for x in range(CELL): |
| 76 | n = ((x * 7 + y * 5) % 21) - 10 |
| 77 | d = ((dy11 + y) * W + (dx11 + x)) * 4 |
| 78 | atlas[d:d+4] = bytes([max(0, 150 + n), max(0, 116 + n), max(0, 172 + n), 255]) |
| 79 | # Cell 12: procedural Ghast skin (pale off-white). |
| 80 | dx12, dy12 = (12 % COLS) * CELL, (12 // COLS) * CELL |
| 81 | for y in range(CELL): |
| 82 | for x in range(CELL): |
| 83 | n = ((x * 5 + y * 9) % 13) - 6 |
| 84 | d = ((dy12 + y) * W + (dx12 + x)) * 4 |
| 85 | atlas[d:d+4] = bytes([min(255, 224 + n), min(255, 224 + n), min(255, 218 + n), 255]) |
| 86 | # White swatch in the last cell (index 15) for tinted particle quads. Rust samples its centre. |
| 87 | wx, wy = (15 % COLS) * CELL, (15 // COLS) * CELL |
| 88 | for y in range(8): |
| 89 | for x in range(8): |
| 90 | d = ((wy + y) * W + (wx + x)) * 4 |
| 91 | atlas[d:d+4] = bytes([255, 255, 255, 255]) |
| 92 | print("white particle swatch at cell 15") |
| 93 | open(OUT, "wb").write(atlas) |
| 94 | print("wrote %s (%dx%d, %d bytes)" % (OUT, W, H, len(atlas))) |
| 95 | |
| 96 | |
| 97 | if __name__ == "__main__": |
| 98 | main() |