hi, is it possible to change a node type from diffuse to glossy?
i tried using updateProperties() but my changes seem to get ignored
Nodes and Nodegraphs in Lua.
- stratified
- 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
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
- stratified
- 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:
Here's a full test script, just select a material and a mesh and run the script. Afterwards, all the connections should be made:
I hope this steers you in the right direction.
cheers,
Thomas
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
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
cheers,
Thomas
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
--
Roeland
I got several codes for each material
it is possible to unite in one code?
and for other mats
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)
i7 2600k, 16gb, Quadro FX1800(not use in Octane) + GTX580 1536Mb
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:
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?
ciao beppe
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:
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
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
- stratified
- Posts: 945
- Joined: Wed Aug 15, 2012 6:32 am
- Location: Auckland, New Zealand
Yes, it's possible but now you would have 3 things in your selection and 6 different cases to consider...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)
and for other matsCode: 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)
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
Thomas
- stratified
- Posts: 945
- Joined: Wed Aug 15, 2012 6:32 am
- Location: Auckland, New Zealand
Hi Beppe,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: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 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
ciao beppeCode: 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
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
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
Thomas