merge ws/blendmat
This commit is contained in:
commit
cfa137730b
13 files changed
+1781
-531
No files matched your search
+264
-41
@@ -165310,10 +165310,13 @@ __FILES["model/blend/Material"] = function()
|
|||||||
-- model/blend/Material: Blender materials to Scene PBR materials. With nodes: the Principled BSDF (the one feeding the
|
-- model/blend/Material: Blender materials to Scene PBR materials. With nodes: the Principled BSDF (the one feeding the
|
||||||
-- material output, else the first): Base Color, Metallic, Roughness, Alpha, Emission (Color) x Emission Strength
|
-- material output, else the first): Base Color, Metallic, Roughness, Alpha, Emission (Color) x Emission Strength
|
||||||
-- (KHR_materials_emissive_strength above 1, as Blender's glTF exporter writes it), images linked directly to Base
|
-- (KHR_materials_emissive_strength above 1, as Blender's glTF exporter writes it), images linked directly to Base
|
||||||
-- Color / Emission and through a Normal Map node to Normal (its Strength as the scale), a Separate RGB / Color node to
|
-- Color / Emission / Roughness / Metallic and through a Normal Map node to Normal (its Strength as the scale), a
|
||||||
-- Roughness (G) and Metallic (B), UV Map nodes for the texCoord. Without nodes (or before 2.8 without a
|
-- Separate RGB / Color node to Roughness (G) and Metallic (B), UV Map nodes for the texCoord; links are followed
|
||||||
-- Principled node): Material.r / g / b / alpha, metallic, roughness. Images: packed files as encoded bytes, external
|
-- through reroutes, Mix / MixRGB (A then B), Hue-Saturation, Bright-Contrast, Gamma, Invert, RGB Curves, Color Ramp
|
||||||
-- ones as uris (with the bytes when opts.files / opts.resolve has them).
|
-- and node groups; a linked input that reaches no image takes a neutral value (base colour 0.8 grey, Blender's
|
||||||
|
-- default; metallic 0, roughness 0.5) and is flagged. Without nodes (or before 2.8 without a Principled node):
|
||||||
|
-- Material.r / g / b / alpha, metallic, roughness. Images: packed files as encoded bytes, external ones as uris (with
|
||||||
|
-- the bytes when opts.files / opts.resolve has them); tiled (UDIM) images keep the <UDIM> token in the uri.
|
||||||
local Blend = __include("containers/Blend")
|
local Blend = __include("containers/Blend")
|
||||||
local Types = __include("Types")
|
local Types = __include("Types")
|
||||||
|
|
||||||
@@ -165379,6 +165382,34 @@ local function texture(ctx: Ctx, img: Blend.View, sampler: Types.Sampler?): numb
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local tex: Types.Texture = { name = name, sampler = sampler }
|
local tex: Types.Texture = { name = name, sampler = sampler }
|
||||||
|
local tiles: { { [string]: any } }? = nil
|
||||||
|
if (img:num("source") or 0) == 6 then -- IMA_SRC_TILED
|
||||||
|
tiles = {}
|
||||||
|
for _, t in img:list("tiles", "ImageTile") do
|
||||||
|
local label = t:str("label")
|
||||||
|
table.insert(tiles :: any, { number = t:num("tile_number") or 1001, label = if label and label ~= "" then label else nil })
|
||||||
|
end
|
||||||
|
if #(tiles :: any) == 0 then
|
||||||
|
table.insert(tiles :: any, { number = 1001 })
|
||||||
|
end
|
||||||
|
if path and not string.find(path, "<UDIM>", 1, true) and not string.find(path, "<UVTILE>", 1, true) then
|
||||||
|
-- the tile number in the file name becomes the token, as Blender's versioning does for older files
|
||||||
|
local first = tostring((tiles :: any)[1].number)
|
||||||
|
local dir, file = string.match(path, "^(.-)([^/\\]*)$")
|
||||||
|
local a, b = nil, nil
|
||||||
|
local from = 1
|
||||||
|
while true do
|
||||||
|
local x, y = string.find(file or "", first, from, true)
|
||||||
|
if not x then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
a, b, from = x, y, x + 1
|
||||||
|
end
|
||||||
|
if a and b and file then
|
||||||
|
path = (dir or "") .. string.sub(file, 1, a - 1) .. "<UDIM>" .. string.sub(file, b + 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
if pf then
|
if pf then
|
||||||
local blk = pf:target("data")
|
local blk = pf:target("data")
|
||||||
local size = pf:num("size") or 0
|
local size = pf:num("size") or 0
|
||||||
@@ -165395,7 +165426,8 @@ local function texture(ctx: Ctx, img: Blend.View, sampler: Types.Sampler?): numb
|
|||||||
uri = string.gsub(uri, "\\", "/")
|
uri = string.gsub(uri, "\\", "/")
|
||||||
if not tex.data then
|
if not tex.data then
|
||||||
tex.uri = uri
|
tex.uri = uri
|
||||||
local data = fetch(ctx, uri)
|
local first = if tiles then tostring(tiles[1].number) else nil
|
||||||
|
local data = fetch(ctx, if first then (string.gsub(string.gsub(uri, "<UDIM>", first), "<UVTILE>", "u1_v1")) else uri)
|
||||||
if data then
|
if data then
|
||||||
tex.data = data
|
tex.data = data
|
||||||
tex.mime = sniffMime(data, 0, buffer.len(data), uri)
|
tex.mime = sniffMime(data, 0, buffer.len(data), uri)
|
||||||
@@ -165403,7 +165435,12 @@ local function texture(ctx: Ctx, img: Blend.View, sampler: Types.Sampler?): numb
|
|||||||
tex.mime = sniffMime(buffer.create(0), 0, 0, uri)
|
tex.mime = sniffMime(buffer.create(0), 0, 0, uri)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
tex.extras = { blend = { filepath = path } }
|
tex.extras = { blend = { filepath = path, tiles = tiles } }
|
||||||
|
if tiles then
|
||||||
|
for _, t in tiles do
|
||||||
|
t.filename = (string.gsub(uri, "<UDIM>", tostring(t.number)))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if not tex.data and not tex.uri then
|
if not tex.data and not tex.uri then
|
||||||
tex.extras = { blend = { generated = true } }
|
tex.extras = { blend = { generated = true } }
|
||||||
@@ -165416,17 +165453,22 @@ local function texture(ctx: Ctx, img: Blend.View, sampler: Types.Sampler?): numb
|
|||||||
return idx
|
return idx
|
||||||
end
|
end
|
||||||
|
|
||||||
type Node = { view: Blend.View, idname: string, inputs: { [string]: Blend.View }, outputs: { [any]: string } }
|
type Node = { view: Blend.View, idname: string, inputs: { [string]: Blend.View }, byId: { [string]: Blend.View }, first: Blend.View?, outputs: { [any]: string }, outIds: { [any]: string } }
|
||||||
type Graph = { nodes: { [any]: Node }, links: { [any]: { node: Node, socket: string } } } -- links by tosock addr
|
type Link = { node: Node, socket: string, ident: string }
|
||||||
|
type Graph = { nodes: { [any]: Node }, links: { [any]: Link } } -- links by tosock addr
|
||||||
|
|
||||||
local function graph(tree: Blend.View): Graph
|
local function graph(tree: Blend.View): Graph
|
||||||
local g: Graph = { nodes = {}, links = {} }
|
local g: Graph = { nodes = {}, links = {} }
|
||||||
for _, n in tree:list("nodes", "bNode") do
|
for _, n in tree:list("nodes", "bNode") do
|
||||||
local node: Node = { view = n, idname = n:str("idname") or "", inputs = {}, outputs = {} }
|
local node: Node = { view = n, idname = n:str("idname") or "", inputs = {}, byId = {}, outputs = {}, outIds = {} }
|
||||||
for _, s in n:list("inputs", "bNodeSocket") do
|
for _, s in n:list("inputs", "bNodeSocket") do
|
||||||
local id = s:str("identifier") or s:str("name") or ""
|
local id = s:str("identifier") or s:str("name") or ""
|
||||||
local nm = s:str("name") or id
|
local nm = s:str("name") or id
|
||||||
node.inputs[nm] = s
|
node.first = node.first or s
|
||||||
|
node.byId[id] = s
|
||||||
|
if node.inputs[nm] == nil then
|
||||||
|
node.inputs[nm] = s
|
||||||
|
end
|
||||||
if node.inputs[id] == nil then
|
if node.inputs[id] == nil then
|
||||||
node.inputs[id] = s
|
node.inputs[id] = s
|
||||||
end
|
end
|
||||||
@@ -165434,6 +165476,7 @@ local function graph(tree: Blend.View): Graph
|
|||||||
for _, s in n:list("outputs", "bNodeSocket") do
|
for _, s in n:list("outputs", "bNodeSocket") do
|
||||||
if s.block then
|
if s.block then
|
||||||
node.outputs[s.block.addr] = s:str("name") or ""
|
node.outputs[s.block.addr] = s:str("name") or ""
|
||||||
|
node.outIds[s.block.addr] = s:str("identifier") or s:str("name") or ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if n.block then
|
if n.block then
|
||||||
@@ -165444,7 +165487,7 @@ local function graph(tree: Blend.View): Graph
|
|||||||
local from, fs, to = l:ptr("fromnode"), l:ptr("fromsock"), l:ptr("tosock")
|
local from, fs, to = l:ptr("fromnode"), l:ptr("fromsock"), l:ptr("tosock")
|
||||||
local fn = from and g.nodes[from]
|
local fn = from and g.nodes[from]
|
||||||
if fn and to ~= nil and bit32.band(l:num("flag") or 0, 0x10) == 0 then
|
if fn and to ~= nil and bit32.band(l:num("flag") or 0, 0x10) == 0 then
|
||||||
g.links[to] = { node = fn, socket = (fs and fn.outputs[fs]) or "" }
|
g.links[to] = { node = fn, socket = (fs and fn.outputs[fs]) or "", ident = (fs and fn.outIds[fs]) or "" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return g
|
return g
|
||||||
@@ -165460,7 +165503,7 @@ local function input(n: Node, ...: string): Blend.View?
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function link(g: Graph, s: Blend.View?): { node: Node, socket: string }?
|
local function link(g: Graph, s: Blend.View?): Link?
|
||||||
if not s or not s.block then
|
if not s or not s.block then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -165479,23 +165522,87 @@ local function value(s: Blend.View?, kind: string): any
|
|||||||
return v and v:num("value")
|
return v and v:num("value")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function imageRef(ctx: Ctx, g: Graph, uvNames: any, s: Blend.View?, through: string?): (Types.TextureRef?, Node?)
|
-- pass-through nodes: the inputs (by identifier) that may lead to an image, in the order tried
|
||||||
|
local PASS: { [string]: { string } } = {
|
||||||
|
NodeReroute = { "Input" }, ShaderNodeMix = { "A_Color", "B_Color" }, ShaderNodeMixRGB = { "Color1", "Color2" },
|
||||||
|
ShaderNodeHueSaturation = { "Color" }, ShaderNodeBrightContrast = { "Color" }, ShaderNodeGamma = { "Color" },
|
||||||
|
ShaderNodeInvert = { "Color" }, ShaderNodeRGBCurve = { "Color" }, ShaderNodeValToRGB = { "Fac" },
|
||||||
|
}
|
||||||
|
|
||||||
|
type Hit = { node: Node, g: Graph, output: string }
|
||||||
|
type Frame = { node: Node, g: Graph }
|
||||||
|
|
||||||
|
local function groupGraph(n: Node): Graph?
|
||||||
|
local tree = n.view:deref("id", 0, "bNodeTree")
|
||||||
|
return if tree then graph(tree) else nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- the first image texture node a socket reaches through pass-through nodes and node groups (via: the nodes passed),
|
||||||
|
-- else the node it is linked to (reroutes skipped)
|
||||||
|
local function trace(g: Graph, s: Blend.View?, via: { string }, stack: { Frame }, depth: number): (Hit?, Node?)
|
||||||
local l = link(g, s)
|
local l = link(g, s)
|
||||||
if not l then
|
if not l or depth > 64 then
|
||||||
return nil, nil
|
return nil, nil
|
||||||
end
|
end
|
||||||
local n = l.node
|
local n = l.node
|
||||||
if through and n.idname == through then
|
if n.idname == "ShaderNodeTexImage" then
|
||||||
local inner = input(n, "Color", "Image")
|
return { node = n, g = g, output = l.socket }, n
|
||||||
local ref, tn = imageRef(ctx, g, uvNames, inner, nil)
|
elseif n.idname == "ShaderNodeGroup" then
|
||||||
return ref, if ref then n else tn
|
local inner = groupGraph(n)
|
||||||
end
|
local out: Node? = nil
|
||||||
if n.idname ~= "ShaderNodeTexImage" then
|
for _, x in if inner then inner.nodes else {} do
|
||||||
|
if x.idname == "NodeGroupOutput" and (out == nil or bit32.band(x.view:num("flag") or 0, 2) ~= 0) then
|
||||||
|
out = x
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local sock = out and out.byId[l.ident]
|
||||||
|
if inner and sock then
|
||||||
|
local stack2 = table.clone(stack)
|
||||||
|
table.insert(stack2, { node = n, g = g })
|
||||||
|
local sub = {}
|
||||||
|
local hit = trace(inner, sock, sub, stack2, depth + 1)
|
||||||
|
if hit then
|
||||||
|
table.insert(via, n.idname)
|
||||||
|
table.move(sub, 1, #sub, #via + 1, via)
|
||||||
|
return hit, n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil, n
|
||||||
|
elseif n.idname == "NodeGroupInput" and #stack > 0 then
|
||||||
|
local top = stack[#stack]
|
||||||
|
local outer = top.node.byId[l.ident]
|
||||||
|
local stack2 = table.clone(stack)
|
||||||
|
table.remove(stack2)
|
||||||
|
if outer then
|
||||||
|
return trace(top.g, outer, via, stack2, depth + 1)
|
||||||
|
end
|
||||||
return nil, n
|
return nil, n
|
||||||
end
|
end
|
||||||
|
local ids = PASS[n.idname]
|
||||||
|
if ids then
|
||||||
|
for _, id in ids do
|
||||||
|
local sock = n.byId[id] or (if n.idname == "NodeReroute" then n.first else nil)
|
||||||
|
local sub = {}
|
||||||
|
local hit, last = trace(g, sock, sub, stack, depth + 1)
|
||||||
|
if hit then
|
||||||
|
table.insert(via, n.idname)
|
||||||
|
table.move(sub, 1, #sub, #via + 1, via)
|
||||||
|
return hit, n
|
||||||
|
end
|
||||||
|
if n.idname == "NodeReroute" then
|
||||||
|
return nil, last or n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil, n
|
||||||
|
end
|
||||||
|
|
||||||
|
-- the TextureRef of an image texture node (its sampler, its UV Map node's texCoord)
|
||||||
|
local function refOf(ctx: Ctx, uvNames: any, hit: Hit): Types.TextureRef?
|
||||||
|
local n, g = hit.node, hit.g
|
||||||
local img = n.view:deref("id", 0, "Image")
|
local img = n.view:deref("id", 0, "Image")
|
||||||
if not img then
|
if not img then
|
||||||
return nil, n
|
return nil
|
||||||
end
|
end
|
||||||
local sampler: Types.Sampler = {}
|
local sampler: Types.Sampler = {}
|
||||||
local custom = false
|
local custom = false
|
||||||
@@ -165515,7 +165622,7 @@ local function imageRef(ctx: Ctx, g: Graph, uvNames: any, s: Blend.View?, throug
|
|||||||
end
|
end
|
||||||
local t = texture(ctx, img, if custom then sampler else nil)
|
local t = texture(ctx, img, if custom then sampler else nil)
|
||||||
if not t then
|
if not t then
|
||||||
return nil, n
|
return nil
|
||||||
end
|
end
|
||||||
local ref: Types.TextureRef = { texture = t }
|
local ref: Types.TextureRef = { texture = t }
|
||||||
local vec = link(g, input(n, "Vector"))
|
local vec = link(g, input(n, "Vector"))
|
||||||
@@ -165526,7 +165633,31 @@ local function imageRef(ctx: Ctx, g: Graph, uvNames: any, s: Blend.View?, throug
|
|||||||
ref.texCoord = uvNames[name]
|
ref.texCoord = uvNames[name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ref, n
|
return ref
|
||||||
|
end
|
||||||
|
|
||||||
|
local function imageRef(ctx: Ctx, g: Graph, uvNames: any, s: Blend.View?): (Types.TextureRef?, Node?, { string }, Hit?)
|
||||||
|
local via = {}
|
||||||
|
local hit, last = trace(g, s, via, {}, 0)
|
||||||
|
if not hit then
|
||||||
|
return nil, last, via, nil
|
||||||
|
end
|
||||||
|
return refOf(ctx, uvNames, hit), last, via, hit
|
||||||
|
end
|
||||||
|
|
||||||
|
-- the vertex colour layer a Vertex Color / Attribute node reads
|
||||||
|
local function vertexColor(n: Node?): string?
|
||||||
|
if not n then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
if n.idname == "ShaderNodeVertexColor" then
|
||||||
|
local st = n.view:deref("storage", 0, "NodeShaderVertexColor")
|
||||||
|
return st and st:str("layer_name") or ""
|
||||||
|
elseif n.idname == "ShaderNodeAttribute" then
|
||||||
|
local st = n.view:deref("storage", 0, "NodeShaderAttribute")
|
||||||
|
return st and st:str("name") or ""
|
||||||
|
end
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function principled(g: Graph): Node?
|
local function principled(g: Graph): Node?
|
||||||
@@ -165590,47 +165721,139 @@ function Material.get(ctx: Ctx, mv: Blend.View): number
|
|||||||
end
|
end
|
||||||
m.metallic = value(input(bsdf, "Metallic"), "float") or m.metallic
|
m.metallic = value(input(bsdf, "Metallic"), "float") or m.metallic
|
||||||
m.roughness = value(input(bsdf, "Roughness"), "float") or m.roughness
|
m.roughness = value(input(bsdf, "Roughness"), "float") or m.roughness
|
||||||
local bref = imageRef(ctx, g, uvNames, input(bsdf, "Base Color"), nil)
|
local linked: { [string]: string } = {}
|
||||||
|
local via: { [string]: { string } } = {}
|
||||||
|
-- node names as Blender 3.4+ shows them (its versioning turns shader MixRGB nodes into Mix nodes)
|
||||||
|
local function api(idname: string): string
|
||||||
|
return if idname == "ShaderNodeMixRGB" and f.version < 304 then "ShaderNodeMix" else idname
|
||||||
|
end
|
||||||
|
local function resolve(key: string, sock: Blend.View?): (Types.TextureRef?, Node?, Hit?)
|
||||||
|
if not link(g :: Graph, sock) then
|
||||||
|
return nil, nil, nil
|
||||||
|
end
|
||||||
|
local ref, last, passed, hit = imageRef(ctx, g :: Graph, uvNames, sock)
|
||||||
|
if ref then
|
||||||
|
if #passed > 0 then
|
||||||
|
for i, x in passed do
|
||||||
|
passed[i] = api(x)
|
||||||
|
end
|
||||||
|
via[key] = passed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ref, last, hit
|
||||||
|
end
|
||||||
|
local function unresolved(key: string, sock: Blend.View?)
|
||||||
|
local l = link(g :: Graph, sock)
|
||||||
|
if l then
|
||||||
|
local _, last = trace(g :: Graph, sock, {}, {}, 0) -- reroutes skipped
|
||||||
|
linked[key] = api((last or l.node).idname)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local baseSock = input(bsdf, "Base Color")
|
||||||
|
local bref, blast = resolve("baseColor", baseSock)
|
||||||
if bref then
|
if bref then
|
||||||
m.baseColorTexture = bref
|
m.baseColorTexture = bref
|
||||||
m.baseColor = { 1, 1, 1, alpha }
|
m.baseColor = { 1, 1, 1, alpha }
|
||||||
|
elseif link(g, baseSock) then
|
||||||
|
local layer = vertexColor(blast)
|
||||||
|
if layer then
|
||||||
|
extras.vertexColor = layer
|
||||||
|
m.baseColor = { 1, 1, 1, alpha }
|
||||||
|
else
|
||||||
|
m.baseColor = { 0.8, 0.8, 0.8, alpha } -- Blender's default base colour, never the linked socket's value
|
||||||
|
unresolved("baseColor", baseSock)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local aref = imageRef(ctx, g, uvNames, input(bsdf, "Alpha"), nil)
|
local alphaSock = input(bsdf, "Alpha")
|
||||||
|
local aref = resolve("alpha", alphaSock)
|
||||||
if aref and not m.baseColorTexture then
|
if aref and not m.baseColorTexture then
|
||||||
m.baseColorTexture = aref
|
m.baseColorTexture = aref
|
||||||
|
elseif not aref and link(g, alphaSock) then
|
||||||
|
m.baseColor[4] = 1
|
||||||
|
unresolved("alpha", alphaSock)
|
||||||
end
|
end
|
||||||
local nref, nnode = imageRef(ctx, g, uvNames, input(bsdf, "Normal"), "ShaderNodeNormalMap")
|
local nl = link(g, input(bsdf, "Normal"))
|
||||||
if nref then
|
if nl and nl.node.idname == "ShaderNodeNormalMap" then
|
||||||
nref.scale = if nnode then value(nnode.inputs.Strength, "float") or 1 else 1
|
local nref = resolve("normal", input(nl.node, "Color"))
|
||||||
m.normalTexture = nref
|
if nref then
|
||||||
|
nref.scale = value(nl.node.inputs.Strength, "float") or 1
|
||||||
|
m.normalTexture = nref
|
||||||
|
else
|
||||||
|
unresolved("normal", input(bsdf, "Normal"))
|
||||||
|
end
|
||||||
|
elseif nl and nl.node.idname == "ShaderNodeBump" then
|
||||||
|
local href = resolve("bump", input(nl.node, "Height"))
|
||||||
|
if href then
|
||||||
|
extras.bumpTexture = href
|
||||||
|
extras.bumpStrength = value(input(nl.node, "Strength"), "float") or 1
|
||||||
|
extras.bumpDistance = value(input(nl.node, "Distance"), "float") or 1
|
||||||
|
else
|
||||||
|
unresolved("normal", input(bsdf, "Normal"))
|
||||||
|
end
|
||||||
|
elseif nl then
|
||||||
|
unresolved("normal", input(bsdf, "Normal"))
|
||||||
end
|
end
|
||||||
local rl = link(g, input(bsdf, "Roughness"))
|
local channelOf = { Red = "R", Green = "G", Blue = "B", R = "R", G = "G", B = "B", Alpha = "A", Color = "R", Fac = "R" }
|
||||||
local ml = link(g, input(bsdf, "Metallic"))
|
local function scalar(key: string, sock: Blend.View?): boolean?
|
||||||
local sep = (rl and rl.node) or (ml and ml.node)
|
local l = link(g :: Graph, sock)
|
||||||
if sep and (sep.idname == "ShaderNodeSeparateRGB" or sep.idname == "ShaderNodeSeparateColor") then
|
if not l then
|
||||||
local mref = imageRef(ctx, g, uvNames, input(sep, "Image", "Color"), nil)
|
return nil
|
||||||
if mref then
|
end
|
||||||
m.metallicRoughnessTexture = mref
|
local sep = l.node
|
||||||
if rl then
|
if sep.idname == "ShaderNodeSeparateRGB" or sep.idname == "ShaderNodeSeparateColor" then
|
||||||
m.roughness = 1
|
local ref = resolve(key, input(sep, "Image", "Color"))
|
||||||
|
if ref then
|
||||||
|
m.metallicRoughnessTexture = m.metallicRoughnessTexture or table.clone(ref)
|
||||||
|
local r = table.clone(ref) :: any
|
||||||
|
r.channel = channelOf[l.socket] or l.socket
|
||||||
|
extras[key .. "Texture"] = r
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
if ml then
|
else
|
||||||
m.metallic = 1
|
local ref, _, hit = resolve(key, sock)
|
||||||
|
if ref and hit then
|
||||||
|
local r = ref :: any
|
||||||
|
r.channel = channelOf[hit.output] or hit.output
|
||||||
|
extras[key .. "Texture"] = r
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
unresolved(key, sock)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local rs = scalar("roughness", input(bsdf, "Roughness"))
|
||||||
|
if rs == true then
|
||||||
|
m.roughness = 1
|
||||||
|
elseif rs == false then
|
||||||
|
m.roughness = 0.5
|
||||||
|
end
|
||||||
|
local ms = scalar("metallic", input(bsdf, "Metallic"))
|
||||||
|
if ms == true then
|
||||||
|
m.metallic = 1
|
||||||
|
elseif ms == false then
|
||||||
|
m.metallic = 0
|
||||||
end
|
end
|
||||||
local es = input(bsdf, "Emission Color", "Emission")
|
local es = input(bsdf, "Emission Color", "Emission")
|
||||||
local ecol = value(es, "rgba") or { 0, 0, 0, 1 }
|
local ecol = value(es, "rgba") or { 0, 0, 0, 1 }
|
||||||
local strength = value(input(bsdf, "Emission Strength"), "float") or 1
|
local strength = value(input(bsdf, "Emission Strength"), "float") or 1
|
||||||
local eref = imageRef(ctx, g, uvNames, es, nil)
|
local eref = resolve("emissive", es)
|
||||||
if eref then
|
if eref then
|
||||||
m.emissiveTexture = eref
|
m.emissiveTexture = eref
|
||||||
ecol = { 1, 1, 1, 1 }
|
ecol = { 1, 1, 1, 1 }
|
||||||
|
elseif link(g, es) then
|
||||||
|
ecol = { 0, 0, 0, 1 }
|
||||||
|
unresolved("emissive", es)
|
||||||
end
|
end
|
||||||
emissive(m, ecol, strength)
|
emissive(m, ecol, strength)
|
||||||
if not eref and m.emissive[1] == 0 and m.emissive[2] == 0 and m.emissive[3] == 0 then
|
if not eref and m.emissive[1] == 0 and m.emissive[2] == 0 and m.emissive[3] == 0 then
|
||||||
m.emissive = { 0, 0, 0 }
|
m.emissive = { 0, 0, 0 }
|
||||||
end
|
end
|
||||||
|
if next(linked) ~= nil then
|
||||||
|
extras.linked = linked
|
||||||
|
end
|
||||||
|
if next(via) ~= nil then
|
||||||
|
extras.via = via
|
||||||
|
end
|
||||||
local alphaLinked = link(g, input(bsdf, "Alpha")) ~= nil
|
local alphaLinked = link(g, input(bsdf, "Alpha")) ~= nil
|
||||||
if alpha < 1 or alphaLinked then
|
if alpha < 1 or alphaLinked then
|
||||||
local bm = mv:num("blend_method") or 0
|
local bm = mv:num("blend_method") or 0
|
||||||
|
|||||||
+180
-180
@@ -440,184 +440,184 @@
|
|||||||
[164598, "src/Rosetta/model/blend/Armature.luau"],
|
[164598, "src/Rosetta/model/blend/Armature.luau"],
|
||||||
[165134, "src/Rosetta/model/blend/Driver.luau"],
|
[165134, "src/Rosetta/model/blend/Driver.luau"],
|
||||||
[165309, "src/Rosetta/model/blend/Material.luau"],
|
[165309, "src/Rosetta/model/blend/Material.luau"],
|
||||||
[165661, "src/Rosetta/model/blend/Mesh.luau"],
|
[165884, "src/Rosetta/model/blend/Mesh.luau"],
|
||||||
[166349, "src/Rosetta/model/blend/Normals.luau"],
|
[166572, "src/Rosetta/model/blend/Normals.luau"],
|
||||||
[166510, "src/Rosetta/model/blend/Prim.luau"],
|
[166733, "src/Rosetta/model/blend/Prim.luau"],
|
||||||
[167017, "src/Rosetta/model/blend/Read.luau"],
|
[167240, "src/Rosetta/model/blend/Read.luau"],
|
||||||
[168105, "src/Rosetta/model/bsp/init.luau"],
|
[168328, "src/Rosetta/model/bsp/init.luau"],
|
||||||
[168296, "src/Rosetta/model/bsp/Lightmap.luau"],
|
[168519, "src/Rosetta/model/bsp/Lightmap.luau"],
|
||||||
[168362, "src/Rosetta/model/bsp/Quake.luau"],
|
[168585, "src/Rosetta/model/bsp/Quake.luau"],
|
||||||
[168751, "src/Rosetta/model/bsp/Quake3.luau"],
|
[168974, "src/Rosetta/model/bsp/Quake3.luau"],
|
||||||
[168980, "src/Rosetta/model/bsp/Tree.luau"],
|
[169203, "src/Rosetta/model/bsp/Tree.luau"],
|
||||||
[169368, "src/Rosetta/model/buildmap/init.luau"],
|
[169591, "src/Rosetta/model/buildmap/init.luau"],
|
||||||
[169640, "src/Rosetta/model/buildmap/Geometry.luau"],
|
[169863, "src/Rosetta/model/buildmap/Geometry.luau"],
|
||||||
[170043, "src/Rosetta/model/d3map/init.luau"],
|
[170266, "src/Rosetta/model/d3map/init.luau"],
|
||||||
[170325, "src/Rosetta/model/d3map/Parse.luau"],
|
[170548, "src/Rosetta/model/d3map/Parse.luau"],
|
||||||
[170523, "src/Rosetta/model/dae/init.luau"],
|
[170746, "src/Rosetta/model/dae/init.luau"],
|
||||||
[170712, "src/Rosetta/model/dae/Math.luau"],
|
[170935, "src/Rosetta/model/dae/Math.luau"],
|
||||||
[170759, "src/Rosetta/model/dae/Read.luau"],
|
[170982, "src/Rosetta/model/dae/Read.luau"],
|
||||||
[172609, "src/Rosetta/model/dae/Write.luau"],
|
[172832, "src/Rosetta/model/dae/Write.luau"],
|
||||||
[172978, "src/Rosetta/model/fbx/init.luau"],
|
[173201, "src/Rosetta/model/fbx/init.luau"],
|
||||||
[173126, "src/Rosetta/model/fbx/Ascii.luau"],
|
[173349, "src/Rosetta/model/fbx/Ascii.luau"],
|
||||||
[173396, "src/Rosetta/model/fbx/Binary.luau"],
|
[173619, "src/Rosetta/model/fbx/Binary.luau"],
|
||||||
[173851, "src/Rosetta/model/fbx/Read.luau"],
|
[174074, "src/Rosetta/model/fbx/Read.luau"],
|
||||||
[175213, "src/Rosetta/model/fbx/Write.luau"],
|
[175436, "src/Rosetta/model/fbx/Write.luau"],
|
||||||
[176198, "src/Rosetta/model/fbx/Xform.luau"],
|
[176421, "src/Rosetta/model/fbx/Xform.luau"],
|
||||||
[176239, "src/Rosetta/model/gltf/init.luau"],
|
[176462, "src/Rosetta/model/gltf/init.luau"],
|
||||||
[176476, "src/Rosetta/model/gltf/Pack.luau"],
|
[176699, "src/Rosetta/model/gltf/Pack.luau"],
|
||||||
[176545, "src/Rosetta/model/gltf/Read.luau"],
|
[176768, "src/Rosetta/model/gltf/Read.luau"],
|
||||||
[177286, "src/Rosetta/model/gltf/Write.luau"],
|
[177509, "src/Rosetta/model/gltf/Write.luau"],
|
||||||
[177972, "src/Rosetta/model/godot/init.luau"],
|
[178195, "src/Rosetta/model/godot/init.luau"],
|
||||||
[178063, "src/Rosetta/model/godot/Build.luau"],
|
[178286, "src/Rosetta/model/godot/Build.luau"],
|
||||||
[178605, "src/Rosetta/model/godot/Primitives.luau"],
|
[178828, "src/Rosetta/model/godot/Primitives.luau"],
|
||||||
[178880, "src/Rosetta/model/godot/Surface.luau"],
|
[179103, "src/Rosetta/model/godot/Surface.luau"],
|
||||||
[179365, "src/Rosetta/model/godot/Write.luau"],
|
[179588, "src/Rosetta/model/godot/Write.luau"],
|
||||||
[179694, "src/Rosetta/model/iqm/init.luau"],
|
[179917, "src/Rosetta/model/iqm/init.luau"],
|
||||||
[179770, "src/Rosetta/model/iqm/Read.luau"],
|
[179993, "src/Rosetta/model/iqm/Read.luau"],
|
||||||
[180125, "src/Rosetta/model/iqm/Write.luau"],
|
[180348, "src/Rosetta/model/iqm/Write.luau"],
|
||||||
[180812, "src/Rosetta/model/ldraw/init.luau"],
|
[181035, "src/Rosetta/model/ldraw/init.luau"],
|
||||||
[180890, "src/Rosetta/model/ldraw/Colors.luau"],
|
[181113, "src/Rosetta/model/ldraw/Colors.luau"],
|
||||||
[181208, "src/Rosetta/model/ldraw/Read.luau"],
|
[181431, "src/Rosetta/model/ldraw/Read.luau"],
|
||||||
[181785, "src/Rosetta/model/lwo/init.luau"],
|
[182008, "src/Rosetta/model/lwo/init.luau"],
|
||||||
[181861, "src/Rosetta/model/lwo/Build.luau"],
|
[182084, "src/Rosetta/model/lwo/Build.luau"],
|
||||||
[182323, "src/Rosetta/model/lwo/Parse.luau"],
|
[182546, "src/Rosetta/model/lwo/Parse.luau"],
|
||||||
[182866, "src/Rosetta/model/map/init.luau"],
|
[183089, "src/Rosetta/model/map/init.luau"],
|
||||||
[183183, "src/Rosetta/model/map/Build.luau"],
|
[183406, "src/Rosetta/model/map/Build.luau"],
|
||||||
[183427, "src/Rosetta/model/map/Parse.luau"],
|
[183650, "src/Rosetta/model/map/Parse.luau"],
|
||||||
[183812, "src/Rosetta/model/map/Write.luau"],
|
[184035, "src/Rosetta/model/map/Write.luau"],
|
||||||
[183958, "src/Rosetta/model/mca/init.luau"],
|
[184181, "src/Rosetta/model/mca/init.luau"],
|
||||||
[184300, "src/Rosetta/model/mca/Chunk.luau"],
|
[184523, "src/Rosetta/model/mca/Chunk.luau"],
|
||||||
[184433, "src/Rosetta/model/mca/Lz4Block.luau"],
|
[184656, "src/Rosetta/model/mca/Lz4Block.luau"],
|
||||||
[184503, "src/Rosetta/model/md2/init.luau"],
|
[184726, "src/Rosetta/model/md2/init.luau"],
|
||||||
[184702, "src/Rosetta/model/md3/init.luau"],
|
[184925, "src/Rosetta/model/md3/init.luau"],
|
||||||
[184930, "src/Rosetta/model/md5/init.luau"],
|
[185153, "src/Rosetta/model/md5/init.luau"],
|
||||||
[185011, "src/Rosetta/model/md5/Read.luau"],
|
[185234, "src/Rosetta/model/md5/Read.luau"],
|
||||||
[185444, "src/Rosetta/model/mdl/init.luau"],
|
[185667, "src/Rosetta/model/mdl/init.luau"],
|
||||||
[185526, "src/Rosetta/model/mdl/HalfLife.luau"],
|
[185749, "src/Rosetta/model/mdl/HalfLife.luau"],
|
||||||
[185830, "src/Rosetta/model/mdl/Quake.luau"],
|
[186053, "src/Rosetta/model/mdl/Quake.luau"],
|
||||||
[186048, "src/Rosetta/model/ms3d/init.luau"],
|
[186271, "src/Rosetta/model/ms3d/init.luau"],
|
||||||
[186120, "src/Rosetta/model/ms3d/Read.luau"],
|
[186343, "src/Rosetta/model/ms3d/Read.luau"],
|
||||||
[186566, "src/Rosetta/model/ms3d/Write.luau"],
|
[186789, "src/Rosetta/model/ms3d/Write.luau"],
|
||||||
[187035, "src/Rosetta/model/obj/init.luau"],
|
[187258, "src/Rosetta/model/obj/init.luau"],
|
||||||
[187853, "src/Rosetta/model/obj/Mtl.luau"],
|
[188076, "src/Rosetta/model/obj/Mtl.luau"],
|
||||||
[188141, "src/Rosetta/model/off/init.luau"],
|
[188364, "src/Rosetta/model/off/init.luau"],
|
||||||
[188603, "src/Rosetta/model/ply/init.luau"],
|
[188826, "src/Rosetta/model/ply/init.luau"],
|
||||||
[189708, "src/Rosetta/model/ply/Binary.luau"],
|
[189931, "src/Rosetta/model/ply/Binary.luau"],
|
||||||
[189909, "src/Rosetta/model/pmx/init.luau"],
|
[190132, "src/Rosetta/model/pmx/init.luau"],
|
||||||
[189978, "src/Rosetta/model/pmx/Build.luau"],
|
[190201, "src/Rosetta/model/pmx/Build.luau"],
|
||||||
[190274, "src/Rosetta/model/pmx/Pmd.luau"],
|
[190497, "src/Rosetta/model/pmx/Pmd.luau"],
|
||||||
[190609, "src/Rosetta/model/pmx/Read.luau"],
|
[190832, "src/Rosetta/model/pmx/Read.luau"],
|
||||||
[191013, "src/Rosetta/model/proc/init.luau"],
|
[191236, "src/Rosetta/model/proc/init.luau"],
|
||||||
[191395, "src/Rosetta/model/qb/init.luau"],
|
[191618, "src/Rosetta/model/qb/init.luau"],
|
||||||
[191788, "src/Rosetta/model/rbxm/init.luau"],
|
[192011, "src/Rosetta/model/rbxm/init.luau"],
|
||||||
[192381, "src/Rosetta/model/rbxmx/init.luau"],
|
[192604, "src/Rosetta/model/rbxmx/init.luau"],
|
||||||
[193057, "src/Rosetta/model/robloxmesh/init.luau"],
|
[193280, "src/Rosetta/model/robloxmesh/init.luau"],
|
||||||
[193716, "src/Rosetta/model/robloxmesh/Parse.luau"],
|
[193939, "src/Rosetta/model/robloxmesh/Parse.luau"],
|
||||||
[194173, "src/Rosetta/model/robloxmesh/Write.luau"],
|
[194396, "src/Rosetta/model/robloxmesh/Write.luau"],
|
||||||
[194282, "src/Rosetta/model/schematic/init.luau"],
|
[194505, "src/Rosetta/model/schematic/init.luau"],
|
||||||
[194603, "src/Rosetta/model/schematic/Common.luau"],
|
[194826, "src/Rosetta/model/schematic/Common.luau"],
|
||||||
[194723, "src/Rosetta/model/schematic/Litematic.luau"],
|
[194946, "src/Rosetta/model/schematic/Litematic.luau"],
|
||||||
[194934, "src/Rosetta/model/schematic/Mcedit.luau"],
|
[195157, "src/Rosetta/model/schematic/Mcedit.luau"],
|
||||||
[195178, "src/Rosetta/model/schematic/Sponge.luau"],
|
[195401, "src/Rosetta/model/schematic/Sponge.luau"],
|
||||||
[195307, "src/Rosetta/model/smd/init.luau"],
|
[195530, "src/Rosetta/model/smd/init.luau"],
|
||||||
[195374, "src/Rosetta/model/smd/Read.luau"],
|
[195597, "src/Rosetta/model/smd/Read.luau"],
|
||||||
[195643, "src/Rosetta/model/smd/Write.luau"],
|
[195866, "src/Rosetta/model/smd/Write.luau"],
|
||||||
[195886, "src/Rosetta/model/sourcemdl/init.luau"],
|
[196109, "src/Rosetta/model/sourcemdl/init.luau"],
|
||||||
[196057, "src/Rosetta/model/sourcemdl/Build.luau"],
|
[196280, "src/Rosetta/model/sourcemdl/Build.luau"],
|
||||||
[196487, "src/Rosetta/model/sourcemdl/Material.luau"],
|
[196710, "src/Rosetta/model/sourcemdl/Material.luau"],
|
||||||
[196648, "src/Rosetta/model/sourcemdl/Mdl.luau"],
|
[196871, "src/Rosetta/model/sourcemdl/Mdl.luau"],
|
||||||
[197175, "src/Rosetta/model/sourcemdl/Phy.luau"],
|
[197398, "src/Rosetta/model/sourcemdl/Phy.luau"],
|
||||||
[197298, "src/Rosetta/model/sourcemdl/Vtx.luau"],
|
[197521, "src/Rosetta/model/sourcemdl/Vtx.luau"],
|
||||||
[197480, "src/Rosetta/model/sourcemdl/Vvd.luau"],
|
[197703, "src/Rosetta/model/sourcemdl/Vvd.luau"],
|
||||||
[197574, "src/Rosetta/model/stl/init.luau"],
|
[197797, "src/Rosetta/model/stl/init.luau"],
|
||||||
[198024, "src/Rosetta/model/stl/Decode.luau"],
|
[198247, "src/Rosetta/model/stl/Decode.luau"],
|
||||||
[198098, "src/Rosetta/model/t3d/init.luau"],
|
[198321, "src/Rosetta/model/t3d/init.luau"],
|
||||||
[198192, "src/Rosetta/model/t3d/Build.luau"],
|
[198415, "src/Rosetta/model/t3d/Build.luau"],
|
||||||
[198597, "src/Rosetta/model/t3d/Parse.luau"],
|
[198820, "src/Rosetta/model/t3d/Parse.luau"],
|
||||||
[198765, "src/Rosetta/model/udmf/init.luau"],
|
[198988, "src/Rosetta/model/udmf/init.luau"],
|
||||||
[198848, "src/Rosetta/model/usda/init.luau"],
|
[199071, "src/Rosetta/model/usda/init.luau"],
|
||||||
[199057, "src/Rosetta/model/usda/Build.luau"],
|
[199280, "src/Rosetta/model/usda/Build.luau"],
|
||||||
[200335, "src/Rosetta/model/usda/Parse.luau"],
|
[200558, "src/Rosetta/model/usda/Parse.luau"],
|
||||||
[201133, "src/Rosetta/model/usda/Write.luau"],
|
[201356, "src/Rosetta/model/usda/Write.luau"],
|
||||||
[201950, "src/Rosetta/model/vbsp/init.luau"],
|
[202173, "src/Rosetta/model/vbsp/init.luau"],
|
||||||
[202396, "src/Rosetta/model/vbsp/Faces.luau"],
|
[202619, "src/Rosetta/model/vbsp/Faces.luau"],
|
||||||
[202620, "src/Rosetta/model/vbsp/Props.luau"],
|
[202843, "src/Rosetta/model/vbsp/Props.luau"],
|
||||||
[202712, "src/Rosetta/model/vmf/init.luau"],
|
[202935, "src/Rosetta/model/vmf/init.luau"],
|
||||||
[203037, "src/Rosetta/model/vmf/Build.luau"],
|
[203260, "src/Rosetta/model/vmf/Build.luau"],
|
||||||
[203461, "src/Rosetta/model/vox/init.luau"],
|
[203684, "src/Rosetta/model/vox/init.luau"],
|
||||||
[204347, "src/Rosetta/model/vox/Grid.luau"],
|
[204570, "src/Rosetta/model/vox/Grid.luau"],
|
||||||
[204404, "src/Rosetta/model/vrml/init.luau"],
|
[204627, "src/Rosetta/model/vrml/init.luau"],
|
||||||
[204470, "src/Rosetta/model/x/init.luau"],
|
[204693, "src/Rosetta/model/x/init.luau"],
|
||||||
[204600, "src/Rosetta/model/x/Build.luau"],
|
[204823, "src/Rosetta/model/x/Build.luau"],
|
||||||
[205163, "src/Rosetta/model/x/Parse.luau"],
|
[205386, "src/Rosetta/model/x/Parse.luau"],
|
||||||
[205460, "src/Rosetta/model/x3d/init.luau"],
|
[205683, "src/Rosetta/model/x3d/init.luau"],
|
||||||
[205538, "src/Rosetta/music/669/init.luau"],
|
[205761, "src/Rosetta/music/669/init.luau"],
|
||||||
[205745, "src/Rosetta/music/ahx/init.luau"],
|
[205968, "src/Rosetta/music/ahx/init.luau"],
|
||||||
[205797, "src/Rosetta/music/far/init.luau"],
|
[206020, "src/Rosetta/music/far/init.luau"],
|
||||||
[206027, "src/Rosetta/music/hmp/init.luau"],
|
[206250, "src/Rosetta/music/hmp/init.luau"],
|
||||||
[206292, "src/Rosetta/music/hvl/init.luau"],
|
[206515, "src/Rosetta/music/hvl/init.luau"],
|
||||||
[206344, "src/Rosetta/music/it/init.luau"],
|
[206567, "src/Rosetta/music/it/init.luau"],
|
||||||
[206763, "src/Rosetta/music/it/Itsex.luau"],
|
[206986, "src/Rosetta/music/it/Itsex.luau"],
|
||||||
[206880, "src/Rosetta/music/med/init.luau"],
|
[207103, "src/Rosetta/music/med/init.luau"],
|
||||||
[207528, "src/Rosetta/music/midi/init.luau"],
|
[207751, "src/Rosetta/music/midi/init.luau"],
|
||||||
[207672, "src/Rosetta/music/midi/Smf.luau"],
|
[207895, "src/Rosetta/music/midi/Smf.luau"],
|
||||||
[208084, "src/Rosetta/music/mod/init.luau"],
|
[208307, "src/Rosetta/music/mod/init.luau"],
|
||||||
[208438, "src/Rosetta/music/mtm/init.luau"],
|
[208661, "src/Rosetta/music/mtm/init.luau"],
|
||||||
[208661, "src/Rosetta/music/mus/init.luau"],
|
[208884, "src/Rosetta/music/mus/init.luau"],
|
||||||
[208819, "src/Rosetta/music/okt/init.luau"],
|
[209042, "src/Rosetta/music/okt/init.luau"],
|
||||||
[209101, "src/Rosetta/music/ptm/init.luau"],
|
[209324, "src/Rosetta/music/ptm/init.luau"],
|
||||||
[209324, "src/Rosetta/music/s3m/init.luau"],
|
[209547, "src/Rosetta/music/s3m/init.luau"],
|
||||||
[209561, "src/Rosetta/music/sf2/init.luau"],
|
[209784, "src/Rosetta/music/sf2/init.luau"],
|
||||||
[209605, "src/Rosetta/music/stm/init.luau"],
|
[209828, "src/Rosetta/music/stm/init.luau"],
|
||||||
[209837, "src/Rosetta/music/ult/init.luau"],
|
[210060, "src/Rosetta/music/ult/init.luau"],
|
||||||
[210142, "src/Rosetta/music/umx/init.luau"],
|
[210365, "src/Rosetta/music/umx/init.luau"],
|
||||||
[210359, "src/Rosetta/music/xm/init.luau"],
|
[210582, "src/Rosetta/music/xm/init.luau"],
|
||||||
[210921, "src/Rosetta/music/xmi/init.luau"],
|
[211144, "src/Rosetta/music/xmi/init.luau"],
|
||||||
[211130, "src/Rosetta/ops/AudioOps.luau"],
|
[211353, "src/Rosetta/ops/AudioOps.luau"],
|
||||||
[211609, "src/Rosetta/ops/ImageOps/init.luau"],
|
[211832, "src/Rosetta/ops/ImageOps/init.luau"],
|
||||||
[212257, "src/Rosetta/ops/ImageOps/Kernels.luau"],
|
[212480, "src/Rosetta/ops/ImageOps/Kernels.luau"],
|
||||||
[212897, "src/Rosetta/ops/LayerOps.luau"],
|
[213120, "src/Rosetta/ops/LayerOps.luau"],
|
||||||
[212990, "src/Rosetta/ops/MeshOps/init.luau"],
|
[213213, "src/Rosetta/ops/MeshOps/init.luau"],
|
||||||
[214130, "src/Rosetta/ops/MeshOps/Greedy.luau"],
|
[214353, "src/Rosetta/ops/MeshOps/Greedy.luau"],
|
||||||
[214297, "src/Rosetta/ops/MusicOps.luau"],
|
[214520, "src/Rosetta/ops/MusicOps.luau"],
|
||||||
[214646, "src/Rosetta/playlist/m3u/init.luau"],
|
[214869, "src/Rosetta/playlist/m3u/init.luau"],
|
||||||
[214999, "src/Rosetta/playlist/pls/init.luau"],
|
[215222, "src/Rosetta/playlist/pls/init.luau"],
|
||||||
[215177, "src/Rosetta/playlist/xspf/init.luau"],
|
[215400, "src/Rosetta/playlist/xspf/init.luau"],
|
||||||
[215380, "src/Rosetta/subtitle/ass/init.luau"],
|
[215603, "src/Rosetta/subtitle/ass/init.luau"],
|
||||||
[215824, "src/Rosetta/subtitle/srt/init.luau"],
|
[216047, "src/Rosetta/subtitle/srt/init.luau"],
|
||||||
[215997, "src/Rosetta/subtitle/vtt/init.luau"],
|
[216220, "src/Rosetta/subtitle/vtt/init.luau"],
|
||||||
[216200, "src/Rosetta/vector/gamemaps/init.luau"],
|
[216423, "src/Rosetta/vector/gamemaps/init.luau"],
|
||||||
[216387, "src/Rosetta/vector/gamemaps/Expand.luau"],
|
[216610, "src/Rosetta/vector/gamemaps/Expand.luau"],
|
||||||
[216484, "src/Rosetta/vector/ldtk/init.luau"],
|
[216707, "src/Rosetta/vector/ldtk/init.luau"],
|
||||||
[216576, "src/Rosetta/vector/ldtk/Read.luau"],
|
[216799, "src/Rosetta/vector/ldtk/Read.luau"],
|
||||||
[216912, "src/Rosetta/vector/ldtk/Write.luau"],
|
[217135, "src/Rosetta/vector/ldtk/Write.luau"],
|
||||||
[217560, "src/Rosetta/vector/ogmo/init.luau"],
|
[217783, "src/Rosetta/vector/ogmo/init.luau"],
|
||||||
[217679, "src/Rosetta/vector/ogmo/Read.luau"],
|
[217902, "src/Rosetta/vector/ogmo/Read.luau"],
|
||||||
[218084, "src/Rosetta/vector/ogmo/Write.luau"],
|
[218307, "src/Rosetta/vector/ogmo/Write.luau"],
|
||||||
[218438, "src/Rosetta/vector/svg/init.luau"],
|
[218661, "src/Rosetta/vector/svg/init.luau"],
|
||||||
[218524, "src/Rosetta/vector/svg/Parse.luau"],
|
[218747, "src/Rosetta/vector/svg/Parse.luau"],
|
||||||
[219270, "src/Rosetta/vector/svg/PathData.luau"],
|
[219493, "src/Rosetta/vector/svg/PathData.luau"],
|
||||||
[219638, "src/Rosetta/vector/svg/Render.luau"],
|
[219861, "src/Rosetta/vector/svg/Render.luau"],
|
||||||
[220055, "src/Rosetta/vector/svg/Style.luau"],
|
[220278, "src/Rosetta/vector/svg/Style.luau"],
|
||||||
[220427, "src/Rosetta/vector/svg/Write.luau"],
|
[220650, "src/Rosetta/vector/svg/Write.luau"],
|
||||||
[220627, "src/Rosetta/vector/tiled/init.luau"],
|
[220850, "src/Rosetta/vector/tiled/init.luau"],
|
||||||
[220807, "src/Rosetta/vector/tiled/Data.luau"],
|
[221030, "src/Rosetta/vector/tiled/Data.luau"],
|
||||||
[220958, "src/Rosetta/vector/tiled/Tmj.luau"],
|
[221181, "src/Rosetta/vector/tiled/Tmj.luau"],
|
||||||
[221589, "src/Rosetta/vector/tiled/Tmx.luau"],
|
[221812, "src/Rosetta/vector/tiled/Tmx.luau"],
|
||||||
[222201, "src/Rosetta/video/avi/init.luau"],
|
[222424, "src/Rosetta/video/avi/init.luau"],
|
||||||
[222495, "src/Rosetta/video/fli/init.luau"],
|
[222718, "src/Rosetta/video/fli/init.luau"],
|
||||||
[222646, "src/Rosetta/video/flv/init.luau"],
|
[222869, "src/Rosetta/video/flv/init.luau"],
|
||||||
[223030, "src/Rosetta/video/flv/Amf.luau"],
|
[223253, "src/Rosetta/video/flv/Amf.luau"],
|
||||||
[223188, "src/Rosetta/video/flv/Mux.luau"],
|
[223411, "src/Rosetta/video/flv/Mux.luau"],
|
||||||
[223469, "src/Rosetta/video/h264/init.luau"],
|
[223692, "src/Rosetta/video/h264/init.luau"],
|
||||||
[223608, "src/Rosetta/video/mkv/init.luau"],
|
[223831, "src/Rosetta/video/mkv/init.luau"],
|
||||||
[223764, "src/Rosetta/video/mkv/Mux.luau"],
|
[223987, "src/Rosetta/video/mkv/Mux.luau"],
|
||||||
[224043, "src/Rosetta/video/mkv/Parse.luau"],
|
[224266, "src/Rosetta/video/mkv/Parse.luau"],
|
||||||
[224764, "src/Rosetta/video/mp4/init.luau"],
|
[224987, "src/Rosetta/video/mp4/init.luau"],
|
||||||
[225092, "src/Rosetta/video/mpegps/init.luau"],
|
[225315, "src/Rosetta/video/mpegps/init.luau"],
|
||||||
[225279, "src/Rosetta/video/mpegts/init.luau"],
|
[225502, "src/Rosetta/video/mpegts/init.luau"],
|
||||||
[225525, "src/Rosetta/video/ogv/init.luau"],
|
[225748, "src/Rosetta/video/ogv/init.luau"],
|
||||||
[225920, "src/Rosetta/video/smk/init.luau"],
|
[226143, "src/Rosetta/video/smk/init.luau"],
|
||||||
[226229, "src/Rosetta/video/smk/Audio.luau"],
|
[226452, "src/Rosetta/video/smk/Audio.luau"],
|
||||||
[226349, "src/Rosetta/video/y4m/init.luau"]
|
[226572, "src/Rosetta/video/y4m/init.luau"]
|
||||||
]
|
]
|
||||||
Binary file not shown.
@@ -124,7 +124,7 @@
|
|||||||
"model_3mf": [[8, "src/Rosetta/model/3mf/init.luau"], [90, "src/Rosetta/model/3mf/Read.luau"], [678, "src/Rosetta/model/3mf/Write.luau"]],
|
"model_3mf": [[8, "src/Rosetta/model/3mf/init.luau"], [90, "src/Rosetta/model/3mf/Read.luau"], [678, "src/Rosetta/model/3mf/Write.luau"]],
|
||||||
"model_ase": [[8, "src/Rosetta/model/ase/init.luau"], [131, "src/Rosetta/model/ase/Build.luau"], [705, "src/Rosetta/model/ase/Parse.luau"], [774, "src/Rosetta/model/ase/Write.luau"]],
|
"model_ase": [[8, "src/Rosetta/model/ase/init.luau"], [131, "src/Rosetta/model/ase/Build.luau"], [705, "src/Rosetta/model/ase/Parse.luau"], [774, "src/Rosetta/model/ase/Write.luau"]],
|
||||||
"model_b3d": [[8, "src/Rosetta/model/b3d/init.luau"], [63, "src/Rosetta/model/b3d/Read.luau"]],
|
"model_b3d": [[8, "src/Rosetta/model/b3d/init.luau"], [63, "src/Rosetta/model/b3d/Read.luau"]],
|
||||||
"model_blend": [[8, "src/Rosetta/model/blend/init.luau"], [108, "src/Rosetta/model/blend/Anim.luau"], [638, "src/Rosetta/model/blend/Armature.luau"], [1174, "src/Rosetta/model/blend/Driver.luau"], [1349, "src/Rosetta/model/blend/Material.luau"], [1701, "src/Rosetta/model/blend/Mesh.luau"], [2389, "src/Rosetta/model/blend/Normals.luau"], [2550, "src/Rosetta/model/blend/Prim.luau"], [3057, "src/Rosetta/model/blend/Read.luau"]],
|
"model_blend": [[8, "src/Rosetta/model/blend/init.luau"], [108, "src/Rosetta/model/blend/Anim.luau"], [638, "src/Rosetta/model/blend/Armature.luau"], [1174, "src/Rosetta/model/blend/Driver.luau"], [1349, "src/Rosetta/model/blend/Material.luau"], [1924, "src/Rosetta/model/blend/Mesh.luau"], [2612, "src/Rosetta/model/blend/Normals.luau"], [2773, "src/Rosetta/model/blend/Prim.luau"], [3280, "src/Rosetta/model/blend/Read.luau"]],
|
||||||
"model_bsp": [[8, "src/Rosetta/model/bsp/init.luau"], [199, "src/Rosetta/model/bsp/Lightmap.luau"], [265, "src/Rosetta/model/bsp/Quake.luau"], [654, "src/Rosetta/model/bsp/Quake3.luau"], [883, "src/Rosetta/model/bsp/Tree.luau"]],
|
"model_bsp": [[8, "src/Rosetta/model/bsp/init.luau"], [199, "src/Rosetta/model/bsp/Lightmap.luau"], [265, "src/Rosetta/model/bsp/Quake.luau"], [654, "src/Rosetta/model/bsp/Quake3.luau"], [883, "src/Rosetta/model/bsp/Tree.luau"]],
|
||||||
"model_buildmap": [[8, "src/Rosetta/model/buildmap/init.luau"], [280, "src/Rosetta/model/buildmap/Geometry.luau"]],
|
"model_buildmap": [[8, "src/Rosetta/model/buildmap/init.luau"], [280, "src/Rosetta/model/buildmap/Geometry.luau"]],
|
||||||
"model_d3map": [[8, "src/Rosetta/model/d3map/init.luau"], [290, "src/Rosetta/model/d3map/Parse.luau"]],
|
"model_d3map": [[8, "src/Rosetta/model/d3map/init.luau"], [290, "src/Rosetta/model/d3map/Parse.luau"]],
|
||||||
|
|||||||
+264
-41
@@ -167598,10 +167598,13 @@ __FILES["model/blend/Material"] = function()
|
|||||||
-- model/blend/Material: Blender materials to Scene PBR materials. With nodes: the Principled BSDF (the one feeding the
|
-- model/blend/Material: Blender materials to Scene PBR materials. With nodes: the Principled BSDF (the one feeding the
|
||||||
-- material output, else the first): Base Color, Metallic, Roughness, Alpha, Emission (Color) x Emission Strength
|
-- material output, else the first): Base Color, Metallic, Roughness, Alpha, Emission (Color) x Emission Strength
|
||||||
-- (KHR_materials_emissive_strength above 1, as Blender's glTF exporter writes it), images linked directly to Base
|
-- (KHR_materials_emissive_strength above 1, as Blender's glTF exporter writes it), images linked directly to Base
|
||||||
-- Color / Emission and through a Normal Map node to Normal (its Strength as the scale), a Separate RGB / Color node to
|
-- Color / Emission / Roughness / Metallic and through a Normal Map node to Normal (its Strength as the scale), a
|
||||||
-- Roughness (G) and Metallic (B), UV Map nodes for the texCoord. Without nodes (or before 2.8 without a
|
-- Separate RGB / Color node to Roughness (G) and Metallic (B), UV Map nodes for the texCoord; links are followed
|
||||||
-- Principled node): Material.r / g / b / alpha, metallic, roughness. Images: packed files as encoded bytes, external
|
-- through reroutes, Mix / MixRGB (A then B), Hue-Saturation, Bright-Contrast, Gamma, Invert, RGB Curves, Color Ramp
|
||||||
-- ones as uris (with the bytes when opts.files / opts.resolve has them).
|
-- and node groups; a linked input that reaches no image takes a neutral value (base colour 0.8 grey, Blender's
|
||||||
|
-- default; metallic 0, roughness 0.5) and is flagged. Without nodes (or before 2.8 without a Principled node):
|
||||||
|
-- Material.r / g / b / alpha, metallic, roughness. Images: packed files as encoded bytes, external ones as uris (with
|
||||||
|
-- the bytes when opts.files / opts.resolve has them); tiled (UDIM) images keep the <UDIM> token in the uri.
|
||||||
local Blend = __include("containers/Blend")
|
local Blend = __include("containers/Blend")
|
||||||
local Types = __include("Types")
|
local Types = __include("Types")
|
||||||
|
|
||||||
@@ -167667,6 +167670,34 @@ local function texture(ctx: Ctx, img: Blend.View, sampler: Types.Sampler?): numb
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local tex: Types.Texture = { name = name, sampler = sampler }
|
local tex: Types.Texture = { name = name, sampler = sampler }
|
||||||
|
local tiles: { { [string]: any } }? = nil
|
||||||
|
if (img:num("source") or 0) == 6 then -- IMA_SRC_TILED
|
||||||
|
tiles = {}
|
||||||
|
for _, t in img:list("tiles", "ImageTile") do
|
||||||
|
local label = t:str("label")
|
||||||
|
table.insert(tiles :: any, { number = t:num("tile_number") or 1001, label = if label and label ~= "" then label else nil })
|
||||||
|
end
|
||||||
|
if #(tiles :: any) == 0 then
|
||||||
|
table.insert(tiles :: any, { number = 1001 })
|
||||||
|
end
|
||||||
|
if path and not string.find(path, "<UDIM>", 1, true) and not string.find(path, "<UVTILE>", 1, true) then
|
||||||
|
-- the tile number in the file name becomes the token, as Blender's versioning does for older files
|
||||||
|
local first = tostring((tiles :: any)[1].number)
|
||||||
|
local dir, file = string.match(path, "^(.-)([^/\\]*)$")
|
||||||
|
local a, b = nil, nil
|
||||||
|
local from = 1
|
||||||
|
while true do
|
||||||
|
local x, y = string.find(file or "", first, from, true)
|
||||||
|
if not x then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
a, b, from = x, y, x + 1
|
||||||
|
end
|
||||||
|
if a and b and file then
|
||||||
|
path = (dir or "") .. string.sub(file, 1, a - 1) .. "<UDIM>" .. string.sub(file, b + 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
if pf then
|
if pf then
|
||||||
local blk = pf:target("data")
|
local blk = pf:target("data")
|
||||||
local size = pf:num("size") or 0
|
local size = pf:num("size") or 0
|
||||||
@@ -167683,7 +167714,8 @@ local function texture(ctx: Ctx, img: Blend.View, sampler: Types.Sampler?): numb
|
|||||||
uri = string.gsub(uri, "\\", "/")
|
uri = string.gsub(uri, "\\", "/")
|
||||||
if not tex.data then
|
if not tex.data then
|
||||||
tex.uri = uri
|
tex.uri = uri
|
||||||
local data = fetch(ctx, uri)
|
local first = if tiles then tostring(tiles[1].number) else nil
|
||||||
|
local data = fetch(ctx, if first then (string.gsub(string.gsub(uri, "<UDIM>", first), "<UVTILE>", "u1_v1")) else uri)
|
||||||
if data then
|
if data then
|
||||||
tex.data = data
|
tex.data = data
|
||||||
tex.mime = sniffMime(data, 0, buffer.len(data), uri)
|
tex.mime = sniffMime(data, 0, buffer.len(data), uri)
|
||||||
@@ -167691,7 +167723,12 @@ local function texture(ctx: Ctx, img: Blend.View, sampler: Types.Sampler?): numb
|
|||||||
tex.mime = sniffMime(buffer.create(0), 0, 0, uri)
|
tex.mime = sniffMime(buffer.create(0), 0, 0, uri)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
tex.extras = { blend = { filepath = path } }
|
tex.extras = { blend = { filepath = path, tiles = tiles } }
|
||||||
|
if tiles then
|
||||||
|
for _, t in tiles do
|
||||||
|
t.filename = (string.gsub(uri, "<UDIM>", tostring(t.number)))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if not tex.data and not tex.uri then
|
if not tex.data and not tex.uri then
|
||||||
tex.extras = { blend = { generated = true } }
|
tex.extras = { blend = { generated = true } }
|
||||||
@@ -167704,17 +167741,22 @@ local function texture(ctx: Ctx, img: Blend.View, sampler: Types.Sampler?): numb
|
|||||||
return idx
|
return idx
|
||||||
end
|
end
|
||||||
|
|
||||||
type Node = { view: Blend.View, idname: string, inputs: { [string]: Blend.View }, outputs: { [any]: string } }
|
type Node = { view: Blend.View, idname: string, inputs: { [string]: Blend.View }, byId: { [string]: Blend.View }, first: Blend.View?, outputs: { [any]: string }, outIds: { [any]: string } }
|
||||||
type Graph = { nodes: { [any]: Node }, links: { [any]: { node: Node, socket: string } } } -- links by tosock addr
|
type Link = { node: Node, socket: string, ident: string }
|
||||||
|
type Graph = { nodes: { [any]: Node }, links: { [any]: Link } } -- links by tosock addr
|
||||||
|
|
||||||
local function graph(tree: Blend.View): Graph
|
local function graph(tree: Blend.View): Graph
|
||||||
local g: Graph = { nodes = {}, links = {} }
|
local g: Graph = { nodes = {}, links = {} }
|
||||||
for _, n in tree:list("nodes", "bNode") do
|
for _, n in tree:list("nodes", "bNode") do
|
||||||
local node: Node = { view = n, idname = n:str("idname") or "", inputs = {}, outputs = {} }
|
local node: Node = { view = n, idname = n:str("idname") or "", inputs = {}, byId = {}, outputs = {}, outIds = {} }
|
||||||
for _, s in n:list("inputs", "bNodeSocket") do
|
for _, s in n:list("inputs", "bNodeSocket") do
|
||||||
local id = s:str("identifier") or s:str("name") or ""
|
local id = s:str("identifier") or s:str("name") or ""
|
||||||
local nm = s:str("name") or id
|
local nm = s:str("name") or id
|
||||||
node.inputs[nm] = s
|
node.first = node.first or s
|
||||||
|
node.byId[id] = s
|
||||||
|
if node.inputs[nm] == nil then
|
||||||
|
node.inputs[nm] = s
|
||||||
|
end
|
||||||
if node.inputs[id] == nil then
|
if node.inputs[id] == nil then
|
||||||
node.inputs[id] = s
|
node.inputs[id] = s
|
||||||
end
|
end
|
||||||
@@ -167722,6 +167764,7 @@ local function graph(tree: Blend.View): Graph
|
|||||||
for _, s in n:list("outputs", "bNodeSocket") do
|
for _, s in n:list("outputs", "bNodeSocket") do
|
||||||
if s.block then
|
if s.block then
|
||||||
node.outputs[s.block.addr] = s:str("name") or ""
|
node.outputs[s.block.addr] = s:str("name") or ""
|
||||||
|
node.outIds[s.block.addr] = s:str("identifier") or s:str("name") or ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if n.block then
|
if n.block then
|
||||||
@@ -167732,7 +167775,7 @@ local function graph(tree: Blend.View): Graph
|
|||||||
local from, fs, to = l:ptr("fromnode"), l:ptr("fromsock"), l:ptr("tosock")
|
local from, fs, to = l:ptr("fromnode"), l:ptr("fromsock"), l:ptr("tosock")
|
||||||
local fn = from and g.nodes[from]
|
local fn = from and g.nodes[from]
|
||||||
if fn and to ~= nil and bit32.band(l:num("flag") or 0, 0x10) == 0 then
|
if fn and to ~= nil and bit32.band(l:num("flag") or 0, 0x10) == 0 then
|
||||||
g.links[to] = { node = fn, socket = (fs and fn.outputs[fs]) or "" }
|
g.links[to] = { node = fn, socket = (fs and fn.outputs[fs]) or "", ident = (fs and fn.outIds[fs]) or "" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return g
|
return g
|
||||||
@@ -167748,7 +167791,7 @@ local function input(n: Node, ...: string): Blend.View?
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function link(g: Graph, s: Blend.View?): { node: Node, socket: string }?
|
local function link(g: Graph, s: Blend.View?): Link?
|
||||||
if not s or not s.block then
|
if not s or not s.block then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -167767,23 +167810,87 @@ local function value(s: Blend.View?, kind: string): any
|
|||||||
return v and v:num("value")
|
return v and v:num("value")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function imageRef(ctx: Ctx, g: Graph, uvNames: any, s: Blend.View?, through: string?): (Types.TextureRef?, Node?)
|
-- pass-through nodes: the inputs (by identifier) that may lead to an image, in the order tried
|
||||||
|
local PASS: { [string]: { string } } = {
|
||||||
|
NodeReroute = { "Input" }, ShaderNodeMix = { "A_Color", "B_Color" }, ShaderNodeMixRGB = { "Color1", "Color2" },
|
||||||
|
ShaderNodeHueSaturation = { "Color" }, ShaderNodeBrightContrast = { "Color" }, ShaderNodeGamma = { "Color" },
|
||||||
|
ShaderNodeInvert = { "Color" }, ShaderNodeRGBCurve = { "Color" }, ShaderNodeValToRGB = { "Fac" },
|
||||||
|
}
|
||||||
|
|
||||||
|
type Hit = { node: Node, g: Graph, output: string }
|
||||||
|
type Frame = { node: Node, g: Graph }
|
||||||
|
|
||||||
|
local function groupGraph(n: Node): Graph?
|
||||||
|
local tree = n.view:deref("id", 0, "bNodeTree")
|
||||||
|
return if tree then graph(tree) else nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- the first image texture node a socket reaches through pass-through nodes and node groups (via: the nodes passed),
|
||||||
|
-- else the node it is linked to (reroutes skipped)
|
||||||
|
local function trace(g: Graph, s: Blend.View?, via: { string }, stack: { Frame }, depth: number): (Hit?, Node?)
|
||||||
local l = link(g, s)
|
local l = link(g, s)
|
||||||
if not l then
|
if not l or depth > 64 then
|
||||||
return nil, nil
|
return nil, nil
|
||||||
end
|
end
|
||||||
local n = l.node
|
local n = l.node
|
||||||
if through and n.idname == through then
|
if n.idname == "ShaderNodeTexImage" then
|
||||||
local inner = input(n, "Color", "Image")
|
return { node = n, g = g, output = l.socket }, n
|
||||||
local ref, tn = imageRef(ctx, g, uvNames, inner, nil)
|
elseif n.idname == "ShaderNodeGroup" then
|
||||||
return ref, if ref then n else tn
|
local inner = groupGraph(n)
|
||||||
end
|
local out: Node? = nil
|
||||||
if n.idname ~= "ShaderNodeTexImage" then
|
for _, x in if inner then inner.nodes else {} do
|
||||||
|
if x.idname == "NodeGroupOutput" and (out == nil or bit32.band(x.view:num("flag") or 0, 2) ~= 0) then
|
||||||
|
out = x
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local sock = out and out.byId[l.ident]
|
||||||
|
if inner and sock then
|
||||||
|
local stack2 = table.clone(stack)
|
||||||
|
table.insert(stack2, { node = n, g = g })
|
||||||
|
local sub = {}
|
||||||
|
local hit = trace(inner, sock, sub, stack2, depth + 1)
|
||||||
|
if hit then
|
||||||
|
table.insert(via, n.idname)
|
||||||
|
table.move(sub, 1, #sub, #via + 1, via)
|
||||||
|
return hit, n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil, n
|
||||||
|
elseif n.idname == "NodeGroupInput" and #stack > 0 then
|
||||||
|
local top = stack[#stack]
|
||||||
|
local outer = top.node.byId[l.ident]
|
||||||
|
local stack2 = table.clone(stack)
|
||||||
|
table.remove(stack2)
|
||||||
|
if outer then
|
||||||
|
return trace(top.g, outer, via, stack2, depth + 1)
|
||||||
|
end
|
||||||
return nil, n
|
return nil, n
|
||||||
end
|
end
|
||||||
|
local ids = PASS[n.idname]
|
||||||
|
if ids then
|
||||||
|
for _, id in ids do
|
||||||
|
local sock = n.byId[id] or (if n.idname == "NodeReroute" then n.first else nil)
|
||||||
|
local sub = {}
|
||||||
|
local hit, last = trace(g, sock, sub, stack, depth + 1)
|
||||||
|
if hit then
|
||||||
|
table.insert(via, n.idname)
|
||||||
|
table.move(sub, 1, #sub, #via + 1, via)
|
||||||
|
return hit, n
|
||||||
|
end
|
||||||
|
if n.idname == "NodeReroute" then
|
||||||
|
return nil, last or n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil, n
|
||||||
|
end
|
||||||
|
|
||||||
|
-- the TextureRef of an image texture node (its sampler, its UV Map node's texCoord)
|
||||||
|
local function refOf(ctx: Ctx, uvNames: any, hit: Hit): Types.TextureRef?
|
||||||
|
local n, g = hit.node, hit.g
|
||||||
local img = n.view:deref("id", 0, "Image")
|
local img = n.view:deref("id", 0, "Image")
|
||||||
if not img then
|
if not img then
|
||||||
return nil, n
|
return nil
|
||||||
end
|
end
|
||||||
local sampler: Types.Sampler = {}
|
local sampler: Types.Sampler = {}
|
||||||
local custom = false
|
local custom = false
|
||||||
@@ -167803,7 +167910,7 @@ local function imageRef(ctx: Ctx, g: Graph, uvNames: any, s: Blend.View?, throug
|
|||||||
end
|
end
|
||||||
local t = texture(ctx, img, if custom then sampler else nil)
|
local t = texture(ctx, img, if custom then sampler else nil)
|
||||||
if not t then
|
if not t then
|
||||||
return nil, n
|
return nil
|
||||||
end
|
end
|
||||||
local ref: Types.TextureRef = { texture = t }
|
local ref: Types.TextureRef = { texture = t }
|
||||||
local vec = link(g, input(n, "Vector"))
|
local vec = link(g, input(n, "Vector"))
|
||||||
@@ -167814,7 +167921,31 @@ local function imageRef(ctx: Ctx, g: Graph, uvNames: any, s: Blend.View?, throug
|
|||||||
ref.texCoord = uvNames[name]
|
ref.texCoord = uvNames[name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ref, n
|
return ref
|
||||||
|
end
|
||||||
|
|
||||||
|
local function imageRef(ctx: Ctx, g: Graph, uvNames: any, s: Blend.View?): (Types.TextureRef?, Node?, { string }, Hit?)
|
||||||
|
local via = {}
|
||||||
|
local hit, last = trace(g, s, via, {}, 0)
|
||||||
|
if not hit then
|
||||||
|
return nil, last, via, nil
|
||||||
|
end
|
||||||
|
return refOf(ctx, uvNames, hit), last, via, hit
|
||||||
|
end
|
||||||
|
|
||||||
|
-- the vertex colour layer a Vertex Color / Attribute node reads
|
||||||
|
local function vertexColor(n: Node?): string?
|
||||||
|
if not n then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
if n.idname == "ShaderNodeVertexColor" then
|
||||||
|
local st = n.view:deref("storage", 0, "NodeShaderVertexColor")
|
||||||
|
return st and st:str("layer_name") or ""
|
||||||
|
elseif n.idname == "ShaderNodeAttribute" then
|
||||||
|
local st = n.view:deref("storage", 0, "NodeShaderAttribute")
|
||||||
|
return st and st:str("name") or ""
|
||||||
|
end
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function principled(g: Graph): Node?
|
local function principled(g: Graph): Node?
|
||||||
@@ -167878,47 +168009,139 @@ function Material.get(ctx: Ctx, mv: Blend.View): number
|
|||||||
end
|
end
|
||||||
m.metallic = value(input(bsdf, "Metallic"), "float") or m.metallic
|
m.metallic = value(input(bsdf, "Metallic"), "float") or m.metallic
|
||||||
m.roughness = value(input(bsdf, "Roughness"), "float") or m.roughness
|
m.roughness = value(input(bsdf, "Roughness"), "float") or m.roughness
|
||||||
local bref = imageRef(ctx, g, uvNames, input(bsdf, "Base Color"), nil)
|
local linked: { [string]: string } = {}
|
||||||
|
local via: { [string]: { string } } = {}
|
||||||
|
-- node names as Blender 3.4+ shows them (its versioning turns shader MixRGB nodes into Mix nodes)
|
||||||
|
local function api(idname: string): string
|
||||||
|
return if idname == "ShaderNodeMixRGB" and f.version < 304 then "ShaderNodeMix" else idname
|
||||||
|
end
|
||||||
|
local function resolve(key: string, sock: Blend.View?): (Types.TextureRef?, Node?, Hit?)
|
||||||
|
if not link(g :: Graph, sock) then
|
||||||
|
return nil, nil, nil
|
||||||
|
end
|
||||||
|
local ref, last, passed, hit = imageRef(ctx, g :: Graph, uvNames, sock)
|
||||||
|
if ref then
|
||||||
|
if #passed > 0 then
|
||||||
|
for i, x in passed do
|
||||||
|
passed[i] = api(x)
|
||||||
|
end
|
||||||
|
via[key] = passed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ref, last, hit
|
||||||
|
end
|
||||||
|
local function unresolved(key: string, sock: Blend.View?)
|
||||||
|
local l = link(g :: Graph, sock)
|
||||||
|
if l then
|
||||||
|
local _, last = trace(g :: Graph, sock, {}, {}, 0) -- reroutes skipped
|
||||||
|
linked[key] = api((last or l.node).idname)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local baseSock = input(bsdf, "Base Color")
|
||||||
|
local bref, blast = resolve("baseColor", baseSock)
|
||||||
if bref then
|
if bref then
|
||||||
m.baseColorTexture = bref
|
m.baseColorTexture = bref
|
||||||
m.baseColor = { 1, 1, 1, alpha }
|
m.baseColor = { 1, 1, 1, alpha }
|
||||||
|
elseif link(g, baseSock) then
|
||||||
|
local layer = vertexColor(blast)
|
||||||
|
if layer then
|
||||||
|
extras.vertexColor = layer
|
||||||
|
m.baseColor = { 1, 1, 1, alpha }
|
||||||
|
else
|
||||||
|
m.baseColor = { 0.8, 0.8, 0.8, alpha } -- Blender's default base colour, never the linked socket's value
|
||||||
|
unresolved("baseColor", baseSock)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local aref = imageRef(ctx, g, uvNames, input(bsdf, "Alpha"), nil)
|
local alphaSock = input(bsdf, "Alpha")
|
||||||
|
local aref = resolve("alpha", alphaSock)
|
||||||
if aref and not m.baseColorTexture then
|
if aref and not m.baseColorTexture then
|
||||||
m.baseColorTexture = aref
|
m.baseColorTexture = aref
|
||||||
|
elseif not aref and link(g, alphaSock) then
|
||||||
|
m.baseColor[4] = 1
|
||||||
|
unresolved("alpha", alphaSock)
|
||||||
end
|
end
|
||||||
local nref, nnode = imageRef(ctx, g, uvNames, input(bsdf, "Normal"), "ShaderNodeNormalMap")
|
local nl = link(g, input(bsdf, "Normal"))
|
||||||
if nref then
|
if nl and nl.node.idname == "ShaderNodeNormalMap" then
|
||||||
nref.scale = if nnode then value(nnode.inputs.Strength, "float") or 1 else 1
|
local nref = resolve("normal", input(nl.node, "Color"))
|
||||||
m.normalTexture = nref
|
if nref then
|
||||||
|
nref.scale = value(nl.node.inputs.Strength, "float") or 1
|
||||||
|
m.normalTexture = nref
|
||||||
|
else
|
||||||
|
unresolved("normal", input(bsdf, "Normal"))
|
||||||
|
end
|
||||||
|
elseif nl and nl.node.idname == "ShaderNodeBump" then
|
||||||
|
local href = resolve("bump", input(nl.node, "Height"))
|
||||||
|
if href then
|
||||||
|
extras.bumpTexture = href
|
||||||
|
extras.bumpStrength = value(input(nl.node, "Strength"), "float") or 1
|
||||||
|
extras.bumpDistance = value(input(nl.node, "Distance"), "float") or 1
|
||||||
|
else
|
||||||
|
unresolved("normal", input(bsdf, "Normal"))
|
||||||
|
end
|
||||||
|
elseif nl then
|
||||||
|
unresolved("normal", input(bsdf, "Normal"))
|
||||||
end
|
end
|
||||||
local rl = link(g, input(bsdf, "Roughness"))
|
local channelOf = { Red = "R", Green = "G", Blue = "B", R = "R", G = "G", B = "B", Alpha = "A", Color = "R", Fac = "R" }
|
||||||
local ml = link(g, input(bsdf, "Metallic"))
|
local function scalar(key: string, sock: Blend.View?): boolean?
|
||||||
local sep = (rl and rl.node) or (ml and ml.node)
|
local l = link(g :: Graph, sock)
|
||||||
if sep and (sep.idname == "ShaderNodeSeparateRGB" or sep.idname == "ShaderNodeSeparateColor") then
|
if not l then
|
||||||
local mref = imageRef(ctx, g, uvNames, input(sep, "Image", "Color"), nil)
|
return nil
|
||||||
if mref then
|
end
|
||||||
m.metallicRoughnessTexture = mref
|
local sep = l.node
|
||||||
if rl then
|
if sep.idname == "ShaderNodeSeparateRGB" or sep.idname == "ShaderNodeSeparateColor" then
|
||||||
m.roughness = 1
|
local ref = resolve(key, input(sep, "Image", "Color"))
|
||||||
|
if ref then
|
||||||
|
m.metallicRoughnessTexture = m.metallicRoughnessTexture or table.clone(ref)
|
||||||
|
local r = table.clone(ref) :: any
|
||||||
|
r.channel = channelOf[l.socket] or l.socket
|
||||||
|
extras[key .. "Texture"] = r
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
if ml then
|
else
|
||||||
m.metallic = 1
|
local ref, _, hit = resolve(key, sock)
|
||||||
|
if ref and hit then
|
||||||
|
local r = ref :: any
|
||||||
|
r.channel = channelOf[hit.output] or hit.output
|
||||||
|
extras[key .. "Texture"] = r
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
unresolved(key, sock)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local rs = scalar("roughness", input(bsdf, "Roughness"))
|
||||||
|
if rs == true then
|
||||||
|
m.roughness = 1
|
||||||
|
elseif rs == false then
|
||||||
|
m.roughness = 0.5
|
||||||
|
end
|
||||||
|
local ms = scalar("metallic", input(bsdf, "Metallic"))
|
||||||
|
if ms == true then
|
||||||
|
m.metallic = 1
|
||||||
|
elseif ms == false then
|
||||||
|
m.metallic = 0
|
||||||
end
|
end
|
||||||
local es = input(bsdf, "Emission Color", "Emission")
|
local es = input(bsdf, "Emission Color", "Emission")
|
||||||
local ecol = value(es, "rgba") or { 0, 0, 0, 1 }
|
local ecol = value(es, "rgba") or { 0, 0, 0, 1 }
|
||||||
local strength = value(input(bsdf, "Emission Strength"), "float") or 1
|
local strength = value(input(bsdf, "Emission Strength"), "float") or 1
|
||||||
local eref = imageRef(ctx, g, uvNames, es, nil)
|
local eref = resolve("emissive", es)
|
||||||
if eref then
|
if eref then
|
||||||
m.emissiveTexture = eref
|
m.emissiveTexture = eref
|
||||||
ecol = { 1, 1, 1, 1 }
|
ecol = { 1, 1, 1, 1 }
|
||||||
|
elseif link(g, es) then
|
||||||
|
ecol = { 0, 0, 0, 1 }
|
||||||
|
unresolved("emissive", es)
|
||||||
end
|
end
|
||||||
emissive(m, ecol, strength)
|
emissive(m, ecol, strength)
|
||||||
if not eref and m.emissive[1] == 0 and m.emissive[2] == 0 and m.emissive[3] == 0 then
|
if not eref and m.emissive[1] == 0 and m.emissive[2] == 0 and m.emissive[3] == 0 then
|
||||||
m.emissive = { 0, 0, 0 }
|
m.emissive = { 0, 0, 0 }
|
||||||
end
|
end
|
||||||
|
if next(linked) ~= nil then
|
||||||
|
extras.linked = linked
|
||||||
|
end
|
||||||
|
if next(via) ~= nil then
|
||||||
|
extras.via = via
|
||||||
|
end
|
||||||
local alphaLinked = link(g, input(bsdf, "Alpha")) ~= nil
|
local alphaLinked = link(g, input(bsdf, "Alpha")) ~= nil
|
||||||
if alpha < 1 or alphaLinked then
|
if alpha < 1 or alphaLinked then
|
||||||
local bm = mv:num("blend_method") or 0
|
local bm = mv:num("blend_method") or 0
|
||||||
|
|||||||
+261
-38
@@ -165952,10 +165952,13 @@ local __compat = __compat local buffer, bit32, type, __iter = __compat.buffer, _
|
|||||||
-- model/blend/Material: Blender materials to Scene PBR materials. With nodes: the Principled BSDF (the one feeding the
|
-- model/blend/Material: Blender materials to Scene PBR materials. With nodes: the Principled BSDF (the one feeding the
|
||||||
-- material output, else the first): Base Color, Metallic, Roughness, Alpha, Emission (Color) x Emission Strength
|
-- material output, else the first): Base Color, Metallic, Roughness, Alpha, Emission (Color) x Emission Strength
|
||||||
-- (KHR_materials_emissive_strength above 1, as Blender's glTF exporter writes it), images linked directly to Base
|
-- (KHR_materials_emissive_strength above 1, as Blender's glTF exporter writes it), images linked directly to Base
|
||||||
-- Color / Emission and through a Normal Map node to Normal (its Strength as the scale), a Separate RGB / Color node to
|
-- Color / Emission / Roughness / Metallic and through a Normal Map node to Normal (its Strength as the scale), a
|
||||||
-- Roughness (G) and Metallic (B), UV Map nodes for the texCoord. Without nodes (or before 2.8 without a
|
-- Separate RGB / Color node to Roughness (G) and Metallic (B), UV Map nodes for the texCoord; links are followed
|
||||||
-- Principled node): Material.r / g / b / alpha, metallic, roughness. Images: packed files as encoded bytes, external
|
-- through reroutes, Mix / MixRGB (A then B), Hue-Saturation, Bright-Contrast, Gamma, Invert, RGB Curves, Color Ramp
|
||||||
-- ones as uris (with the bytes when opts.files / opts.resolve has them).
|
-- and node groups; a linked input that reaches no image takes a neutral value (base colour 0.8 grey, Blender's
|
||||||
|
-- default; metallic 0, roughness 0.5) and is flagged. Without nodes (or before 2.8 without a Principled node):
|
||||||
|
-- Material.r / g / b / alpha, metallic, roughness. Images: packed files as encoded bytes, external ones as uris (with
|
||||||
|
-- the bytes when opts.files / opts.resolve has them); tiled (UDIM) images keep the <UDIM> token in the uri.
|
||||||
local Blend = __include("containers/Blend")
|
local Blend = __include("containers/Blend")
|
||||||
local Types = __include("Types")
|
local Types = __include("Types")
|
||||||
|
|
||||||
@@ -166021,6 +166024,34 @@ local f = ctx.f
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local tex= { name = name, sampler = sampler }
|
local tex= { name = name, sampler = sampler }
|
||||||
|
local tiles= nil
|
||||||
|
if (img:num("source") or 0) == 6 then -- IMA_SRC_TILED
|
||||||
|
tiles = {}
|
||||||
|
for _, t in __iter(img:list("tiles", "ImageTile")) do
|
||||||
|
local label = t:str("label")
|
||||||
|
table.insert(tiles , { number = t:num("tile_number") or 1001, label = (label and label ~= "" and{label }or{nil })[1]})
|
||||||
|
end
|
||||||
|
if #(tiles ) == 0 then
|
||||||
|
table.insert(tiles , { number = 1001 })
|
||||||
|
end
|
||||||
|
if path and not string.find(path, "<UDIM>", 1, true) and not string.find(path, "<UVTILE>", 1, true) then
|
||||||
|
-- the tile number in the file name becomes the token, as Blender's versioning does for older files
|
||||||
|
local first = tostring((tiles )[1].number)
|
||||||
|
local dir, file = string.match(path, "^(.-)([^/\\]*)$")
|
||||||
|
local a, b = nil, nil
|
||||||
|
local from = 1
|
||||||
|
while true do
|
||||||
|
local x, y = string.find(file or "", first, from, true)
|
||||||
|
if not x then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
a, b, from = x, y, x + 1
|
||||||
|
end
|
||||||
|
if a and b and file then
|
||||||
|
path = (dir or "") .. string.sub(file, 1, a - 1) .. "<UDIM>" .. string.sub(file, b + 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
if pf then
|
if pf then
|
||||||
local blk = pf:target("data")
|
local blk = pf:target("data")
|
||||||
local size = pf:num("size") or 0
|
local size = pf:num("size") or 0
|
||||||
@@ -166037,7 +166068,8 @@ local f = ctx.f
|
|||||||
uri = string.gsub(uri, "\\", "/")
|
uri = string.gsub(uri, "\\", "/")
|
||||||
if not tex.data then
|
if not tex.data then
|
||||||
tex.uri = uri
|
tex.uri = uri
|
||||||
local data = fetch(ctx, uri)
|
local first = (tiles and{(tostring(tiles[1].number) )}or{nil
|
||||||
|
})[1] local data = fetch(ctx, (first and{(string.gsub(string.gsub(uri, "<UDIM>", first), "<UVTILE>", "u1_v1")) }or{uri})[1])
|
||||||
if data then
|
if data then
|
||||||
tex.data = data
|
tex.data = data
|
||||||
tex.mime = sniffMime(data, 0, buffer.len(data), uri)
|
tex.mime = sniffMime(data, 0, buffer.len(data), uri)
|
||||||
@@ -166045,7 +166077,12 @@ local f = ctx.f
|
|||||||
tex.mime = sniffMime(buffer.create(0), 0, 0, uri)
|
tex.mime = sniffMime(buffer.create(0), 0, 0, uri)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
tex.extras = { blend = { filepath = path } }
|
tex.extras = { blend = { filepath = path, tiles = tiles } }
|
||||||
|
if tiles then
|
||||||
|
for _, t in __iter(tiles) do
|
||||||
|
t.filename = (string.gsub(uri, "<UDIM>", tostring(t.number)))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if not tex.data and not tex.uri then
|
if not tex.data and not tex.uri then
|
||||||
tex.extras = { blend = { generated = true } }
|
tex.extras = { blend = { generated = true } }
|
||||||
@@ -166061,14 +166098,19 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function graph(tree)
|
local function graph(tree)
|
||||||
local g= { nodes = {}, links = {} }
|
local g= { nodes = {}, links = {} }
|
||||||
for _, n in __iter(tree:list("nodes", "bNode")) do
|
for _, n in __iter(tree:list("nodes", "bNode")) do
|
||||||
local node= { view = n, idname = n:str("idname") or "", inputs = {}, outputs = {} }
|
local node= { view = n, idname = n:str("idname") or "", inputs = {}, byId = {}, outputs = {}, outIds = {} }
|
||||||
for _, s in __iter(n:list("inputs", "bNodeSocket")) do
|
for _, s in __iter(n:list("inputs", "bNodeSocket")) do
|
||||||
local id = s:str("identifier") or s:str("name") or ""
|
local id = s:str("identifier") or s:str("name") or ""
|
||||||
local nm = s:str("name") or id
|
local nm = s:str("name") or id
|
||||||
node.inputs[nm] = s
|
node.first = node.first or s
|
||||||
|
node.byId[id] = s
|
||||||
|
if node.inputs[nm] == nil then
|
||||||
|
node.inputs[nm] = s
|
||||||
|
end
|
||||||
if node.inputs[id] == nil then
|
if node.inputs[id] == nil then
|
||||||
node.inputs[id] = s
|
node.inputs[id] = s
|
||||||
end
|
end
|
||||||
@@ -166076,6 +166118,7 @@ local g= { nodes = {}, links = {} }
|
|||||||
for _, s in __iter(n:list("outputs", "bNodeSocket")) do
|
for _, s in __iter(n:list("outputs", "bNodeSocket")) do
|
||||||
if s.block then
|
if s.block then
|
||||||
node.outputs[s.block.addr] = s:str("name") or ""
|
node.outputs[s.block.addr] = s:str("name") or ""
|
||||||
|
node.outIds[s.block.addr] = s:str("identifier") or s:str("name") or ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if n.block then
|
if n.block then
|
||||||
@@ -166086,7 +166129,7 @@ local g= { nodes = {}, links = {} }
|
|||||||
local from, fs, to = l:ptr("fromnode"), l:ptr("fromsock"), l:ptr("tosock")
|
local from, fs, to = l:ptr("fromnode"), l:ptr("fromsock"), l:ptr("tosock")
|
||||||
local fn = from and g.nodes[from]
|
local fn = from and g.nodes[from]
|
||||||
if fn and to ~= nil and bit32.band(l:num("flag") or 0, 0x10) == 0 then
|
if fn and to ~= nil and bit32.band(l:num("flag") or 0, 0x10) == 0 then
|
||||||
g.links[to] = { node = fn, socket = (fs and fn.outputs[fs]) or "" }
|
g.links[to] = { node = fn, socket = (fs and fn.outputs[fs]) or "", ident = (fs and fn.outIds[fs]) or "" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return g
|
return g
|
||||||
@@ -166121,23 +166164,87 @@ if not s then
|
|||||||
return v and v:num("value")
|
return v and v:num("value")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function imageRef(ctx, g, uvNames, s, through)
|
-- pass-through nodes: the inputs (by identifier) that may lead to an image, in the order tried
|
||||||
|
local PASS= {
|
||||||
|
NodeReroute = { "Input" }, ShaderNodeMix = { "A_Color", "B_Color" }, ShaderNodeMixRGB = { "Color1", "Color2" },
|
||||||
|
ShaderNodeHueSaturation = { "Color" }, ShaderNodeBrightContrast = { "Color" }, ShaderNodeGamma = { "Color" },
|
||||||
|
ShaderNodeInvert = { "Color" }, ShaderNodeRGBCurve = { "Color" }, ShaderNodeValToRGB = { "Fac" },
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function groupGraph(n)
|
||||||
|
local tree = n.view:deref("id", 0, "bNodeTree")
|
||||||
|
return (tree and{(graph(tree) )}or{nil
|
||||||
|
})[1]end
|
||||||
|
|
||||||
|
-- the first image texture node a socket reaches through pass-through nodes and node groups (via: the nodes passed),
|
||||||
|
-- else the node it is linked to (reroutes skipped)
|
||||||
|
local function trace(g, s, via, stack, depth)
|
||||||
local l = link(g, s)
|
local l = link(g, s)
|
||||||
if not l then
|
if not l or depth > 64 then
|
||||||
return nil, nil
|
return nil, nil
|
||||||
end
|
end
|
||||||
local n = l.node
|
local n = l.node
|
||||||
if through and n.idname == through then
|
if n.idname == "ShaderNodeTexImage" then
|
||||||
local inner = input(n, "Color", "Image")
|
return { node = n, g = g, output = l.socket }, n
|
||||||
local ref, tn = imageRef(ctx, g, uvNames, inner, nil)
|
elseif n.idname == "ShaderNodeGroup" then
|
||||||
return ref, (ref and{n }or{tn
|
local inner = groupGraph(n)
|
||||||
})[1] end
|
local out= nil
|
||||||
if n.idname ~= "ShaderNodeTexImage" then
|
for _, x in __iter((inner and{inner.nodes }or{{} })[1])do
|
||||||
|
if x.idname == "NodeGroupOutput" and (out == nil or bit32.band(x.view:num("flag") or 0, 2) ~= 0) then
|
||||||
|
out = x
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local sock = out and out.byId[l.ident]
|
||||||
|
if inner and sock then
|
||||||
|
local stack2 = table.clone(stack)
|
||||||
|
table.insert(stack2, { node = n, g = g })
|
||||||
|
local sub = {}
|
||||||
|
local hit = trace(inner, sock, sub, stack2, depth + 1)
|
||||||
|
if hit then
|
||||||
|
table.insert(via, n.idname)
|
||||||
|
table.move(sub, 1, #sub, #via + 1, via)
|
||||||
|
return hit, n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil, n
|
||||||
|
elseif n.idname == "NodeGroupInput" and #stack > 0 then
|
||||||
|
local top = stack[#stack]
|
||||||
|
local outer = top.node.byId[l.ident]
|
||||||
|
local stack2 = table.clone(stack)
|
||||||
|
table.remove(stack2)
|
||||||
|
if outer then
|
||||||
|
return trace(top.g, outer, via, stack2, depth + 1)
|
||||||
|
end
|
||||||
return nil, n
|
return nil, n
|
||||||
end
|
end
|
||||||
|
local ids = PASS[n.idname]
|
||||||
|
if ids then
|
||||||
|
for _, id in __iter(ids) do
|
||||||
|
local sock = n.byId[id] or ((n.idname == "NodeReroute" and{n.first }or{nil})[1])
|
||||||
|
local sub = {}
|
||||||
|
local hit, last = trace(g, sock, sub, stack, depth + 1)
|
||||||
|
if hit then
|
||||||
|
table.insert(via, n.idname)
|
||||||
|
table.move(sub, 1, #sub, #via + 1, via)
|
||||||
|
return hit, n
|
||||||
|
end
|
||||||
|
if n.idname == "NodeReroute" then
|
||||||
|
return nil, last or n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil, n
|
||||||
|
end
|
||||||
|
|
||||||
|
-- the TextureRef of an image texture node (its sampler, its UV Map node's texCoord)
|
||||||
|
local function refOf(ctx, uvNames, hit)
|
||||||
|
local n, g = hit.node, hit.g
|
||||||
local img = n.view:deref("id", 0, "Image")
|
local img = n.view:deref("id", 0, "Image")
|
||||||
if not img then
|
if not img then
|
||||||
return nil, n
|
return nil
|
||||||
end
|
end
|
||||||
local sampler= {}
|
local sampler= {}
|
||||||
local custom = false
|
local custom = false
|
||||||
@@ -166157,7 +166264,7 @@ local l = link(g, s)
|
|||||||
end
|
end
|
||||||
local t = texture(ctx, img, (custom and{sampler }or{nil})[1])
|
local t = texture(ctx, img, (custom and{sampler }or{nil})[1])
|
||||||
if not t then
|
if not t then
|
||||||
return nil, n
|
return nil
|
||||||
end
|
end
|
||||||
local ref= { texture = t }
|
local ref= { texture = t }
|
||||||
local vec = link(g, input(n, "Vector"))
|
local vec = link(g, input(n, "Vector"))
|
||||||
@@ -166168,7 +166275,31 @@ local l = link(g, s)
|
|||||||
ref.texCoord = uvNames[name]
|
ref.texCoord = uvNames[name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ref, n
|
return ref
|
||||||
|
end
|
||||||
|
|
||||||
|
local function imageRef(ctx, g, uvNames, s)
|
||||||
|
local via = {}
|
||||||
|
local hit, last = trace(g, s, via, {}, 0)
|
||||||
|
if not hit then
|
||||||
|
return nil, last, via, nil
|
||||||
|
end
|
||||||
|
return refOf(ctx, uvNames, hit), last, via, hit
|
||||||
|
end
|
||||||
|
|
||||||
|
-- the vertex colour layer a Vertex Color / Attribute node reads
|
||||||
|
local function vertexColor(n)
|
||||||
|
if not n then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
if n.idname == "ShaderNodeVertexColor" then
|
||||||
|
local st = n.view:deref("storage", 0, "NodeShaderVertexColor")
|
||||||
|
return st and st:str("layer_name") or ""
|
||||||
|
elseif n.idname == "ShaderNodeAttribute" then
|
||||||
|
local st = n.view:deref("storage", 0, "NodeShaderAttribute")
|
||||||
|
return st and st:str("name") or ""
|
||||||
|
end
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function principled(g)
|
local function principled(g)
|
||||||
@@ -166232,47 +166363,139 @@ local key = mv.block and mv.block.addr
|
|||||||
end
|
end
|
||||||
m.metallic = value(input(bsdf, "Metallic"), "float") or m.metallic
|
m.metallic = value(input(bsdf, "Metallic"), "float") or m.metallic
|
||||||
m.roughness = value(input(bsdf, "Roughness"), "float") or m.roughness
|
m.roughness = value(input(bsdf, "Roughness"), "float") or m.roughness
|
||||||
local bref = imageRef(ctx, g, uvNames, input(bsdf, "Base Color"), nil)
|
local linked= {}
|
||||||
|
local via= {}
|
||||||
|
-- node names as Blender 3.4+ shows them (its versioning turns shader MixRGB nodes into Mix nodes)
|
||||||
|
local function api(idname)
|
||||||
|
return idname == "ShaderNodeMixRGB" and f.version < 304 and"ShaderNodeMix" or idname
|
||||||
|
end
|
||||||
|
local function resolve(key, sock)
|
||||||
|
if not link(g , sock) then
|
||||||
|
return nil, nil, nil
|
||||||
|
end
|
||||||
|
local ref, last, passed, hit = imageRef(ctx, g , uvNames, sock)
|
||||||
|
if ref then
|
||||||
|
if #passed > 0 then
|
||||||
|
for i, x in __iter(passed) do
|
||||||
|
passed[i] = api(x)
|
||||||
|
end
|
||||||
|
via[key] = passed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ref, last, hit
|
||||||
|
end
|
||||||
|
local function unresolved(key, sock)
|
||||||
|
local l = link(g , sock)
|
||||||
|
if l then
|
||||||
|
local _, last = trace(g , sock, {}, {}, 0) -- reroutes skipped
|
||||||
|
linked[key] = api((last or l.node).idname)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local baseSock = input(bsdf, "Base Color")
|
||||||
|
local bref, blast = resolve("baseColor", baseSock)
|
||||||
if bref then
|
if bref then
|
||||||
m.baseColorTexture = bref
|
m.baseColorTexture = bref
|
||||||
m.baseColor = { 1, 1, 1, alpha }
|
m.baseColor = { 1, 1, 1, alpha }
|
||||||
|
elseif link(g, baseSock) then
|
||||||
|
local layer = vertexColor(blast)
|
||||||
|
if layer then
|
||||||
|
extras.vertexColor = layer
|
||||||
|
m.baseColor = { 1, 1, 1, alpha }
|
||||||
|
else
|
||||||
|
m.baseColor = { 0.8, 0.8, 0.8, alpha } -- Blender's default base colour, never the linked socket's value
|
||||||
|
unresolved("baseColor", baseSock)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local aref = imageRef(ctx, g, uvNames, input(bsdf, "Alpha"), nil)
|
local alphaSock = input(bsdf, "Alpha")
|
||||||
|
local aref = resolve("alpha", alphaSock)
|
||||||
if aref and not m.baseColorTexture then
|
if aref and not m.baseColorTexture then
|
||||||
m.baseColorTexture = aref
|
m.baseColorTexture = aref
|
||||||
|
elseif not aref and link(g, alphaSock) then
|
||||||
|
m.baseColor[4] = 1
|
||||||
|
unresolved("alpha", alphaSock)
|
||||||
end
|
end
|
||||||
local nref, nnode = imageRef(ctx, g, uvNames, input(bsdf, "Normal"), "ShaderNodeNormalMap")
|
local nl = link(g, input(bsdf, "Normal"))
|
||||||
if nref then
|
if nl and nl.node.idname == "ShaderNodeNormalMap" then
|
||||||
nref.scale = (nnode and{value(nnode.inputs.Strength, "float") or 1 }or{1
|
local nref = resolve("normal", input(nl.node, "Color"))
|
||||||
})[1] m.normalTexture = nref
|
if nref then
|
||||||
|
nref.scale = value(nl.node.inputs.Strength, "float") or 1
|
||||||
|
m.normalTexture = nref
|
||||||
|
else
|
||||||
|
unresolved("normal", input(bsdf, "Normal"))
|
||||||
|
end
|
||||||
|
elseif nl and nl.node.idname == "ShaderNodeBump" then
|
||||||
|
local href = resolve("bump", input(nl.node, "Height"))
|
||||||
|
if href then
|
||||||
|
extras.bumpTexture = href
|
||||||
|
extras.bumpStrength = value(input(nl.node, "Strength"), "float") or 1
|
||||||
|
extras.bumpDistance = value(input(nl.node, "Distance"), "float") or 1
|
||||||
|
else
|
||||||
|
unresolved("normal", input(bsdf, "Normal"))
|
||||||
|
end
|
||||||
|
elseif nl then
|
||||||
|
unresolved("normal", input(bsdf, "Normal"))
|
||||||
end
|
end
|
||||||
local rl = link(g, input(bsdf, "Roughness"))
|
local channelOf = { Red = "R", Green = "G", Blue = "B", R = "R", G = "G", B = "B", Alpha = "A", Color = "R", Fac = "R" }
|
||||||
local ml = link(g, input(bsdf, "Metallic"))
|
local function scalar(key, sock)
|
||||||
local sep = (rl and rl.node) or (ml and ml.node)
|
local l = link(g , sock)
|
||||||
if sep and (sep.idname == "ShaderNodeSeparateRGB" or sep.idname == "ShaderNodeSeparateColor") then
|
if not l then
|
||||||
local mref = imageRef(ctx, g, uvNames, input(sep, "Image", "Color"), nil)
|
return nil
|
||||||
if mref then
|
end
|
||||||
m.metallicRoughnessTexture = mref
|
local sep = l.node
|
||||||
if rl then
|
if sep.idname == "ShaderNodeSeparateRGB" or sep.idname == "ShaderNodeSeparateColor" then
|
||||||
m.roughness = 1
|
local ref = resolve(key, input(sep, "Image", "Color"))
|
||||||
|
if ref then
|
||||||
|
m.metallicRoughnessTexture = m.metallicRoughnessTexture or table.clone(ref)
|
||||||
|
local r = (table.clone(ref) )
|
||||||
|
r.channel = channelOf[l.socket] or l.socket
|
||||||
|
extras[key .. "Texture"] = r
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
if ml then
|
else
|
||||||
m.metallic = 1
|
local ref, _, hit = resolve(key, sock)
|
||||||
|
if ref and hit then
|
||||||
|
local r = ref
|
||||||
|
r.channel = channelOf[hit.output] or hit.output
|
||||||
|
extras[key .. "Texture"] = r
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
unresolved(key, sock)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local rs = scalar("roughness", input(bsdf, "Roughness"))
|
||||||
|
if rs == true then
|
||||||
|
m.roughness = 1
|
||||||
|
elseif rs == false then
|
||||||
|
m.roughness = 0.5
|
||||||
|
end
|
||||||
|
local ms = scalar("metallic", input(bsdf, "Metallic"))
|
||||||
|
if ms == true then
|
||||||
|
m.metallic = 1
|
||||||
|
elseif ms == false then
|
||||||
|
m.metallic = 0
|
||||||
end
|
end
|
||||||
local es = input(bsdf, "Emission Color", "Emission")
|
local es = input(bsdf, "Emission Color", "Emission")
|
||||||
local ecol = value(es, "rgba") or { 0, 0, 0, 1 }
|
local ecol = value(es, "rgba") or { 0, 0, 0, 1 }
|
||||||
local strength = value(input(bsdf, "Emission Strength"), "float") or 1
|
local strength = value(input(bsdf, "Emission Strength"), "float") or 1
|
||||||
local eref = imageRef(ctx, g, uvNames, es, nil)
|
local eref = resolve("emissive", es)
|
||||||
if eref then
|
if eref then
|
||||||
m.emissiveTexture = eref
|
m.emissiveTexture = eref
|
||||||
ecol = { 1, 1, 1, 1 }
|
ecol = { 1, 1, 1, 1 }
|
||||||
|
elseif link(g, es) then
|
||||||
|
ecol = { 0, 0, 0, 1 }
|
||||||
|
unresolved("emissive", es)
|
||||||
end
|
end
|
||||||
emissive(m, ecol, strength)
|
emissive(m, ecol, strength)
|
||||||
if not eref and m.emissive[1] == 0 and m.emissive[2] == 0 and m.emissive[3] == 0 then
|
if not eref and m.emissive[1] == 0 and m.emissive[2] == 0 and m.emissive[3] == 0 then
|
||||||
m.emissive = { 0, 0, 0 }
|
m.emissive = { 0, 0, 0 }
|
||||||
end
|
end
|
||||||
|
if next(linked) ~= nil then
|
||||||
|
extras.linked = linked
|
||||||
|
end
|
||||||
|
if next(via) ~= nil then
|
||||||
|
extras.via = via
|
||||||
|
end
|
||||||
local alphaLinked = link(g, input(bsdf, "Alpha")) ~= nil
|
local alphaLinked = link(g, input(bsdf, "Alpha")) ~= nil
|
||||||
if alpha < 1 or alphaLinked then
|
if alpha < 1 or alphaLinked then
|
||||||
local bm = mv:num("blend_method") or 0
|
local bm = mv:num("blend_method") or 0
|
||||||
|
|||||||
+180
-180
@@ -440,184 +440,184 @@
|
|||||||
[165240, "src/Rosetta/model/blend/Armature.luau"],
|
[165240, "src/Rosetta/model/blend/Armature.luau"],
|
||||||
[165776, "src/Rosetta/model/blend/Driver.luau"],
|
[165776, "src/Rosetta/model/blend/Driver.luau"],
|
||||||
[165951, "src/Rosetta/model/blend/Material.luau"],
|
[165951, "src/Rosetta/model/blend/Material.luau"],
|
||||||
[166303, "src/Rosetta/model/blend/Mesh.luau"],
|
[166526, "src/Rosetta/model/blend/Mesh.luau"],
|
||||||
[166991, "src/Rosetta/model/blend/Normals.luau"],
|
[167214, "src/Rosetta/model/blend/Normals.luau"],
|
||||||
[167152, "src/Rosetta/model/blend/Prim.luau"],
|
[167375, "src/Rosetta/model/blend/Prim.luau"],
|
||||||
[167659, "src/Rosetta/model/blend/Read.luau"],
|
[167882, "src/Rosetta/model/blend/Read.luau"],
|
||||||
[168747, "src/Rosetta/model/bsp/init.luau"],
|
[168970, "src/Rosetta/model/bsp/init.luau"],
|
||||||
[168938, "src/Rosetta/model/bsp/Lightmap.luau"],
|
[169161, "src/Rosetta/model/bsp/Lightmap.luau"],
|
||||||
[169004, "src/Rosetta/model/bsp/Quake.luau"],
|
[169227, "src/Rosetta/model/bsp/Quake.luau"],
|
||||||
[169393, "src/Rosetta/model/bsp/Quake3.luau"],
|
[169616, "src/Rosetta/model/bsp/Quake3.luau"],
|
||||||
[169622, "src/Rosetta/model/bsp/Tree.luau"],
|
[169845, "src/Rosetta/model/bsp/Tree.luau"],
|
||||||
[170010, "src/Rosetta/model/buildmap/init.luau"],
|
[170233, "src/Rosetta/model/buildmap/init.luau"],
|
||||||
[170282, "src/Rosetta/model/buildmap/Geometry.luau"],
|
[170505, "src/Rosetta/model/buildmap/Geometry.luau"],
|
||||||
[170685, "src/Rosetta/model/d3map/init.luau"],
|
[170908, "src/Rosetta/model/d3map/init.luau"],
|
||||||
[170967, "src/Rosetta/model/d3map/Parse.luau"],
|
[171190, "src/Rosetta/model/d3map/Parse.luau"],
|
||||||
[171165, "src/Rosetta/model/dae/init.luau"],
|
[171388, "src/Rosetta/model/dae/init.luau"],
|
||||||
[171354, "src/Rosetta/model/dae/Math.luau"],
|
[171577, "src/Rosetta/model/dae/Math.luau"],
|
||||||
[171401, "src/Rosetta/model/dae/Read.luau"],
|
[171624, "src/Rosetta/model/dae/Read.luau"],
|
||||||
[173251, "src/Rosetta/model/dae/Write.luau"],
|
[173474, "src/Rosetta/model/dae/Write.luau"],
|
||||||
[173620, "src/Rosetta/model/fbx/init.luau"],
|
[173843, "src/Rosetta/model/fbx/init.luau"],
|
||||||
[173768, "src/Rosetta/model/fbx/Ascii.luau"],
|
[173991, "src/Rosetta/model/fbx/Ascii.luau"],
|
||||||
[174038, "src/Rosetta/model/fbx/Binary.luau"],
|
[174261, "src/Rosetta/model/fbx/Binary.luau"],
|
||||||
[174493, "src/Rosetta/model/fbx/Read.luau"],
|
[174716, "src/Rosetta/model/fbx/Read.luau"],
|
||||||
[175855, "src/Rosetta/model/fbx/Write.luau"],
|
[176078, "src/Rosetta/model/fbx/Write.luau"],
|
||||||
[176840, "src/Rosetta/model/fbx/Xform.luau"],
|
[177063, "src/Rosetta/model/fbx/Xform.luau"],
|
||||||
[176881, "src/Rosetta/model/gltf/init.luau"],
|
[177104, "src/Rosetta/model/gltf/init.luau"],
|
||||||
[177118, "src/Rosetta/model/gltf/Pack.luau"],
|
[177341, "src/Rosetta/model/gltf/Pack.luau"],
|
||||||
[177187, "src/Rosetta/model/gltf/Read.luau"],
|
[177410, "src/Rosetta/model/gltf/Read.luau"],
|
||||||
[177928, "src/Rosetta/model/gltf/Write.luau"],
|
[178151, "src/Rosetta/model/gltf/Write.luau"],
|
||||||
[178614, "src/Rosetta/model/godot/init.luau"],
|
[178837, "src/Rosetta/model/godot/init.luau"],
|
||||||
[178705, "src/Rosetta/model/godot/Build.luau"],
|
[178928, "src/Rosetta/model/godot/Build.luau"],
|
||||||
[179247, "src/Rosetta/model/godot/Primitives.luau"],
|
[179470, "src/Rosetta/model/godot/Primitives.luau"],
|
||||||
[179522, "src/Rosetta/model/godot/Surface.luau"],
|
[179745, "src/Rosetta/model/godot/Surface.luau"],
|
||||||
[180007, "src/Rosetta/model/godot/Write.luau"],
|
[180230, "src/Rosetta/model/godot/Write.luau"],
|
||||||
[180336, "src/Rosetta/model/iqm/init.luau"],
|
[180559, "src/Rosetta/model/iqm/init.luau"],
|
||||||
[180412, "src/Rosetta/model/iqm/Read.luau"],
|
[180635, "src/Rosetta/model/iqm/Read.luau"],
|
||||||
[180767, "src/Rosetta/model/iqm/Write.luau"],
|
[180990, "src/Rosetta/model/iqm/Write.luau"],
|
||||||
[181454, "src/Rosetta/model/ldraw/init.luau"],
|
[181677, "src/Rosetta/model/ldraw/init.luau"],
|
||||||
[181532, "src/Rosetta/model/ldraw/Colors.luau"],
|
[181755, "src/Rosetta/model/ldraw/Colors.luau"],
|
||||||
[181850, "src/Rosetta/model/ldraw/Read.luau"],
|
[182073, "src/Rosetta/model/ldraw/Read.luau"],
|
||||||
[182427, "src/Rosetta/model/lwo/init.luau"],
|
[182650, "src/Rosetta/model/lwo/init.luau"],
|
||||||
[182503, "src/Rosetta/model/lwo/Build.luau"],
|
[182726, "src/Rosetta/model/lwo/Build.luau"],
|
||||||
[182965, "src/Rosetta/model/lwo/Parse.luau"],
|
[183188, "src/Rosetta/model/lwo/Parse.luau"],
|
||||||
[183508, "src/Rosetta/model/map/init.luau"],
|
[183731, "src/Rosetta/model/map/init.luau"],
|
||||||
[183825, "src/Rosetta/model/map/Build.luau"],
|
[184048, "src/Rosetta/model/map/Build.luau"],
|
||||||
[184069, "src/Rosetta/model/map/Parse.luau"],
|
[184292, "src/Rosetta/model/map/Parse.luau"],
|
||||||
[184454, "src/Rosetta/model/map/Write.luau"],
|
[184677, "src/Rosetta/model/map/Write.luau"],
|
||||||
[184600, "src/Rosetta/model/mca/init.luau"],
|
[184823, "src/Rosetta/model/mca/init.luau"],
|
||||||
[184942, "src/Rosetta/model/mca/Chunk.luau"],
|
[185165, "src/Rosetta/model/mca/Chunk.luau"],
|
||||||
[185075, "src/Rosetta/model/mca/Lz4Block.luau"],
|
[185298, "src/Rosetta/model/mca/Lz4Block.luau"],
|
||||||
[185145, "src/Rosetta/model/md2/init.luau"],
|
[185368, "src/Rosetta/model/md2/init.luau"],
|
||||||
[185344, "src/Rosetta/model/md3/init.luau"],
|
[185567, "src/Rosetta/model/md3/init.luau"],
|
||||||
[185572, "src/Rosetta/model/md5/init.luau"],
|
[185795, "src/Rosetta/model/md5/init.luau"],
|
||||||
[185653, "src/Rosetta/model/md5/Read.luau"],
|
[185876, "src/Rosetta/model/md5/Read.luau"],
|
||||||
[186086, "src/Rosetta/model/mdl/init.luau"],
|
[186309, "src/Rosetta/model/mdl/init.luau"],
|
||||||
[186168, "src/Rosetta/model/mdl/HalfLife.luau"],
|
[186391, "src/Rosetta/model/mdl/HalfLife.luau"],
|
||||||
[186472, "src/Rosetta/model/mdl/Quake.luau"],
|
[186695, "src/Rosetta/model/mdl/Quake.luau"],
|
||||||
[186690, "src/Rosetta/model/ms3d/init.luau"],
|
[186913, "src/Rosetta/model/ms3d/init.luau"],
|
||||||
[186762, "src/Rosetta/model/ms3d/Read.luau"],
|
[186985, "src/Rosetta/model/ms3d/Read.luau"],
|
||||||
[187208, "src/Rosetta/model/ms3d/Write.luau"],
|
[187431, "src/Rosetta/model/ms3d/Write.luau"],
|
||||||
[187677, "src/Rosetta/model/obj/init.luau"],
|
[187900, "src/Rosetta/model/obj/init.luau"],
|
||||||
[188495, "src/Rosetta/model/obj/Mtl.luau"],
|
[188718, "src/Rosetta/model/obj/Mtl.luau"],
|
||||||
[188783, "src/Rosetta/model/off/init.luau"],
|
[189006, "src/Rosetta/model/off/init.luau"],
|
||||||
[189245, "src/Rosetta/model/ply/init.luau"],
|
[189468, "src/Rosetta/model/ply/init.luau"],
|
||||||
[190350, "src/Rosetta/model/ply/Binary.luau"],
|
[190573, "src/Rosetta/model/ply/Binary.luau"],
|
||||||
[190551, "src/Rosetta/model/pmx/init.luau"],
|
[190774, "src/Rosetta/model/pmx/init.luau"],
|
||||||
[190620, "src/Rosetta/model/pmx/Build.luau"],
|
[190843, "src/Rosetta/model/pmx/Build.luau"],
|
||||||
[190916, "src/Rosetta/model/pmx/Pmd.luau"],
|
[191139, "src/Rosetta/model/pmx/Pmd.luau"],
|
||||||
[191251, "src/Rosetta/model/pmx/Read.luau"],
|
[191474, "src/Rosetta/model/pmx/Read.luau"],
|
||||||
[191655, "src/Rosetta/model/proc/init.luau"],
|
[191878, "src/Rosetta/model/proc/init.luau"],
|
||||||
[192037, "src/Rosetta/model/qb/init.luau"],
|
[192260, "src/Rosetta/model/qb/init.luau"],
|
||||||
[192430, "src/Rosetta/model/rbxm/init.luau"],
|
[192653, "src/Rosetta/model/rbxm/init.luau"],
|
||||||
[193023, "src/Rosetta/model/rbxmx/init.luau"],
|
[193246, "src/Rosetta/model/rbxmx/init.luau"],
|
||||||
[193699, "src/Rosetta/model/robloxmesh/init.luau"],
|
[193922, "src/Rosetta/model/robloxmesh/init.luau"],
|
||||||
[194358, "src/Rosetta/model/robloxmesh/Parse.luau"],
|
[194581, "src/Rosetta/model/robloxmesh/Parse.luau"],
|
||||||
[194815, "src/Rosetta/model/robloxmesh/Write.luau"],
|
[195038, "src/Rosetta/model/robloxmesh/Write.luau"],
|
||||||
[194924, "src/Rosetta/model/schematic/init.luau"],
|
[195147, "src/Rosetta/model/schematic/init.luau"],
|
||||||
[195245, "src/Rosetta/model/schematic/Common.luau"],
|
[195468, "src/Rosetta/model/schematic/Common.luau"],
|
||||||
[195365, "src/Rosetta/model/schematic/Litematic.luau"],
|
[195588, "src/Rosetta/model/schematic/Litematic.luau"],
|
||||||
[195576, "src/Rosetta/model/schematic/Mcedit.luau"],
|
[195799, "src/Rosetta/model/schematic/Mcedit.luau"],
|
||||||
[195820, "src/Rosetta/model/schematic/Sponge.luau"],
|
[196043, "src/Rosetta/model/schematic/Sponge.luau"],
|
||||||
[195949, "src/Rosetta/model/smd/init.luau"],
|
[196172, "src/Rosetta/model/smd/init.luau"],
|
||||||
[196016, "src/Rosetta/model/smd/Read.luau"],
|
[196239, "src/Rosetta/model/smd/Read.luau"],
|
||||||
[196285, "src/Rosetta/model/smd/Write.luau"],
|
[196508, "src/Rosetta/model/smd/Write.luau"],
|
||||||
[196528, "src/Rosetta/model/sourcemdl/init.luau"],
|
[196751, "src/Rosetta/model/sourcemdl/init.luau"],
|
||||||
[196699, "src/Rosetta/model/sourcemdl/Build.luau"],
|
[196922, "src/Rosetta/model/sourcemdl/Build.luau"],
|
||||||
[197129, "src/Rosetta/model/sourcemdl/Material.luau"],
|
[197352, "src/Rosetta/model/sourcemdl/Material.luau"],
|
||||||
[197290, "src/Rosetta/model/sourcemdl/Mdl.luau"],
|
[197513, "src/Rosetta/model/sourcemdl/Mdl.luau"],
|
||||||
[197817, "src/Rosetta/model/sourcemdl/Phy.luau"],
|
[198040, "src/Rosetta/model/sourcemdl/Phy.luau"],
|
||||||
[197940, "src/Rosetta/model/sourcemdl/Vtx.luau"],
|
[198163, "src/Rosetta/model/sourcemdl/Vtx.luau"],
|
||||||
[198122, "src/Rosetta/model/sourcemdl/Vvd.luau"],
|
[198345, "src/Rosetta/model/sourcemdl/Vvd.luau"],
|
||||||
[198216, "src/Rosetta/model/stl/init.luau"],
|
[198439, "src/Rosetta/model/stl/init.luau"],
|
||||||
[198666, "src/Rosetta/model/stl/Decode.luau"],
|
[198889, "src/Rosetta/model/stl/Decode.luau"],
|
||||||
[198740, "src/Rosetta/model/t3d/init.luau"],
|
[198963, "src/Rosetta/model/t3d/init.luau"],
|
||||||
[198834, "src/Rosetta/model/t3d/Build.luau"],
|
[199057, "src/Rosetta/model/t3d/Build.luau"],
|
||||||
[199239, "src/Rosetta/model/t3d/Parse.luau"],
|
[199462, "src/Rosetta/model/t3d/Parse.luau"],
|
||||||
[199407, "src/Rosetta/model/udmf/init.luau"],
|
[199630, "src/Rosetta/model/udmf/init.luau"],
|
||||||
[199490, "src/Rosetta/model/usda/init.luau"],
|
[199713, "src/Rosetta/model/usda/init.luau"],
|
||||||
[199699, "src/Rosetta/model/usda/Build.luau"],
|
[199922, "src/Rosetta/model/usda/Build.luau"],
|
||||||
[200977, "src/Rosetta/model/usda/Parse.luau"],
|
[201200, "src/Rosetta/model/usda/Parse.luau"],
|
||||||
[201775, "src/Rosetta/model/usda/Write.luau"],
|
[201998, "src/Rosetta/model/usda/Write.luau"],
|
||||||
[202592, "src/Rosetta/model/vbsp/init.luau"],
|
[202815, "src/Rosetta/model/vbsp/init.luau"],
|
||||||
[203038, "src/Rosetta/model/vbsp/Faces.luau"],
|
[203261, "src/Rosetta/model/vbsp/Faces.luau"],
|
||||||
[203262, "src/Rosetta/model/vbsp/Props.luau"],
|
[203485, "src/Rosetta/model/vbsp/Props.luau"],
|
||||||
[203354, "src/Rosetta/model/vmf/init.luau"],
|
[203577, "src/Rosetta/model/vmf/init.luau"],
|
||||||
[203679, "src/Rosetta/model/vmf/Build.luau"],
|
[203902, "src/Rosetta/model/vmf/Build.luau"],
|
||||||
[204103, "src/Rosetta/model/vox/init.luau"],
|
[204326, "src/Rosetta/model/vox/init.luau"],
|
||||||
[204989, "src/Rosetta/model/vox/Grid.luau"],
|
[205212, "src/Rosetta/model/vox/Grid.luau"],
|
||||||
[205046, "src/Rosetta/model/vrml/init.luau"],
|
[205269, "src/Rosetta/model/vrml/init.luau"],
|
||||||
[205112, "src/Rosetta/model/x/init.luau"],
|
[205335, "src/Rosetta/model/x/init.luau"],
|
||||||
[205242, "src/Rosetta/model/x/Build.luau"],
|
[205465, "src/Rosetta/model/x/Build.luau"],
|
||||||
[205805, "src/Rosetta/model/x/Parse.luau"],
|
[206028, "src/Rosetta/model/x/Parse.luau"],
|
||||||
[206102, "src/Rosetta/model/x3d/init.luau"],
|
[206325, "src/Rosetta/model/x3d/init.luau"],
|
||||||
[206180, "src/Rosetta/music/669/init.luau"],
|
[206403, "src/Rosetta/music/669/init.luau"],
|
||||||
[206387, "src/Rosetta/music/ahx/init.luau"],
|
[206610, "src/Rosetta/music/ahx/init.luau"],
|
||||||
[206439, "src/Rosetta/music/far/init.luau"],
|
[206662, "src/Rosetta/music/far/init.luau"],
|
||||||
[206669, "src/Rosetta/music/hmp/init.luau"],
|
[206892, "src/Rosetta/music/hmp/init.luau"],
|
||||||
[206934, "src/Rosetta/music/hvl/init.luau"],
|
[207157, "src/Rosetta/music/hvl/init.luau"],
|
||||||
[206986, "src/Rosetta/music/it/init.luau"],
|
[207209, "src/Rosetta/music/it/init.luau"],
|
||||||
[207405, "src/Rosetta/music/it/Itsex.luau"],
|
[207628, "src/Rosetta/music/it/Itsex.luau"],
|
||||||
[207522, "src/Rosetta/music/med/init.luau"],
|
[207745, "src/Rosetta/music/med/init.luau"],
|
||||||
[208170, "src/Rosetta/music/midi/init.luau"],
|
[208393, "src/Rosetta/music/midi/init.luau"],
|
||||||
[208314, "src/Rosetta/music/midi/Smf.luau"],
|
[208537, "src/Rosetta/music/midi/Smf.luau"],
|
||||||
[208726, "src/Rosetta/music/mod/init.luau"],
|
[208949, "src/Rosetta/music/mod/init.luau"],
|
||||||
[209080, "src/Rosetta/music/mtm/init.luau"],
|
[209303, "src/Rosetta/music/mtm/init.luau"],
|
||||||
[209303, "src/Rosetta/music/mus/init.luau"],
|
[209526, "src/Rosetta/music/mus/init.luau"],
|
||||||
[209461, "src/Rosetta/music/okt/init.luau"],
|
[209684, "src/Rosetta/music/okt/init.luau"],
|
||||||
[209743, "src/Rosetta/music/ptm/init.luau"],
|
[209966, "src/Rosetta/music/ptm/init.luau"],
|
||||||
[209966, "src/Rosetta/music/s3m/init.luau"],
|
[210189, "src/Rosetta/music/s3m/init.luau"],
|
||||||
[210203, "src/Rosetta/music/sf2/init.luau"],
|
[210426, "src/Rosetta/music/sf2/init.luau"],
|
||||||
[210247, "src/Rosetta/music/stm/init.luau"],
|
[210470, "src/Rosetta/music/stm/init.luau"],
|
||||||
[210479, "src/Rosetta/music/ult/init.luau"],
|
[210702, "src/Rosetta/music/ult/init.luau"],
|
||||||
[210784, "src/Rosetta/music/umx/init.luau"],
|
[211007, "src/Rosetta/music/umx/init.luau"],
|
||||||
[211001, "src/Rosetta/music/xm/init.luau"],
|
[211224, "src/Rosetta/music/xm/init.luau"],
|
||||||
[211563, "src/Rosetta/music/xmi/init.luau"],
|
[211786, "src/Rosetta/music/xmi/init.luau"],
|
||||||
[211772, "src/Rosetta/ops/AudioOps.luau"],
|
[211995, "src/Rosetta/ops/AudioOps.luau"],
|
||||||
[212251, "src/Rosetta/ops/ImageOps/init.luau"],
|
[212474, "src/Rosetta/ops/ImageOps/init.luau"],
|
||||||
[212899, "src/Rosetta/ops/ImageOps/Kernels.luau"],
|
[213122, "src/Rosetta/ops/ImageOps/Kernels.luau"],
|
||||||
[213539, "src/Rosetta/ops/LayerOps.luau"],
|
[213762, "src/Rosetta/ops/LayerOps.luau"],
|
||||||
[213632, "src/Rosetta/ops/MeshOps/init.luau"],
|
[213855, "src/Rosetta/ops/MeshOps/init.luau"],
|
||||||
[214772, "src/Rosetta/ops/MeshOps/Greedy.luau"],
|
[214995, "src/Rosetta/ops/MeshOps/Greedy.luau"],
|
||||||
[214939, "src/Rosetta/ops/MusicOps.luau"],
|
[215162, "src/Rosetta/ops/MusicOps.luau"],
|
||||||
[215288, "src/Rosetta/playlist/m3u/init.luau"],
|
[215511, "src/Rosetta/playlist/m3u/init.luau"],
|
||||||
[215641, "src/Rosetta/playlist/pls/init.luau"],
|
[215864, "src/Rosetta/playlist/pls/init.luau"],
|
||||||
[215819, "src/Rosetta/playlist/xspf/init.luau"],
|
[216042, "src/Rosetta/playlist/xspf/init.luau"],
|
||||||
[216022, "src/Rosetta/subtitle/ass/init.luau"],
|
[216245, "src/Rosetta/subtitle/ass/init.luau"],
|
||||||
[216466, "src/Rosetta/subtitle/srt/init.luau"],
|
[216689, "src/Rosetta/subtitle/srt/init.luau"],
|
||||||
[216639, "src/Rosetta/subtitle/vtt/init.luau"],
|
[216862, "src/Rosetta/subtitle/vtt/init.luau"],
|
||||||
[216842, "src/Rosetta/vector/gamemaps/init.luau"],
|
[217065, "src/Rosetta/vector/gamemaps/init.luau"],
|
||||||
[217029, "src/Rosetta/vector/gamemaps/Expand.luau"],
|
[217252, "src/Rosetta/vector/gamemaps/Expand.luau"],
|
||||||
[217126, "src/Rosetta/vector/ldtk/init.luau"],
|
[217349, "src/Rosetta/vector/ldtk/init.luau"],
|
||||||
[217218, "src/Rosetta/vector/ldtk/Read.luau"],
|
[217441, "src/Rosetta/vector/ldtk/Read.luau"],
|
||||||
[217554, "src/Rosetta/vector/ldtk/Write.luau"],
|
[217777, "src/Rosetta/vector/ldtk/Write.luau"],
|
||||||
[218202, "src/Rosetta/vector/ogmo/init.luau"],
|
[218425, "src/Rosetta/vector/ogmo/init.luau"],
|
||||||
[218321, "src/Rosetta/vector/ogmo/Read.luau"],
|
[218544, "src/Rosetta/vector/ogmo/Read.luau"],
|
||||||
[218726, "src/Rosetta/vector/ogmo/Write.luau"],
|
[218949, "src/Rosetta/vector/ogmo/Write.luau"],
|
||||||
[219080, "src/Rosetta/vector/svg/init.luau"],
|
[219303, "src/Rosetta/vector/svg/init.luau"],
|
||||||
[219166, "src/Rosetta/vector/svg/Parse.luau"],
|
[219389, "src/Rosetta/vector/svg/Parse.luau"],
|
||||||
[219912, "src/Rosetta/vector/svg/PathData.luau"],
|
[220135, "src/Rosetta/vector/svg/PathData.luau"],
|
||||||
[220280, "src/Rosetta/vector/svg/Render.luau"],
|
[220503, "src/Rosetta/vector/svg/Render.luau"],
|
||||||
[220697, "src/Rosetta/vector/svg/Style.luau"],
|
[220920, "src/Rosetta/vector/svg/Style.luau"],
|
||||||
[221069, "src/Rosetta/vector/svg/Write.luau"],
|
[221292, "src/Rosetta/vector/svg/Write.luau"],
|
||||||
[221269, "src/Rosetta/vector/tiled/init.luau"],
|
[221492, "src/Rosetta/vector/tiled/init.luau"],
|
||||||
[221449, "src/Rosetta/vector/tiled/Data.luau"],
|
[221672, "src/Rosetta/vector/tiled/Data.luau"],
|
||||||
[221600, "src/Rosetta/vector/tiled/Tmj.luau"],
|
[221823, "src/Rosetta/vector/tiled/Tmj.luau"],
|
||||||
[222231, "src/Rosetta/vector/tiled/Tmx.luau"],
|
[222454, "src/Rosetta/vector/tiled/Tmx.luau"],
|
||||||
[222843, "src/Rosetta/video/avi/init.luau"],
|
[223066, "src/Rosetta/video/avi/init.luau"],
|
||||||
[223137, "src/Rosetta/video/fli/init.luau"],
|
[223360, "src/Rosetta/video/fli/init.luau"],
|
||||||
[223288, "src/Rosetta/video/flv/init.luau"],
|
[223511, "src/Rosetta/video/flv/init.luau"],
|
||||||
[223672, "src/Rosetta/video/flv/Amf.luau"],
|
[223895, "src/Rosetta/video/flv/Amf.luau"],
|
||||||
[223830, "src/Rosetta/video/flv/Mux.luau"],
|
[224053, "src/Rosetta/video/flv/Mux.luau"],
|
||||||
[224111, "src/Rosetta/video/h264/init.luau"],
|
[224334, "src/Rosetta/video/h264/init.luau"],
|
||||||
[224250, "src/Rosetta/video/mkv/init.luau"],
|
[224473, "src/Rosetta/video/mkv/init.luau"],
|
||||||
[224406, "src/Rosetta/video/mkv/Mux.luau"],
|
[224629, "src/Rosetta/video/mkv/Mux.luau"],
|
||||||
[224685, "src/Rosetta/video/mkv/Parse.luau"],
|
[224908, "src/Rosetta/video/mkv/Parse.luau"],
|
||||||
[225406, "src/Rosetta/video/mp4/init.luau"],
|
[225629, "src/Rosetta/video/mp4/init.luau"],
|
||||||
[225734, "src/Rosetta/video/mpegps/init.luau"],
|
[225957, "src/Rosetta/video/mpegps/init.luau"],
|
||||||
[225921, "src/Rosetta/video/mpegts/init.luau"],
|
[226144, "src/Rosetta/video/mpegts/init.luau"],
|
||||||
[226167, "src/Rosetta/video/ogv/init.luau"],
|
[226390, "src/Rosetta/video/ogv/init.luau"],
|
||||||
[226562, "src/Rosetta/video/smk/init.luau"],
|
[226785, "src/Rosetta/video/smk/init.luau"],
|
||||||
[226871, "src/Rosetta/video/smk/Audio.luau"],
|
[227094, "src/Rosetta/video/smk/Audio.luau"],
|
||||||
[226991, "src/Rosetta/video/y4m/init.luau"]
|
[227214, "src/Rosetta/video/y4m/init.luau"]
|
||||||
]
|
]
|
||||||
+20
-1
@@ -956,7 +956,7 @@ cameras, lights, armatures, skins, shape keys and actions. Blender is z-up (`met
|
|||||||
|---|---|
|
|---|---|
|
||||||
| Meshes | every storage generation: MFace (before 2.63 and the 2.7x "legacy mesh format"), MPoly / MLoop (2.63 - 3.x), attribute layers (`position`, `.corner_vert`, ... 3.x - 4.x), AttributeStorage (5.x); a primitive per used material slot, `triangulate = false` keeps the faces (`"polygons"`) |
|
| Meshes | every storage generation: MFace (before 2.63 and the 2.7x "legacy mesh format"), MPoly / MLoop (2.63 - 3.x), attribute layers (`position`, `.corner_vert`, ... 3.x - 4.x), AttributeStorage (5.x); a primitive per used material slot, `triangulate = false` keeps the faces (`"polygons"`) |
|
||||||
| Mesh data | UV maps (`TEXCOORD_n`, v flipped to glTF's origin), colour attributes (byte and float, point and corner) as linear `COLOR_n`, corner normals from Blender's smooth fans (sharp edges / faces, auto smooth before 4.1) or the stored custom normals, weights (`JOINTS_0` / `WEIGHTS_0`: the 4 largest deform-bone groups, normalized) |
|
| Mesh data | UV maps (`TEXCOORD_n`, v flipped to glTF's origin), colour attributes (byte and float, point and corner) as linear `COLOR_n`, corner normals from Blender's smooth fans (sharp edges / faces, auto smooth before 4.1) or the stored custom normals, weights (`JOINTS_0` / `WEIGHTS_0`: the 4 largest deform-bone groups, normalized) |
|
||||||
| Materials | the Principled BSDF (base colour, metallic, roughness, alpha, emission and its strength, image textures on Base Color / Emission, Normal through a Normal Map node, Roughness / Metallic through Separate RGB), else the legacy `r, g, b` colour |
|
| Materials | the Principled BSDF (base colour, metallic, roughness, alpha, emission and its strength, image textures on Base Color / Emission / Roughness / Metallic, Normal through a Normal Map node, Roughness / Metallic through Separate RGB / Color as `metallicRoughnessTexture`), else the legacy `r, g, b` colour; images are found through pass-through nodes (see [Material graphs](#material-graphs)) |
|
||||||
| Images | packed images as encoded bytes (`texture.data`), external ones as `uri` (relative to the `.blend`, bytes through `files` / `resolve`) |
|
| Images | packed images as encoded bytes (`texture.data`), external ones as `uri` (relative to the `.blend`, bytes through `files` / `resolve`) |
|
||||||
| Cameras, lights | perspective (`yfov` from the lens, sensor fit and render aspect) / orthographic; point, sun, spot (watts to candela / lux as Blender's glTF exporter does); area lights are skipped (`meta.source.skippedLights`) |
|
| Cameras, lights | perspective (`yfov` from the lens, sensor fit and render aspect) / orthographic; point, sun, spot (watts to candela / lux as Blender's glTF exporter does); area lights are skipped (`meta.source.skippedLights`) |
|
||||||
| Armatures | a joint node per bone (rest pose times the saved pose), one skin per deformed mesh; the rig data (bones, collections, colours, custom shapes, constraints) in `extras.blend`, see [Rig data](#rig-data) |
|
| Armatures | a joint node per bone (rest pose times the saved pose), one skin per deformed mesh; the rig data (bones, collections, colours, custom shapes, constraints) in `extras.blend`, see [Rig data](#rig-data) |
|
||||||
@@ -975,6 +975,25 @@ assert(scene.materials[1].name == "Skin" and scene.materials[1].roughness > 0.69
|
|||||||
print(src.modifiers.Tube[1].type) -- Armature (not applied)
|
print(src.modifiers.Tube[1].type) -- Armature (not applied)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Material graphs
|
||||||
|
|
||||||
|
Each mapped Principled input follows its link through reroutes, Mix / MixRGB (A, then B), Hue-Saturation,
|
||||||
|
Bright-Contrast, Gamma, Invert, RGB Curves, Color Ramp (its Factor) and node groups (into the group and back out of
|
||||||
|
its inputs) to the first Image Texture node. In `material.extras.blend`:
|
||||||
|
|
||||||
|
| Field | Meaning |
|
||||||
|
|---|---|
|
||||||
|
| `via` | per input (`baseColor`, `roughness`, `metallic`, `normal`, `bump`, `alpha`, `emissive`), the node idnames passed on the way to the image (`{ baseColor = { "ShaderNodeMix" } }`); MixRGB nodes of files before 3.4 are named `ShaderNodeMix`, as Blender's conversion names them |
|
||||||
|
| `linked` | per input, the node an input is linked to when it reaches no image (`{ baseColor = "ShaderNodeTexNoise" }`); that input then takes a neutral value instead of the socket's unused default: base colour 0.8 grey (Blender's default Principled colour), metallic 0, roughness 0.5, no emission, alpha 1 |
|
||||||
|
| `vertexColor` | the colour attribute a Vertex Color (or Attribute) node feeding Base Color reads; the base colour is then white, to multiply with that `COLOR_n` |
|
||||||
|
| `roughnessTexture`, `metallicTexture` | a TextureRef plus `channel` (`"R"` for a grey map's colour, `"A"` for its alpha, or the Separate RGB / Color output used); the factor (`roughness`, `metallic`) is then 1, as glTF multiplies them |
|
||||||
|
| `bumpTexture`, `bumpStrength`, `bumpDistance` | a Bump node on Normal: the height image and the node's Strength and Distance (not a normal map, so not `normalTexture`) |
|
||||||
|
|
||||||
|
Tiled (UDIM) images (`Image.source` TILED) keep the `<UDIM>` token in `texture.uri` (`textures/body.<UDIM>.png`;
|
||||||
|
older files naming the first tile, `body.1001.png`, get the token as Blender's versioning does), and
|
||||||
|
`texture.extras.blend.tiles` lists `{ number, label?, filename }` per tile (`filename` = the uri with the number). The
|
||||||
|
texture's `data` is the first tile, through `files` / `resolve`.
|
||||||
|
|
||||||
### Rig data
|
### Rig data
|
||||||
|
|
||||||
Field names are Blender's Python API names. Spaces: the armature node carries the armature object's transform; each
|
Field names are Blender's Python API names. Spaces: the armature node carries the armature object's transform; each
|
||||||
|
|||||||
@@ -2,10 +2,13 @@
|
|||||||
-- model/blend/Material: Blender materials to Scene PBR materials. With nodes: the Principled BSDF (the one feeding the
|
-- model/blend/Material: Blender materials to Scene PBR materials. With nodes: the Principled BSDF (the one feeding the
|
||||||
-- material output, else the first): Base Color, Metallic, Roughness, Alpha, Emission (Color) x Emission Strength
|
-- material output, else the first): Base Color, Metallic, Roughness, Alpha, Emission (Color) x Emission Strength
|
||||||
-- (KHR_materials_emissive_strength above 1, as Blender's glTF exporter writes it), images linked directly to Base
|
-- (KHR_materials_emissive_strength above 1, as Blender's glTF exporter writes it), images linked directly to Base
|
||||||
-- Color / Emission and through a Normal Map node to Normal (its Strength as the scale), a Separate RGB / Color node to
|
-- Color / Emission / Roughness / Metallic and through a Normal Map node to Normal (its Strength as the scale), a
|
||||||
-- Roughness (G) and Metallic (B), UV Map nodes for the texCoord. Without nodes (or before 2.8 without a
|
-- Separate RGB / Color node to Roughness (G) and Metallic (B), UV Map nodes for the texCoord; links are followed
|
||||||
-- Principled node): Material.r / g / b / alpha, metallic, roughness. Images: packed files as encoded bytes, external
|
-- through reroutes, Mix / MixRGB (A then B), Hue-Saturation, Bright-Contrast, Gamma, Invert, RGB Curves, Color Ramp
|
||||||
-- ones as uris (with the bytes when opts.files / opts.resolve has them).
|
-- and node groups; a linked input that reaches no image takes a neutral value (base colour 0.8 grey, Blender's
|
||||||
|
-- default; metallic 0, roughness 0.5) and is flagged. Without nodes (or before 2.8 without a Principled node):
|
||||||
|
-- Material.r / g / b / alpha, metallic, roughness. Images: packed files as encoded bytes, external ones as uris (with
|
||||||
|
-- the bytes when opts.files / opts.resolve has them); tiled (UDIM) images keep the <UDIM> token in the uri.
|
||||||
local Blend = require("@rosetta/containers/Blend")
|
local Blend = require("@rosetta/containers/Blend")
|
||||||
local Types = require("@rosetta/Types")
|
local Types = require("@rosetta/Types")
|
||||||
|
|
||||||
@@ -71,6 +74,34 @@ local function texture(ctx: Ctx, img: Blend.View, sampler: Types.Sampler?): numb
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local tex: Types.Texture = { name = name, sampler = sampler }
|
local tex: Types.Texture = { name = name, sampler = sampler }
|
||||||
|
local tiles: { { [string]: any } }? = nil
|
||||||
|
if (img:num("source") or 0) == 6 then -- IMA_SRC_TILED
|
||||||
|
tiles = {}
|
||||||
|
for _, t in img:list("tiles", "ImageTile") do
|
||||||
|
local label = t:str("label")
|
||||||
|
table.insert(tiles :: any, { number = t:num("tile_number") or 1001, label = if label and label ~= "" then label else nil })
|
||||||
|
end
|
||||||
|
if #(tiles :: any) == 0 then
|
||||||
|
table.insert(tiles :: any, { number = 1001 })
|
||||||
|
end
|
||||||
|
if path and not string.find(path, "<UDIM>", 1, true) and not string.find(path, "<UVTILE>", 1, true) then
|
||||||
|
-- the tile number in the file name becomes the token, as Blender's versioning does for older files
|
||||||
|
local first = tostring((tiles :: any)[1].number)
|
||||||
|
local dir, file = string.match(path, "^(.-)([^/\\]*)$")
|
||||||
|
local a, b = nil, nil
|
||||||
|
local from = 1
|
||||||
|
while true do
|
||||||
|
local x, y = string.find(file or "", first, from, true)
|
||||||
|
if not x then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
a, b, from = x, y, x + 1
|
||||||
|
end
|
||||||
|
if a and b and file then
|
||||||
|
path = (dir or "") .. string.sub(file, 1, a - 1) .. "<UDIM>" .. string.sub(file, b + 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
if pf then
|
if pf then
|
||||||
local blk = pf:target("data")
|
local blk = pf:target("data")
|
||||||
local size = pf:num("size") or 0
|
local size = pf:num("size") or 0
|
||||||
@@ -87,7 +118,8 @@ local function texture(ctx: Ctx, img: Blend.View, sampler: Types.Sampler?): numb
|
|||||||
uri = string.gsub(uri, "\\", "/")
|
uri = string.gsub(uri, "\\", "/")
|
||||||
if not tex.data then
|
if not tex.data then
|
||||||
tex.uri = uri
|
tex.uri = uri
|
||||||
local data = fetch(ctx, uri)
|
local first = if tiles then tostring(tiles[1].number) else nil
|
||||||
|
local data = fetch(ctx, if first then (string.gsub(string.gsub(uri, "<UDIM>", first), "<UVTILE>", "u1_v1")) else uri)
|
||||||
if data then
|
if data then
|
||||||
tex.data = data
|
tex.data = data
|
||||||
tex.mime = sniffMime(data, 0, buffer.len(data), uri)
|
tex.mime = sniffMime(data, 0, buffer.len(data), uri)
|
||||||
@@ -95,7 +127,12 @@ local function texture(ctx: Ctx, img: Blend.View, sampler: Types.Sampler?): numb
|
|||||||
tex.mime = sniffMime(buffer.create(0), 0, 0, uri)
|
tex.mime = sniffMime(buffer.create(0), 0, 0, uri)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
tex.extras = { blend = { filepath = path } }
|
tex.extras = { blend = { filepath = path, tiles = tiles } }
|
||||||
|
if tiles then
|
||||||
|
for _, t in tiles do
|
||||||
|
t.filename = (string.gsub(uri, "<UDIM>", tostring(t.number)))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if not tex.data and not tex.uri then
|
if not tex.data and not tex.uri then
|
||||||
tex.extras = { blend = { generated = true } }
|
tex.extras = { blend = { generated = true } }
|
||||||
@@ -108,17 +145,22 @@ local function texture(ctx: Ctx, img: Blend.View, sampler: Types.Sampler?): numb
|
|||||||
return idx
|
return idx
|
||||||
end
|
end
|
||||||
|
|
||||||
type Node = { view: Blend.View, idname: string, inputs: { [string]: Blend.View }, outputs: { [any]: string } }
|
type Node = { view: Blend.View, idname: string, inputs: { [string]: Blend.View }, byId: { [string]: Blend.View }, first: Blend.View?, outputs: { [any]: string }, outIds: { [any]: string } }
|
||||||
type Graph = { nodes: { [any]: Node }, links: { [any]: { node: Node, socket: string } } } -- links by tosock addr
|
type Link = { node: Node, socket: string, ident: string }
|
||||||
|
type Graph = { nodes: { [any]: Node }, links: { [any]: Link } } -- links by tosock addr
|
||||||
|
|
||||||
local function graph(tree: Blend.View): Graph
|
local function graph(tree: Blend.View): Graph
|
||||||
local g: Graph = { nodes = {}, links = {} }
|
local g: Graph = { nodes = {}, links = {} }
|
||||||
for _, n in tree:list("nodes", "bNode") do
|
for _, n in tree:list("nodes", "bNode") do
|
||||||
local node: Node = { view = n, idname = n:str("idname") or "", inputs = {}, outputs = {} }
|
local node: Node = { view = n, idname = n:str("idname") or "", inputs = {}, byId = {}, outputs = {}, outIds = {} }
|
||||||
for _, s in n:list("inputs", "bNodeSocket") do
|
for _, s in n:list("inputs", "bNodeSocket") do
|
||||||
local id = s:str("identifier") or s:str("name") or ""
|
local id = s:str("identifier") or s:str("name") or ""
|
||||||
local nm = s:str("name") or id
|
local nm = s:str("name") or id
|
||||||
node.inputs[nm] = s
|
node.first = node.first or s
|
||||||
|
node.byId[id] = s
|
||||||
|
if node.inputs[nm] == nil then
|
||||||
|
node.inputs[nm] = s
|
||||||
|
end
|
||||||
if node.inputs[id] == nil then
|
if node.inputs[id] == nil then
|
||||||
node.inputs[id] = s
|
node.inputs[id] = s
|
||||||
end
|
end
|
||||||
@@ -126,6 +168,7 @@ local function graph(tree: Blend.View): Graph
|
|||||||
for _, s in n:list("outputs", "bNodeSocket") do
|
for _, s in n:list("outputs", "bNodeSocket") do
|
||||||
if s.block then
|
if s.block then
|
||||||
node.outputs[s.block.addr] = s:str("name") or ""
|
node.outputs[s.block.addr] = s:str("name") or ""
|
||||||
|
node.outIds[s.block.addr] = s:str("identifier") or s:str("name") or ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if n.block then
|
if n.block then
|
||||||
@@ -136,7 +179,7 @@ local function graph(tree: Blend.View): Graph
|
|||||||
local from, fs, to = l:ptr("fromnode"), l:ptr("fromsock"), l:ptr("tosock")
|
local from, fs, to = l:ptr("fromnode"), l:ptr("fromsock"), l:ptr("tosock")
|
||||||
local fn = from and g.nodes[from]
|
local fn = from and g.nodes[from]
|
||||||
if fn and to ~= nil and bit32.band(l:num("flag") or 0, 0x10) == 0 then
|
if fn and to ~= nil and bit32.band(l:num("flag") or 0, 0x10) == 0 then
|
||||||
g.links[to] = { node = fn, socket = (fs and fn.outputs[fs]) or "" }
|
g.links[to] = { node = fn, socket = (fs and fn.outputs[fs]) or "", ident = (fs and fn.outIds[fs]) or "" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return g
|
return g
|
||||||
@@ -152,7 +195,7 @@ local function input(n: Node, ...: string): Blend.View?
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function link(g: Graph, s: Blend.View?): { node: Node, socket: string }?
|
local function link(g: Graph, s: Blend.View?): Link?
|
||||||
if not s or not s.block then
|
if not s or not s.block then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -171,23 +214,87 @@ local function value(s: Blend.View?, kind: string): any
|
|||||||
return v and v:num("value")
|
return v and v:num("value")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function imageRef(ctx: Ctx, g: Graph, uvNames: any, s: Blend.View?, through: string?): (Types.TextureRef?, Node?)
|
-- pass-through nodes: the inputs (by identifier) that may lead to an image, in the order tried
|
||||||
|
local PASS: { [string]: { string } } = {
|
||||||
|
NodeReroute = { "Input" }, ShaderNodeMix = { "A_Color", "B_Color" }, ShaderNodeMixRGB = { "Color1", "Color2" },
|
||||||
|
ShaderNodeHueSaturation = { "Color" }, ShaderNodeBrightContrast = { "Color" }, ShaderNodeGamma = { "Color" },
|
||||||
|
ShaderNodeInvert = { "Color" }, ShaderNodeRGBCurve = { "Color" }, ShaderNodeValToRGB = { "Fac" },
|
||||||
|
}
|
||||||
|
|
||||||
|
type Hit = { node: Node, g: Graph, output: string }
|
||||||
|
type Frame = { node: Node, g: Graph }
|
||||||
|
|
||||||
|
local function groupGraph(n: Node): Graph?
|
||||||
|
local tree = n.view:deref("id", 0, "bNodeTree")
|
||||||
|
return if tree then graph(tree) else nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- the first image texture node a socket reaches through pass-through nodes and node groups (via: the nodes passed),
|
||||||
|
-- else the node it is linked to (reroutes skipped)
|
||||||
|
local function trace(g: Graph, s: Blend.View?, via: { string }, stack: { Frame }, depth: number): (Hit?, Node?)
|
||||||
local l = link(g, s)
|
local l = link(g, s)
|
||||||
if not l then
|
if not l or depth > 64 then
|
||||||
return nil, nil
|
return nil, nil
|
||||||
end
|
end
|
||||||
local n = l.node
|
local n = l.node
|
||||||
if through and n.idname == through then
|
if n.idname == "ShaderNodeTexImage" then
|
||||||
local inner = input(n, "Color", "Image")
|
return { node = n, g = g, output = l.socket }, n
|
||||||
local ref, tn = imageRef(ctx, g, uvNames, inner, nil)
|
elseif n.idname == "ShaderNodeGroup" then
|
||||||
return ref, if ref then n else tn
|
local inner = groupGraph(n)
|
||||||
end
|
local out: Node? = nil
|
||||||
if n.idname ~= "ShaderNodeTexImage" then
|
for _, x in if inner then inner.nodes else {} do
|
||||||
|
if x.idname == "NodeGroupOutput" and (out == nil or bit32.band(x.view:num("flag") or 0, 2) ~= 0) then
|
||||||
|
out = x
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local sock = out and out.byId[l.ident]
|
||||||
|
if inner and sock then
|
||||||
|
local stack2 = table.clone(stack)
|
||||||
|
table.insert(stack2, { node = n, g = g })
|
||||||
|
local sub = {}
|
||||||
|
local hit = trace(inner, sock, sub, stack2, depth + 1)
|
||||||
|
if hit then
|
||||||
|
table.insert(via, n.idname)
|
||||||
|
table.move(sub, 1, #sub, #via + 1, via)
|
||||||
|
return hit, n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil, n
|
||||||
|
elseif n.idname == "NodeGroupInput" and #stack > 0 then
|
||||||
|
local top = stack[#stack]
|
||||||
|
local outer = top.node.byId[l.ident]
|
||||||
|
local stack2 = table.clone(stack)
|
||||||
|
table.remove(stack2)
|
||||||
|
if outer then
|
||||||
|
return trace(top.g, outer, via, stack2, depth + 1)
|
||||||
|
end
|
||||||
return nil, n
|
return nil, n
|
||||||
end
|
end
|
||||||
|
local ids = PASS[n.idname]
|
||||||
|
if ids then
|
||||||
|
for _, id in ids do
|
||||||
|
local sock = n.byId[id] or (if n.idname == "NodeReroute" then n.first else nil)
|
||||||
|
local sub = {}
|
||||||
|
local hit, last = trace(g, sock, sub, stack, depth + 1)
|
||||||
|
if hit then
|
||||||
|
table.insert(via, n.idname)
|
||||||
|
table.move(sub, 1, #sub, #via + 1, via)
|
||||||
|
return hit, n
|
||||||
|
end
|
||||||
|
if n.idname == "NodeReroute" then
|
||||||
|
return nil, last or n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil, n
|
||||||
|
end
|
||||||
|
|
||||||
|
-- the TextureRef of an image texture node (its sampler, its UV Map node's texCoord)
|
||||||
|
local function refOf(ctx: Ctx, uvNames: any, hit: Hit): Types.TextureRef?
|
||||||
|
local n, g = hit.node, hit.g
|
||||||
local img = n.view:deref("id", 0, "Image")
|
local img = n.view:deref("id", 0, "Image")
|
||||||
if not img then
|
if not img then
|
||||||
return nil, n
|
return nil
|
||||||
end
|
end
|
||||||
local sampler: Types.Sampler = {}
|
local sampler: Types.Sampler = {}
|
||||||
local custom = false
|
local custom = false
|
||||||
@@ -207,7 +314,7 @@ local function imageRef(ctx: Ctx, g: Graph, uvNames: any, s: Blend.View?, throug
|
|||||||
end
|
end
|
||||||
local t = texture(ctx, img, if custom then sampler else nil)
|
local t = texture(ctx, img, if custom then sampler else nil)
|
||||||
if not t then
|
if not t then
|
||||||
return nil, n
|
return nil
|
||||||
end
|
end
|
||||||
local ref: Types.TextureRef = { texture = t }
|
local ref: Types.TextureRef = { texture = t }
|
||||||
local vec = link(g, input(n, "Vector"))
|
local vec = link(g, input(n, "Vector"))
|
||||||
@@ -218,7 +325,31 @@ local function imageRef(ctx: Ctx, g: Graph, uvNames: any, s: Blend.View?, throug
|
|||||||
ref.texCoord = uvNames[name]
|
ref.texCoord = uvNames[name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ref, n
|
return ref
|
||||||
|
end
|
||||||
|
|
||||||
|
local function imageRef(ctx: Ctx, g: Graph, uvNames: any, s: Blend.View?): (Types.TextureRef?, Node?, { string }, Hit?)
|
||||||
|
local via = {}
|
||||||
|
local hit, last = trace(g, s, via, {}, 0)
|
||||||
|
if not hit then
|
||||||
|
return nil, last, via, nil
|
||||||
|
end
|
||||||
|
return refOf(ctx, uvNames, hit), last, via, hit
|
||||||
|
end
|
||||||
|
|
||||||
|
-- the vertex colour layer a Vertex Color / Attribute node reads
|
||||||
|
local function vertexColor(n: Node?): string?
|
||||||
|
if not n then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
if n.idname == "ShaderNodeVertexColor" then
|
||||||
|
local st = n.view:deref("storage", 0, "NodeShaderVertexColor")
|
||||||
|
return st and st:str("layer_name") or ""
|
||||||
|
elseif n.idname == "ShaderNodeAttribute" then
|
||||||
|
local st = n.view:deref("storage", 0, "NodeShaderAttribute")
|
||||||
|
return st and st:str("name") or ""
|
||||||
|
end
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function principled(g: Graph): Node?
|
local function principled(g: Graph): Node?
|
||||||
@@ -282,47 +413,139 @@ function Material.get(ctx: Ctx, mv: Blend.View): number
|
|||||||
end
|
end
|
||||||
m.metallic = value(input(bsdf, "Metallic"), "float") or m.metallic
|
m.metallic = value(input(bsdf, "Metallic"), "float") or m.metallic
|
||||||
m.roughness = value(input(bsdf, "Roughness"), "float") or m.roughness
|
m.roughness = value(input(bsdf, "Roughness"), "float") or m.roughness
|
||||||
local bref = imageRef(ctx, g, uvNames, input(bsdf, "Base Color"), nil)
|
local linked: { [string]: string } = {}
|
||||||
|
local via: { [string]: { string } } = {}
|
||||||
|
-- node names as Blender 3.4+ shows them (its versioning turns shader MixRGB nodes into Mix nodes)
|
||||||
|
local function api(idname: string): string
|
||||||
|
return if idname == "ShaderNodeMixRGB" and f.version < 304 then "ShaderNodeMix" else idname
|
||||||
|
end
|
||||||
|
local function resolve(key: string, sock: Blend.View?): (Types.TextureRef?, Node?, Hit?)
|
||||||
|
if not link(g :: Graph, sock) then
|
||||||
|
return nil, nil, nil
|
||||||
|
end
|
||||||
|
local ref, last, passed, hit = imageRef(ctx, g :: Graph, uvNames, sock)
|
||||||
|
if ref then
|
||||||
|
if #passed > 0 then
|
||||||
|
for i, x in passed do
|
||||||
|
passed[i] = api(x)
|
||||||
|
end
|
||||||
|
via[key] = passed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ref, last, hit
|
||||||
|
end
|
||||||
|
local function unresolved(key: string, sock: Blend.View?)
|
||||||
|
local l = link(g :: Graph, sock)
|
||||||
|
if l then
|
||||||
|
local _, last = trace(g :: Graph, sock, {}, {}, 0) -- reroutes skipped
|
||||||
|
linked[key] = api((last or l.node).idname)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local baseSock = input(bsdf, "Base Color")
|
||||||
|
local bref, blast = resolve("baseColor", baseSock)
|
||||||
if bref then
|
if bref then
|
||||||
m.baseColorTexture = bref
|
m.baseColorTexture = bref
|
||||||
m.baseColor = { 1, 1, 1, alpha }
|
m.baseColor = { 1, 1, 1, alpha }
|
||||||
|
elseif link(g, baseSock) then
|
||||||
|
local layer = vertexColor(blast)
|
||||||
|
if layer then
|
||||||
|
extras.vertexColor = layer
|
||||||
|
m.baseColor = { 1, 1, 1, alpha }
|
||||||
|
else
|
||||||
|
m.baseColor = { 0.8, 0.8, 0.8, alpha } -- Blender's default base colour, never the linked socket's value
|
||||||
|
unresolved("baseColor", baseSock)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local aref = imageRef(ctx, g, uvNames, input(bsdf, "Alpha"), nil)
|
local alphaSock = input(bsdf, "Alpha")
|
||||||
|
local aref = resolve("alpha", alphaSock)
|
||||||
if aref and not m.baseColorTexture then
|
if aref and not m.baseColorTexture then
|
||||||
m.baseColorTexture = aref
|
m.baseColorTexture = aref
|
||||||
|
elseif not aref and link(g, alphaSock) then
|
||||||
|
m.baseColor[4] = 1
|
||||||
|
unresolved("alpha", alphaSock)
|
||||||
end
|
end
|
||||||
local nref, nnode = imageRef(ctx, g, uvNames, input(bsdf, "Normal"), "ShaderNodeNormalMap")
|
local nl = link(g, input(bsdf, "Normal"))
|
||||||
if nref then
|
if nl and nl.node.idname == "ShaderNodeNormalMap" then
|
||||||
nref.scale = if nnode then value(nnode.inputs.Strength, "float") or 1 else 1
|
local nref = resolve("normal", input(nl.node, "Color"))
|
||||||
m.normalTexture = nref
|
if nref then
|
||||||
|
nref.scale = value(nl.node.inputs.Strength, "float") or 1
|
||||||
|
m.normalTexture = nref
|
||||||
|
else
|
||||||
|
unresolved("normal", input(bsdf, "Normal"))
|
||||||
|
end
|
||||||
|
elseif nl and nl.node.idname == "ShaderNodeBump" then
|
||||||
|
local href = resolve("bump", input(nl.node, "Height"))
|
||||||
|
if href then
|
||||||
|
extras.bumpTexture = href
|
||||||
|
extras.bumpStrength = value(input(nl.node, "Strength"), "float") or 1
|
||||||
|
extras.bumpDistance = value(input(nl.node, "Distance"), "float") or 1
|
||||||
|
else
|
||||||
|
unresolved("normal", input(bsdf, "Normal"))
|
||||||
|
end
|
||||||
|
elseif nl then
|
||||||
|
unresolved("normal", input(bsdf, "Normal"))
|
||||||
end
|
end
|
||||||
local rl = link(g, input(bsdf, "Roughness"))
|
local channelOf = { Red = "R", Green = "G", Blue = "B", R = "R", G = "G", B = "B", Alpha = "A", Color = "R", Fac = "R" }
|
||||||
local ml = link(g, input(bsdf, "Metallic"))
|
local function scalar(key: string, sock: Blend.View?): boolean?
|
||||||
local sep = (rl and rl.node) or (ml and ml.node)
|
local l = link(g :: Graph, sock)
|
||||||
if sep and (sep.idname == "ShaderNodeSeparateRGB" or sep.idname == "ShaderNodeSeparateColor") then
|
if not l then
|
||||||
local mref = imageRef(ctx, g, uvNames, input(sep, "Image", "Color"), nil)
|
return nil
|
||||||
if mref then
|
end
|
||||||
m.metallicRoughnessTexture = mref
|
local sep = l.node
|
||||||
if rl then
|
if sep.idname == "ShaderNodeSeparateRGB" or sep.idname == "ShaderNodeSeparateColor" then
|
||||||
m.roughness = 1
|
local ref = resolve(key, input(sep, "Image", "Color"))
|
||||||
|
if ref then
|
||||||
|
m.metallicRoughnessTexture = m.metallicRoughnessTexture or table.clone(ref)
|
||||||
|
local r = table.clone(ref) :: any
|
||||||
|
r.channel = channelOf[l.socket] or l.socket
|
||||||
|
extras[key .. "Texture"] = r
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
if ml then
|
else
|
||||||
m.metallic = 1
|
local ref, _, hit = resolve(key, sock)
|
||||||
|
if ref and hit then
|
||||||
|
local r = ref :: any
|
||||||
|
r.channel = channelOf[hit.output] or hit.output
|
||||||
|
extras[key .. "Texture"] = r
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
unresolved(key, sock)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local rs = scalar("roughness", input(bsdf, "Roughness"))
|
||||||
|
if rs == true then
|
||||||
|
m.roughness = 1
|
||||||
|
elseif rs == false then
|
||||||
|
m.roughness = 0.5
|
||||||
|
end
|
||||||
|
local ms = scalar("metallic", input(bsdf, "Metallic"))
|
||||||
|
if ms == true then
|
||||||
|
m.metallic = 1
|
||||||
|
elseif ms == false then
|
||||||
|
m.metallic = 0
|
||||||
end
|
end
|
||||||
local es = input(bsdf, "Emission Color", "Emission")
|
local es = input(bsdf, "Emission Color", "Emission")
|
||||||
local ecol = value(es, "rgba") or { 0, 0, 0, 1 }
|
local ecol = value(es, "rgba") or { 0, 0, 0, 1 }
|
||||||
local strength = value(input(bsdf, "Emission Strength"), "float") or 1
|
local strength = value(input(bsdf, "Emission Strength"), "float") or 1
|
||||||
local eref = imageRef(ctx, g, uvNames, es, nil)
|
local eref = resolve("emissive", es)
|
||||||
if eref then
|
if eref then
|
||||||
m.emissiveTexture = eref
|
m.emissiveTexture = eref
|
||||||
ecol = { 1, 1, 1, 1 }
|
ecol = { 1, 1, 1, 1 }
|
||||||
|
elseif link(g, es) then
|
||||||
|
ecol = { 0, 0, 0, 1 }
|
||||||
|
unresolved("emissive", es)
|
||||||
end
|
end
|
||||||
emissive(m, ecol, strength)
|
emissive(m, ecol, strength)
|
||||||
if not eref and m.emissive[1] == 0 and m.emissive[2] == 0 and m.emissive[3] == 0 then
|
if not eref and m.emissive[1] == 0 and m.emissive[2] == 0 and m.emissive[3] == 0 then
|
||||||
m.emissive = { 0, 0, 0 }
|
m.emissive = { 0, 0, 0 }
|
||||||
end
|
end
|
||||||
|
if next(linked) ~= nil then
|
||||||
|
extras.linked = linked
|
||||||
|
end
|
||||||
|
if next(via) ~= nil then
|
||||||
|
extras.via = via
|
||||||
|
end
|
||||||
local alphaLinked = link(g, input(bsdf, "Alpha")) ~= nil
|
local alphaLinked = link(g, input(bsdf, "Alpha")) ~= nil
|
||||||
if alpha < 1 or alphaLinked then
|
if alpha < 1 or alphaLinked then
|
||||||
local bm = mv:num("blend_method") or 0
|
local bm = mv:num("blend_method") or 0
|
||||||
|
|||||||
+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" }
|
"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 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 = {}
|
local samples = {}
|
||||||
|
|
||||||
t:check(#Sets.old >= 4, "the old demo files were fetched (" .. #Sets.old .. ")")
|
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]
|
local g = glMats[m.name]
|
||||||
if m.extras.blend.principled and g then
|
if m.extras.blend.principled and g then
|
||||||
local pbr = g.pbrMetallicRoughness or {}
|
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))
|
-- an input linked to no image: the exporter writes its own guess, the reader a neutral value (checked below)
|
||||||
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")
|
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))
|
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 ges = g.extensions and g.extensions.KHR_materials_emissive_strength
|
||||||
local es = m.extensions and m.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(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.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.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
|
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")
|
t:check(near(m.normalTexture.scale, g.normalTexture.scale or 1, 1e-5), label .. ": " .. m.name .. " normal scale")
|
||||||
end
|
end
|
||||||
checked.materials += 1
|
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
|
elseif not m.extras.blend.principled then
|
||||||
for _, rm in ref.materials do
|
for _, rm in ref.materials do
|
||||||
if rm.name == m.name then
|
if rm.name == m.name then
|
||||||
@@ -952,7 +1015,7 @@ for _, tag in { "old", "279", "293", "35", "41", "cur" } do
|
|||||||
end
|
end
|
||||||
end
|
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",
|
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)
|
checked.worlds, checked.meshes, checked.normals, checked.weights, checked.shapes, checked.curves, checked.frames, checked.skinned, checked.materials, checked.cameras, checked.lights)
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,10 @@
|
|||||||
# track constraints; bone inheritance and b-bone settings; a saved pose basis; drivers
|
# track constraints; bone inheritance and b-bone settings; a saved pose basis; drivers
|
||||||
# (every variable type, keys, modifiers) on the rig, its data and the shape keys; custom
|
# (every variable type, keys, modifiers) on the rig, its data and the shape keys; custom
|
||||||
# properties on pose bones, bones and objects
|
# properties on pose bones, bones and objects
|
||||||
|
# mat_<ver>.blend material graphs: images through Mix / MixRGB, Hue-Saturation, Bright-Contrast, Gamma,
|
||||||
|
# Invert, RGB Curves, Color Ramp, reroutes and node groups; roughness images linked directly
|
||||||
|
# or through a ramp; vertex colours; bump; unresolved links; a UDIM image with two tiles
|
||||||
|
# (2.82+, the tiles as udim.1001.png / udim.1002.png next to the file)
|
||||||
import bpy, sys, os, math
|
import bpy, sys, os, math
|
||||||
|
|
||||||
out = sys.argv[sys.argv.index("--") + 1]
|
out = sys.argv[sys.argv.index("--") + 1]
|
||||||
@@ -824,9 +828,169 @@ def ctl_file():
|
|||||||
save(os.path.join(out, "ctl_%s.blend" % TAG))
|
save(os.path.join(out, "ctl_%s.blend" % TAG))
|
||||||
|
|
||||||
|
|
||||||
|
def mat_file():
|
||||||
|
reset()
|
||||||
|
old_mix = V < (3, 4)
|
||||||
|
diffuse = image("diffuse", 4, 4, lambda x, y: [x / 3, y / 3, 0.5, 1.0])
|
||||||
|
rough = image("rough", 4, 4, lambda x, y: [0.25 + x / 8] * 3 + [1.0])
|
||||||
|
bump = image("height", 4, 4, lambda x, y: [(x + y) / 6] * 3 + [1.0])
|
||||||
|
nrm = image("nrm", 4, 4, lambda x, y: [0.5, 0.5, 1.0, 1.0])
|
||||||
|
udim = None
|
||||||
|
if V >= (2, 82):
|
||||||
|
paths = []
|
||||||
|
for tile, col in ((1001, (1.0, 0.0, 0.0)), (1002, (0.0, 0.0, 1.0))):
|
||||||
|
p = os.path.join(out, "udim.%d.png" % tile)
|
||||||
|
t = bpy.data.images.new("udim_%d" % tile, 2, 2)
|
||||||
|
t.pixels = list(col + (1.0,)) * 4
|
||||||
|
t.filepath_raw = p
|
||||||
|
t.file_format = "PNG"
|
||||||
|
t.save()
|
||||||
|
bpy.data.images.remove(t)
|
||||||
|
paths.append(p)
|
||||||
|
udim = bpy.data.images.load(paths[0])
|
||||||
|
udim.name = "udim"
|
||||||
|
udim.source = "TILED"
|
||||||
|
if len(udim.tiles) < 2:
|
||||||
|
udim.tiles.new(1002)
|
||||||
|
udim.tiles[0].label = "front"
|
||||||
|
udim.filepath = "//" + os.path.basename(udim.filepath.replace("1001", "<UDIM>" if V >= (3, 0) else "1001"))
|
||||||
|
|
||||||
|
def material(name):
|
||||||
|
m = bpy.data.materials.new(name)
|
||||||
|
bsdf = principled(m, (0.8, 0.8, 0.8, 1.0), 0.0, 0.5)
|
||||||
|
return m, m.node_tree, bsdf
|
||||||
|
|
||||||
|
def tex(nt, img):
|
||||||
|
t = nt.nodes.new("ShaderNodeTexImage")
|
||||||
|
t.image = img
|
||||||
|
return t
|
||||||
|
|
||||||
|
def mix(nt, a, b, fac):
|
||||||
|
if old_mix:
|
||||||
|
n = nt.nodes.new("ShaderNodeMixRGB")
|
||||||
|
ia, ib, f, o = n.inputs["Color1"], n.inputs["Color2"], n.inputs["Fac"], n.outputs["Color"]
|
||||||
|
else:
|
||||||
|
n = nt.nodes.new("ShaderNodeMix")
|
||||||
|
n.data_type = "RGBA"
|
||||||
|
ia, ib, f, o = n.inputs[6], n.inputs[7], n.inputs[0], n.outputs[2]
|
||||||
|
if a:
|
||||||
|
nt.links.new(a, ia)
|
||||||
|
if b:
|
||||||
|
nt.links.new(b, ib)
|
||||||
|
if fac:
|
||||||
|
nt.links.new(fac, f)
|
||||||
|
return o
|
||||||
|
|
||||||
|
def vcol(nt):
|
||||||
|
if V >= (2, 81):
|
||||||
|
n = nt.nodes.new("ShaderNodeVertexColor")
|
||||||
|
n.layer_name = "Col"
|
||||||
|
else:
|
||||||
|
n = nt.nodes.new("ShaderNodeAttribute")
|
||||||
|
n.attribute_name = "Col"
|
||||||
|
return n.outputs["Color"]
|
||||||
|
|
||||||
|
def ramp(nt, src):
|
||||||
|
n = nt.nodes.new("ShaderNodeValToRGB")
|
||||||
|
nt.links.new(src, n.inputs["Fac"])
|
||||||
|
return n.outputs["Color"]
|
||||||
|
|
||||||
|
def reroute(nt, src):
|
||||||
|
n = nt.nodes.new("NodeReroute")
|
||||||
|
nt.links.new(src, n.inputs[0])
|
||||||
|
return n.outputs[0]
|
||||||
|
|
||||||
|
mats = []
|
||||||
|
# body: Mix(A = image, B = HueSat(image), Fac = ramp(vertex colour)); roughness image linked directly
|
||||||
|
m, nt, b = material("MatBody")
|
||||||
|
img = udim or diffuse
|
||||||
|
hs = nt.nodes.new("ShaderNodeHueSaturation")
|
||||||
|
nt.links.new(tex(nt, img).outputs["Color"], hs.inputs["Color"])
|
||||||
|
nt.links.new(mix(nt, tex(nt, img).outputs["Color"], hs.outputs["Color"], ramp(nt, vcol(nt))), b.inputs["Base Color"])
|
||||||
|
nt.links.new(tex(nt, rough).outputs["Color"], b.inputs["Roughness"])
|
||||||
|
mats.append(m)
|
||||||
|
# hands: Mix(A = image, Fac = ramp(vertex colour)), B unlinked
|
||||||
|
m, nt, b = material("MatHands")
|
||||||
|
nt.links.new(mix(nt, tex(nt, diffuse).outputs["Color"], None, ramp(nt, vcol(nt))), b.inputs["Base Color"])
|
||||||
|
nt.links.new(tex(nt, rough).outputs["Color"], b.inputs["Roughness"])
|
||||||
|
mats.append(m)
|
||||||
|
# hair: reroutes; roughness through a reroute and a ramp
|
||||||
|
m, nt, b = material("MatHair")
|
||||||
|
nt.links.new(reroute(nt, reroute(nt, tex(nt, diffuse).outputs["Color"])), b.inputs["Base Color"])
|
||||||
|
nt.links.new(reroute(nt, ramp(nt, tex(nt, rough).outputs["Color"])), b.inputs["Roughness"])
|
||||||
|
mats.append(m)
|
||||||
|
# eyebrows: vertex colour
|
||||||
|
m, nt, b = material("MatVcol")
|
||||||
|
nt.links.new(vcol(nt), b.inputs["Base Color"])
|
||||||
|
mats.append(m)
|
||||||
|
# jeans: image, normal map, roughness image linked directly, metallic through Separate RGB (packed)
|
||||||
|
m, nt, b = material("MatJeans")
|
||||||
|
nt.links.new(tex(nt, diffuse).outputs["Color"], b.inputs["Base Color"])
|
||||||
|
nm = nt.nodes.new("ShaderNodeNormalMap")
|
||||||
|
nt.links.new(tex(nt, nrm).outputs["Color"], nm.inputs["Color"])
|
||||||
|
nt.links.new(nm.outputs["Normal"], b.inputs["Normal"])
|
||||||
|
nt.links.new(tex(nt, rough).outputs["Color"], b.inputs["Roughness"])
|
||||||
|
mats.append(m)
|
||||||
|
# a chain of colour adjustments
|
||||||
|
m, nt, b = material("MatChain")
|
||||||
|
src = tex(nt, diffuse).outputs["Color"]
|
||||||
|
for idname in ("ShaderNodeRGBCurve", "ShaderNodeInvert", "ShaderNodeGamma", "ShaderNodeBrightContrast"):
|
||||||
|
n = nt.nodes.new(idname)
|
||||||
|
nt.links.new(src, n.inputs["Color"])
|
||||||
|
src = n.outputs["Color"]
|
||||||
|
nt.links.new(src, b.inputs["Base Color"])
|
||||||
|
mats.append(m)
|
||||||
|
# a node group: an image inside it, and a pass-through of an outside image
|
||||||
|
grp = bpy.data.node_groups.new("TexGroup", "ShaderNodeTree")
|
||||||
|
gi, go = grp.nodes.new("NodeGroupInput"), grp.nodes.new("NodeGroupOutput")
|
||||||
|
if hasattr(grp, "interface"):
|
||||||
|
grp.interface.new_socket("Tint", in_out="INPUT", socket_type="NodeSocketColor")
|
||||||
|
grp.interface.new_socket("Color", in_out="OUTPUT", socket_type="NodeSocketColor")
|
||||||
|
grp.interface.new_socket("Through", in_out="OUTPUT", socket_type="NodeSocketColor")
|
||||||
|
else:
|
||||||
|
grp.inputs.new("NodeSocketColor", "Tint")
|
||||||
|
grp.outputs.new("NodeSocketColor", "Color")
|
||||||
|
grp.outputs.new("NodeSocketColor", "Through")
|
||||||
|
inner = grp.nodes.new("ShaderNodeTexImage")
|
||||||
|
inner.image = rough
|
||||||
|
grp.links.new(inner.outputs["Color"], go.inputs[0])
|
||||||
|
grp.links.new(gi.outputs[0], go.inputs[1])
|
||||||
|
m, nt, b = material("MatGroup")
|
||||||
|
gn = nt.nodes.new("ShaderNodeGroup")
|
||||||
|
gn.node_tree = grp
|
||||||
|
nt.links.new(tex(nt, diffuse).outputs["Color"], gn.inputs[0])
|
||||||
|
nt.links.new(gn.outputs[1], b.inputs["Base Color"])
|
||||||
|
nt.links.new(gn.outputs[0], b.inputs["Roughness"])
|
||||||
|
mats.append(m)
|
||||||
|
# bump, and unresolved links (a noise texture, a math node)
|
||||||
|
m, nt, b = material("MatBump")
|
||||||
|
bp = nt.nodes.new("ShaderNodeBump")
|
||||||
|
bp.inputs["Strength"].default_value = 0.5
|
||||||
|
bp.inputs["Distance"].default_value = 0.2
|
||||||
|
nt.links.new(tex(nt, bump).outputs["Color"], bp.inputs["Height"])
|
||||||
|
nt.links.new(bp.outputs["Normal"], b.inputs["Normal"])
|
||||||
|
nz = nt.nodes.new("ShaderNodeTexNoise")
|
||||||
|
nt.links.new(nz.outputs["Color"], b.inputs["Base Color"])
|
||||||
|
b.inputs["Base Color"].default_value = (0.0, 0.0, 0.0, 1.0)
|
||||||
|
mt = nt.nodes.new("ShaderNodeMath")
|
||||||
|
nt.links.new(mt.outputs[0], b.inputs["Metallic"])
|
||||||
|
b.inputs["Metallic"].default_value = 0.9
|
||||||
|
mats.append(m)
|
||||||
|
for i, m in enumerate(mats):
|
||||||
|
me = mesh("Quad" + m.name, [(0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0)], [(0, 1, 2, 3)])
|
||||||
|
uv(me, "UVMap", lambda k: ((k % 2) * 1.0, (k // 2) * 1.0))
|
||||||
|
byte_colors(me, "Col")
|
||||||
|
me.materials.append(m)
|
||||||
|
ob = link(bpy.data.objects.new("Quad" + m.name, me))
|
||||||
|
ob.location = (i * 1.5, 0, 0)
|
||||||
|
update()
|
||||||
|
save(os.path.join(out, "mat_%s.blend" % TAG))
|
||||||
|
|
||||||
|
|
||||||
scene_file()
|
scene_file()
|
||||||
rig_file()
|
rig_file()
|
||||||
ctl_file()
|
ctl_file()
|
||||||
|
mat_file()
|
||||||
if OLD:
|
if OLD:
|
||||||
scene_file()
|
scene_file()
|
||||||
save(os.path.join(out, "compat_%s.blend" % TAG), compat=True)
|
save(os.path.join(out, "compat_%s.blend" % TAG), compat=True)
|
||||||
|
|||||||
@@ -93,9 +93,115 @@ def linked_image(s):
|
|||||||
return "?" + n.bl_idname
|
return "?" + n.bl_idname
|
||||||
|
|
||||||
|
|
||||||
|
PASS = {"NodeReroute": ["Input"], "ShaderNodeMix": ["A_Color", "B_Color"], "ShaderNodeMixRGB": ["Color1", "Color2"],
|
||||||
|
"ShaderNodeHueSaturation": ["Color"], "ShaderNodeBrightContrast": ["Color"], "ShaderNodeGamma": ["Color"],
|
||||||
|
"ShaderNodeInvert": ["Color"], "ShaderNodeRGBCurve": ["Color"], "ShaderNodeValToRGB": ["Fac"]}
|
||||||
|
|
||||||
|
|
||||||
|
def by_identifier(sockets, ident):
|
||||||
|
for s in sockets:
|
||||||
|
if s.identifier == ident:
|
||||||
|
return s
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def trace(sock, via, stack, depth=0):
|
||||||
|
"""bpy's view of the reader's rules: (end node, from-socket name, group stack) of the first image, else the last node"""
|
||||||
|
if depth > 64 or not sock.is_linked:
|
||||||
|
return None, None
|
||||||
|
link = sock.links[0]
|
||||||
|
n, out = link.from_node, link.from_socket
|
||||||
|
if n.bl_idname == "ShaderNodeTexImage":
|
||||||
|
return n, out.name
|
||||||
|
if n.bl_idname == "ShaderNodeGroup" and n.node_tree:
|
||||||
|
outs = [x for x in n.node_tree.nodes if x.bl_idname == "NodeGroupOutput"]
|
||||||
|
if outs:
|
||||||
|
inner = by_identifier(outs[0].inputs, out.identifier)
|
||||||
|
if inner is not None:
|
||||||
|
via.append(n.bl_idname)
|
||||||
|
r, nm = trace(inner, via, stack + [n], depth + 1)
|
||||||
|
if r is not None and r.bl_idname == "ShaderNodeTexImage":
|
||||||
|
return r, nm
|
||||||
|
via.pop()
|
||||||
|
return n, out.name
|
||||||
|
if n.bl_idname == "NodeGroupInput" and stack:
|
||||||
|
g = stack[-1]
|
||||||
|
outer = by_identifier(g.inputs, out.identifier)
|
||||||
|
if outer is not None:
|
||||||
|
return trace(outer, via, stack[:-1], depth + 1)
|
||||||
|
return n, out.name
|
||||||
|
if n.bl_idname in PASS:
|
||||||
|
last = n
|
||||||
|
for ident in PASS[n.bl_idname]:
|
||||||
|
s = by_identifier(n.inputs, ident) or (n.inputs.get(ident) if hasattr(n.inputs, "get") else None)
|
||||||
|
if s is None and n.bl_idname == "NodeReroute":
|
||||||
|
s = n.inputs[0]
|
||||||
|
if s is None:
|
||||||
|
continue
|
||||||
|
sub = []
|
||||||
|
r, nm = trace(s, sub, stack, depth + 1)
|
||||||
|
if r is not None and r.bl_idname == "ShaderNodeTexImage":
|
||||||
|
via.append(n.bl_idname)
|
||||||
|
via.extend(sub)
|
||||||
|
return r, nm
|
||||||
|
if n.bl_idname == "NodeReroute":
|
||||||
|
return (r, nm) if r is not None else (n, out.name)
|
||||||
|
return last, out.name
|
||||||
|
return n, out.name
|
||||||
|
|
||||||
|
|
||||||
|
def image_info(img):
|
||||||
|
info = {"name": img.name, "source": img.source, "filepath": img.filepath}
|
||||||
|
if img.source == "TILED":
|
||||||
|
info["tiles"] = [{"number": t.number, "label": t.label} for t in img.tiles]
|
||||||
|
return info
|
||||||
|
|
||||||
|
|
||||||
|
def graph_info(m):
|
||||||
|
out = {}
|
||||||
|
if not m.node_tree:
|
||||||
|
return out
|
||||||
|
bsdf = None # the reader's choice: the Principled BSDF linked to an output's Surface, else the first
|
||||||
|
for n in m.node_tree.nodes:
|
||||||
|
if n.bl_idname == "ShaderNodeOutputMaterial" and n.inputs["Surface"].is_linked:
|
||||||
|
f = n.inputs["Surface"].links[0].from_node
|
||||||
|
if f.bl_idname == "ShaderNodeBsdfPrincipled":
|
||||||
|
bsdf = f
|
||||||
|
if bsdf is None:
|
||||||
|
bsdf = next((n for n in m.node_tree.nodes if n.bl_idname == "ShaderNodeBsdfPrincipled"), None)
|
||||||
|
if bsdf is None:
|
||||||
|
return out
|
||||||
|
for name in ("Base Color", "Metallic", "Roughness", "Normal", "Alpha", "Emission Color", "Emission"):
|
||||||
|
s = bsdf.inputs.get(name)
|
||||||
|
if s is None or not s.is_linked:
|
||||||
|
continue
|
||||||
|
sock = s
|
||||||
|
e = {"linked": s.links[0].from_node.bl_idname}
|
||||||
|
if name == "Normal" and e["linked"] in ("ShaderNodeNormalMap", "ShaderNodeBump"):
|
||||||
|
nn = s.links[0].from_node
|
||||||
|
sock = nn.inputs["Color"] if e["linked"] == "ShaderNodeNormalMap" else nn.inputs["Height"]
|
||||||
|
if e["linked"] == "ShaderNodeBump":
|
||||||
|
e["strength"] = r6(nn.inputs["Strength"].default_value)
|
||||||
|
e["distance"] = r6(nn.inputs["Distance"].default_value)
|
||||||
|
via = []
|
||||||
|
n, outname = trace(sock, via, [])
|
||||||
|
if n is not None and n.bl_idname == "ShaderNodeTexImage" and n.image:
|
||||||
|
e["image"] = image_info(n.image)
|
||||||
|
e["via"] = via
|
||||||
|
e["output"] = outname
|
||||||
|
elif n is not None:
|
||||||
|
e["end"] = n.bl_idname
|
||||||
|
if n.bl_idname == "ShaderNodeVertexColor":
|
||||||
|
e["vertexColor"] = n.layer_name
|
||||||
|
elif n.bl_idname == "ShaderNodeAttribute":
|
||||||
|
e["vertexColor"] = n.attribute_name
|
||||||
|
out[name] = e
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
def material_info(m):
|
def material_info(m):
|
||||||
info = {"name": m.name, "diffuse": [r6(x) for x in m.diffuse_color], "metallic": r6(m.metallic), "roughness": r6(m.roughness),
|
info = {"name": m.name, "diffuse": [r6(x) for x in m.diffuse_color], "metallic": r6(m.metallic), "roughness": r6(m.roughness),
|
||||||
"use_nodes": bool(m.use_nodes), "cull": bool(m.use_backface_culling)}
|
"use_nodes": bool(m.use_nodes), "cull": bool(m.use_backface_culling), "graph": graph_info(m)}
|
||||||
if m.node_tree:
|
if m.node_tree:
|
||||||
for n in m.node_tree.nodes:
|
for n in m.node_tree.nodes:
|
||||||
if n.bl_idname == "ShaderNodeBsdfPrincipled":
|
if n.bl_idname == "ShaderNodeBsdfPrincipled":
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
# old demos (fetched, never committed; 32-bit pointers, big-endian SGI / PowerPC files among them), with references
|
# old demos (fetched, never committed; 32-bit pointers, big-endian SGI / PowerPC files among them), with references
|
||||||
# from Blender 4.1 (5.0 dropped big-endian files).
|
# from Blender 4.1 (5.0 dropped big-endian files).
|
||||||
# tests/gen/blend_<ver>.luau { { name, data, ref } } (<ver>: 279, 293, 35, 41, cur, old)
|
# tests/gen/blend_<ver>.luau { { name, data, ref } } (<ver>: 279, 293, 35, 41, cur, old)
|
||||||
# tests/gen/blend_files.luau sibling files the scenes refer to ({ ["outside.png"] = bytes })
|
# tests/gen/blend_files.luau sibling files the scenes refer to ({ ["outside.png"] = bytes, UDIM tiles })
|
||||||
import json, os, shutil, subprocess, tempfile
|
import json, os, shutil, subprocess, tempfile
|
||||||
|
|
||||||
INPUTS = ["tools/fixtures/_blend_make.py", "tools/fixtures/_blend_ref.py"]
|
INPUTS = ["tools/fixtures/_blend_make.py", "tools/fixtures/_blend_ref.py"]
|
||||||
@@ -118,6 +118,7 @@ def generate(ctx):
|
|||||||
if not ok:
|
if not ok:
|
||||||
raise RuntimeError("blend: the reference Blender failed: " + log[-2000:])
|
raise RuntimeError("blend: the reference Blender failed: " + log[-2000:])
|
||||||
sibling = None
|
sibling = None
|
||||||
|
tiles = {}
|
||||||
for tag, (out, files) in made.items():
|
for tag, (out, files) in made.items():
|
||||||
cases = []
|
cases = []
|
||||||
for f in files:
|
for f in files:
|
||||||
@@ -132,10 +133,15 @@ def generate(ctx):
|
|||||||
ctx.emit("blend_" + name, cases)
|
ctx.emit("blend_" + name, cases)
|
||||||
if sibling is None and os.path.exists(os.path.join(out, "outside.png")):
|
if sibling is None and os.path.exists(os.path.join(out, "outside.png")):
|
||||||
sibling = open(os.path.join(out, "outside.png"), "rb").read()
|
sibling = open(os.path.join(out, "outside.png"), "rb").read()
|
||||||
|
for tile in ("udim.1001.png", "udim.1002.png"):
|
||||||
|
if tile not in tiles and os.path.exists(os.path.join(out, tile)):
|
||||||
|
tiles[tile] = open(os.path.join(out, tile), "rb").read()
|
||||||
for tag, _ in OLD + [("cur", None)]:
|
for tag, _ in OLD + [("cur", None)]:
|
||||||
if tag not in made:
|
if tag not in made:
|
||||||
ctx.emit("blend_" + tag, [])
|
ctx.emit("blend_" + tag, [])
|
||||||
ctx.emit("blend_old", old_samples(ctx, tmp))
|
ctx.emit("blend_old", old_samples(ctx, tmp))
|
||||||
ctx.emit("blend_files", {"outside.png": sibling or b""})
|
files = {"outside.png": sibling or b""}
|
||||||
|
files.update(tiles)
|
||||||
|
ctx.emit("blend_files", files)
|
||||||
ctx.emit("blend_versions", sorted(made.keys()))
|
ctx.emit("blend_versions", sorted(made.keys()))
|
||||||
shutil.rmtree(tmp, ignore_errors=True)
|
shutil.rmtree(tmp, ignore_errors=True)
|
||||||
Reference in new issue
Block a user