Change node from "diffuse" to "glossy"

Forums: Change node from "diffuse" to "glossy"
Forum for OctaneRender Lua scripting examples, discussion and support.

Change node from "diffuse" to "glossy"

Postby Namijr » Tue Apr 01, 2014 6:24 pm

Namijr Tue Apr 01, 2014 6:24 pm
Hi!

I know there was already a post with a similar question, but it really beats me :?
Here is the original thread: 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
Namijr
Licensed Customer
Licensed Customer
 
Posts: 5
Joined: Fri May 31, 2013 7:57 am

Re: Change node from "diffuse" to "glossy"

Postby grimm » Tue Apr 01, 2014 10:05 pm

grimm Tue Apr 01, 2014 10:05 pm
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 20 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 460.56
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1321
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Change node from "diffuse" to "glossy"

Postby Namijr » Wed Apr 02, 2014 6:57 am

Namijr Wed Apr 02, 2014 6: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:
Namijr
Licensed Customer
Licensed Customer
 
Posts: 5
Joined: Fri May 31, 2013 7:57 am

Re: Change node from "diffuse" to "glossy"

Postby grimm » Wed Apr 02, 2014 4:51 pm

grimm Wed Apr 02, 2014 4:51 pm
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 20 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 460.56
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1321
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Change node from "diffuse" to "glossy"

Postby Namijr » Wed Apr 02, 2014 8:06 pm

Namijr Wed Apr 02, 2014 8:06 pm
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
Namijr
Licensed Customer
Licensed Customer
 
Posts: 5
Joined: Fri May 31, 2013 7:57 am

Re: Change node from "diffuse" to "glossy"

Postby grimm » Wed Apr 02, 2014 8:51 pm

grimm Wed Apr 02, 2014 8:51 pm
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 20 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 460.56
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1321
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Change node from "diffuse" to "glossy"

Postby roeland » Wed Apr 02, 2014 9:16 pm

roeland Wed Apr 02, 2014 9:16 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
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1808
Joined: Wed Mar 09, 2011 10:09 pm

Re: Change node from "diffuse" to "glossy"

Postby grimm » Wed Apr 02, 2014 10:03 pm

grimm Wed Apr 02, 2014 10:03 pm
Ah, that explains it, thanks Roeland. :)
Linux Mint 20 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 460.56
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1321
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Change node from "diffuse" to "glossy"

Postby Namijr » Wed Apr 02, 2014 10:12 pm

Namijr Wed Apr 02, 2014 10:12 pm
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
Namijr
Licensed Customer
Licensed Customer
 
Posts: 5
Joined: Fri May 31, 2013 7:57 am

Re: Change node from "diffuse" to "glossy"

Postby Zay » Thu Mar 02, 2017 2:40 pm

Zay Thu Mar 02, 2017 2:40 pm
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 546.01| Modo/Blender/ZBrush/Daz/Poser
Zay
Licensed Customer
Licensed Customer
 
Posts: 1113
Joined: Sun Jan 17, 2010 2:53 am

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 5 guests

Thu Mar 28, 2024 7:08 pm [ UTC ]