Change node from "diffuse" to "glossy"

Forum for OctaneRender Lua scripting examples, discussion and support.
Post Reply
Namijr
Licensed Customer
Posts: 5
Joined: Fri May 31, 2013 7:57 am

Hi!

I know there was already a post with a similar question, but it really beats me :?
Here is the original thread: http://render.otoy.com/forum/viewtopic.php?f=73&t=37602

My problem:
I try to change a node from "Diffuse" to "Glossy", because the exporter of the DAZ Studio exports all materials as diffuse ones.

Here is my little piece of code, which does not work (in the output I can see that the type changed to "glossy"):

-- Get the selected mesh.
local mesh = octane.project.getSelection()[1]
assert(mesh:getProperties().type == octane.NT_GEO_MESH, "mesh expected")

local matNode = mesh:getConnectedNode('Torso')
if matNode then
print(string.format("material %s", matNode:getProperties().name))
matProps = matNode:getProperties()

-- change to glossy
matProps['type'] = octane.NT_MAT_GLOSSY
matNode:updateProperties(matProps)
octane.nodegraph.evaluate(matNode)
octane.changemanager.update()

print "---------- Properties ----------"
for key,value in pairs(matProps) do print(key,value) end
end



Any help or code snippet would be very appreciated :D


Thx,
Christian
User avatar
grimm
Licensed Customer
Posts: 1332
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Hi Christian,

The first problem I see with your script is this line here: :)

Code: Select all

local matNode = mesh:getConnectedNode('Torso')
getConnectedNode does not work like this, but you can try this line instead:

Code: Select all

local matNode = octane.nodegraph.findItemsByName(octane.project.getSceneGraph(), 'Torso', true)[1]
With this line you wouldn't need to get the selected mesh but it would also only find the first instance of any nodes named "Torso". Hope this helps.

Jason
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
Namijr
Licensed Customer
Posts: 5
Joined: Fri May 31, 2013 7:57 am

Hi Jason,

thank you for your code change, but it doesn't work as it should, I have changed it a little bit, so I have not to select the mesh anymore.
The problem seems to be that the only item in the SceneGraph is the mesh node?

My real problem is the following: I want to change the material node from "diffuse" to "glossy" directly in the original node.
Do you think this this possible, or do I have to create a new material node and connect this one to the "Torso" node?

Sorry for my english, I live in Austria and my native language is german ;)


Codechanges:
------------

Code: Select all

local sceneGraph = octane.project.getSceneGraph()
local meshNode = sceneGraph:findFirstNode(octane.NT_GEO_MESH)
local matNode = meshNode:getConnectedNode('Torso')

Bye,
Christian

PS: Oh boy, I hate it to be an absolute beginner :oops:
User avatar
grimm
Licensed Customer
Posts: 1332
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Hi Christian,

No problem. ;) I think there is an issue here as I'm not getting any results when I tested your code either. I was thinking it was because the node isn't being found but it appears that it's just not working. I'm still confused by the difference between these "internal" nodes and the "external" graph nodes. I have not been able to use any "internal" node and have only been able to get the "external" nodes to work. Maybe Thomas or another developer can comment and explain the difference to us. I tested this with Octane 1.51 and it didn't help. :?

Jason
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
Namijr
Licensed Customer
Posts: 5
Joined: Fri May 31, 2013 7:57 am

Oh man,

I am getting too old for this :lol:

Thank you for your help, I'll try to solve my problem with the external nodes.
Let's see how far I get ^^

Bye,
Christian
User avatar
grimm
Licensed Customer
Posts: 1332
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

I have reviewed the posts that Thomas wrote on nodes, etc. The difference appears to be that a node can be either owned by a graph ("external") or by a pin ("internal"). I think your code is working, where the problem is, is another thing. Instead of getting the properties of the node, just do a setAttribute on it. In this case something like this:

Code: Select all

matNode:setAttributes('type', octane.NT_MAT_GLOSSY, true)
Then do a change manager update and see if that works.

Jason
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
User avatar
roeland
OctaneRender Team
Posts: 1823
Joined: Wed Mar 09, 2011 10:09 pm

You can't change the type of a node after it's created. You can create a new node with the correct type, but then you get a node initialised with the default settings. The functions to replace nodes are not exposed in the LUA API yet.

--
Roeland
User avatar
grimm
Licensed Customer
Posts: 1332
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Ah, that explains it, thanks Roeland. :)
Linux Mint 21.3 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 535.171
Namijr
Licensed Customer
Posts: 5
Joined: Fri May 31, 2013 7:57 am

Hi Roeland and Jason!

Thank you very much for the explanation and the help.

This forum ist really cool, and the members are so helpful :D

--
Christian
Zay
Licensed Customer
Posts: 1123
Joined: Sun Jan 17, 2010 2:53 am

Is it possible now to replace nodes ? Got a 100's of materials where I like to change Diffuse to Glossy.
Win 11 Pro | i5 12600K | 32GB ram | 2x GTX 1080Ti + 3080Ti - studio driver 560.94| Modo/Blender/ZBrush/Daz/Poser
Post Reply

Return to “Lua Scripting”