Page 5 of 6

Re: Nodes and Nodegraphs in Lua.

Posted: Sat Jan 18, 2014 8:10 am
by bepeg4d
thanks thomas :)
now i can see my mistakes, i'm learning very slowly, sorry.
ciao beppe

Re: Nodes and Nodegraphs in Lua.

Posted: Mon Jan 20, 2014 7:17 am
by Slide3D
stratified wrote:
Yes, it's possible but now you would have 3 things in your selection and 6 different cases to consider...
how can I identify the material if same type in the two materials?
possible to identify them by name?
is it possible to connect the material is not on the index pin but its name?
stratified wrote: 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
I want to automate the connection of materials that I did for Daz Victoria
principle of such:
I load the mesh and my materials for him
script must connect each material to the corresponding input of the mesh material
all materials and inputs have their constant names


why this script works differently (connects not those mesh pins and mats as specified or gives an error)
if I select in sequence that it is given?

Code: Select all

--
-- Select a mesh and mats in strict sequence
--

local mesh, limbs, face, lips, torso  = nil, nil, nil, nil, nil

local selection = octane.project.getSelection()
if #selection ~= 5 then error("a material and a mesh needs to be selected") end
mesh, limbs, face, lips, torso  = selection[1], selection[2], selection[3], selection[4], selection[5]  


-- connect the material to a pins of the mesh
pinIx=1,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)
pinIx=3,mesh:getPinCount()
mesh:connectToIx(pinIx, face)
pinIx=6,mesh:getPinCount()
mesh:connectToIx(pinIx, lips)
pinIx=12,mesh:getPinCount()
mesh:connectToIx(pinIx, face)
pinIx=16,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)
pinIx=17,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)
pinIx=18,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)
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=23,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)
pinIx=24,mesh:getPinCount()
mesh:connectToIx(pinIx, limbs)
pinIx=28,mesh:getPinCount()
mesh:connectToIx(pinIx, torso)

Re: Nodes and Nodegraphs in Lua.

Posted: Mon Jan 20, 2014 7:40 pm
by stratified
Hi there,

You can distinguish materials of the same type by name, if they have a different name (e.g. myMaterialNode:getProperties().name). If both name and type are identical, there's no easy way to distinguish them.

Yes, you can connect a material to a pin identifying the pin by it's name. For example myMeshNode:connectTo("dzmat_Neck", v6TorsoNode). You should only use the index of a pin when iterating over all the pins. Otherwise you should use the name or the id of the pin. It makes the code more readable.

If you now that the materials and mesh input pins get some pre-defined names in Daz, you could do something smart with them. Maybe this example helps: http://render.otoy.com/forum/viewtopic.php?f=73&t=37817. Here, Roeland tries to connect an Alembic archive exported from Cinema4d with materials. Altough it's not a mesh, the principle is the same. He tries to make connections based on the names of the pins (which are following some Cinema4d convention).

Not sure why your script doesn't work. But pinIx=1,mesh:getPinCount() doesn't do anything for you mesh:getPinCount() is superfluous. Are you sure that mesh is really a mesh? The selection depends on how you dragged the lasso in the nodegraph editor.

cheers,
Thomas

Re: Nodes and Nodegraphs in Lua.

Posted: Tue Jan 21, 2014 3:02 am
by Slide3D
Stratified
Yes!!! I did it!
Thank you very much!

Code: Select all

local v6mesh, mtorso, mface = nil, nil, nil

local selection = octane.project.getSelection()

if selection[1]:getProperties().type == octane.NT_GEO_MESH then
v6mesh = selection[1]
elseif selection[1]:getProperties().name == "torso" then
mtorso = selection[1]
elseif selection[1]:getProperties().name == "face" then
mface = selection[1]
end

if selection[2]:getProperties().type == octane.NT_GEO_MESH then
v6mesh = selection[2]
elseif selection[2]:getProperties().name == "torso" then
mtorso = selection[2]
elseif selection[2]:getProperties().name == "face" then
mface = selection[2]
end

