Groups, materials (texture uri), joints -> nodes + skin + one animation, version 4 sub-versioned blocks (comments, vertex extras with up to four bones, joint colours, model extras). Writer: groups per placed primitive, the first skin plus animated nodes as joints (rigid meshes bound to them), weights in percent. Tested against assimp and through glTF skin models.
45 lines
1.4 KiB
Luau
45 lines
1.4 KiB
Luau
-- tools/fixtures/_ms3d_encode: run by tools/fixtures/ms3d.py (luau CLI, repo root): decodes every MS3D case and every
|
|
-- glTF sample model with our readers and writes them with our MS3D writer, printing "<file>\t<hex>" lines for assimp
|
|
-- to read back. Files: case_<i>.ms3d, gltf_<i>.ms3d.
|
|
local Ms3d = require("@formats/model/ms3d")
|
|
local Gltf = require("@formats/model/gltf")
|
|
local Bytes = require("@formats/core/Bytes")
|
|
local Cases = require("@tests/gen/ms3d_cases")
|
|
local Picks = require("@tests/gen/ms3d_gltf")
|
|
|
|
local HEX = {}
|
|
for i = 0, 255 do
|
|
HEX[i] = string.format("%02x", i)
|
|
end
|
|
local function hex(b: buffer): string
|
|
local out = table.create(buffer.len(b))
|
|
for i = 0, buffer.len(b) - 1 do
|
|
out[i + 1] = HEX[buffer.readu8(b, i)]
|
|
end
|
|
return table.concat(out)
|
|
end
|
|
|
|
local function emit(name: string, scene: any)
|
|
local out, err = Ms3d.encode(scene)
|
|
if out then
|
|
print(name .. "\t" .. hex(out))
|
|
else
|
|
print("encode failed " .. name .. ": " .. tostring(err))
|
|
end
|
|
end
|
|
|
|
for i, c in Cases do
|
|
local scene, err = Ms3d.decode(Bytes.reader(buffer.fromstring(c.data)))
|
|
if scene then
|
|
emit(string.format("case_%d.ms3d", i), scene)
|
|
else
|
|
print("skipped " .. c.name .. ": " .. tostring(err))
|
|
end
|
|
end
|
|
for i, g in Picks do
|
|
local scene = Gltf.decode(Bytes.reader(buffer.fromstring(g.data)), { files = g.files })
|
|
if scene then
|
|
emit(string.format("gltf_%d.ms3d", i), scene)
|
|
end
|
|
end
|