C2, the hierarchy (tools/move.py, every reference rewritten mechanically): - codecs/compress: Deflate Lzma Zstd Brotli Bzip2 Lzw; codecs/entropy: Huffman (from core) RangeCoder; codecs/image: Jpeg Dct Vp8 Vp8L Yuv Quantize Raster Blend Pixels; codecs/audio: Mdct Aac Alac Pcm Resample VorbisComment Tracker SoundFont Stream; codecs/video: H264 Mpeg1 Video; codecs/text: Json Xml Text Url; codecs/font: TrueType Cff; codecs/model: MeshFlatten Mat4. containers/ stays flat; core/ keeps Bytes Bits Err Crc32 Adler32 Base64 Md5 Input Sniff. - LAYERS lint: codecs must sit in a domain folder; gen_registry lists codecs by domain (docs/FORMATS.md). - Checked: build.py both targets, rojo build of build/roblox, the full suite on both runtimes. C3, generic code out of format folders: - containers/Chunks (new): the chunked-file walker (RIFF / RIFX / IFF / PNG / CAF layouts: endianness, size first, trailer, padding, lenient missing pad, open-ended ids, size hooks). containers/Riff walks with it (RF64 ds64 through the resize hook); image/png, audio/aiff and audio/caf list their chunk handlers over it. - codecs/audio/Stream (new): Stream.packets, the packet-decoder Decoder (read / seek with pre-roll / position, priming and end trimming) that aac, caf and m4a each carried (~70 lines each). - codecs/image/Pixels: image/bmp/Pixels promoted (+ rgb555); image/ico's DIB decoder uses its row loops instead of its own (the AND mask / alpha rule stay ICO's). - codecs/model/Mat4 (new): matrices / quaternions / TRS shared by FBX (Xform keeps only the FBX transform model), Collada (Math keeps only <lookat> / <skew>) and USD (its matrix helpers and general 4x4 inverse); Mat4.mul is Types.Scene.mul. The Collada normal matrix is now the inverse transpose (it was the inverse; same result for the fixtures' bind shapes). - README rewritten (install for Rojo and LÖVE / LuaJIT, quick start per category, F.* and F.ops, host notes: FORMATS_NO_JIT_TUNE, paths, layout); docs/STYLE.md: the codec domains, "what belongs in a format folder" with the shared building blocks and the DUP rule, conventions (WAVE order, lower-case tags, loops, the api hooks decodeImage / encodeImage / openAudio / plugins / resolve, the codecs/video/Video registry), Err.from, the type baseline. New tests: tests/containers/chunks, tests/codecs/mat4. Type baseline 93.
107 lines
5.4 KiB
Python
107 lines
5.4 KiB
Python
# Collada fixtures (tools/fixtures.py): assimp's Collada test models (read from the nixpkgs assimp source at fixture
|
|
# time, never committed: test/models/Collada, licences in that folder's licence.md), glTF sample models converted to
|
|
# .dae by assimp's Collada exporter (skins, animations, cameras, textures), with reference values from `assimp info -r`
|
|
# (meshes, faces, vertices, bounds, materials, animations, cameras, lights, bones). Blender 5 has no Collada support.
|
|
# tests/gen/dae_cases.luau { name, main, data, files = { name -> bytes }, assimp, gltf? + gltfFiles? (the original
|
|
# of an assimp export: the test compares skins and animations with it) }
|
|
# tests/gen/dae_xcheck.luau our encoder's .dae of every case (tools/fixtures/_dae_encode.luau) read back by assimp:
|
|
# { name, case, assimp }
|
|
import importlib.util, os, re, subprocess
|
|
|
|
INPUTS = ["src/Formats/model/dae", "src/Formats/codecs/text/Xml", "tools/fixtures/_model_ref.py", "tools/fixtures/_dae_encode.luau",
|
|
"tests/fixtures/gltf"]
|
|
|
|
|
|
def ref_module(ctx):
|
|
spec = importlib.util.spec_from_file_location("_model_ref", os.path.join(ctx.root, "tools", "fixtures", "_model_ref.py"))
|
|
m = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(m)
|
|
return m
|
|
|
|
|
|
def assimp_src():
|
|
out = subprocess.run(["nix", "build", "nixpkgs#assimp.src", "--no-link", "--print-out-paths"], capture_output=True, check=True)
|
|
return out.stdout.decode().strip().split("\n")[-1]
|
|
|
|
|
|
def info(ctx, M, path):
|
|
a = M.assimp_info(ctx, [path], raw=True)[0]
|
|
try:
|
|
txt = ctx.nix("assimp", ["assimp", "info", path, "-r"]).decode("utf-8", "replace")
|
|
except subprocess.CalledProcessError:
|
|
return {"failed": True}
|
|
for label in ("Animations", "Cameras", "Lights", "Bones", "Materials"):
|
|
m = re.search(r"^" + label + r":\s+(\d+)", txt, re.M)
|
|
if m:
|
|
a[label.lower()] = int(m.group(1))
|
|
# assimp's root node transform (its Collada importer bakes up axis / unit conversion into it): not reported by
|
|
# `assimp info`; the test applies the conversion itself
|
|
return a
|
|
|
|
|
|
IMAGE_EXT = (".jpg", ".jpeg", ".png", ".tga", ".bmp")
|
|
|
|
|
|
def generate(ctx):
|
|
M = ref_module(ctx)
|
|
src = os.path.join(assimp_src(), "test", "models", "Collada")
|
|
cases = []
|
|
images = {f: os.path.join(src, f) for f in sorted(os.listdir(src)) if f.lower().endswith(IMAGE_EXT)}
|
|
for f in sorted(os.listdir(src)):
|
|
if not (f.lower().endswith(".dae") or f.lower().endswith(".zae")) or "_triangulate" in f:
|
|
continue # the *_triangulate files are the same models again (fixture size)
|
|
path = os.path.join(src, f)
|
|
data = open(path, "rb").read()
|
|
files = {}
|
|
text = data.decode("latin-1")
|
|
for im, ip in images.items():
|
|
if im in text:
|
|
files[im] = open(ip, "rb").read()
|
|
cases.append({"name": "assimp/" + f, "main": f, "path": path, "files": files})
|
|
# glTF samples -> assimp's Collada exporter
|
|
tmp = M.tempdir()
|
|
groot = os.path.join(ctx.root, "tests", "fixtures", "gltf")
|
|
for model, variant, main in (("SimpleSkin", "glTF", "SimpleSkin.gltf"), ("RiggedSimple", "glTF-Binary", "RiggedSimple.glb"),
|
|
("BoxTextured", "glTF", "BoxTextured.gltf"), ("AnimatedTriangle", "glTF", "AnimatedTriangle.gltf"),
|
|
("Cameras", "glTF", "Cameras.gltf"), ("BoxVertexColors", "glTF-Binary", "BoxVertexColors.glb"),
|
|
("SimpleMeshes", "glTF", "SimpleMeshes.gltf"), ("InterpolationTest", "glTF-Binary", "InterpolationTest.glb"),
|
|
("MultiUVTest", "glTF-Binary", "MultiUVTest.glb")):
|
|
d = os.path.join(groot, model, variant)
|
|
if not os.path.exists(os.path.join(d, main)):
|
|
continue
|
|
out = os.path.join(tmp, model + ".dae")
|
|
try:
|
|
ctx.nix("assimp", ["assimp", "export", os.path.join(d, main), out, "-fcollada"])
|
|
except subprocess.CalledProcessError:
|
|
continue
|
|
files = {}
|
|
text = open(out, "rb").read().decode("latin-1")
|
|
for f in os.listdir(tmp):
|
|
if f.lower().endswith(IMAGE_EXT) and f in text:
|
|
files[f] = open(os.path.join(tmp, f), "rb").read()
|
|
for f in os.listdir(d):
|
|
if f.lower().endswith(IMAGE_EXT) and f in text:
|
|
files[f] = open(os.path.join(d, f), "rb").read()
|
|
orig = {f: open(os.path.join(d, f), "rb").read() for f in sorted(os.listdir(d)) if f != main}
|
|
cases.append({"name": "assimp-export/" + model, "main": model + ".dae", "path": out, "files": files,
|
|
"gltf": open(os.path.join(d, main), "rb").read(), "gltfFiles": orig})
|
|
for c in cases:
|
|
c["assimp"] = info(ctx, M, c["path"])
|
|
c["data"] = open(c["path"], "rb").read()
|
|
del c["path"]
|
|
ctx.emit("dae_cases", cases)
|
|
|
|
# assimp reads our output
|
|
ours = M.luau_encode(ctx, "tools/fixtures/_dae_encode.luau")
|
|
xtmp = M.tempdir()
|
|
names = []
|
|
for name, data in sorted(ours.items()):
|
|
with open(os.path.join(xtmp, name), "wb") as f:
|
|
f.write(data)
|
|
if name.endswith(".dae") or name.endswith(".zae"):
|
|
names.append(name)
|
|
out = []
|
|
for n in names:
|
|
out.append({"name": n, "case": int(n.split("_")[1].split(".")[0]), "assimp": info(ctx, M, os.path.join(xtmp, n))})
|
|
ctx.emit("dae_xcheck", out)
|