plugins/tools/make-jerboa-art.py
unimatrixgit bcc768a751
Some checks failed
Arrakis Jerboa Redesign Build / jerboa (push) Failing after 1m0s
DuneRealms Plugin CI / plugins (push) Failing after 2m21s
Roll out the redesigned Arrakis jerboa
2026-11-30 20:53:15 +01:00

104 lines
8.5 KiB
Python

#!/usr/bin/env python3
"""Regenerates the Arrakis jerboa display art: a real jerboa (Dipodidae) - small round body, huge ears and eyes, very long
bipedal hind legs, long tufted tail - as a 64x64 palette atlas plus four item models (idle, two hop frames, curled).
usage: make-jerboa-art.py [REPO_ROOT] (needs Pillow). Model front is -Z, ground is y=0, centre x=8 z=8 (same as before)."""
import json, pathlib, random, sys
from PIL import Image, ImageDraw
ROOT = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else pathlib.Path(__file__).resolve().parents[1])
ECO = ROOT / "DuneRealmsGUI/ecology"
LEGACY = ROOT / "network/resource-pack/central/legacy/assets/dunerealms"
rng = random.Random(1964)
CELL = dict(back=(0, 0), dorsal=(1, 0), belly=(2, 0), face=(3, 0), earout=(4, 0), earin=(5, 0), eye=(6, 0), nose=(7, 0),
foot=(0, 1), claw=(1, 1), tailbase=(2, 1), band=(3, 1), tip=(4, 1), arm=(5, 1), leg=(6, 1), muzzle=(7, 1))
BASE = dict(back=(214, 172, 112), dorsal=(184, 138, 84), belly=(247, 240, 228), face=(232, 204, 156), earout=(224, 184, 136),
earin=(238, 168, 168), eye=(14, 10, 10), nose=(190, 112, 116), foot=(240, 216, 192), claw=(88, 68, 60),
tailbase=(206, 164, 106), band=(28, 24, 26), tip=(250, 248, 244), arm=(238, 214, 178), leg=(222, 186, 134), muzzle=(240, 222, 190))
def texture():
im = Image.new("RGBA", (64, 64), (0, 0, 0, 0)); px = im.load(); d = ImageDraw.Draw(im)
for name, (cx, cy) in CELL.items():
base = BASE[name]
for y in range(8):
for x in range(8):
j = rng.randint(-7, 7) if name not in ("eye", "band", "tip", "claw") else 0
px[cx * 8 + x, cy * 8 + y] = tuple(max(0, min(255, c + j)) for c in base) + (255,)
ex, ey = CELL["eye"][0] * 8, CELL["eye"][1] * 8 # big dark eye with a highlight
d.ellipse([ex + 1, ey + 1, ex + 6, ey + 6], fill=(10, 8, 8, 255)); d.rectangle([ex + 2, ey + 2, ex + 3, ey + 3], fill=(250, 250, 250, 255))
nx, ny = CELL["nose"][0] * 8, CELL["nose"][1] * 8
d.rectangle([nx + 2, ny + 2, nx + 5, ny + 5], fill=(150, 84, 92, 255))
ex2, ey2 = CELL["earin"][0] * 8, CELL["earin"][1] * 8 # pink inner ear with a cream rim
d.rectangle([ex2, ey2, ex2 + 7, ey2 + 7], outline=(240, 214, 190, 255))
return im
def uv(cell): cx, cy = CELL[cell]; return [cx * 2, cy * 2, cx * 2 + 2, cy * 2 + 2]
def box(a, b, top=None, side=None, bottom=None, front=None, rot=None, **faces):
top = top or side; bottom = bottom or side; front = front or side
f = {"up": top, "down": bottom, "north": front, "south": side, "west": side, "east": side}; f.update(faces)
el = {"from": [round(v, 3) for v in a], "to": [round(v, 3) for v in b], "faces": {k: {"uv": uv(c), "texture": "#fur"} for k, c in f.items()}}
if rot: el["rotation"] = {"angle": rot[0], "axis": rot[1], "origin": list(rot[2])}
return el
def jerboa(foot_l=(0, 0), foot_r=(0, 0), body_dy=0.0, body_dz=0.0, ear=0, tail_dy=0.0, pitch=0):
"""foot_* = (dz, dy): forward/back shift and lift of each hind foot. Returns the element list."""
e = []; B = body_dy
for sx, (dz, dy) in ((-1.55, foot_l), (1.55, foot_r)): # long hind legs: foot, shank, thigh
x = 8 + sx; zf = 4.8 + dz
e.append(box([x - .6, dy, zf], [x + .6, .7 + dy, zf + 4.8], top="foot", side="foot", bottom="claw", front="claw")) # long foot, toes toward -z
e.append(box([x - .45, .7 + dy, zf + 3.6], [x + .45, 5.9 + dy, zf + 4.6], side="leg", rot=(22.5, "x", (x, .7 + dy, zf + 4.1)))) # thin shank
e.append(box([x - .95, 4.6 + dy * .5, 6.2 + dz * .4], [x + .95, 8.0 + B, 9.4 + dz * .4], side="leg", front="leg")) # thigh
z0 = body_dz
e.append(box([5.8, 5.0 + B, 3.2 + z0], [10.2, 9.0 + B, 9.8 + z0], top="back", side="back", bottom="belly", front="back")) # body
e.append(box([6.2, 5.2 + B, 3.4 + z0], [9.8, 5.9 + B, 9.4 + z0], top="belly", side="belly", bottom="belly", front="belly")) # pale belly line
e.append(box([7.4, 9.0 + B, 4.4 + z0], [8.6, 9.2 + B, 9.0 + z0], top="dorsal", side="dorsal", bottom="dorsal", front="dorsal")) # dark dorsal stripe
for sx in (-1.55, 1.55): # tiny forelimbs held to the chest
e.append(box([8 + sx - .4, 3.9 + B, 3.0 + z0], [8 + sx + .4, 5.8 + B, 3.8 + z0], side="arm", front="arm"))
hy = 6.0 + B; hz = z0 # head, muzzle, nose
e.append(box([6.4, hy, 0.6 + hz], [9.6, hy + 3.3, 4.0 + hz], top="face", side="face", bottom="belly", front="face"))
e.append(box([7.15, hy + .4, -0.7 + hz], [8.85, hy + 2.0, 0.6 + hz], top="muzzle", side="muzzle", bottom="belly", front="muzzle"))
e.append(box([7.5, hy + 1.1, -0.95 + hz], [8.5, hy + 1.8, -0.7 + hz], side="nose", front="nose"))
for sx in (-1, 1): # big dark eyes and very large ears
ex = 8 + sx * 1.62
e.append(box([ex - (.2 if sx < 0 else .2), hy + 1.5, 1.4 + hz], [ex + (.2 if sx < 0 else .2), hy + 3.0, 2.7 + hz], side="eye", front="eye", top="eye", bottom="eye"))
o = (8 + sx * 1.3, hy + 3.2, 2.4 + hz)
e.append(box([o[0] - .55, o[1], o[2] - .4], [o[0] + .55, o[1] + 3.6, o[2] + .4], side="earout", front="earin", rot=(ear * sx, "z", (o[0], o[1], o[2]))))
e.append(box([o[0] - .35, o[1] + .2, o[2] - .45], [o[0] + .35, o[1] + 3.3, o[2] - .4], side="earin", front="earin", rot=(ear * sx, "z", (o[0], o[1], o[2]))))
ty = 5.4 + B + tail_dy # very long tail with a black band and a white tuft
e.append(box([7.6, ty, 9.4 + z0], [8.4, ty + .8, 15.2 + z0], top="tailbase", side="tailbase", bottom="tailbase", front="tailbase"))
e.append(box([7.4, ty - .1 + tail_dy * .2, 15.2 + z0], [8.6, ty + 1.0 + tail_dy * .2, 17.6 + z0], top="band", side="band", bottom="band", front="band"))
e.append(box([7.3, ty - .2 + tail_dy * .3, 17.6 + z0], [8.7, ty + 1.2 + tail_dy * .3, 19.8 + z0], top="tip", side="tip", bottom="tip", front="tip"))
return e
def curled():
e = [box([5.0, 0.2, 3.6], [11.0, 6.0, 10.4], top="back", side="back", bottom="belly", front="back"),
box([5.4, 0.1, 4.0], [10.6, 1.4, 10.0], top="belly", side="belly", bottom="belly", front="belly"),
box([6.3, 0.8, 1.9], [9.7, 4.0, 4.1], top="face", side="face", bottom="belly", front="face"),
box([7.2, 1.0, 1.2], [8.8, 2.4, 2.0], top="muzzle", side="muzzle", bottom="belly", front="muzzle"),
box([6.1, 2.3, 2.6], [6.4, 3.4, 3.7], side="eye", front="eye", top="eye", bottom="eye"), box([9.6, 2.3, 2.6], [9.9, 3.4, 3.7], side="eye", front="eye", top="eye", bottom="eye"),
box([6.0, 5.8, 3.7], [7.2, 6.2, 6.2], side="earout", top="earout", bottom="earin", front="earout"), box([8.8, 5.8, 3.7], [10.0, 6.2, 6.2], side="earout", top="earout", bottom="earin", front="earout"),
box([5.4, 0.2, 10.4], [10.6, 1.2, 11.2], top="tailbase", side="tailbase", bottom="tailbase", front="tailbase"),
box([5.0, 0.2, 7.0], [5.8, 1.2, 10.8], top="band", side="band", bottom="band", front="band"),
box([5.0, 0.2, 5.0], [5.8, 1.4, 7.0], top="tip", side="tip", bottom="tip", front="tip"),
box([5.4, 0.0, 6.0], [6.4, 0.7, 9.6], top="foot", side="foot", bottom="claw", front="claw"), box([9.6, 0.0, 6.0], [10.6, 0.7, 9.6], top="foot", side="foot", bottom="claw", front="claw")]
return e
def model(elements): return {"ambientocclusion": False, "textures": {"fur": "dunerealms:entity/jerboa", "particle": "#fur"}, "elements": elements}
MODELS = {
"jerboa": model(jerboa()), # alert: upright on both feet, ears up
"jerboa_walk_left": model(jerboa(foot_l=(-2.4, .9), foot_r=(1.0, 0), body_dy=.5, body_dz=-.3, ear=22.5, tail_dy=.5, pitch=1)), # hop: feet gathered forward
"jerboa_walk_right": model(jerboa(foot_l=(1.0, 0), foot_r=(-2.4, .9), body_dy=.5, body_dz=-.3, ear=22.5, tail_dy=.5, pitch=1)),
"jerboa_curled": model(curled()),
}
def write_json(path, obj): path.parent.mkdir(parents=True, exist_ok=True); path.write_text(json.dumps(obj, separators=(",", ":")))
tex = texture()
for name, m in MODELS.items():
write_json(ECO / "models" / f"{name}.json", m)
if (LEGACY / "models/entity").exists(): write_json(LEGACY / "models/entity" / f"{name}.json", m)
(ECO / "textures").mkdir(parents=True, exist_ok=True); tex.save(ECO / "textures/jerboa.png")
if (LEGACY / "textures/entity").exists(): tex.save(LEGACY / "textures/entity/jerboa.png")
print("wrote", len(MODELS), "models and the 64x64 atlas")