if selection[3]:getProperties().type == octane.NT_GEO_MESH then
v6mesh = selection[3]
elseif selection[3]:getProperties().name == "torso" then
mtorso = selection[3]
elseif selection[3]:getProperties().name == "face" then
mface = selection[3]
end

v6mesh:connectTo("Head", mtorso)
v6mesh:connectTo("Ears", mtorso)
v6mesh:connectTo("Neck", mtorso)
v6mesh:connectTo("Torso", mtorso)
v6mesh:connectTo("Nipples", mtorso)
v6mesh:connectTo("Hips", mtorso)
v6mesh:connectTo("Face", mface)
v6mesh:connectTo("Nostrils", mface)

Re: Nodes and Nodegraphs in Lua.

Posted: Tue Jan 21, 2014 3:07 am
by stratified
Slide3D wrote:Stratified
Yes!!! I did it!

Code: Select all

local v6mesh, mtorso, mface = nil, nil, nil

local selection = octane.project.getSelection()

if selection[1]:getProperties().type == octane.NT_GEO_MESH then
v6mesh = selection[1]
elseif selection[1]:getProperties().name == "torso" then
mtorso = selection[1]
elseif selection[1]:getProperties().name == "face" then
mface = selection[1]
end

if selection[2]:getProperties().type == octane.NT_GEO_MESH then
v6mesh = selection[2]
elseif selection[2]:getProperties().name == "torso" then
mtorso = selection[2]
elseif selection[2]:getProperties().name == "face" then
mface = selection[2]
end

if selection[3]:getProperties().type == octane.NT_GEO_MESH then
v6mesh = selection[3]
elseif selection[3]:getProperties().name == "torso" then
mtorso = selection[3]
elseif selection[3]:getProperties().name == "face" then
mface = selection[3]
end

v6mesh:connectTo("Head", mtorso)
v6mesh:connectTo("Ears", mtorso)
v6mesh:connectTo("Neck", mtorso)
v6mesh:connectTo("Torso", mtorso)
v6mesh:connectTo("Nipples", mtorso)
v6mesh:connectTo("Hips", mtorso)
v6mesh:connectTo("Face", mface)
v6mesh:connectTo("Nostrils", mface)
Hi there,

Congrats, keep up the good work! Is this pass of a larger project or was it just a test with lua?

cheers,
Thomas

Re: Nodes and Nodegraphs in Lua.

Posted: Tue Jan 21, 2014 3:13 am
by Slide3D
stratified wrote: Congrats, keep up the good work! Is this pass of a larger project or was it just a test with lua?

cheers,
Thomas
Thanks!
this makes it possible to easily apply materials prepared in octane
for scenes with frequently used models
for me it is a great benefit!
it was not a test
it was to create a tool for practical use

Re: Nodes and Nodegraphs in Lua.

Posted: Tue Jan 21, 2014 3:20 am
by Slide3D
my work which had painstakingly hand joining materials
it was very boring :)
http://slide3d.deviantart.com/gallery/40795322

Re: Nodes and Nodegraphs in Lua.

Posted: Tue Jan 21, 2014 3:49 am
by Tugpsx
Slide3D wrote:my work which had painstakingly hand joining materials
it was very boring :)
http://slide3d.deviantart.com/gallery/40795322
Will your script be available or only for your personal use

Re: Nodes and Nodegraphs in Lua.

Posted: Tue Jan 21, 2014 4:06 am
by Slide3D
Tugpsx wrote: Will your script be available or only for your personal use
principle is shown in the script that I posted
it can be used for your materials
specifying the required values
if you make a preset materials that it is possible to write the correct script
may eventually get something similar to what is in the Poser \ Daz Studio
the user selects the model and applies the material

Re: Nodes and Nodegraphs in Lua.

Posted: Tue Jan 21, 2014 5:04 am
by Slide3D
Stratified
how to use octane.project.select (item) ?
can use this to select a node that is needed?
I would remove the need to select nodes manually