Nodes and Nodegraphs in Lua.

Forum for OctaneRender Lua scripting examples, discussion and support.
colorcurvature
Licensed Customer
Posts: 17
Joined: Fri Aug 20, 2010 11:17 am

hi, is it possible to change a node type from diffuse to glossy?
i tried using updateProperties() but my changes seem to get ignored
User avatar
stratified
OctaneRender Team
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

No, once a node is created, you can't alter it's type anymore.

We can add replacement to the API. As a work around, you can create a glossy node, delete the diffuse node and reconnect the glossy node with everything the diffuse node was connected to.

cheers,
Thomas
Slide3D
Licensed Customer
Posts: 44
Joined: Mon Nov 26, 2012 2:16 am

Please help to write a script for automatic connecting mix material(macro) with objects material nodes
example of what i need in the picture
Attachments
Снимок.JPG
i7 2600k, 16gb, Quadro FX1800(not use in Octane) + GTX580 1536Mb
User avatar
stratified
OctaneRender Team
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Hi there,

I don't know the exact connection logic you're after but I can give you an example of how you connect a material to a mesh. The next snippet connects a material to all the pins of the mesh. You would need to write your own code to figure out exactly which connections to make:

Code: Select all

-- connect the material to all the pins of the mesh
for pinIx=1,mesh:getPinCount() do
    mesh:connectToIx(pinIx, material)
end
Here's a full test script, just select a material and a mesh and run the script. Afterwards, all the connections should be made:

Code: Select all

--
-- Select a material and a mesh
--

local mesh, material = nil, nil

-- figure out the selection of the material and the mesh
local selection = octane.project.getSelection()
if #selection ~= 2 then error("a material and a mesh needs to be selected") end
if selection[1]:getProperties().type == octane.NT_GEO_MESH and
   selection[2]:getProperties().type == octane.NT_MAT_DIFFUSE then
    mesh, material = selection[1], selection[2]
elseif selection[1]:getProperties().type == octane.NT_MAT_DIFFUSE and
       selection[2]:getProperties().type == octane.NT_GEO_MESH then
    mesh, material = selection[2], selection[1]
else
    error("a material and a mesh need to be selected")
end

-- connect the material to all the pins of the mesh
for pinIx=1,mesh:getPinCount() do
    mesh:connectToIx(pinIx, material)
end
before running the script
before running the script
before.png (10.44 KiB) Viewed 5801 times
after running the script, all connections are made
after running the script, all connections are made
I hope this steers you in the right direction.

cheers,
Thomas
User avatar
roeland
OctaneRender Team
Posts: 1822
Joined: Wed Mar 09, 2011 10:09 pm

There is a script doing something similar with imported alembic scenes (Alembic and material assignments), maybe it can be adapted for mesh nodes too.

--
Roeland
Slide3D
Licensed Customer
Posts: 44
Joined: Mon Nov 26, 2012 2:16 am

Thanks Stratified
whether it is possible to select multiple materials?
i7 2600k, 16gb, Quadro FX1800(not use in Octane) + GTX580 1536Mb
Slide3D
Licensed Customer
Posts: 44
Joined: Mon Nov 26, 2012 2:16 am

I got several codes for each material
it is possible to unite in one code?

Code: Select all

--
-- Select a limbs material and a mesh
--

local mesh, limbs = nil, nil

-- figure out the selection of the limbs material and the mesh
local selection = octane.project.getSelection()
if #selection ~= 2 then error("a material and a mesh needs to be selected") end
if selection[1]:getProperties().type == octane.NT_GEO_MESH and
   selection[2]:getProperties().type == octane.NT_MAT_MIX then
    mesh, limbs = selection[1], selection[2]
elseif selection[1]:getProperties().type == octane.NT_MAT_MIX and
       selection[2]:getProperties().type == octane.NT_GEO_MESH then
    mesh, limbs = selection[2], selection[1]
else
    error("a material and a mesh need to be selected")
end

-- connect the material to all the pins of the mesh
pinIx=1,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)
pinIx=17,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)
pinIx=18,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)
pinIx=23,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)
pinIx=24,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)

Code: Select all

--
-- Select a toso material and a mesh
--

local mesh, torso = nil, nil

-- figure out the selection of the torso material and the mesh
local selection = octane.project.getSelection()
if #selection ~= 2 then error("a material and a mesh needs to be selected") end
if selection[1]:getProperties().type == octane.NT_GEO_MESH and
   selection[2]:getProperties().type == octane.NT_MAT_MIX then
    mesh, torso = selection[1], selection[2]
elseif selection[1]:getProperties().type == octane.NT_MAT_MIX and
       selection[2]:getProperties().type == octane.NT_GEO_MESH then
    mesh, torso = selection[2], selection[1]
else
    error("a material and a mesh need to be selected")
end

