This article will document a custom script created to assign textures automatically to Shaders and Labels
Using the script, it is possible to have textures automatically assigned to the shader and also use it to assign textures to labels. The material below is created using the script.
Using the Script
Before running the script, you need to drag a set of textures into the Material Graph of a Material.
The script will create additional nodes if required, for example
- A Color Composite Node for combining Ambient Occlusion with the Diffuse Color.
- Connecting the Displacement texture with the Geometry input.
- An Invert Node for converting a Glossiness texture to Roughness
- Another Color Composite Node for combining a Label displacement with a displacement that is already present.
Running the script, you will receive a prompt to
- Select the Material name from a drop-down menu,
- Enter the UV Scale,
- Check if you want a Mapping node added to all textures,
- If you want to delete the unused Nodes. Having this checked will delete any texture that could not be connected to any input.
After the script finishes, you can align the nodes by pressing the Align Nodes button on top of the Material Graph.
Some Shaders may not have all the inputs for your textures, e.g. the Diffuse node will have no input for the metalness and roughness, etc.
If you want to add textures for a Label, please make sure to remove the unconnected nodes or to check "Delete unused Nodes".
For a label you can add an additional shader. Please drag in your second set of textures that you want to use for the Label.
If the script detects more than one shaders, after the first prompt, you will receive a second prompt asking you to
- Select which Shader you want to use from a dropdown menu,
- Check if you only want to use only Textures that are not yet connected to a Material (checking this will ignore textures that are already connected to another shader)
- Check if you want to add that Shader as a Label
- Check if you want the texture to repeat horizontally and/or vertically.
Below is a demonstration of using the script.
Comprehensiveness
This script is a work in progress. It uses a library in order to classify what type of texture it is using the suffix in the texture name.
It also tries to consider workflows so that for example a texture set in the metalness workflow won't have every texture detected as a metallic texture.
While trying to make the dictionary as comprehensive as possible, there might be suffix variations that were not considered.
I would be grateful if you would inform me of any missing suffix at nikita.krutov@keyshot.com
Installing the Script
First, please download and install the script below.
Please note that Custom Scripts are not supported by KeyShot.
Additionally, any changes performed by scripts cannot be reversed with the undo function.
Please make sure to save your Scene before running a script so that you can restore your previous Scene in case of unwanted or unexpected changes.
In order to add the script to KeyShot, you can unzip the script and import the .py file through the scripting console or by copying it into the Scripts folder in your Resource Folder
The Resource Folder by default is installed in the following locations:
Windows:
-
Installed Just For Me:
%UserProfile%\Documents/KeyShot or
C:\Users\<username>\Documents\KeyShot -
Installed For Everybody:
C:\Users\Public\Documents\KeyShot or
%Public%\Documents\KeyShot
macOS:
-
/Library/Application Support/KeyShot