Page 2 of 2

Re: Copy material from mesh pin to new material node?

PostPosted: Fri May 15, 2015 5:24 pm
by Wallan
Here is a picture of what the code does so far.
Hopefully that answers any remaining questions in what I tried to accomplish.

The specular nodes are just diffuse nodes with faked names so far.
The last step, to really make them specular nodes still remains.
Thank's to your sample code I feel confident about making it work :)

Regards
Wallan

Image

Re: Copy material from mesh pin to new material node?

PostPosted: Fri May 15, 2015 10:27 pm
by Wallan
Code: Select all
-- Copies the content of the diffuse pin of the diffuse material into the transmission pin
-- of the specular material.

-- create materials
local diffuseMatNode = octane.node.create{ type = octane.NT_MAT_DIFFUSE, name = "source node" }
local texNode        = octane.node.create{ type = octane.NT_TEX_CHECKS, "checkers" }
diffuseMatNode:connectTo(octane.P_DIFFUSE, texNode)
local specularMatNode = octane.node.create{ type = octane.NT_MAT_SPECULAR, name = "dest. node" }

-- wrap up the full tree connect to the diffuse pin in a seperate nodegraph and make sure that
-- this graph has a texture output node
local tmpGraph = octane.nodegraph.create{ type = octane.GT_STANDARD, name = "Mess wrapper" }
local matOutputNode = octane.node.create{ type = octane.NT_OUT_TEXTURE, graphOwner = tmpGraph, name = "texture output" }
local copy = tmpGraph:copyItemTree(texNode)
matOutputNode:connectTo(octane.P_INPUT, copy)

-- copy the full graph into the transmission pin of the specular material
specularMatNode:copyFrom(octane.P_TRANSMISSION, tmpGraph)

-- tidy up
octane.project.getSceneGraph():unfold()


In your example you copy the texNode.
But, in your case that is a reference to the node created before.

In my case I don't create that node from code so I don't have direct access to it.
I guess I have to get it from the diffuse pin in the material somehow or?

Re: Copy material from mesh pin to new material node?

PostPosted: Sat May 16, 2015 4:50 am
by stratified
Wallan wrote:
Code: Select all
-- Copies the content of the diffuse pin of the diffuse material into the transmission pin
-- of the specular material.

-- create materials
local diffuseMatNode = octane.node.create{ type = octane.NT_MAT_DIFFUSE, name = "source node" }
local texNode        = octane.node.create{ type = octane.NT_TEX_CHECKS, "checkers" }
diffuseMatNode:connectTo(octane.P_DIFFUSE, texNode)
local specularMatNode = octane.node.create{ type = octane.NT_MAT_SPECULAR, name = "dest. node" }

-- wrap up the full tree connect to the diffuse pin in a seperate nodegraph and make sure that
-- this graph has a texture output node
local tmpGraph = octane.nodegraph.create{ type = octane.GT_STANDARD, name = "Mess wrapper" }
local matOutputNode = octane.node.create{ type = octane.NT_OUT_TEXTURE, graphOwner = tmpGraph, name = "texture output" }
local copy = tmpGraph:copyItemTree(texNode)
matOutputNode:connectTo(octane.P_INPUT, copy)

-- copy the full graph into the transmission pin of the specular material
specularMatNode:copyFrom(octane.P_TRANSMISSION, tmpGraph)

-- tidy up
octane.project.getSceneGraph():unfold()


In your example you copy the texNode.
But, in your case that is a reference to the node created before.

In my case I don't create that node from code so I don't have direct access to it.
I guess I have to get it from the diffuse pin in the material somehow or?


You can access the input node via diffuseMaterialNode:getInputNode(octane.P_DIFFUSE).

cheers,
Thomas

Re: Copy material from mesh pin to new material node?

PostPosted: Sat May 16, 2015 12:42 pm
by Wallan
:)

Progressing fine so far.
Was thinking about changing all diffuse to specular as it gives som more control to shininess.

Does Octane not import specular maps?

Another small problem, how do I check if something exists before i destroy it.