tests/model: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:50:23 -05:00
1 parent 5f7f6005f6
commit fe7566cbba
37 files changed
+72 -440

No files matched your search

+2 -15
View File
@@ -1,8 +1,5 @@
-- model/obj tests: OBJ / MTL files (materials and texture maps, objects and groups, n-gons, negative indices, vertex
-- colours, continuations, lines and points, a concave polygon, assimp's exporter output) against assimp (meshes,
-- vertices, faces, bounds, materials) and trimesh (area, triangles); MTL mapping; ear clipping (MeshOps) against the
-- exact polygon area; round trips through the writer, and assimp / trimesh reading our output (obj_xcheck); errors;
-- the fuzz no-throw pass. Fixtures: tools/fixtures/obj.py.
-- model/obj tests: OBJ / MTL files against assimp and trimesh; ear clipping against the exact polygon area.
-- Fixtures: tools/fixtures/obj.py.
local T = require("@tests/T")
local Obj = require("@rosetta/model/obj")
local MeshOps = require("@rosetta/ops/MeshOps")
@@ -87,7 +84,6 @@ for _, c in Cases do
if #scene.materials > 0 then
t:eq(#scene.materials, c.assimp.materials, c.name .. ": materials (assimp)")
end
-- round trip through our writer
local files = {}
local out, eerr = Obj.encode(scene, { name = "rt.obj", files = files })
t:check(out, c.name .. ": encode: " .. tostring(eerr))
@@ -110,7 +106,6 @@ for _, c in Cases do
t:eq(#back.materials, #scene.materials, c.name .. ": round trip materials")
end
-- the reference tools read our output like the original
for _, x in Xcheck do
local orig = byName[string.sub(x.name, 4)]
t:check(orig ~= nil, x.name .. ": a case")
@@ -128,7 +123,6 @@ for _, x in Xcheck do
end
t:note("%d files match assimp / trimesh; %d of our files read back by assimp / trimesh", #Cases, #Xcheck)
-- the cube in detail: nodes, materials, textures
do
local c = byName["cube.obj"]
local s = decode(c.data, { files = c.files })
@@ -146,7 +140,6 @@ do
t:check(red.extras.obj.values.Ns[1] == 50 and red.extras.obj.values.illum[1] == 2, "Phong values in extras")
t:check(blue.baseColor[4] == 0.5 and blue.alphaMode == "blend" and blue.roughness == 0.25 and blue.metallic == 1 and blue.emissive[3] == 0.3, "blue: d, Pr, Pm, Ke")
t:check(s.nodes[root.children[1]].extras.obj.smoothing == "1", "smoothing group kept")
-- the uv flip
local top = s.meshes[s.nodes[root.children[1]].mesh].primitives[1]
t:check(top.attributes.TEXCOORD_0 ~= nil and buffer.readf32(top.attributes.TEXCOORD_0.data, 4) == 1, "vt 0 0 -> (0, 1) (top-left origin)")
local s2 = decode(c.data, { files = c.files, flipV = false })
@@ -155,7 +148,6 @@ do
-- without the MTL: named default materials, the library listed as missing
local s3 = decode(c.data)
t:check(#s3.materials == 2 and s3.meta.source.missingMtl[1] == "cube.mtl", "missing mtllib")
-- through opts.mtl / resolve
local s4 = decode(c.data, { mtl = c.files["cube.mtl"] })
t:check(s4.materials[1].baseColor[1] == 1 and s4.textures[1].data == nil, "opts.mtl (texture bytes not found)")
local asked = {}
@@ -164,7 +156,6 @@ do
return c.files[uri]
end })
t:check(s5.materials[2].baseColor[4] == 0.5 and table.find(asked, "cube.mtl") and table.find(asked, "textures/tex.png"), "opts.resolve")
-- the MTL written back keeps the maps and their options
local files = {}
Obj.encode(s, { name = "x.obj", files = files })
local mtl = files["x.mtl"]
@@ -183,14 +174,12 @@ do
t:check(near(triArea(tri), c.polygonArea, 1e-9), "ear clipping area " .. triArea(tri) .. " = " .. c.polygonArea)
local fan = MeshOps.triangulate(p, { method = "fan" }) :: any
t:check(near(triArea(fan), c.trimesh.area, 1e-9), "fan area = trimesh's (fan) area")
-- n-gons written as n-gons
local out = Obj.encode(s) :: buffer
t:check(string.find(buffer.tostring(out), "\nf 7 8 9 10 11 12 13 14", 1, true) ~= nil, "an octagon written as one face")
local back = decode(out, { triangulate = false })
t:eq(back.meshes[1].primitives[1].faces.count, 2, "polygons round trip")
end
-- lines and points
do
local s = decode(byName["wire.obj"].data)
local modes = {}
@@ -200,7 +189,6 @@ do
t:check(modes.lines and modes.lines.indices.count == 8 and modes.points and modes.triangles, "l (polyline -> 4 segments), p, f")
end
-- errors
do
local _, e = decode("v 0 0 0\nf 1 2 3\n")
t:check(e and e.code == Err.CORRUPT, "index out of range: " .. tostring(e))
@@ -216,7 +204,6 @@ do
t:check(empty and #empty.nodes == 0, "an empty file is an empty scene")
end
-- fuzz
do
local samples = {}
for _, c in Cases do