merge ws/3d3-a (model/3ds, model/ms3d)
This commit is contained in:
commit
feb8d18cfb
16 files changed
+4539
-4
No files matched your search
@@ -0,0 +1,101 @@
|
||||
# 3DS fixtures (tools/fixtures.py): assimp's 3DS test models (test/models/3DS and test/models-nonbsd/3DS: meshes,
|
||||
# materials, textures, keyframer hierarchies, pivots, rotation / camera / target animation, cameras, lights; read from
|
||||
# the nixpkgs assimp source, never committed) and files written by assimp's 3DS exporter from glTF sample models, with
|
||||
# reference values from assimp (`assimp info -r`: meshes, faces, vertices, materials, animations, cameras, lights,
|
||||
# nodes; world bounds from its PreTransformVertices export). Then our encoder's output (tools/fixtures/_3ds_encode.luau,
|
||||
# from every case and the glTF models) read back by assimp. (Blender 5's 3DS importer is an extension that is not
|
||||
# installed by default, so assimp is the only reference.)
|
||||
# tests/gen/3ds_cases.luau { name, data, assimp }
|
||||
# tests/gen/3ds_gltf.luau glTF sample models for the writer round trips: { name, data, files }
|
||||
# tests/gen/3ds_xcheck.luau { name, case? | gltf?, assimp }
|
||||
import importlib.util, os
|
||||
|
||||
INPUTS = ["src/Formats/model/3ds", "tests/fixtures/gltf", "tools/fixtures/_model_ref.py", "tools/fixtures/fbx.py",
|
||||
"tools/fixtures/_3ds_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", "BoxVertexColors", "Cameras", "SimpleMeshes", "RiggedSimple", "SimpleSkin", "MultiUVTest",
|
||||
"NegativeScaleTest", "PointLightIntensityTest", "AnimatedTriangle", "TextureCoordinateTest", "TextureTransformTest",
|
||||
"InterpolationTest", "LightVisibility")
|
||||
|
||||
|
||||
def reference(ctx, M, X, paths, tmp):
|
||||
out = []
|
||||
for p, a in zip(paths, M.assimp_info(ctx, paths, raw=True)):
|
||||
a.update(X.assimp_extra(ctx, p))
|
||||
a.pop("min", None)
|
||||
a.pop("max", None)
|
||||
a.pop("perMesh", None)
|
||||
if not a.get("failed"):
|
||||
a.update(X.ptv_bounds(ctx, p, tmp))
|
||||
out.append(a)
|
||||
return out
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
M = load(ctx, "_model_ref")
|
||||
X = load(ctx, "fbx")
|
||||
tmp = M.tempdir()
|
||||
src = X.assimp_src(ctx)
|
||||
cases = []
|
||||
for sub in ("models", "models-nonbsd"):
|
||||
d = os.path.join(src, "test", sub, "3DS")
|
||||
for f in sorted(os.listdir(d)):
|
||||
if f.lower().endswith(".3ds"):
|
||||
cases.append({"name": "assimp/%s/%s" % (sub, f), "path": os.path.join(d, f)})
|
||||
# assimp's exporter
|
||||
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)):
|
||||
d = os.path.join(d0, variant)
|
||||
if not os.path.isdir(d):
|
||||
continue
|
||||
mains = [f for f in sorted(os.listdir(d)) if f.endswith(".gltf") or f.endswith(".glb")]
|
||||
if not mains:
|
||||
continue
|
||||
main = os.path.join(d, mains[0])
|
||||
picks.append({"name": model + "/" + variant, "data": open(main, "rb").read(),
|
||||
"files": {f: open(os.path.join(d, f), "rb").read() for f in sorted(os.listdir(d)) if f != mains[0]}})
|
||||
out = os.path.join(tmp, model + ".3ds")
|
||||
try:
|
||||
ctx.nix("assimp", ["assimp", "export", main, out, "-f3ds"])
|
||||
cases.append({"name": "assimp-export/" + model + ".3ds", "path": out})
|
||||
except Exception:
|
||||
pass
|
||||
break
|
||||
refs = reference(ctx, M, X, [c["path"] for c in cases], tmp)
|
||||
for c, a in zip(cases, refs):
|
||||
c["assimp"] = a
|
||||
c["data"] = open(c["path"], "rb").read()
|
||||
del c["path"]
|
||||
ctx.emit("3ds_cases", cases)
|
||||
ctx.emit("3ds_gltf", picks)
|
||||
|
||||
# assimp reads our files
|
||||
ours = M.luau_encode(ctx, "tools/fixtures/_3ds_encode.luau")
|
||||
xtmp = M.tempdir()
|
||||
names = sorted(n for n in ours if n.endswith(".3ds"))
|
||||
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, reference(ctx, M, X, paths, xtmp)):
|
||||
kind, idx = n[:-4].split("_")
|
||||
e = {"name": n, "assimp": a}
|
||||
e["case" if kind == "case" else "gltf"] = int(idx)
|
||||
xs.append(e)
|
||||
ctx.emit("3ds_xcheck", xs)
|
||||
@@ -0,0 +1,44 @@
|
||||
-- tools/fixtures/_3ds_encode: run by tools/fixtures/3ds.py (luau CLI, repo root): decodes every 3DS case and every
|
||||
-- glTF sample model with our readers and writes them with our 3DS writer, printing "<file>\t<hex>" lines for assimp
|
||||
-- to read back. Files: case_<i>.3ds, gltf_<i>.3ds.
|
||||
local ThreeDs = require("@formats/model/3ds")
|
||||
local Gltf = require("@formats/model/gltf")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Cases = require("@tests/gen/3ds_cases")
|
||||
local Picks = require("@tests/gen/3ds_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 = ThreeDs.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 = ThreeDs.decode(Bytes.reader(buffer.fromstring(c.data)))
|
||||
if scene then
|
||||
emit(string.format("case_%d.3ds", 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.3ds", i), scene)
|
||||
end
|
||||
end
|
||||
@@ -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