Page 1 of 1

Getting Textures from a material

PostPosted: Fri May 27, 2016 10:49 pm
by MB
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

Re: Getting Textures from a material

PostPosted: Sun May 29, 2016 3:41 am
by MB
After several hours I seem to have this working, so no help required at the moment.

Re: Getting Textures from a material

PostPosted: Mon May 30, 2016 2:11 am
by roeland
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

Re: Getting Textures from a material

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

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

thx

mark

Re: Getting Textures from a material

PostPosted: Thu Jun 02, 2016 10:06 pm
by roeland
  • 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