-- tools/fixtures/_off_encode.luau: run by tools/fixtures/off.py under the luau CLI (no file I/O): encodes the scenes of -- tests/gen/off_scenes with each listed option set ("default" = {}, "plain" = no colours / normals / texcoords) and -- prints "/ " lines, which the fixture step hands to trimesh, assimp and its own reader. local Off = require("@rosetta/model/off") local Types = require("@rosetta/Types") local Scenes = require("@tests/gen/off_scenes") local function build(spec: any): Types.Scene local scene = Types.Scene.new() for i, m in spec.meshes do local prims = {} for _, p in m.prims do local attrs = {} for name, a in p.attrs do attrs[name] = Types.Scene.accessor(buffer.fromstring(a[3]), a[1], a[2], p.count) end local prim: any = { attributes = attrs, mode = p.mode } if p.indices then prim.indices = Types.Scene.accessor(buffer.fromstring(p.indices), "u32", 1, #p.indices // 4) end if p.faces then prim.faces = Types.Scene.accessor(buffer.fromstring(p.faces), "u32", 1, #p.faces // 4) end if p.faceColors then prim.extras = { faceColors = Types.Scene.accessor(buffer.fromstring(p.faceColors), "unorm8", 4, #p.faceColors // 4) } end table.insert(prims, prim) end scene.meshes[i] = { primitives = prims } end for i, n in spec.nodes do scene.nodes[i] = { mesh = n.mesh, children = n.children or {}, translation = n.translation, rotation = n.rotation, scale = n.scale, matrix = n.matrix } end scene.roots = spec.roots return scene 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] = string.format("%02x", buffer.readu8(b, i)) end return table.concat(out) end local OPTS: { [string]: any } = { default = {}, plain = { colors = false, normals = false, texcoords = false } } for _, spec in Scenes do local scene = build(spec) for e in spec.encodings do local b, err = Off.encode(scene, OPTS[e]) if not b then error(spec.name .. "/" .. e .. ": " .. tostring(err)) end print(spec.name .. "/" .. e .. " " .. hex(b)) end end