Render Animation Passes
Print
Render Animation Passes allows the user to seamlessly render animation frames with the option to output "ambient occlusion" and/or "toon outline shading" passes. At the end of the article, you will find the annotated script code for your reference.
How the script works:
At the top of most scripts we import the external Python libraries first:
import os, re.
Section 1: Create a function that will setup the scene to render ambient occlusion.
Change the environment to the "All White.hdr" using lux.setEnvironmentImage.
Lines 10 and 11, go through all the parts in the scene tree using lux.getSceneTree and assign the "Matt White" material to all of them using lux.setMaterial.
Section 2: Create a function that will setup the scene to render a "toon pass".
- Lines 14 and 15, go through all the parts in the scene tree using lux.getSceneTree and assign the "Toon Outline Black" material to all of them using lux.setMaterial.
Section 3: Create a function that will render out the frames.
Assign the output file format to the fmt variable. Replace the %d and %s with the frame number and the type of pass it is respectively.
Assign the file path to the path variable after joining the folder path and fmt.
Render the image using the lux.renderImage function.
Apply the old environment to the scene.
Apply the old materials back to the model.
Section 4: Create the main function, define attributes, and display them in a user prompt.
Get the animation information using lux.getAnimationInfo.
On lines 53 and 54, if there are no frames, give error message.
Get the scene information using the lux.getSceneInfo() function.
Between lines 32 and 45, lux.DIALOG functions define the following attributes:
Output frames folder, folder.
Output file format, fmt.
Frame dimensions, width and height.
Start and end frames.
"Ambient occlusion" pass checkbox, occl.
"Toon outline shading" pass checkbox, toon.
"Add to queue" checkbox, queue.
- "Process the queue after running script" checkbox, process.
Lines 45 through 49, open the actual user prompt window by using lux.getInputDialog. On line 49, an "id" tag recalls the most recent values given by the user. For more information regarding the dialog function, click here.
- If there is an error with the inputs, the script exits gracefully.
Section 5: Checks for errors and exit peacefully if errors arrise. Assigns user input to corresponding variables. Here is a line-by-line code breakdown:
- If the output folder is empty or not valid, give an error message.
Assign the given folder path to the fld variable.
Assign the file format to the fmt variable.
If the file format empty, give an error message.
On lines 60 through 63, if the file format given does not contain %d or %s, give error message.
Width gets assigned to the width variable.
Height gets assigned the given height variable.
Assign the starting frame number to the start variable.
Assign the ending frame number to the end variable.
If the start variable is greater than the end variable, give error.
If the user left both the ambient occlusion and the toon pass unchecked, give an error message.
Make a boolean variable queue and assign "True" or "False" depending on user choice.
Make boolean variable process and assign "True" or "False" depending on user choice.
Save the current environment settings to the env variable using lux.getEnvironmentImage.
Save the all the materials applied to the model to the mmap variable using lux.getMaterialMapping.
Assign the render options to the ropts variable using lux.getRenderOptions.
Set the render options to add to queue depending on the user input.
Section 6: To wrap up this script, render the necessary passes and process the queue.
- Create a for-loop that will go from the start frame to the last frame and goes through the following.
- Set the current animation frame using lux.setAnimationFrame.
- On lines 90 through 92, if "ambient occlusion" was selected, call the ambOcclusionPass function defined at the top and then render the frames.
- On lines 94 through 96, if "toon pass" was selected, call the toonShaderPass function defined at the top and then render the frames.
- If the user chose to render the queue, do so.
- Finally, call the main function.