33 lines
1.1 KiB
Luau
33 lines
1.1 KiB
Luau
-- tools/fixtures/_obj_encode: run by tools/fixtures/obj.py (luau CLI, repo root): decodes every OBJ case with our
|
|
-- reader, encodes it again with our writer and prints "<file>\t<hex>" lines (the OBJ, its .mtl, textures) for the
|
|
-- reference tools (assimp, trimesh) to read back.
|
|
local Obj = require("@formats/model/obj")
|
|
local Bytes = require("@formats/core/Bytes")
|
|
local Cases = require("@tests/gen/obj_cases")
|
|
|
|
local HEX = {}
|
|
for i = 0, 255 do
|
|
HEX[i] = string.format("%02x", i)
|
|
end
|
|
local function hex(s: string): string
|
|
local out = table.create(#s)
|
|
for i = 1, #s do
|
|
out[i] = HEX[string.byte(s, i)]
|
|
end
|
|
return table.concat(out)
|
|
end
|
|
|
|
for _, c in Cases do
|
|
local scene, err = Obj.decode(Bytes.reader(buffer.fromstring(c.data)), { files = c.files })
|
|
if not scene then
|
|
error(c.name .. ": " .. tostring(err))
|
|
end
|
|
local name = "rt_" .. c.name
|
|
local files = {}
|
|
local out = assert(Obj.encode(scene, { name = name, files = files }))
|
|
print(name .. "\t" .. hex(buffer.tostring(out)))
|
|
for fname, data in files do
|
|
print(fname .. "\t" .. hex(if type(data) == "string" then data else buffer.tostring(data)))
|
|
end
|
|
end
|