Page 1 of 1

Material linker

PostPosted: Mon Sep 10, 2018 10:54 pm
by lance_uppercut
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

Re: Material linker

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

It only works with OBJ imports at the moment.

Re: Material linker

PostPosted: Thu Jul 21, 2022 5:22 pm
by elsksa
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.

Re: Material linker

PostPosted: Thu Jul 21, 2022 5:31 pm
by leehenshall
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?

Re: Material linker

PostPosted: Thu Jul 21, 2022 5:36 pm
by leehenshall
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 :)

Re: Material linker

PostPosted: Thu Jul 21, 2022 5:47 pm
by elsksa
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 3622 times

I should include that on the Standalone page.