Search This Blog

Tuesday, January 17, 2012

Some Unity3D goodness - Scripts for Adding Lights

Learning to write scripts for assistance in editing/adding geometry within Unity3D is a must for anyone bringing in models from Revit or 3DSMax for Architectural Walkthroughs.  One particular pain point is putting in all the lights or the lights that you wish to cast light within your "game".  To use these scripts add an Editor folder under the assets folder in your Unity3D project folder.  Once they scripts are copied to this folder, you see new options in the "Game Object" pulldown menu item.  Select some light geometry, for example, some lamp shades in your scene, then click on Game Object - Add pt lights ^n from the menu pulldown.

The results will be a child game object component added to each of your selected geometry objects with the same position as the parent object. Also, because it is a child component, it will move should you reposition the light.

Note: a few objects might require tweaking.

 Here are a couple of scripts:
  1. Add point lights - This script will add a point light with the name "_pointlight" with the same transform position as a selected light geometry within the Unity3D editor.
  2. Add spot lights - This script will add a spot light with the name "_spotlight" with the same transform position as the selected light geometry within the Unity3D editor. 
Note: the light cone is automatically rotated down and is useful for downlighting. 

No comments: