35 lines
1.3 KiB
Luau
35 lines
1.3 KiB
Luau
-- tools/fixtures/qb.py helper: our model/qb encoder's output for the reference reader there. Prints "<name>\t<hex>".
|
|
local Qb = require("@rosetta/model/qb")
|
|
local Bytes = require("@rosetta/core/Bytes")
|
|
local Types = require("@rosetta/Types")
|
|
local Fx = require("@tests/gen/qb")
|
|
|
|
local function hex(b: buffer): string
|
|
local t = table.create(buffer.len(b))
|
|
for i = 0, buffer.len(b) - 1 do
|
|
t[i + 1] = string.format("%02x", buffer.readu8(b, i))
|
|
end
|
|
return table.concat(t)
|
|
end
|
|
local function emit(name: string, b: buffer?, e: any)
|
|
if not b then
|
|
error(name .. ": " .. tostring(e))
|
|
end
|
|
print(name .. "\t" .. hex(b))
|
|
end
|
|
|
|
for _, c in Fx.cases do
|
|
local s = assert(Qb.decode(Bytes.reader(buffer.fromstring(c.data))))
|
|
emit(c.name .. "_same", Qb.encode(s))
|
|
emit(c.name .. "_flip", Qb.encode(s, { rightHanded = not c.rightHanded, compressed = not c.compressed, colorFormat = if c.colorFormat == "rgba" then "bgra" else "rgba" }))
|
|
end
|
|
-- a palette grid (no true colours) with a visibility mask computed by the encoder
|
|
local v = Types.Voxels.new(3, 3, 3)
|
|
v.palette[1] = { 200, 10, 10, 255 }
|
|
v.palette[2] = { 10, 200, 10, 255 }
|
|
for i = 0, 26 do
|
|
buffer.writeu8(v.data, i, if i == 13 then 2 elseif i % 2 == 0 then 1 else 0)
|
|
end
|
|
emit("palette_mask", Qb.encode(v, { visibilityMask = true }))
|
|
emit("palette_plain", Qb.encode(v))
|