Files

39 lines
1.3 KiB
Luau

-- tools/fixtures/_iqm_encode: run by tools/fixtures/iqm.py (luau CLI, repo root): writes mrfixit.iqm back through our
-- reader and writer, and every glTF pick through our writer, printing "<file>\t<hex>" lines for assimp and the
-- Python IQM reader. Files: rt_mrfixit.iqm, gltf_<name>.iqm.
local Iqm = require("@rosetta/model/iqm")
local Gltf = require("@rosetta/model/gltf")
local Bytes = require("@rosetta/core/Bytes")
local Cases = require("@tests/gen/iqm_cases")
local Picks = require("@tests/gen/iqm_gltf")
local HEX = {}
for i = 0, 255 do
HEX[i] = string.format("%02x", i)
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] = HEX[buffer.readu8(b, i)]
end
return table.concat(out)
end
for _, c in Cases do
local scene = assert(Iqm.decode(Bytes.reader(buffer.fromstring(c.data))))
print("rt_mrfixit.iqm\t" .. hex(assert(Iqm.encode(scene))))
end
for _, p in Picks do
local scene, err = Gltf.decode(Bytes.reader(buffer.fromstring(p.data)), { files = p.files })
if scene then
local out, e2 = Iqm.encode(scene)
if out then
print("gltf_" .. p.name .. ".iqm\t" .. hex(out))
else
print("encode failed " .. p.name .. ": " .. tostring(e2))
end
else
print("skipped " .. p.name .. ": " .. tostring(err))
end
end