merge ws/3d3-mesh

This commit is contained in:
4DBug committed 2026-10-31 16:16:07 -05:00
commit d2727aeab0
7 files changed
+291 -36

No files matched your search

+3 -2
View File
@@ -1,7 +1,7 @@
-- model/robloxmesh tests: meshes of every version written by the fixture's spec writer (1.00 / 1.01 ASCII, 2.00 with
-- 36- and 40-byte vertices, 3.00 / 3.01 LODs, 4.00 / 4.01 / 5.00 skinned with one and several subsets, 5.00 FACS,
-- 6.00 / 7.00 chunked) decode to the values they were written from (attribute CRCs, LOD index CRCs, global joints and
-- weights, bone names / parents / world transforms, FACS, raw chunks); a Draco COREMESH is UNSUPPORTED; our 2.00 /
-- weights, bone names / parents / world transforms, FACS, raw chunks); a COREMESH v2 that is not a Draco stream is CORRUPT; our 2.00 /
-- 4.00 output read back by the fixture's reader (verdicts); round trips; errors and the fuzz pass.
-- Fixtures: tools/fixtures/robloxmesh.py.
local T = require("@tests/T")
@@ -45,7 +45,8 @@ local ncases = 0
for _, c in Fx.cases do
local scene, err = decode(c.data)
if c.unsupported then
t:check(scene == nil and err and err.code == Err.UNSUPPORTED, c.name .. ": unsupported (" .. tostring(err) .. ")")
-- a COREMESH v2 whose body is not a Draco stream (real Draco meshes: tests/model/robloxmesh_draco.luau)
t:check(scene == nil and err and err.code == Err.CORRUPT, c.name .. ": not Draco data (" .. tostring(err) .. ")")
continue
end
t:check(scene ~= nil, c.name .. ": " .. tostring(err))
+57
View File
@@ -0,0 +1,57 @@
-- 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("@formats/model/robloxmesh")
local Bytes = require("@formats/core/Bytes")
local Crc32 = require("@formats/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()