ws-game: model/bsp (Quake 1 / Half-Life / Quake II brush maps, Quake III maps with patches and lightmaps, entities); core/Input.sibling (opts.files / opts.resolve lookup shared by mdl / bsp / md5 / vpk; additive)

This commit is contained in:
4DBug committed 2026-10-31 15:01:06 -05:00
1 parent 9b2b50fe75
commit 4932fa7148
11 files changed
+1212 -47

No files matched your search

+3 -17
View File
@@ -9,6 +9,7 @@
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@formats/core/Err")
local Bytes = require("@formats/core/Bytes")
local Input = require("@formats/core/Input")
local Types = require("@formats/Types")
local Quake = require("@formats/model/mdl/Quake")
local HalfLife = require("@formats/model/mdl/HalfLife")
@@ -19,7 +20,7 @@ local Mdl = {
category = "model",
extensions = { "mdl" },
mime = { "model/x-mdl" },
deps = { "core/Err", "core/Bytes", "Types", "codecs/image/Pixels", "codecs/model/Mat4", "codecs/model/Rig" },
deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels", "codecs/model/Mat4", "codecs/model/Rig" },
caps = { decode = true, encode = false, variants = { "quake", "halflife" }, morph = true, skins = true, animation = true },
}
@@ -48,21 +49,6 @@ function Mdl.sniff(r: Bytes.Reader): number
end
-- ------------------------------------------------------------------------------------------------ decode
local function fetch(opts: DecodeOptions?, uri: string): buffer?
if not opts then
return nil
end
local v: any = nil
if type(opts.files) == "table" then
v = opts.files[uri]
end
if v == nil and type(opts.resolve) == "function" then
local ok, got = pcall(opts.resolve, uri)
v = if ok then got else nil
end
return Bytes.toBuffer(v)
end
function Mdl.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?)
local size = r.limit - r.base
if size < 8 then
@@ -74,7 +60,7 @@ function Mdl.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.E
if version ~= 6 then
return nil, Err.new(Err.UNSUPPORTED, "Quake MDL version " .. version, 4)
end
local pal = if opts and opts.palette then Bytes.toBuffer(opts.palette) else fetch(opts, "gfx/palette.lmp")
local pal = if opts and opts.palette then Bytes.toBuffer(opts.palette) else Input.sibling(opts, "gfx/palette.lmp")
if pal and buffer.len(pal) < 768 then
pal = nil
end