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:
1 parent
9b2b50fe75
commit
4932fa7148
11 files changed
+1212
-47
No files matched your search
@@ -9,6 +9,7 @@
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@formats/core/Err")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Input = require("@formats/core/Input")
|
||||
local Sniff = require("@formats/core/Sniff")
|
||||
local Types = require("@formats/Types")
|
||||
local Read = require("@formats/model/md5/Read")
|
||||
@@ -19,7 +20,7 @@ local Md5 = {
|
||||
category = "model",
|
||||
extensions = { "md5mesh", "md5anim" },
|
||||
mime = { "model/x-md5mesh", "model/x-md5anim" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/model/Rig" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "core/Sniff", "Types", "codecs/model/Rig" },
|
||||
caps = { decode = true, encode = false, skins = true, animation = true },
|
||||
}
|
||||
|
||||
@@ -41,21 +42,6 @@ function Md5.sniff(r: Bytes.Reader): number
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
local function fetch(opts: DecodeOptions, uri: string): string?
|
||||
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
|
||||
if type(v) == "buffer" then
|
||||
return buffer.tostring(v)
|
||||
end
|
||||
return if type(v) == "string" then v else nil
|
||||
end
|
||||
|
||||
local function stem(name: string): string
|
||||
local base = string.match(name, "([^/\\]+)$") or name
|
||||
return (string.gsub(base, "%.[^.]*$", ""))
|
||||
@@ -76,7 +62,8 @@ function Md5.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.E
|
||||
end
|
||||
if opts and type(opts.anims) == "table" then
|
||||
for _, name in opts.anims do
|
||||
local src = if type(name) == "string" then fetch(opts, name) else nil
|
||||
local got = if type(name) == "string" then Input.sibling(opts, name) else nil
|
||||
local src = if got then buffer.tostring(got) else nil
|
||||
if not src then
|
||||
if not opts.skipMissing then
|
||||
return nil, Err.new(Err.UNSUPPORTED, "animation " .. tostring(name) .. " not available (opts.resolve / opts.files)")
|
||||
|
||||
Reference in new issue
Block a user