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.
This commit is contained in:
1 parent
a43d81538e
commit
730820d1f6
9 files changed
+1620
-2
No files matched your search
@@ -0,0 +1,44 @@
|
||||
-- tools/fixtures/_ms3d_encode: run by tools/fixtures/ms3d.py (luau CLI, repo root): decodes every MS3D case and every
|
||||
-- glTF sample model with our readers and writes them with our MS3D writer, printing "<file>\t<hex>" lines for assimp
|
||||
-- to read back. Files: case_<i>.ms3d, gltf_<i>.ms3d.
|
||||
local Ms3d = require("@formats/model/ms3d")
|
||||
local Gltf = require("@formats/model/gltf")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Cases = require("@tests/gen/ms3d_cases")
|
||||
local Picks = require("@tests/gen/ms3d_gltf")
|
||||
|
||||
local HEX = {}
|
||||
for i = 0, 255 do
|
||||
HEX[i] = string.format("%02x", i)
|
||||
end
|
||||
local function hex(b: buffer): string
|
||||
local out = table.create(buffer.len(b))
|
||||
for i = 0, buffer.len(b) - 1 do
|
||||
out[i + 1] = HEX[buffer.readu8(b, i)]
|
||||
end
|
||||
return table.concat(out)
|
||||
end
|
||||
|
||||
local function emit(name: string, scene: any)
|
||||
local out, err = Ms3d.encode(scene)
|
||||
if out then
|
||||
print(name .. "\t" .. hex(out))
|
||||
else
|
||||
print("encode failed " .. name .. ": " .. tostring(err))
|
||||
end
|
||||
end
|
||||
|
||||
for i, c in Cases do
|
||||
local scene, err = Ms3d.decode(Bytes.reader(buffer.fromstring(c.data)))
|
||||
if scene then
|
||||
emit(string.format("case_%d.ms3d", i), scene)
|
||||
else
|
||||
print("skipped " .. c.name .. ": " .. tostring(err))
|
||||
end
|
||||
end
|
||||
for i, g in Picks do
|
||||
local scene = Gltf.decode(Bytes.reader(buffer.fromstring(g.data)), { files = g.files })
|
||||
if scene then
|
||||
emit(string.format("gltf_%d.ms3d", i), scene)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,68 @@
|
||||
# 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)
|
||||
Reference in new issue
Block a user