Files
rosetta/tools/fixtures/ms3d.py
T
4DBug 730820d1f6 ws-3d3: model/ms3d (MilkShape 3D) read + write
Groups, materials (texture uri), joints -> nodes + skin + one animation,
version 4 sub-versioned blocks (comments, vertex extras with up to four
bones, joint colours, model extras). Writer: groups per placed primitive,
the first skin plus animated nodes as joints (rigid meshes bound to them),
weights in percent. Tested against assimp and through glTF skin models.
2026-10-31 14:33:46 -05:00

69 lines
3.2 KiB
Python

# MS3D fixtures (tools/fixtures.py): assimp's MilkShape 3D test models (test/models/MS3D: groups, materials, textures,
# version 4 with and without the sub-versioned blocks; read from the nixpkgs assimp source, never committed), with
# reference values from assimp (`assimp info -r`: meshes, faces, vertices, materials, animations, bones; world bounds
# from its PreTransformVertices export). No tool writes MS3D with joints, so skins and animation are checked through
# our writer: glTF sample models (skins, animation, textures) written by tools/fixtures/_ms3d_encode.luau and read
# back by assimp.
# tests/gen/ms3d_cases.luau { name, data, assimp }
# tests/gen/ms3d_gltf.luau glTF sample models: { name, data, files }
# tests/gen/ms3d_xcheck.luau { name, case? | gltf?, assimp }
import importlib.util, os
INPUTS = ["src/Formats/model/ms3d", "tests/fixtures/gltf", "tools/fixtures/_model_ref.py", "tools/fixtures/fbx.py",
"tools/fixtures/3ds.py", "tools/fixtures/_ms3d_encode.luau"]
def load(ctx, name):
spec = importlib.util.spec_from_file_location("_" + name.replace(".", "_"), os.path.join(ctx.root, "tools", "fixtures", name + ".py"))
m = importlib.util.module_from_spec(spec)
spec.loader.exec_module(m)
return m
GLTF = ("Box", "BoxTextured", "SimpleSkin", "RiggedSimple", "SimpleMeshes", "MultiUVTest", "NegativeScaleTest",
"AnimatedTriangle", "TextureCoordinateTest", "MeshPrimitiveModes")
def generate(ctx):
M = load(ctx, "_model_ref")
X = load(ctx, "fbx")
R = load(ctx, "3ds")
tmp = M.tempdir()
d = os.path.join(X.assimp_src(ctx), "test", "models", "MS3D")
cases = [{"name": "assimp/" + f, "path": os.path.join(d, f)} for f in sorted(os.listdir(d)) if f.lower().endswith(".ms3d")]
for c, a in zip(cases, R.reference(ctx, M, X, [c["path"] for c in cases], tmp)):
c["assimp"] = a
c["data"] = open(c["path"], "rb").read()
del c["path"]
ctx.emit("ms3d_cases", cases)
gl = os.path.join(ctx.root, "tests", "fixtures", "gltf")
picks = []
for model in GLTF:
d0 = os.path.join(gl, model)
if not os.path.isdir(d0):
continue
for variant in sorted(os.listdir(d0)):
dd = os.path.join(d0, variant)
mains = [f for f in sorted(os.listdir(dd)) if f.endswith(".gltf") or f.endswith(".glb")] if os.path.isdir(dd) else []
if mains:
picks.append({"name": model + "/" + variant, "data": open(os.path.join(dd, mains[0]), "rb").read(),
"files": {f: open(os.path.join(dd, f), "rb").read() for f in sorted(os.listdir(dd)) if f != mains[0]}})
break
ctx.emit("ms3d_gltf", picks)
ours = M.luau_encode(ctx, "tools/fixtures/_ms3d_encode.luau")
xtmp = M.tempdir()
names = sorted(n for n in ours if n.endswith(".ms3d"))
paths = []
for n in names:
p = os.path.join(xtmp, n)
with open(p, "wb") as f:
f.write(ours[n])
paths.append(p)
xs = []
for n, a in zip(names, R.reference(ctx, M, X, paths, xtmp)):
kind, idx = n[:-5].split("_")
e = {"name": n, "assimp": a}
e["case" if kind == "case" else "gltf"] = int(idx)
xs.append(e)
ctx.emit("ms3d_xcheck", xs)