model/sourcemdl: Source MDL v44-49 with .vvd / .vtx / .phy / .ani (WIP, no tests yet); codecs/model/SourceAnim shared with model/mdl's GoldSrc animation values
This commit is contained in:
1 parent
01c044805f
commit
c7e0639913
12 files changed
+1752
-31
No files matched your search
@@ -6,6 +6,7 @@ local Types = require("@rosetta/Types")
|
||||
local Mat4 = require("@rosetta/codecs/model/Mat4")
|
||||
local Pixels = require("@rosetta/codecs/image/Pixels")
|
||||
local Rig = require("@rosetta/codecs/model/Rig")
|
||||
local SourceAnim = require("@rosetta/codecs/model/SourceAnim")
|
||||
|
||||
local HalfLife = {}
|
||||
|
||||
@@ -44,31 +45,6 @@ local function textures(b: buffer, base: number, size: number, maxPixels: number
|
||||
return out, names
|
||||
end
|
||||
|
||||
-- bone default + stored value * scale
|
||||
local function animValue(b: buffer, at: number, limit: number, f: number): number?
|
||||
local p = at
|
||||
local k = f
|
||||
for _ = 1, 65536 do
|
||||
if p + 2 > limit then
|
||||
return nil
|
||||
end
|
||||
local valid, total = readu8(b, p), readu8(b, p + 1)
|
||||
if total == 0 then
|
||||
return nil
|
||||
end
|
||||
if total > k then
|
||||
local idx = if valid > k then k + 1 else valid
|
||||
if p + idx * 2 + 2 > limit then
|
||||
return nil
|
||||
end
|
||||
return readi16(b, p + idx * 2)
|
||||
end
|
||||
k -= total
|
||||
p += (valid + 1) * 2
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function HalfLife.decode(b: buffer, base: number, size: number, opts: Options?): (Types.Scene?, string?)
|
||||
if size < 244 then
|
||||
return nil, "truncated header"
|
||||
@@ -293,7 +269,7 @@ function HalfLife.decode(b: buffer, base: number, size: number, opts: Options?):
|
||||
local v: { number } = {}
|
||||
for k = 0, 5 do
|
||||
local off = readu16(b, ao + k * 2)
|
||||
local raw = if off ~= 0 then animValue(b, ao + off, limit, f) else nil
|
||||
local raw = if off ~= 0 then SourceAnim.value(b, ao + off, limit, f) else nil
|
||||
v[k + 1] = bn.value[k + 1] + (raw or 0) * bn.scale[k + 1]
|
||||
end
|
||||
table.insert(tr, v[1])
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
--!strict
|
||||
-- model/mdl: Quake 1 ("IDPO" v6, model/mdl/Quake) and GoldSrc ("IDST" v10, model/mdl/HalfLife) models. Quake skins
|
||||
-- need gfx/palette.lmp (not redistributable, never built in; else a grey ramp). Not supported: Source MDL (v44+).
|
||||
-- need gfx/palette.lmp (not redistributable, never built in; else a grey ramp). Source MDL (v44+) is model/sourcemdl.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -16,7 +16,7 @@ local Mdl = {
|
||||
category = "model",
|
||||
extensions = { "mdl" },
|
||||
mime = { "model/x-mdl" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "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", "codecs/model/SourceAnim" },
|
||||
caps = { decode = true, encode = false, variants = { "quake", "halflife" }, morph = true, skins = true, animation = true },
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user