Render Panoramic

Render Panoramic Frames

Print


Render panoramic frames renders a series of frames that can be used to create a panoramic view of the product. This article walks you through every code section in the script. 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: Set up rotation along the Y axis.

  • Create a function, rotateY, and use it to rotate the scene in the "Y" direction. Take vector parameters for the selected camera (vec), the angle of the camera (angle), and the direction of the rotation (clockwise).

  • If the direction of the rotation is clockwise, multiply the angle by -1. This is due to the rotation being counter-clockwise by default in KeyShot.

  • Return the new camera vector, angle of the camera, and direction of the rotation.


Section 2: Create the main function, define attributes, and display them in a user prompt. Get the scene information by using the lux.getSceneInfo function.

  • Between line 18 and 28, lux.DIALOG functions define the attributes:

    • Camera name, cam.

    • Frame number, frames.

    • Output frame format, fnt.

    • Frames folder, folder.

    • Frame dimensions, width and height.

    • Whether or not to add the frames to a render queue, queue.

    • Whether or not to process the render queue after adding the frames, process.

    • Whether to rotate clockwise or counter-clockwise, clockwise.
       

  • For each dialog attribute there are 3 or 4 pieces of information needed.

    • Data type (e.g. lux.DIALOG_INTEGER will save and integer value).

    • Displayed name.

    • Default value.

    • Constrains (e.g. for the frames the constraints are 1 to 360 frames.)


Lines 29 through 32, include the lux.getInputDialog function which generates the actual user prompt. In line 32, an "id" tag recalls the most recent input values. For more information regarding the dialog function, click here.

Section 3: Check for errors and exit peacefully if errors arise. Assign user input to corresponding variables. A line-by-line code breakdown is shown below.

  • Assign the user's camera choice to the cam variable.

  • Assign the number of frames specified by the user to the frames variable.

  • Assign the file format to the fmt variable.

  • If the output format or incorrect, give error message.

  • Assign the folder path to the folder variable.

  • If the output folder is not valid, give error message.

  • Assign the width requested by the user to the width variable.

  • Assign the height requested by the user to the height 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.

  • Assign the current camera information to the oldcam variable.

  • Assign the angle needed in between each frame to move the camera to the angle variable.

 

Section 4: Create a loop for rendering each frame. See below for a line-by-line code breakdown.

  • Make boolean expression cancelled and set it to "False",

  • Set the camera to the specified position for the first frame.

  • Create the loop to go through the number of times specified by the user.

    •  Use lux.setCameraDirection, rotateY, and lux.getCameraDirection to set the new camera direction.

    • Use lux.setCameraUp, rotateY, and lux.getCameraUp to set the new camera's up vector.

    • Merge the folder variable with the name of the file and assign it to the path variable.

    • Output the current status of the render to the console.

    • Get the render options using lux.getRenderOptions and assign them to the opts variable.

    • From line 70 to 73 render the image using the given information. If something goes wrong, exit gracefully and set the cancelled variable to "True".

  • Set camera back to the original camera.

  • If process = True, then process the queue and render each frame.