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 -17
View File
@@ -1,9 +1,5 @@
-- model/3mf tests: the lib3mf test suite and SDK files, assimp's box.3mf and files from assimp's / trimesh's 3MF
-- exporters against lib3mf (world triangles, area, bounds through build items and components; unit), assimp and
-- trimesh; our writer's output read back by lib3mf / assimp / trimesh (3mf_xcheck); round trips through our own reader
-- (materials, vertex colours, textures, hierarchy, units); hand-written packages for per-corner colour / texture
-- groups, composite and multiproperties, components across model parts (p:path), units; error codes; the fuzz
-- no-throw pass. Fixtures: tools/fixtures/3mf.py.
-- model/3mf tests: lib3mf's suite and SDK files, assimp and trimesh exports, against lib3mf, assimp and trimesh.
-- Fixtures: tools/fixtures/3mf.py.
local T = require("@tests/T")
local ThreeMf = require("@rosetta/model/3mf")
local Bytes = require("@rosetta/core/Bytes")
@@ -28,7 +24,6 @@ local function near(a: number, b: number, eps: number): boolean
return math.abs(a - b) <= eps * math.max(1, math.abs(a), math.abs(b))
end
-- world-space triangles, area and bounds of every placed primitive
local function metrics(scene: any): (number, number, { number }, { number })
local tris, area = 0, 0
local lo, hi = { math.huge, math.huge, math.huge }, { -math.huge, -math.huge, -math.huge }
@@ -75,7 +70,6 @@ local function boundsNear(lo: { number }, hi: { number }, rmin: { number }, rmax
return true
end
-- ------------------------------------------------------------------------------------------------ reference files
local UNIT_NAMES = { micron = 1e-6, millimeter = 1e-3, centimeter = 1e-2, inch = 0.0254, foot = 0.3048, meter = 1 }
local refCount, rejectedOk, unsupported = 0, 0, 0
local byIndex = {}
@@ -115,7 +109,6 @@ for i, c in Cases do
end
t:note("%d files: %d against lib3mf, %d rejected by lib3mf (decoded without throwing), %d secure content (UNSUPPORTED)", #Cases, refCount, rejectedOk, unsupported)
-- ------------------------------------------------------------------------------------------------ our output read back
local xchecked, withTextures = 0, 0
for _, x in Xcheck do
local c = Cases[x.case]
@@ -159,7 +152,6 @@ for _, x in Xcheck do
end
t:note("%d of our files read back by lib3mf / assimp / trimesh like the originals (%d with textures)", xchecked, withTextures)
-- ------------------------------------------------------------------------------------------------ round trips (ours)
local rts = 0
for i, c in Cases do
local scene = byIndex[i]
@@ -173,7 +165,6 @@ for i, c in Cases do
t:eq(a2, a1, c.name .. ": round trip triangles")
t:check(near(b2, b1, 1e-6), c.name .. ": round trip area")
t:eq(back.meta.unit, scene.meta.unit, c.name .. ": round trip unit")
-- textures: the same bytes
local used = 0
for _, m in back.materials do
if m.baseColorTexture then
@@ -186,7 +177,6 @@ for i, c in Cases do
end
t:note("%d round trips through our writer", rts)
-- ------------------------------------------------------------------------------------------------ hand-written packages
local function package(model: string, extra: { [string]: string }?): buffer
local w = Zip.writer()
w:add("[Content_Types].xml", '<?xml version="1.0"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="model" ContentType="application/vnd.ms-package.3dmanufacturing-3dmodel+xml"/></Types>', { method = "store" })
@@ -232,7 +222,6 @@ do -- per-corner colours: vertex 0 has two different colours -> split
t:check(math.abs(col[8] - 128 / 255) < 1e-6, "colours: alpha kept linear")
t:eq(s.nodes[1].matrix[13], 10, "colours: transform tx")
t:eq(s.nodes[1].matrix[15], 30, "colours: transform tz")
-- through our writer and back: the same colours
local back = decode((ThreeMf.encode(s)))
local col2 = f32s(back.meshes[1].primitives[1].attributes.COLOR_0)
local same = #col2 == #col
@@ -285,7 +274,6 @@ do -- base materials, object defaults, composite, multiproperties, textures
t:eq(s.materials[prims[4].material].name, "half", "materials: multiproperties -> first layer")
t:eq(prims[4].indices.count, 6, "materials: multi and base 'half' share a primitive")
t:check(math.abs(s.materials[prims[4].material].baseColor[1] - half ^ 2.4) < 1e-6, "materials: sRGB -> linear")
-- round trip: texture + materials survive
local out = assert(ThreeMf.encode(s))
local back = assert(decode(out))
local tm = nil
@@ -375,7 +363,6 @@ do -- a Scene built by hand: strips, fans, polygons, vertex colours + texture co
t:check(select(2, ThreeMf.encode({} :: any)).code == Err.ARG, "encode: not a scene")
end
-- ------------------------------------------------------------------------------------------------ errors
do
local _, e1 = decode("not a zip at all")
t:check(e1 and e1.code ~= nil, "errors: not a zip")
@@ -395,13 +382,11 @@ do
t:eq(e6 and e6.code, Err.LIMIT, "errors: maxVertices")
table.insert(samples, package(bad))
table.insert(samples, package(cyc))
-- sniff
t:eq(ThreeMf.sniff(Bytes.reader(package(bad))), 0.95, "sniff: a 3MF package")
t:eq(ThreeMf.sniff(Bytes.reader((w:finish()))), 0, "sniff: another zip")
t:eq(ThreeMf.sniff(Bytes.reader(buffer.fromstring("solid x"))), 0, "sniff: not a zip")
end
-- ------------------------------------------------------------------------------------------------ fuzz
do
for _, c in Cases do
if #c.data < 20000 then