model/blend: material inputs traced through reroutes, mix, colour adjustments, colour ramps and node groups; unresolved links flagged with neutral values; roughness / metallic image textures with their channel; vertex colours; bump; UDIM images with the <UDIM> token and their tiles
This commit is contained in:
1 parent
8fd5a4c3f2
commit
3a56a66ac1
13 files changed
+1781
-531
No files matched your search
+68
-5
@@ -228,7 +228,7 @@ local BONE_KEYS = { "inherit_scale", "use_inherit_rotation", "use_local_location
|
||||
"bbone_custom_handle_start", "bbone_custom_handle_end", "use_endroll_as_inroll", "bbone_mapping_mode" }
|
||||
local COMMON = { "type", "name", "influence", "mute", "target", "subtarget", "owner_space", "target_space" }
|
||||
|
||||
local checked = { drivers = 0, props = 0, actions = 0, rigs = 0, constraints = 0, worlds = 0, meshes = 0, normals = 0, weights = 0, shapes = 0, frames = 0, skinned = 0, curves = 0, materials = 0, cameras = 0, lights = 0 }
|
||||
local checked = { graphs = 0, drivers = 0, props = 0, actions = 0, rigs = 0, constraints = 0, worlds = 0, meshes = 0, normals = 0, weights = 0, shapes = 0, frames = 0, skinned = 0, curves = 0, materials = 0, cameras = 0, lights = 0 }
|
||||
local samples = {}
|
||||
|
||||
t:check(#Sets.old >= 4, "the old demo files were fetched (" .. #Sets.old .. ")")
|
||||
@@ -486,8 +486,10 @@ for _, tag in { "old", "279", "293", "35", "41", "cur" } do
|
||||
local g = glMats[m.name]
|
||||
if m.extras.blend.principled and g then
|
||||
local pbr = g.pbrMetallicRoughness or {}
|
||||
t:check(nearList(m.baseColor, pbr.baseColorFactor or { 1, 1, 1, 1 }, 1e-5), label .. ": " .. m.name .. " base colour " .. fmt(m.baseColor))
|
||||
t:check(near(m.metallic, pbr.metallicFactor or 1, 1e-5) and near(m.roughness, pbr.roughnessFactor or 1, 1e-5), label .. ": " .. m.name .. " metallic / roughness")
|
||||
-- an input linked to no image: the exporter writes its own guess, the reader a neutral value (checked below)
|
||||
local linked = m.extras.blend.linked or {}
|
||||
t:check(linked.baseColor or nearList(m.baseColor, pbr.baseColorFactor or { 1, 1, 1, 1 }, 1e-5), label .. ": " .. m.name .. " base colour " .. fmt(m.baseColor))
|
||||
t:check((linked.metallic or near(m.metallic, pbr.metallicFactor or 1, 1e-5)) and (linked.roughness or near(m.roughness, pbr.roughnessFactor or 1, 1e-5)), label .. ": " .. m.name .. " metallic / roughness")
|
||||
t:check(nearList(m.emissive, g.emissiveFactor or { 0, 0, 0 }, 1e-5), label .. ": " .. m.name .. " emissive " .. fmt(m.emissive))
|
||||
local ges = g.extensions and g.extensions.KHR_materials_emissive_strength
|
||||
local es = m.extensions and m.extensions.KHR_materials_emissive_strength
|
||||
@@ -495,11 +497,72 @@ for _, tag in { "old", "279", "293", "35", "41", "cur" } do
|
||||
t:eq(string.upper(m.alphaMode), g.alphaMode or "OPAQUE", label .. ": " .. m.name .. " alpha mode")
|
||||
t:eq(m.baseColorTexture ~= nil, pbr.baseColorTexture ~= nil, label .. ": " .. m.name .. " base colour texture")
|
||||
t:eq(m.emissiveTexture ~= nil, g.emissiveTexture ~= nil, label .. ": " .. m.name .. " emissive texture")
|
||||
t:eq(m.normalTexture ~= nil, g.normalTexture ~= nil, label .. ": " .. m.name .. " normal texture")
|
||||
-- the exporter writes a bump height map as the normal texture; the reader keeps it as extras.blend.bumpTexture
|
||||
t:eq(m.normalTexture ~= nil or m.extras.blend.bumpTexture ~= nil, g.normalTexture ~= nil, label .. ": " .. m.name .. " normal texture")
|
||||
-- images found through pass-through nodes, as the exporter finds them: base colour, and roughness as its
|
||||
-- metallic-roughness texture
|
||||
local function texName(ref: any): string?
|
||||
return ref and scene.textures[ref.texture] and scene.textures[ref.texture].name
|
||||
end
|
||||
local function glName(info: any): string?
|
||||
local tx = info and gl.textures and gl.textures[info.index + 1]
|
||||
local im = tx and tx.source and gl.images and gl.images[tx.source + 1]
|
||||
return im and im.name
|
||||
end
|
||||
if pbr.baseColorTexture and texName(m.baseColorTexture) then
|
||||
t:check(string.find(glName(pbr.baseColorTexture) or "", texName(m.baseColorTexture) :: string, 1, true) == 1, label .. ": " .. m.name .. " base colour image " .. tostring(texName(m.baseColorTexture)) .. " / " .. tostring(glName(pbr.baseColorTexture)))
|
||||
end
|
||||
t:eq(m.metallicRoughnessTexture ~= nil or m.extras.blend.roughnessTexture ~= nil or m.extras.blend.metallicTexture ~= nil, pbr.metallicRoughnessTexture ~= nil, label .. ": " .. m.name .. " metallic / roughness texture")
|
||||
if g.normalTexture and m.normalTexture then
|
||||
t:check(near(m.normalTexture.scale, g.normalTexture.scale or 1, 1e-5), label .. ": " .. m.name .. " normal scale")
|
||||
end
|
||||
checked.materials += 1
|
||||
-- the graph against bpy: the image each input reaches, the nodes passed, vertex colours, unresolved links
|
||||
for _, rm in ref.materials do
|
||||
if rm.name ~= m.name then
|
||||
continue
|
||||
end
|
||||
local KEYS = { ["Base Color"] = "baseColor", Roughness = "roughness", Metallic = "metallic", Normal = "normal", Alpha = "alpha", ["Emission Color"] = "emissive", Emission = "emissive" }
|
||||
local e = m.extras.blend
|
||||
for input, rg in rm.graph or {} do
|
||||
local key = KEYS[input]
|
||||
local what = label .. ": " .. m.name .. " " .. input
|
||||
local ref = if key == "baseColor" then m.baseColorTexture elseif key == "normal" then (m.normalTexture or e.bumpTexture)
|
||||
elseif key == "emissive" then m.emissiveTexture else e[key .. "Texture"]
|
||||
if rg.image then
|
||||
local tex = ref and scene.textures[ref.texture]
|
||||
t:check(tex and tex.name == rg.image.name, what .. " image " .. tostring(tex and tex.name) .. " / " .. rg.image.name)
|
||||
local viaKey = if key == "normal" and rg.linked == "ShaderNodeBump" then "bump" else key
|
||||
t:check(same((e.via or {})[viaKey] or {}, rg.via, 0), what .. " via")
|
||||
if key == "roughness" or key == "metallic" then
|
||||
t:eq(ref and ref.channel, if rg.output == "Alpha" then "A" else "R", what .. " channel")
|
||||
end
|
||||
if rg.image.tiles and tex then
|
||||
local tiles = tex.extras.blend.tiles or {}
|
||||
t:eq(#tiles, #rg.image.tiles, what .. " tiles")
|
||||
for q, rt in rg.image.tiles do
|
||||
local tile = tiles[q] or {}
|
||||
t:check(tile.number == rt.number and (tile.label or tostring(tile.number)) == rt.label, what .. " tile " .. rt.number)
|
||||
end
|
||||
t:eq(tex.uri, (string.gsub(rg.image.filepath, "^//", "")), what .. " uri with the <UDIM> token")
|
||||
t:check(tex.data and buffer.tostring(tex.data) == Files["udim.1001.png"], what .. " the first tile's bytes")
|
||||
end
|
||||
if rg.linked == "ShaderNodeBump" then
|
||||
t:check(near(e.bumpStrength, rg.strength, 1e-5) and near(e.bumpDistance, rg.distance, 1e-5), what .. " bump strength / distance")
|
||||
end
|
||||
elseif rg.vertexColor then
|
||||
t:eq(e.vertexColor, rg.vertexColor, what .. " vertex colour")
|
||||
else
|
||||
t:eq((e.linked or {})[key], rg["end"], what .. " flagged as linked")
|
||||
if key == "baseColor" then
|
||||
t:check(nearList({ m.baseColor[1], m.baseColor[2], m.baseColor[3] }, { 0.8, 0.8, 0.8 }, 1e-6), what .. " neutral grey")
|
||||
elseif key == "metallic" then
|
||||
t:eq(m.metallic, 0, what .. " neutral metallic")
|
||||
end
|
||||
end
|
||||
checked.graphs += 1
|
||||
end
|
||||
end
|
||||
elseif not m.extras.blend.principled then
|
||||
for _, rm in ref.materials do
|
||||
if rm.name == m.name then
|
||||
@@ -952,7 +1015,7 @@ for _, tag in { "old", "279", "293", "35", "41", "cur" } do
|
||||
end
|
||||
end
|
||||
end
|
||||
t:note("checked: %d rigs, %d constraints, %d raw action curves, %d drivers, %d property sets", checked.rigs, checked.constraints, checked.actions, checked.drivers, checked.props)
|
||||
t:note("checked: %d rigs, %d constraints, %d raw action curves, %d drivers, %d property sets, %d material inputs", checked.rigs, checked.constraints, checked.actions, checked.drivers, checked.props, checked.graphs)
|
||||
t:note("checked: %d world matrices, %d meshes, %d corner normal sets, %d weight sets, %d shape key sets, %d f-curves, %d posed frames, %d skinned frames, %d materials, %d cameras, %d lights",
|
||||
checked.worlds, checked.meshes, checked.normals, checked.weights, checked.shapes, checked.curves, checked.frames, checked.skinned, checked.materials, checked.cameras, checked.lights)
|
||||
|
||||
|
||||
Reference in new issue
Block a user