# .blend fixtures (tools/fixtures.py): the same test scenes built by Blender 2.79, 2.93, 3.5, 4.1 (old nixpkgs # releases) and the current nixpkgs Blender (5.x) through tools/fixtures/_blend_make.py, covering every mesh storage # generation (MFace legacy save, MPoly / MLoop, attribute layers, AttributeStorage), gzip and zstd compression, the # 5.0 header, layered actions. Reference values come from the current Blender opening each file # (tools/fixtures/_blend_ref.py: bpy values plus its glTF exporter's output). An old Blender that does not run is # skipped (its cases are missing; the test notes it). # tests/gen/blend_.luau { { name, data, ref } } # tests/gen/blend_files.luau sibling files the scenes refer to ({ ["outside.png"] = bytes }) import json, os, shutil, subprocess, tempfile INPUTS = ["tools/fixtures/_blend_make.py", "tools/fixtures/_blend_ref.py"] OLD = [ ("279", ["--impure", "--expr", '(import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-19.03.tar.gz") {}).blender']), ("293", ["github:NixOS/nixpkgs/nixos-21.11#blender"]), ("35", ["github:NixOS/nixpkgs/nixos-23.05#blender"]), ("41", ["github:NixOS/nixpkgs/nixos-24.05#blender"]), ] def env(): e = dict(os.environ) e.pop("LD_LIBRARY_PATH", None) # the host's alsa / pipewire libraries need a newer glibc than old Blenders have return e def current(): exe = shutil.which("blender") return [exe] if exe else ["nix", "shell", "nixpkgs#blender", "-c", "blender"] def run(cmd, timeout=1800): try: res = subprocess.run(cmd, capture_output=True, timeout=timeout, env=env()) return res.returncode == 0, res.stdout.decode("utf-8", "replace") + res.stderr.decode("utf-8", "replace") except (subprocess.TimeoutExpired, OSError) as e: return False, str(e) def clean(v): if isinstance(v, dict): return {k: clean(x) for k, x in v.items() if x is not None} if isinstance(v, list): return [False if x is None else clean(x) for x in v] return v def generate(ctx): tmp = tempfile.mkdtemp(prefix="blendfx") make = os.path.join(ctx.root, "tools", "fixtures", "_blend_make.py") ref = os.path.join(ctx.root, "tools", "fixtures", "_blend_ref.py") made = {} for tag, inst in OLD + [("cur", None)]: out = os.path.join(tmp, tag) os.makedirs(out) if inst is None: cmd = current() else: cmd = ["nix", "shell"] + inst + ["-c", "blender"] ok, log = run(cmd + ["-b", "--factory-startup", "--python", make, "--", out]) files = sorted(f for f in os.listdir(out) if f.endswith(".blend")) if not ok or not files: print("blend: Blender %s did not run (skipped): %s" % (tag, log[-400:])) continue made[tag] = (out, files) paths = [os.path.join(out, f) for out, files in made.values() for f in files] refdir = os.path.join(tmp, "ref") os.makedirs(refdir) ok, log = run(current() + ["-b", "--factory-startup", "--python", ref, "--", json.dumps(paths), refdir], timeout=3600) if not ok: raise RuntimeError("blend: the reference Blender failed: " + log[-2000:]) sibling = None for tag, (out, files) in made.items(): cases = [] for f in files: p = os.path.join(out, f) r = json.load(open(os.path.join(refdir, f + ".json"))) g = r.get("gltf") if g: for k in ("bufferViews", "asset", "scene", "scenes", "extensionsUsed", "samplers"): g.pop(k, None) cases.append({"name": f, "data": open(p, "rb").read(), "ref": clean(r)}) name = "cur" if tag == "cur" else tag ctx.emit("blend_" + name, cases) if sibling is None and os.path.exists(os.path.join(out, "outside.png")): sibling = open(os.path.join(out, "outside.png"), "rb").read() for tag, _ in OLD + [("cur", None)]: if tag not in made: ctx.emit("blend_" + tag, []) ctx.emit("blend_files", {"outside.png": sibling or b""}) ctx.emit("blend_versions", sorted(made.keys())) shutil.rmtree(tmp, ignore_errors=True)