ws-3d: model/obj (OBJ + MTL read/write: objects/groups -> nodes, per-material primitives, n-gons fan-triangulated or kept as polygons, vertex colours, lines/points, PBR MTL extension, texture maps with options, files through opts.files/resolve); tests vs assimp + trimesh, and assimp/trimesh reading our output
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
58f6b32541
commit
c3bbae0271
6 files changed
+1641
No files matched your search
@@ -0,0 +1,32 @@
|
||||
-- tools/fixtures/_obj_encode: run by tools/fixtures/obj.py (luau CLI, repo root): decodes every OBJ case with our
|
||||
-- reader, encodes it again with our writer and prints "<file>\t<hex>" lines (the OBJ, its .mtl, textures) for the
|
||||
-- reference tools (assimp, trimesh) to read back.
|
||||
local Obj = require("@formats/model/obj")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Cases = require("@tests/gen/obj_cases")
|
||||
|
||||
local HEX = {}
|
||||
for i = 0, 255 do
|
||||
HEX[i] = string.format("%02x", i)
|
||||
end
|
||||
local function hex(s: string): string
|
||||
local out = table.create(#s)
|
||||
for i = 1, #s do
|
||||
out[i] = HEX[string.byte(s, i)]
|
||||
end
|
||||
return table.concat(out)
|
||||
end
|
||||
|
||||
for _, c in Cases do
|
||||
local scene, err = Obj.decode(Bytes.reader(buffer.fromstring(c.data)), { files = c.files })
|
||||
if not scene then
|
||||
error(c.name .. ": " .. tostring(err))
|
||||
end
|
||||
local name = "rt_" .. c.name
|
||||
local files = {}
|
||||
local out = assert(Obj.encode(scene, { name = name, files = files }))
|
||||
print(name .. "\t" .. hex(buffer.tostring(out)))
|
||||
for fname, data in files do
|
||||
print(fname .. "\t" .. hex(if type(data) == "string" then data else buffer.tostring(data)))
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user