Cant figure out how to copy material

Forums: Cant figure out how to copy material
Forum for OctaneRender Lua scripting examples, discussion and support.

Cant figure out how to copy material

Postby Wallan » Tue May 12, 2015 9:37 pm

Wallan Tue May 12, 2015 9:37 pm
Hi.

Need a little help to get me going.
I want to write some code that from an imported mesh creates material nodes for some known materials in the mesh.
In this case it's models exported from DAZ that I would like to handle.
If someone could supply some code snippets that help me get starteds I would be very greateful.

I want to create one material node for every type of material. I know as an example that legs, feets, hands, arms etc use the same material so for them i would want to create a material Limbs that has the same properties as Legs and then connect the material pin of legs, feets, hands, arms etc to that material instead.

Splitting it up it would be something like this.

1 Create a "mastermateriallist" list with the name of the master materials and the name I want for the created material node. [legs = Limbsmaterial,head = Headmaterial]

2 Create a "linklist" list with info on witch materials should use witch material node. [legs=Limbsmaterials,feets=Limbsmaterials,hands=Limbsmaterial] and so on.

3 Find the known mastermateriallist materials in the mesh by name and create a new material with the name given by the mastermateriallist that is a copy of of the found material in the mesh.

4 Use the linklist and connect all the the material pins in the mesh as given by the linklist to the material also given by the linklist.


Regards
Wallan
Last edited by Wallan on Wed May 13, 2015 8:57 pm, edited 1 time in total.
Windows 7 Ultimate 64bit 32Gb RAM. Intel Core i7-5820K [email protected] GHZ. Display uses a Gigabyte GTX 460 1Gb VRAM. Octane uses an EVGA GTX 970 4Gb VRAM.
Wallan
Licensed Customer
Licensed Customer
 
Posts: 47
Joined: Fri Jan 23, 2015 6:13 pm

Re: In need for a little help to get me going

Postby Wallan » Wed May 13, 2015 6:33 pm

Wallan Wed May 13, 2015 6:33 pm
So far I figured out how to build lists and iterate the mesh pins.
Also figured out how to create default materials.

Still need to figure out how to copy materials in the most easy way....

LUA makes me somewhat crazy some things are straightforward but some stuff expected to be easy is not.
Mainly because i don't understand the syntax in the examples I find ;)
Windows 7 Ultimate 64bit 32Gb RAM. Intel Core i7-5820K [email protected] GHZ. Display uses a Gigabyte GTX 460 1Gb VRAM. Octane uses an EVGA GTX 970 4Gb VRAM.
Wallan
Licensed Customer
Licensed Customer
 
Posts: 47
Joined: Fri Jan 23, 2015 6:13 pm

Re: In need for a little help to get me going

Postby grimm » Wed May 13, 2015 6:49 pm

grimm Wed May 13, 2015 6:49 pm
If you post the code that you are having problems with, we can definitely help you understand it. :)
Linux Mint 20 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 460.56
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1321
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: In need for a little help to get me going

Postby Wallan » Wed May 13, 2015 7:33 pm

Wallan Wed May 13, 2015 7:33 pm
At the moment I don't have a one of those problems.
Have worked around them so far.

What I have problem figuring out is how to copy materials from the mesh node either as a new material node or to an existing node.
Whatever is the most simple.

Code below is where i want to either copy the material from the mesh pin with name "Legs" to the already created material "matLimbs" or if more easy to a new material.

if pinInfo.name == "Legs" then
print("Copy Legs to matLimbs");

Code: Select all
function tprint (tbl, indent)
  if not indent then indent = 0 end
  for k, v in pairs(tbl) do
    formatting = string.rep("  ", indent) .. k .. ": "
    if type(v) == "table" then
      print(formatting)
      tprint(v, indent+1)
    elseif type(v) == 'boolean' then
      print(formatting .. tostring(v))     
    else
      print(formatting .. tostring(v))
    end
  end
end



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


local mesh = nil