-- connect the material to all the pins of the mesh
pinIx=16,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)
pinIx=19,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)
pinIx=20,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)
pinIx=21,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)
pinIx=22,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)
pinIx=28,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)
and for other mats
Attachments
Снимок.JPG
i7 2600k, 16gb, Quadro FX1800(not use in Octane) + GTX580 1536Mb
User avatar
bepeg4d
Octane Guru
Posts: 10325
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy
Contact:

hi thomas,
i have tried to convert your script for connecting an object layer node to all the pins of an object layer map node, but it works only for some pins and leaves always the others unconnected:
Schermata 2014-01-17 alle 10.59.03.jpg

Code: Select all

--
-- Select an object layer map and an object layer node
--

local Object_Layer_Map, Object_Layer = nil, nil

-- figure out the selection of the material and the mesh
local selection = octane.project.getSelection()
if #selection ~= 2 then error("an object layer map and an object layer node needs to be selected") end
if selection[1]:getProperties().type == octane.NT_OBJECTLAYER_MAP and
   selection[2]:getProperties().type == octane.NT_OBJECTLAYER then
    Object_Layer_Map, Object_Layer = selection[1], selection[2]
elseif selection[1]:getProperties().type == octane.NT_OBJECTLAYER and
       selection[2]:getProperties().type == octane.NT_OBJECTLAYER_MAP then
    Object_Layer_Map, Object_Layer = selection[2], selection[1]
else
    error("an object layer map and an object layer node need to be selected")
end

-- connect the object layer to all the pins of the object layer map
for pinIx=17,Object_Layer_Map:getPinCount() do
    Object_Layer_Map:connectToIx(pinIx, Object_Layer)
end
another question, the best would be to use an "object layer in" node but i'm not able to sobstitute the "Object_Layer" with the input version, where is the mistake?

Code: Select all

--
-- Select an object layer map and an object layer in node
--

local Object_Layer_Map, Object_Layer_In = nil, nil

-- figure out the selection of the material and the mesh
local selection = octane.project.getSelection()
if #selection ~= 2 then error("an object layer map and an object layer in node needs to be selected") end
if selection[1]:getProperties().type == octane.NT_OBJECTLAYER_MAP and
   selection[2]:getProperties().type == octane.IN_OBJECTLAYER then
    Object_Layer_Map, Object_Layer_In = selection[1], selection[2]
elseif selection[1]:getProperties().type == octane.IN_OBJECTLAYER and
       selection[2]:getProperties().type == octane.NT_OBJECTLAYER_MAP then
    Object_Layer_Map, Object_Layer_In = selection[2], selection[1]
else
    error("an object layer map and an object layer in node need to be selected")
end

-- connect the object layer in node to all the pins of the object layer map
for pinIx=17,Object_Layer_Map:getPinCount() do
    Object_Layer_Map:connectToIx(pinIx, Object_Layer_In)
end
ciao beppe
User avatar
stratified
OctaneRender Team
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Slide3D wrote:I got several codes for each material
it is possible to unite in one code?

Code: Select all

--
-- Select a limbs material and a mesh
--

local mesh, limbs = nil, nil

-- figure out the selection of the limbs material and the mesh
local selection = octane.project.getSelection()
if #selection ~= 2 then error("a material and a mesh needs to be selected") end
if selection[1]:getProperties().type == octane.NT_GEO_MESH and
   selection[2]:getProperties().type == octane.NT_MAT_MIX then
    mesh, limbs = selection[1], selection[2]
elseif selection[1]:getProperties().type == octane.NT_MAT_MIX and
       selection[2]:getProperties().type == octane.NT_GEO_MESH then
    mesh, limbs = selection[2], selection[1]
else
    error("a material and a mesh need to be selected")
end

-- connect the material to all the pins of the mesh
pinIx=1,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)
pinIx=17,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)
pinIx=18,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)
pinIx=23,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)
pinIx=24,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)

Code: Select all

--
-- Select a toso material and a mesh
--

local mesh, torso = nil, nil

-- figure out the selection of the torso material and the mesh
local selection = octane.project.getSelection()
if #selection ~= 2 then error("a material and a mesh needs to be selected") end
if selection[1]:getProperties().type == octane.NT_GEO_MESH and
   selection[2]:getProperties().type == octane.NT_MAT_MIX then
    mesh, torso = selection[1], selection[2]
elseif selection[1]:getProperties().type == octane.NT_MAT_MIX and
       selection[2]:getProperties().type == octane.NT_GEO_MESH then
    mesh, torso = selection[2], selection[1]
else
    error("a material and a mesh need to be selected")
end

-- connect the material to all the pins of the mesh
pinIx=16,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)
pinIx=19,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)
pinIx=20,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)
pinIx=21,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)
pinIx=22,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)
pinIx=28,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)
and for other mats
Yes, it's possible but now you would have 3 things in your selection and 6 different cases to consider...

