# VOX fixtures (tools/fixtures.py). There is no MagicaVoxel reader in nixpkgs, so the reference is (1) files saved by # MagicaVoxel itself (tests/fixtures/vox: ephtracy/voxel-model samples, version 150, and jpaver/opengametools demo files # with scene graphs, layers, materials, render objects, cameras, notes and META; licences in licenses/), parsed here # by an independent Python reader written from the spec, and (2) synthetic files written here with every chunk type, # rotations (including mirrors), nested groups, animation frames and odd cases. # tests/gen/vox_cases.luau { name, data, version, models = { { size, count, crc (of the dense x-fastest grid), # faces (exposed unit faces: the greedy mesh area) } }, paletteCrc, chunks = { id = n }, # nodes = { { name, world (row-major 3x4: R | t) } } for every shape node, names, layers, # materials, notes, cameras, robjs } import os, struct, zlib INPUTS = ["tests/fixtures/vox"] def default_palette(): steps = [0xff, 0xcc, 0x99, 0x66, 0x33, 0] pal = [(r, g, b, 255) for r in steps for g in steps for b in steps][:215] ramp = [0xee, 0xdd, 0xbb, 0xaa, 0x88, 0x77, 0x55, 0x44, 0x22, 0x11] for ch in range(3): for v in ramp: c = [0, 0, 0, 255] c[ch] = v pal.append(tuple(c)) pal += [(v, v, v, 255) for v in ramp] return pal def spec_palette(text): # the default_palette[256] array of the spec text (ABGR words, entry i = palette index i) body = text[text.index("default_palette[256]"):] body = body[body.index("{") + 1:body.index("}")] words = [int(w, 16) for w in body.replace(",", " ").split()] return [(w & 255, (w >> 8) & 255, (w >> 16) & 255, w >> 24) for w in words] # ---------------------------------------------------------------------------------------------- reader (reference) def rd_dict(d, p): n, = struct.unpack_from("> 2) & 3 i2 = 3 - i0 - i1 R = [[0] * 3 for _ in range(3)] for row, (i, bit) in enumerate(((i0, 4), (i1, 5), (i2, 6))): R[row][i] = -1 if b & (1 << bit) else 1 return R def matmul(A, B): # 3x4 affine (R | t) R = [[sum(A[r][k] * B[k][c] for k in range(3)) for c in range(3)] for r in range(3)] t = [sum(A[r][k] * B[k][3] for k in range(3)) + A[r][3] for r in range(3)] return [R[r] + [t[r]] for r in range(3)] def parse(d): assert d[:4] == b"VOX " version, = struct.unpack_from(" 1 else {}) for i, m in enumerate(models_))) def rgba(rng): return chunk("RGBA", bytes(rng.randrange(256) for _ in range(1024))) def synthetic(rng): out = [] # 1. a plain v150 model without a palette (the default palette) out.append(("syn-default-palette", vox(model(rng, 7, 5, 3), 150))) # 2. full scene: nested groups, every rotation family, mirrors, hidden, layers, materials, notes, cameras, IMAP, META ch = [] for _ in range(4): ch += model(rng, rng.randrange(1, 12), rng.randrange(1, 12), rng.randrange(1, 12)) ch += [ ntrn(0, 1, layer=-1), ngrp(1, [2, 4, 8]), ntrn(2, 3, {"_name": "a"}, [{"_r": "4", "_t": "1 2 3"}]), nshp(3, [0]), ntrn(4, 5, {"_name": "group", "_hidden": "1"}, [{"_r": "17", "_t": "-5 0 7"}], layer=1), # 90 deg about z ngrp(5, [6, 10]), ntrn(6, 7, {"_name": "b"}, [{"_r": "20", "_t": "0 0 -4"}]), # a mirror (x flipped) nshp(7, [1]), ntrn(8, 9, {"_name": "anim"}, [{"_r": "9", "_t": "3 3 3", "_f": "0"}, {"_r": "4", "_t": "4 4 4", "_f": "5"}]), nshp(9, [2, 3]), ntrn(10, 11, {"_name": "c"}, [{"_r": "98", "_t": "10 -20 30"}]), nshp(11, [3]), chunk("LAYR", struct.pack("