Render Ambient OcclusionRender Ambient Occlusion, will render an ambient occlusion pass of your scene. 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.

Section1: Create the main function, define attributes, and display them in a user prompt.

  • Get the scene information by using the lux.getSceneInfo function.

  • Between lines 10 and 17, lux.DIALOG functions define the following attributes:

    • Output destination folder, folder.

    • Name of the output file, name.

    • Image dimensions, width and height.

    • Render time defined by the user, time.

    • Whether or not the user wants to send the image to the queue, queue.

    • Whether or not the user would like to process the queue after the job is added, process.

 

  • Lines 18 through 21, open the actual user prompt window by using lux.getInputDialog. On line 21, an "id" tag recalls the most recent input values. For more information regarding the dialog function, click here.

 

Section 2: Checks for errors and exit peacefully if errors arise. Assigns user input to corresponding variables.. See below for a line-by-line code breakdown.

  • If the output folder is not valid or left blank, give error message.
  • If the file name is left empty, give error message.

  • Get the current environment image using lux.getEnvironmentImage and assign it to variable env.

  • Get the current material from the model using lux.getMaterialMapping and assign it to the variable mmap.

  • Change the environment to the "All White.hdr" using lux.setEnvironmentImage.

  • Lines 34 and 35, 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.

  • Assign the output path the the path variable.

  • Assign the desired width to the width variable.

  • Assign the desired height to the height variable.

  • Assign the render time desired to the time variable

  • Make boolean expression called queue and set it to "True" or "False" depending on the user's choice.

  • Make boolean expression called process and set it to "True" or "False" depending on the user's choice.


Section 3:  Setup the render options.

  • Assign the render options to ropts variable by using lux.getRenderOptions.

  • Set the render options to "max time" by using the setMaxTimeRendering variable.

  • If the user set "add to queue" as "True", then it will be added to the internal KeyShot queue.


Section 4: Render the image and set all the previous parameters back up.

  • Render the image using the lux.renderImage function.

  • Apply the old environment to the scene.

  • Apply the old materials back to the model.

  • For lines 53 to 55, if the user requested to process the queue, do so.

Call the main function.