model/sourcemdl: .vmt materials through codecs/text/KeyValues (cdmaterials search, patch include / insert / replace, $basetexture / $bumpmap as .vtf references), docs/guide scene section
This commit is contained in:
1 parent
d8212c6839
commit
80fd9cf1e8
6 files changed
+280
-7
No files matched your search
@@ -110,6 +110,40 @@ for _, c in Fx.cases do
|
||||
t:eq(total, st.total_verts, tag .. "total vertices (srctools)")
|
||||
t:check(string.find(src.physics.text, '"mass" "12.5', 1, true) ~= nil and st.phys_mass == 12.5, tag .. "phy keyvalues (srctools)")
|
||||
|
||||
-- materials: the .vmt srctools finds through cdmaterials, its $basetexture / $bumpmap
|
||||
local seen = 0
|
||||
for _, vmt in st.textures do
|
||||
local mat
|
||||
for _, m in s.materials do
|
||||
if m.extras and m.extras.vmt and m.extras.vmt.path == vmt then
|
||||
mat = m
|
||||
end
|
||||
end
|
||||
t:check(mat, tag .. vmt .. ": resolved as srctools")
|
||||
if mat then
|
||||
seen += 1
|
||||
local want = st.materials[vmt]
|
||||
t:eq(mat.extras.vmt.shader, want.shader, tag .. vmt .. ": shader (srctools)")
|
||||
local base = string.gsub(want.basetexture, "\\", "/")
|
||||
t:eq(s.textures[mat.baseColorTexture.texture].uri, "materials/" .. base .. ".vtf", tag .. vmt .. ": $basetexture (srctools)")
|
||||
if want.bumpmap ~= "" then
|
||||
t:eq(s.textures[mat.normalTexture.texture].uri, "materials/" .. want.bumpmap .. ".vtf", tag .. vmt .. ": $bumpmap (srctools)")
|
||||
else
|
||||
t:check(mat.normalTexture == nil, tag .. vmt .. ": no bumpmap")
|
||||
end
|
||||
t:eq(mat.alphaMode, if want.translucent == "1" then "blend" elseif string.find(vmt, "metal") then "mask" else "opaque", tag .. vmt .. ": alpha mode")
|
||||
t:eq(mat.doubleSided, string.find(vmt, "metal") ~= nil, tag .. vmt .. ": $nocull")
|
||||
end
|
||||
end
|
||||
t:eq(seen, #s.materials, tag .. "every texture has its .vmt")
|
||||
if c.version == 49 then
|
||||
local Vtf = require("@tests/gen/vtf")
|
||||
local loaded, errs = F.model.loadTextures(s, { resolve = function(uri: string): string?
|
||||
return if string.sub(uri, -4) == ".vtf" then Vtf[1].data else nil
|
||||
end })
|
||||
t:check(next(errs) == nil and loaded.textures[1].image and loaded.textures[1].image.width > 0, tag .. "F.model.loadTextures decodes the .vtf references")
|
||||
end
|
||||
|
||||
-- skeleton
|
||||
local skin = s.skins[1]
|
||||
t:eq(#skin.joints, #e.bones, tag .. "joints")
|
||||
@@ -262,7 +296,7 @@ for _, c in Fx.cases do
|
||||
t:fuzz(tag .. "mdl", function(b: buffer)
|
||||
return SourceMdl.decode(Bytes.reader(b), { files = c.files })
|
||||
end, samples, { mutations = 40 })
|
||||
for _, name in { "model.vvd", "model.dx90.vtx", "model.phy" } do
|
||||
for _, name in { "model.vvd", "model.dx90.vtx", "model.phy", "materials/models/test/skin_c.vmt" } do
|
||||
t:fuzz(tag .. name, function(b: buffer)
|
||||
local files = table.clone(c.files)
|
||||
files[name] = buffer.tostring(b)
|
||||
|
||||
Reference in new issue
Block a user