model formats (mca..x3d): comments are specs only

This commit is contained in:
4DBug committed 2026-11-01 01:54:32 -05:00
1 parent 0bd7b87d2b
commit b952c10222
49 files changed
+310 -936

No files matched your search

+2 -11
View File
@@ -1,8 +1,6 @@
--!strict
-- model/obj/Mtl: Wavefront .mtl material libraries (Paul Bourke's MTL spec + the common PBR extension: Pr, Pm, Ps, Pc,
-- Pcr, aniso, anisor, Ke, map_Pr, map_Pm, map_Ke, norm). parse(text) -> { name -> { statement -> values } } keeping
-- every statement; toMaterial maps one onto the Scene Material (glTF PBR, Phong values in extras.obj); write is the
-- reverse (from extras.obj when present, else from the PBR fields).
-- model/obj/Mtl: Wavefront .mtl (Paul Bourke's MTL spec + the PBR extension: Pr, Pm, Ps, Pc, Pcr, aniso, anisor, Ke,
-- map_Pr, map_Pm, map_Ke, norm); Phong values are kept in extras.obj.
local Types = require("@rosetta/Types")
local Mtl = {}
@@ -35,7 +33,6 @@ local function parseMap(args: { string }): Map
end
end
else
-- -o / -s / -t: up to three numbers
while i <= #args and #vals < 3 and tonumber(args[i]) ~= nil and i < #args do
table.insert(vals, args[i])
i += 1
@@ -48,7 +45,6 @@ local function parseMap(args: { string }): Map
return { file = file, options = opts }
end
-- parse(text) -> { Entry } in file order
function Mtl.parse(text: string): { Entry }
local out: { Entry } = {}
local cur: Entry? = nil
@@ -96,7 +92,6 @@ function Mtl.mime(file: string): string?
return if ext then MIME[string.lower(ext)] else nil
end
-- toMaterial(entry, texture) -> Material: texture(map) returns the scene texture index for a map
function Mtl.toMaterial(e: Entry, texture: (Map) -> number): Types.Material
local m = Types.Scene.material(e.name)
local v = e.values
@@ -144,7 +139,6 @@ function Mtl.toMaterial(e: Entry, texture: (Map) -> number): Types.Material
if m.emissiveTexture and not ke then
m.emissive = { 1, 1, 1 }
end
-- everything else as it was, for the writer and for Phong renderers
local extra: { [string]: any } = {}
for k, vals in v do
extra[k] = vals
@@ -171,7 +165,6 @@ local function num(v: number): string
end
Mtl.num = num
-- write(materials, name, textureFile) -> MTL text. textureFile(index) -> the file name a map refers to.
function Mtl.write(materials: { Types.Material }, names: { string }, textureFile: (number) -> string?): string
local out = { "# written by rosetta" }
for i, m in materials do
@@ -190,7 +183,6 @@ function Mtl.write(materials: { Types.Material }, names: { string }, textureFile
end
order = table.clone(saved.order or {})
end
-- the PBR fields win over the saved Phong values they map to
local bc = m.baseColor or { 1, 1, 1, 1 }
values.Kd = { bc[1], bc[2], bc[3] }
if (bc[4] or 1) < 1 or values.d then
@@ -235,7 +227,6 @@ function Mtl.write(materials: { Types.Material }, names: { string }, textureFile
setMap("norm", m.normalTexture)
end
setMap("map_ORM", m.metallicRoughnessTexture)
-- the saved order first, then the rest sorted
local keys = {}
local seen = {}
for _, k in order do