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

+3 -27
View File
@@ -1,10 +1,5 @@
-- model/usda tests: stages authored with OpenUSD's API (every xform op kind / order, pivots, resetXformStack,
-- primvar interpolations, holes, leftHanded, n-gons, UsdPreviewSurface networks, GeomSubsets, inherited bindings,
-- cameras, lights, time samples, a USDZ package, a USDC file), a hand-written grammar test, assimp's USD models
-- (usda + usdc converted by Sdf), Blender 5 exports of glTF samples - all against OpenUSD (pxr: world transforms,
-- triangles, area and bounds per mesh, bound materials, PreviewSurface inputs and textures, cameras, lights, xform time
-- samples); OpenUSD's schema layers parse-only (prim spec counts); round trips through our writer (stable text) and
-- pxr reading our output (usda_xcheck); the api; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/usda.py.
-- model/usda tests: OpenUSD-authored stages, assimp's USD models and Blender exports against OpenUSD (pxr).
-- Fixtures: tools/fixtures/usda.py.
local T = require("@tests/T")
local F = require("@rosetta")
local Usda = require("@rosetta/model/usda")
@@ -42,8 +37,6 @@ local function nearAll(a: { number }, b: { number }, eps: number): boolean
return true
end
-- ------------------------------------------------------------------------------------------------ scene helpers
-- a node's channels evaluated at time s (seconds): translation / rotation / scale overrides
local function animated(scene: any, s: number?): { [number]: any }
local out: { [number]: any } = {}
if not s then
@@ -79,7 +72,6 @@ local function animated(scene: any, s: number?): { [number]: any }
return out
end
-- world matrices of every node (at animation time s when given)
local function worlds(scene: any, s: number?): { [number]: { number } }
local over = animated(scene, s)
local out: { [number]: { number } } = {}
@@ -118,7 +110,6 @@ local function byPath(scene: any): { [string]: number }
return out
end
-- triangles, world area and bounds of a node's mesh (or of everything: node = nil)
local function geometry(scene: any, ws: { [number]: { number } }, only: number?): (number, number, { number }, { number })
local tris, area = 0, 0
local lo, hi = { math.huge, math.huge, math.huge }, { -math.huge, -math.huge, -math.huge }
@@ -152,7 +143,6 @@ local function geometry(scene: any, ws: { [number]: { number } }, only: number?)
return tris, area, lo, hi
end
-- pxr's totals over every mesh
local function refTotals(ref: 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 }
@@ -172,7 +162,6 @@ end
local LIGHT_TYPES = { DistantLight = "directional", SphereLight = "point", RectLight = "spot", DiskLight = "spot" }
local SKIP_TYPES = { Skeleton = true, SkelRoot = true }
-- ------------------------------------------------------------------------------------------------ against pxr
local decoded: { [number]: any } = {}
local counts = { xforms = 0, meshes = 0, materials = 0, cameras = 0, lights = 0, samples = 0, textures = 0 }
for ci, c in Cases do
@@ -206,7 +195,6 @@ for ci, c in Cases do
end
end
end
-- meshes
for _, m in ref.meshes do
local ni = paths[m.path]
local node = ni and scene.nodes[ni]
@@ -236,7 +224,6 @@ for ci, c in Cases do
counts.meshes += 1
end
end
-- cameras
for _, cam in ref.cameras do
local ni = paths[cam.path]
local camera = ni and scene.nodes[ni].camera and scene.cameras[scene.nodes[ni].camera]
@@ -252,7 +239,6 @@ for ci, c in Cases do
counts.cameras += 1
end
end
-- lights
for _, l in ref.lights do
local ni = paths[l.path]
local light = ni and scene.nodes[ni].light and scene.lights[scene.nodes[ni].light]
@@ -267,7 +253,6 @@ for ci, c in Cases do
counts.lights += 1
end
end
-- materials
local mats = {}
for _, m in scene.materials do
if m.extras and m.extras.usd and m.extras.usd.path then
@@ -311,7 +296,6 @@ for ci, c in Cases do
counts.materials += 1
end
end
-- xform time samples
for _, a in ref.anim do
local ni = paths[a.path]
for _, smp in a.samples do
@@ -330,7 +314,6 @@ for ci, c in Cases do
end
t:note("%d files against pxr: %d transforms, %d meshes, %d materials (%d textures), %d cameras, %d lights, %d time samples", #Cases, counts.xforms, counts.meshes, counts.materials, counts.textures, counts.cameras, counts.lights, counts.samples)
-- ------------------------------------------------------------------------------------------------ specific facts
do
local hand
for ci, c in Cases do
@@ -382,7 +365,6 @@ do
end
end
-- ------------------------------------------------------------------------------------------------ parse-only
for _, s in Specs do
local layer, err = Usda.parse(s.data)
t:check(layer, s.name .. ": parse: " .. tostring(err))
@@ -400,7 +382,6 @@ for _, s in Specs do
end
t:note("%d OpenUSD schema layers parsed", #Specs)
-- ------------------------------------------------------------------------------------------------ round trips
local rt = 0
local texts: { [number]: string } = {}
for ci = 1, #Cases do
@@ -440,8 +421,7 @@ for ci = 1, #Cases do
t:check(near(x2, y2, 1e-4) and nearAll(x3, y3, 1e-4), string.format("%s: round trip animation at %g s", name, s))
end
end
-- our text is stable: after one cycle (a scene with several roots gains a "root" prim), writing what we
-- read from our own output gives the same text
-- a scene with several roots gains a "root" prim on the first cycle; after that our text is stable
local again = Usda.encode(back, { files = {}, name = "rt.usda" }) :: buffer
local third = Usda.encode((decode(again)), { files = {}, name = "rt.usda" }) :: buffer
t:eq(buffer.tostring(third), buffer.tostring(again), name .. ": stable text")
@@ -451,7 +431,6 @@ for ci = 1, #Cases do
end
t:note("%d round trips", rt)
-- ------------------------------------------------------------------------------------------------ pxr reads our output
local xc = 0
for _, x in Xcheck do
local scene = decoded[x.case]
@@ -500,7 +479,6 @@ for _, x in Xcheck do
end
t:note("%d of our files read back by pxr like the originals", xc)
-- ------------------------------------------------------------------------------------------------ api
do
local scene, err = F.model.load(Cases[1].data)
t:check(scene and scene.meta.source.format == "usda", "api: F.model.load sniffs usda: " .. tostring(err))
@@ -511,7 +489,6 @@ do
t:eq(F.detect(Cases[1].data), "usda", "api: detect")
end
-- ------------------------------------------------------------------------------------------------ errors
do
local _, e1 = decode("#usda 1.0\ndef Xform \"a\" {\n")
t:check(e1 and e1.code == Err.TRUNCATED, "truncated prim: " .. tostring(e1))
@@ -530,7 +507,6 @@ do
t:check(e7 and e7.code == Err.CORRUPT, "nesting limit")
end
-- ------------------------------------------------------------------------------------------------ fuzz
local samples = {}
for _, c in Cases do
if #c.data < 40000 then