I'm not sure what you're trying to accomplish with your script? You just want to make the connectios or is there a general rule to which connections to make? You could store a table mapping a material to all the pins on the mesh it connects to and loop over this to make the desired connections.

Code: Select all

-- maps a matterial to all the pins
connections = { ["V6Torso"] = { "dzmat_Head", "dzmat_Neck", "dzmat_Hips", "dzmat_Torso" } }

for i,pinName in ipairs(connections["V6Torso"]) do
    print(string.format("connect material %s to pin %s", "V6Torso", pinName))
    -- do the connections here...
end
cheers,
Thomas
User avatar
stratified
OctaneRender Team
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

bepeg4d wrote:hi thomas,
i have tried to convert your script for connecting an object layer node to all the pins of an object layer map node, but it works only for some pins and leaves always the others unconnected:
Schermata 2014-01-17 alle 10.59.03.jpg

Code: Select all

--
-- Select an object layer map and an object layer node
--

local Object_Layer_Map, Object_Layer = nil, nil

-- figure out the selection of the material and the mesh
local selection = octane.project.getSelection()
if #selection ~= 2 then error("an object layer map and an object layer node needs to be selected") end
if selection[1]:getProperties().type == octane.NT_OBJECTLAYER_MAP and
   selection[2]:getProperties().type == octane.NT_OBJECTLAYER then
    Object_Layer_Map, Object_Layer = selection[1], selection[2]
elseif selection[1]:getProperties().type == octane.NT_OBJECTLAYER and
       selection[2]:getProperties().type == octane.NT_OBJECTLAYER_MAP then
    Object_Layer_Map, Object_Layer = selection[2], selection[1]
else
    error("an object layer map and an object layer node need to be selected")
end

-- connect the object layer to all the pins of the object layer map
for pinIx=17,Object_Layer_Map:getPinCount() do
    Object_Layer_Map:connectToIx(pinIx, Object_Layer)
end
another question, the best would be to use an "object layer in" node but i'm not able to sobstitute the "Object_Layer" with the input version, where is the mistake?

Code: Select all

--
-- Select an object layer map and an object layer in node
--

local Object_Layer_Map, Object_Layer_In = nil, nil

-- figure out the selection of the material and the mesh
local selection = octane.project.getSelection()
if #selection ~= 2 then error("an object layer map and an object layer in node needs to be selected") end
if selection[1]:getProperties().type == octane.NT_OBJECTLAYER_MAP and
   selection[2]:getProperties().type == octane.IN_OBJECTLAYER then
    Object_Layer_Map, Object_Layer_In = selection[1], selection[2]
elseif selection[1]:getProperties().type == octane.IN_OBJECTLAYER and
       selection[2]:getProperties().type == octane.NT_OBJECTLAYER_MAP then
    Object_Layer_Map, Object_Layer_In = selection[2], selection[1]
else
    error("an object layer map and an object layer in node need to be selected")
end

-- connect the object layer in node to all the pins of the object layer map
for pinIx=17,Object_Layer_Map:getPinCount() do
    Object_Layer_Map:connectToIx(pinIx, Object_Layer_In)
end
ciao beppe
Hi Beppe,

You only start making connections from pin 17 in your code (If you look at your picture, the first 16 pins aren't connected). You should make connections starting from pin 2 (The first pin takes a mesh so we should skip it):

Code: Select all

-- connect the object layer to all the pins of the object layer map
for pinIx=2,Object_Layer_Map:getPinCount() do
    Object_Layer_Map:connectToIx(pinIx, Object_Layer)
end
The type for an input linker taking as input an object layer is octane.NT_IN_OBJECTLAYER not IN_OBJECT_LAYER.

This code should do the trick:

Code: Select all

--
-- Select an object layer map and an object layer in node
--

local Object_Layer_Map, Object_Layer_In = nil, nil

-- figure out the selection of the material and the mesh
local selection = octane.project.getSelection()
if #selection ~= 2 then error("an object layer map and an object layer in node needs to be selected") end
if selection[1]:getProperties().type == octane.NT_OBJECTLAYER_MAP and
   selection[2]:getProperties().type == octane.NT_IN_OBJECTLAYER then
    Object_Layer_Map, Object_Layer_In = selection[1], selection[2]
elseif selection[1]:getProperties().type == octane.NT_IN_OBJECTLAYER and
       selection[2]:getProperties().type == octane.NT_OBJECTLAYER_MAP then
    Object_Layer_Map, Object_Layer_In = selection[2], selection[1]
else
    error("an object layer map and an object layer in node need to be selected")
end

-- connect the object layer in node to all the pins of the object layer map
for pinIx=2,Object_Layer_Map:getPinCount() do
    Object_Layer_Map:connectToIx(pinIx, Object_Layer_In)
end
cheers,
Thomas
Post Reply

Return to “Lua Scripting”