Files
rosetta/tests/model/robloxmesh_draco.luau
T

58 lines
2.4 KiB
Luau

-- model/robloxmesh with a Draco-compressed COREMESH (6.00 / 7.00, COREMESH v2): draco_encoder streams of a UV sphere
-- (normals, uvs) and a coloured PLY at three compression levels, wrapped in the chunk layout. Positions, normals,
-- uvs, colours and indices match libdraco's decode byte for byte, and the scene equals the decode of the same mesh
-- written with a plain COREMESH v1; corrupt streams fail without throwing (fuzz). Fixtures:
-- tools/fixtures/robloxmesh_draco.py.
local T = require("@tests/T")
local RobloxMesh = require("@rosetta/model/robloxmesh")
local Bytes = require("@rosetta/core/Bytes")
local Crc32 = require("@rosetta/core/Crc32")
local Cases = require("@tests/gen/robloxmesh_draco")
local t = T.suite("robloxmesh_draco")
local function decode(data: string): (any, any)
return RobloxMesh.decode(Bytes.reader(buffer.fromstring(data)))
end
local samples = {}
for _, c in Cases do
local scene, err = decode(c.data)
t:check(scene, c.name .. ": " .. tostring(err))
if scene then
t:check(scene.meta.source.draco == true, c.name .. ": meta.source.draco")
local prim = scene.meshes[1].primitives[1]
local a = prim.attributes
t:eq(a.POSITION.count, c.points, c.name .. ": vertices")
t:eq(prim.indices.count, c.faces * 3, c.name .. ": indices")
t:eq(Crc32.of(prim.indices.data), c.indices, c.name .. ": index CRC")
t:eq(Crc32.of(a.POSITION.data), c.pos, c.name .. ": positions")
if c.nrm then
t:eq(Crc32.of(a.NORMAL.data), c.nrm, c.name .. ": normals")
end
if c.uv then
t:eq(Crc32.of(a.TEXCOORD_0.data), c.uv, c.name .. ": uvs")
end
if c.col then
t:eq(Crc32.of(a.COLOR_0.data), c.col, c.name .. ": colours")
end
-- the same mesh as a plain COREMESH v1
local plain = assert(decode(c.plain))
local pp = plain.meshes[1].primitives[1]
for _, name in { "POSITION", "NORMAL", "TEXCOORD_0" } do
t:eq(Crc32.of(a[name].data), Crc32.of(pp.attributes[name].data), c.name .. ": " .. name .. " like COREMESH v1")
end
t:eq(Crc32.of(prim.indices.data), Crc32.of(pp.indices.data), c.name .. ": indices like COREMESH v1")
-- written back as 2.00 and read again
local back = assert(decode(buffer.tostring(assert(RobloxMesh.encode(scene)))))
t:eq(back.meshes[1].primitives[1].indices.count, c.faces * 3, c.name .. ": round trip")
if #c.data < 3000 then
table.insert(samples, c.data)
end
end
end
t:fuzz("decode", function(b: buffer)
return RobloxMesh.decode(Bytes.reader(b))
end, samples, { mutations = 12, keepHeader = 13 })
t:done()