#!/usr/bin/env python3 """Writes small PMX/PMD test models (and a checker texture) into tests/data. Geometry is authored in the viewer's right-handed space and converted to MMD's left-handed convention (z mirrored, triangle winding reversed) on write. """ import os import struct import zlib OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "tests", "data") RINGS = [0.0, 2.5, 5.0, 7.5, 10.0] CORNERS = [(1, 1), (-1, 1), (-1, -1), (1, -1)] # (x, z) counter-clockwise seen from +Y def column(): """Square column: 5 rings x 4 corners, outward faces CCW (right-handed).""" verts = [] for y in RINGS: for i, (x, z) in enumerate(CORNERS): verts.append(((x, y, z), (x * 0.7071, 0.0, z * 0.7071), (i / 4.0, y / 10.0))) tris = [] for r in range(len(RINGS) - 1): for i in range(4): a = r * 4 + i b = r * 4 + (i + 1) % 4 c = a + 4 d = b + 4 # Seen from outside: a (bottom), b (bottom, next corner), d, c (top) tris.append((a, c, b)) tris.append((b, c, d)) return verts, tris def lh(v): return (v[0], v[1], -v[2]) def write_png(path, size=8): rows = b"" for y in range(size): rows += b"\x00" for x in range(size): on = ((x // 2) + (y // 2)) % 2 == 0 rows += bytes((230, 60, 60, 255) if on else (240, 240, 240, 255)) def chunk(tag, data): return struct.pack(">I", len(data)) + tag + data + struct.pack(">I", zlib.crc32(tag + data) & 0xFFFFFFFF) png = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0)) png += chunk(b"IDAT", zlib.compress(rows)) + chunk(b"IEND", b"") with open(path, "wb") as f: f.write(png) def pmx_text(s): b = s.encode("utf-16-le") return struct.pack("