Now that we have the Powergon command attached to the polygon we selected, Save the object and load it into Layout. With the object selected, choose the Convert Powergon command located under the Items Tab in the Add sub-menu. (Items > Add > Cvt Powergons) This command will execute any command scripts that are attached to the selected object.
The default script that we added creates a spotlight named LGON, positions it at the center of the polygon, rotates it to match the polygon's normal, parents the light to the object and creates a keyframe at frame 0 (Fig.04
Once a Powergon script is executed in Layout, you can clear the object if it is unneeded otherwise. However, the default command parents the lights to the object, so be careful since you don't want to delete the children.
Fig.04 - CVT Powergons executes the command we attached to the polygon
Understanding the Default Powergon Command Script
Now that we've seen the result of the Powergon, let's take a closer look at the script and break it into its individual components.
AddSpotlight LGON\rPosition \c\rRotation \n\rParentItem \i\rCreateKey 0
• AddSpotlight LGON
simply adds a Spotlight to the scene and gives it the name "LGON".
is a special "escape" character that creates a line return to signify the end of the current command and the start of the next.
• Position \c\r
uses the \c special "escape" character to return the position of the polygon's center in the form "x y z". This is used to position the light at the center of the polygon we applied the Powergon to. The \r at the end is used as another line return so we can continue adding commands to this script.
• Rotation \n\r
uses the \n special "escape" character to return the polygon's normal converted into heading, pitch and bank angles (bank is always 0) in the form "h p b". This rotates the Spotlight to match the polygon normal. Again we use the \r character as a line return.
• ParentItem \i\r
uses the \i special character. This returns the item ID of the object containing the polygon so we can assign the Spotlight as a child to our object.
• CreateKey 0
simply creates a keyframe at frame 0. Note that the \r special "escape" character is not needed at the very end of the last command.
So now we know what the default script does, but where do these commands come from and how many different special "escape" characters are there? Let's start with the special characters since there are only six to work with and we already covered four of them. Here are the six special "escape" characters that can be used when generating a Powergon Command:
returns the area of the polygon.
returns the position of the polygon's center in the form "x y z".
returns the polygon's normal vector as "nx ny nz".
returns the item ID of the object containing the polygon.
returns the polygon's normal converted into heading, pitch and bank angles (bank is always 0) in the form "h p b".
creates a line return to signify the end of the current command and the start of the next. Note that it is not needed at the very end of the last command.
Once you work with Powergons for awhile you'll be able to call these six characters up from memory with ease, but what about the Layout commands? Where do they come from?
Nearly all of your actions in Layout are executed by sending discrete commands. When you click on the VIPER button (Render > Utilities > VIPER) it sends a command to Layout to open and display VIPER. We can watch what commands are being sent to Layout by using the Command History window found under the Utilities Tab (Utilities > Commands > Cmd History).
Clear the current scene and launch the Command History window (Utilities > Commands > Cmd History)(Fig.05
Fig.05 - Command History Window in Layout
Leave the Command History window open, add a Spotlight to the scene and name it "LGON" (Items > Add > Lights > Spotlight.