Material linker

Forums: Material linker
Forum for OctaneRender Lua scripting examples, discussion and support.

Material linker

Postby lance_uppercut » Mon Sep 10, 2018 10:54 pm

lance_uppercut Mon Sep 10, 2018 10:54 pm
Hi,

I'm sharing a script that I wrote to help deal with the large number of materials and meshes I have in my architectural scenes. I used to spend a lot of time connecting pins to each other for every new mesh in my scene, and it was tedious especially with so many lines covering the scene graph. This script runs through all the material input pins of the selected meshes, and matches them to material output pins that reside inside a separate node graph where I have all my materials. Here's how it's used:

Inside your materials node graph, the output pins should be named to match the material names that come in with your mesh. (I work in Sketchup and bring in OBJ files)
MaterialsLinker_NodeGraph.jpg


Select at least one mesh, and ONE node graph with the materials.
MaterialsLinker_Selection.jpg


Run the script (shortcut is ALT-L) and all names that match will be linked up.
MaterialsLinker_Linked.jpg


One more thing to note, there is a variable at the top of the lua file that goes:

local copy_materials = false
change this to
local copy_materials = true
and the script will COPY the materials rather than linking them. This will NOT copy any material input nodes, like diffuse textures, that are expanded out of the material. To get them to copy over, you have to collapse these other nodes into the material node. Roeland's script Move Nodes into Node Pins can help with this:
https://render.otoy.com/forum/viewtopic.php?f=73&t=54108
Attachments
MaterialsLinker.lua
(3.5 KiB) Downloaded 533 times
lance_uppercut
Licensed Customer
Licensed Customer
 
Posts: 11
Joined: Fri Jan 23, 2015 12:51 am
Location: Toronto, Canada

Re: Material linker

Postby leehenshall » Thu Jul 21, 2022 2:50 pm

leehenshall Thu Jul 21, 2022 2:50 pm
Can this be adapted to work with FBX files too?

It only works with OBJ imports at the moment.
leehenshall
Licensed Customer
Licensed Customer
 
Posts: 183
Joined: Sun Oct 25, 2015 5:44 pm
Location: England

Re: Material linker

Postby elsksa » Thu Jul 21, 2022 5:22 pm

elsksa Thu Jul 21, 2022 5:22 pm
There is also this native way. It's a gif that has to be open in order to auto-play.
efficient_material_assignation_octane_standalone_elsksa.gif
By holding the CTRL key and plugin the input.
elsksa
Licensed Customer
Licensed Customer
 
Posts: 784
Joined: Sat Jul 24, 2021 1:06 am

Re: Material linker

Postby leehenshall » Thu Jul 21, 2022 5:31 pm

leehenshall Thu Jul 21, 2022 5:31 pm
I tried this hoping it would work before I went looking for LUA scripts. It seems it only wants to connect one material to all slots, rather than each material to all slots by name.

I actually discovered the ctrl + drag shortcut, amongst many other useful workflows from your website....it truly is an excellent resource.

Am I using it wrong or does it only connect a material to all slots rather than plug existing materials by name?
Last edited by leehenshall on Thu Jul 21, 2022 5:53 pm, edited 1 time in total.
leehenshall
Licensed Customer
Licensed Customer
 
Posts: 183
Joined: Sun Oct 25, 2015 5:44 pm
Location: England

Re: Material linker

Postby leehenshall » Thu Jul 21, 2022 5:36 pm

leehenshall Thu Jul 21, 2022 5:36 pm
Looking again..It was actually the ctrl drag to cut nodes that's on your website...but after learning that...I then discovered I could do the same in reverse to connect :)
leehenshall
Licensed Customer
Licensed Customer
 
Posts: 183
Joined: Sun Oct 25, 2015 5:44 pm
Location: England

Re: Material linker

Postby elsksa » Thu Jul 21, 2022 5:47 pm

elsksa Thu Jul 21, 2022 5:47 pm
leehenshall wrote:I actually discovered the ctrl + drag shortcut, amongst many other useful workflows from your website....it truly is an excellent resource.

Thank you.
leehenshall wrote:Am I using it wrong or does it only connect a material to all slots rather than plug existing materials by name?

There should be a search function to enter words, and filter by the nomenclature.
I can't double check at the moment, this is a screenshot from a older demonstration:
octane_standalone_filter_search_material_assignation.jpg
octane_standalone_filter_search_material_assignation.jpg (7.29 KiB) Viewed 3623 times

I should include that on the Standalone page.
elsksa
Licensed Customer
Licensed Customer
 
Posts: 784
Joined: Sat Jul 24, 2021 1:06 am

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 8 guests

Thu Mar 28, 2024 1:26 pm [ UTC ]