Page 1 of 1
Getting the path to a texture image file from material nodes
Posted: Mon May 23, 2016 6:44 pm
by MB
All,
I have been unable to figure out how to get the paths to any texture image files used within a material.
I would like to get all image files a material might use, i.e. normal and bump maps as well as diffuse and specular. Could anyone enlighten me.
Many thanks
Mark
Re: Getting the path to a texture image file from material nodes
Posted: Mon May 30, 2016 2:27 am
by roeland
You can recursively walk over all the input nodes of the given node:
Code: Select all
local function walk(node, list)
-- recursive walk
for i = 1,node:getPinCount() do
local src = node:getInputNodeIx(i)
if src ~= nil then walk(src, list) end
end
-- see if this node has a filename attribute
local ok, value = pcall(node.getAttribute, node, "filename")
if ok then
table.insert(list, value)
end
end
local list = {}
walk(octane.project.getSelection()[1], list)
for k, v in ipairs(list) do
print(v)
end
To check if any node has a file name attribute, you can use
pcall
, a standard Lua function which calls another function (
octane.node.getAttribute
in our case) with the given arguments and catches any errors raised.
This code gives you the file names of
any kind of file referenced by the nodes, not just image textures.
--
Roeland
Re: Getting the path to a texture image file from material nodes
Posted: Wed Jun 01, 2016 9:51 pm
by MB
Many Thanks Roeland