Files
rosetta/tools/fixtures/_ms3d_encode.luau
T

45 lines
1.4 KiB
Luau

-- tools/fixtures/_ms3d_encode: run by tools/fixtures/ms3d.py (luau CLI, repo root): decodes every MS3D case and every
-- glTF sample model with our readers and writes them with our MS3D writer, printing "<file>\t<hex>" lines for assimp
-- to read back. Files: case_<i>.ms3d, gltf_<i>.ms3d.
local Ms3d = require("@rosetta/model/ms3d")
local Gltf = require("@rosetta/model/gltf")
local Bytes = require("@rosetta/core/Bytes")
local Cases = require("@tests/gen/ms3d_cases")
local Picks = require("@tests/gen/ms3d_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
local function emit(name: string, scene: any)
local out, err = Ms3d.encode(scene)
if out then
print(name .. "\t" .. hex(out))
else
print("encode failed " .. name .. ": " .. tostring(err))
end
end
for i, c in Cases do
local scene, err = Ms3d.decode(Bytes.reader(buffer.fromstring(c.data)))
if scene then
emit(string.format("case_%d.ms3d", i), scene)
else
print("skipped " .. c.name .. ": " .. tostring(err))
end
end
for i, g in Picks do
local scene = Gltf.decode(Bytes.reader(buffer.fromstring(g.data)), { files = g.files })
if scene then
emit(string.format("gltf_%d.ms3d", i), scene)
end
end