-- figure out the selection of the mesh
local selection = octane.project.getSelection()
if #selection ~= 1 then error("One mesh and one mesh only must be selected!") end
if selection[1]:getProperties().type == octane.NT_GEO_MESH then
    mesh = selection[1]
    print("Found mesh " .. mesh.name .. " with " .. mesh:getPinCount() .. " pins.");
else
    error("One mesh and one mesh only must be selected!")
end




--create materials

matToPin = {Legs="Limbs",EyeReflection="Eyes",Nostrils="Face",Lacrimals="Eyes",Pupils="Eyes",Lips="Face",Tear="Eyes",Gums="Mouth"}
masterMaterials = {Legs="Limbs",Irises="Eyes",Face="Face",Torso="Torso",Gums="Mouth"}

matEyes = octane.node.create{type = octane.NT_MAT_DIFFUSE,name = mesh.name.."_Eyes"};
matTorso = octane.node.create{type = octane.NT_MAT_DIFFUSE,name = mesh.name.."_Torso"};
matLimbs = octane.node.create{type = octane.NT_MAT_DIFFUSE,name = mesh.name.."_Limbs"};
matFace = octane.node.create{type = octane.NT_MAT_DIFFUSE,name = mesh.name.."_Face"};
matMouth = octane.node.create{type = octane.NT_MAT_DIFFUSE,name = mesh.name.."_Mouth"};



print("------  Looking for known materials to copy  -------")


for pinIx=1,mesh:getPinCount() do

    pinInfo = mesh:getPinInfoIx(pinIx);
    masterMaterialname = masterMaterials[pinInfo.name];

    if masterMaterialname ~= nil then
        print("Pin Name " .. pinInfo.name .. " should be copied to material " .. masterMaterialname)

        if pinInfo.name == "Legs" then
            print("Copy Legs to matLimbs");
           
        elseif pinInfo.name == "Irises" then
            print("Copy Irises to matEyes");

        elseif pinInfo.name == "Face" then
            print("Copy Face to matFace");

        elseif pinInfo.name == "Torso" then
            print("Copy Torso to matTorso");

        elseif pinInfo.name == "Gums" then
            print("Copy Gums to matMouth");

        end

    else
        --print("Pin Name " .. pinInfo.name .. " ignored")
    end
end


print("------  Looking for known materials to connect  ------")


for pinIx=1,mesh:getPinCount() do

    pinInfo = mesh:getPinInfoIx(pinIx);
    diffMatNodeName = matToPin[pinInfo.name];

    if diffMatNodeName ~= nil then
        print("Pin Name " .. pinInfo.name .. " should connect to " .. diffMatNodeName)
    else
        --print("Pin Name " .. pinInfo.name .. " has no material to connect to")
    end
end
Windows 7 Ultimate 64bit 32Gb RAM. Intel Core i7-5820K [email protected] GHZ. Display uses a Gigabyte GTX 460 1Gb VRAM. Octane uses an EVGA GTX 970 4Gb VRAM.
Wallan
Licensed Customer
Licensed Customer
 
Posts: 47
Joined: Fri Jan 23, 2015 6:13 pm

Re: Cant figure out how to copy material

Postby Wallan » Thu May 14, 2015 9:37 am

Wallan Thu May 14, 2015 9:37 am
Seems as I'm mostly talking to myself here ... ;)

Anyway, finally managed to transfer color from one node to another.

So, main issues are under control.
Windows 7 Ultimate 64bit 32Gb RAM. Intel Core i7-5820K [email protected] GHZ. Display uses a Gigabyte GTX 460 1Gb VRAM. Octane uses an EVGA GTX 970 4Gb VRAM.
Wallan
Licensed Customer
Licensed Customer
 
Posts: 47
Joined: Fri Jan 23, 2015 6:13 pm

Re: Cant figure out how to copy material

Postby grimm » Fri May 15, 2015 7:32 am

grimm Fri May 15, 2015 7:32 am
Sorry about that, I got busy. I see that you have help though, from the master himself (Thomas). :)
Linux Mint 20 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 460.56
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1321
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 6 guests

Fri Mar 29, 2024 6:44 am [ UTC ]