Getting Textures from a material

Forums: Getting Textures from a material
Forum for OctaneRender Lua scripting examples, discussion and support.

Getting Textures from a material

Postby MB » Fri May 27, 2016 10:49 pm

MB Fri May 27, 2016 10:49 pm
I have the following situation illustrated at end of post.

I am successfully looping through the material pins on a mesh node, identifying there type and getting some information. I was surprised I did not need to do anything specific to tell octane to look for external materials nodes connected to a pin. However I cannot seem to get to the texture file information from any node. Can someone please point me in the right direction. Current routine is included below.

--if node type is glossy
if internalMatNode.type == octane.NT_MAT_GLOSSY then

print (" ")
print("Glossy Material")
print ("----------------------------------")

-- get the diffuse pin values
tblDiffuseValues = internalMatNode:getPinValue(octane.P_DIFFUSE)
print ("Diffuse Pin Values For: " ..internalMatNode.name)
for k, v in pairs(tblDiffuseValues) do
print(k, v)
end

-- if pin has an image, get image file name
-- first determine if another node is attatched

local inputNodeA =internalMatNode:getConnectedNode(octane.P_DIFFUSE)
print ("Glossy input a",inputnodeA)

local inputNodeB =internalMatNode:getConnectedNodeIx(pinIx)
print ("Glossy input b",inputnodeB)

local inputNodeC =internalMatNode:getInputNode(octane.P_SPECULAR)
print ("Glossy input c",inputnodeC)

local inputNodeD =internalMatNode:getInputNodeIx(pinIx)
print ("Glossy input d",inputnodeD)

local inputNodeE =internalMatNode:getOwnedItemIx(pinIx)
print ("Glossy input e",inputnodeE)

local inputNodes =internalMatNode:getInputNodes()

for k, v in pairs(inputNodes) do
print(k, v)
end

-- get the specular pin values
tblSpecularValues = internalMatNode:getPinValue(octane.P_SPECULAR)
print ("Specular Pin Values For: " ..internalMatNode.name)
for k, v in pairs( tblSpecularValues) do
print(k, v)
end
-- if pin has an image, get image file name, check if pin has an inputnode
-- get the opacity pin values
tblOpacityValues = internalMatNode:getPinValue(octane.P_OPACITY)
print ("Opacity Pin Values For: " ..internalMatNode.name)
for k, v in pairs(tblOpacityValues) do
print(k, v)
end
-- if pin has an image, get image file name
-- get the Normal pin values
tblNormalValues = internalMatNode:getPinValue(octane.P_NORMAL)
print ("Normal Pin Values For: " ..internalMatNode.name)
for k, v in pairs(tblNormalValues) do
print(k, v)
end
-- if pin has an image, get image file name
-- get the Bump pin values
tblBumpValues = internalMatNode:getPinValue(octane.P_BUMP)
print ("Bump Pin Values For: " ..internalMatNode.name)
for k, v in pairs(tblBumpValues) do
print(k, v)
end
-- if pin has an image, get image file name
end

thx

mark
Attachments
Texture file nodes.png
Windows 11, 2x Intel I9, 64GB Ram, 2x GTX 1080 TI, 1 x RTX 380 TI, Oculus Quest 2
User avatar
MB
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.

Re: Getting Textures from a material

Postby MB » Sun May 29, 2016 3:41 am

MB Sun May 29, 2016 3:41 am
After several hours I seem to have this working, so no help required at the moment.
Windows 11, 2x Intel I9, 64GB Ram, 2x GTX 1080 TI, 1 x RTX 380 TI, Oculus Quest 2
User avatar
MB
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.

Re: Getting Textures from a material

Postby roeland » Mon May 30, 2016 2:11 am

roeland Mon May 30, 2016 2:11 am
For reference this is how you can find out the filename of the image texture used by the material:

Assume we have a material node matNode:
Code: Select all
-- get the node connected to the diffuse pin (skipping linker nodes)
local texNode = matNode:getInputNode("diffuse")
-- assuming T is an image texture node:
local filename = texNode:getAttribute("filename")


By default the diffuse input will have an RGB colour. In that case getPinValue can get the colour directly:
Code: Select all
-- now, assuming we have an RGB colour node:
local rgbColour = matNode:getPinValue("diffuse")


--
Roeland
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1810
Joined: Wed Mar 09, 2011 10:09 pm

Re: Getting Textures from a material

Postby MB » Wed Jun 01, 2016 10:15 pm

MB Wed Jun 01, 2016 10:15 pm
Roeland,

I wondered when you have a moment if you could explain in more detail the difference between getConnectedNode and getInputNode.

thx

mark
Windows 11, 2x Intel I9, 64GB Ram, 2x GTX 1080 TI, 1 x RTX 380 TI, Oculus Quest 2
User avatar
MB
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.

Re: Getting Textures from a material

Postby roeland » Thu Jun 02, 2016 10:06 pm

roeland Thu Jun 02, 2016 10:06 pm
  • getConnectedNode gives you the node directly connected to an input pin. This may be an input or output node of a graph.
  • getInputNode automatically skips linker nodes

So suppose for instance if you use a liveDB material (which will imported as a node graph) and connect it to a mesh. If you call getConnectedNode it will return the output linker node of that nodegraph. getInputNode returns the actual material node inside the node graph.

--
Roeland
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1810
Joined: Wed Mar 09, 2011 10:09 pm

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 2 guests

Thu Apr 18, 2024 6:31 pm [ UTC ]