Files
rosetta/tools/fixtures/_ply_encode.luau
T

53 lines
1.8 KiB
Luau

-- tools/fixtures/_ply_encode.luau: run by tools/fixtures/ply.py under the luau CLI (no file I/O): encodes the scenes of
-- tests/gen/ply_scenes in the three encodings and prints "<scene>/<encoding> <hex>" lines, which the fixture step
-- hands to plyfile and assimp.
local Ply = require("@formats/model/ply")
local Types = require("@formats/Types")
local Scenes = require("@tests/gen/ply_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
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
for _, spec in Scenes do
local scene = build(spec)
for _, e in { "ascii", "binary_little_endian", "binary_big_endian" } do
local b, err = Ply.encode(scene, { format = e })
if not b then
error(spec.name .. "/" .. e .. ": " .. tostring(err))
end
print(spec.name .. "/" .. e .. " " .. hex(b))
end
end