58 lines
2.9 KiB
Python
58 lines
2.9 KiB
Python
# Inter-Quake Model fixtures (tools/fixtures.py): assimp's IQM test model (mrfixit.iqm, from the nixpkgs assimp
|
|
# source, never committed) with assimp's view of it (`assimp info -r`, PreTransformVertices bounds) and an independent
|
|
# Python reading (tools/fixtures/_iqm_reference.py: counts, and the bounds of the skinned vertices per frame computed
|
|
# from joints / poses / frames, next to the bounds block the IQM tool stored); glTF sample models (tests/fixtures/gltf)
|
|
# for the writer; then our encoder's output (tools/fixtures/_iqm_encode.luau) read back by assimp and the Python reader.
|
|
# tests/gen/iqm_cases.luau { name, data, assimp, ref }
|
|
# tests/gen/iqm_gltf.luau { name, data, files }
|
|
# tests/gen/iqm_xcheck.luau { name, assimp, ref }
|
|
import importlib.util, os
|
|
|
|
INPUTS = ["src/Rosetta/model/iqm", "src/Rosetta/codecs/model", "tools/fixtures/_model_ref.py", "tools/fixtures/fbx.py",
|
|
"tools/fixtures/_iqm_reference.py", "tools/fixtures/_iqm_encode.luau", "tests/fixtures/gltf"]
|
|
|
|
|
|
def module(ctx, name):
|
|
spec = importlib.util.spec_from_file_location(name, os.path.join(ctx.root, "tools", "fixtures", name + ".py"))
|
|
m = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(m)
|
|
return m
|
|
|
|
|
|
def info(ctx, M, fbx, path, tmp):
|
|
a = M.assimp_info(ctx, [path], raw=True)[0]
|
|
for k in ("min", "max", "perMesh"):
|
|
a.pop(k, None)
|
|
if not a.get("failed"):
|
|
a.update(fbx.ptv_bounds(ctx, path, tmp))
|
|
return a
|
|
|
|
|
|
def generate(ctx):
|
|
M = module(ctx, "_model_ref")
|
|
fbx = module(ctx, "fbx")
|
|
R = module(ctx, "_iqm_reference")
|
|
tmp = M.tempdir()
|
|
p = os.path.join(fbx.assimp_src(ctx), "test", "models", "IQM", "mrfixit.iqm")
|
|
data = open(p, "rb").read()
|
|
ctx.emit("iqm_cases", [{"name": "mrfixit.iqm", "data": data, "assimp": info(ctx, M, fbx, p, tmp), "ref": R.read(data)}])
|
|
gl = os.path.join(ctx.root, "tests", "fixtures", "gltf")
|
|
picks = []
|
|
for model in ("RiggedSimple", "SimpleSkin", "Box", "BoxTextured", "BoxVertexColors", "MeshPrimitiveModes", "SimpleMeshes"):
|
|
d0 = os.path.join(gl, model)
|
|
for variant in sorted(os.listdir(d0)) if os.path.isdir(d0) else []:
|
|
d = os.path.join(d0, variant)
|
|
mains = [f for f in sorted(os.listdir(d)) if f.endswith((".gltf", ".glb"))] if os.path.isdir(d) else []
|
|
if mains:
|
|
picks.append({"name": model, "data": open(os.path.join(d, mains[0]), "rb").read(),
|
|
"files": {f: open(os.path.join(d, f), "rb").read() for f in sorted(os.listdir(d)) if f != mains[0]}})
|
|
break
|
|
ctx.emit("iqm_gltf", picks)
|
|
ours = M.luau_encode(ctx, "tools/fixtures/_iqm_encode.luau")
|
|
out = []
|
|
for name in sorted(ours):
|
|
q = os.path.join(tmp, name)
|
|
open(q, "wb").write(ours[name])
|
|
out.append({"name": name, "assimp": info(ctx, M, fbx, q, tmp), "ref": R.read(ours[name])})
|
|
ctx.emit("iqm_xcheck", out)
|