Page 1 of 1

Change node from "diffuse" to "glossy"

PostPosted: Tue Apr 01, 2014 6:24 pm
by Namijr
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

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

PostPosted: Tue Apr 01, 2014 10:05 pm
by grimm
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

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

PostPosted: Wed Apr 02, 2014 6:57 am
by Namijr
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:

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

PostPosted: Wed Apr 02, 2014 4:51 pm
by grimm
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

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

PostPosted: Wed Apr 02, 2014 8:06 pm
by Namijr
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

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

PostPosted: Wed Apr 02, 2014 8:51 pm
by grimm
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

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

PostPosted: Wed Apr 02, 2014 9:16 pm
by roeland
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

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

PostPosted: Wed Apr 02, 2014 10:03 pm
by grimm
Ah, that explains it, thanks Roeland. :)

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

PostPosted: Wed Apr 02, 2014 10:12 pm
by Namijr
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

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

PostPosted: Thu Mar 02, 2017 2:40 pm
by Zay
Is it possible now to replace nodes ? Got a 100's of materials where I like to change Diffuse to Glossy.