Files
rosetta/tests/model/robloxmesh_draco.luau

54 lines
2.1 KiB
Luau

-- model/robloxmesh Draco COREMESH v2 tests: draco_encoder streams against libdraco's decode, byte for byte.
-- 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")
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()