-- tools/fixtures/_stl_encode.luau: run by tools/fixtures/stl.py under the luau CLI (no file I/O): encodes the scenes of -- tests/gen/stl_scenes with every encoding they list and prints "/ " lines, which the fixture -- step hands to trimesh and assimp. local Stl = require("@formats/model/stl") local Types = require("@formats/Types") local Scenes = require("@tests/gen/stl_scenes") local function acc(s: string, t: string, comps: number, count: number): Types.Accessor return Types.Scene.accessor(buffer.fromstring(s), t, comps, count) end 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 prim: any = { attributes = { POSITION = acc(p.pos, p.posType or "f32", 3, p.count) }, mode = p.mode } if p.indices then prim.indices = acc(p.indices, "u32", 1, #p.indices // 4) end if p.faces then prim.faces = acc(p.faces, "u32", 1, #p.faces // 4) end if p.color then prim.attributes.COLOR_0 = acc(p.color, "unorm8", 4, p.count) end table.insert(prims, prim) end scene.meshes[i] = { name = m.name, primitives = prims } end for i, n in spec.nodes do scene.nodes[i] = { name = n.name, 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 } = { binary = {}, ascii = { ascii = true }, viscam = { colors = "viscam" }, magics = { colors = "magics" } } for _, spec in Scenes do local scene = build(spec) for _, e in spec.encodings do local b, err = Stl.encode(scene, OPTS[e]) if not b then error(spec.name .. "/" .. e .. ": " .. tostring(err)) end print(spec.name .. "/" .. e .. " " .. hex(b)) end end