Mel Script - Light Data [API]

 

 

 

A light within Maya is used to illuminate the scene. A variety of light types are available including ambient, point, spot, directional etc. A light is a simple geometry object and is positioned within the scene using a transform node.

 

 

 

Finding All Lights in a Scene

All lights within Maya are derived from the generic type "light". We could specifically ask for pointLight, areaLight etc, however if we list all light nodes we will access all lights, no matter what type they are.

 

 


		// get a list of all lights in the scene
		$lights = `ls -type "light"`;

		// loop through each light
		for( $light in $lights )
		{
			// print the name of the light node
			print( $light + " " );
			
			// print the light type
			print( `nodeType $light` + "\n" );
		}
		

 

 

Creating lights

we can declare our own lights fairly simply as shown in the example below.

 


			
			// do ambient light
			defaultAmbientLight(1, 0.45, 1,1,1, "0", 0,0,0, "1");
			xform -t -5 0 0;
			
			// do directional light
			defaultDirectionalLight(1, 1,1,1, "0", 0,0,0);
			xform -t -3 0 0;
			
			// do point light
			defaultPointLight(1, 1,1,1, 0, 0, 0,0,0, 1);
			xform -t -1 0 0;
			
			// do spot light
			defaultSpotLight(1, 1,1,1, 0, 40, 0, 0, 0, 0,0,0, 1);
			xform -t 1 0 0;
			
			// do area light
			defaultAreaLight(1, 1,1,1, 0, 0, 0,0,0, 1);
			xform -t 3 0 0;
			
			// do volume light
			defaultVolumeLight(1, 1,1,1, 0, 0, 0,0,0, 1);
			xform -t 5 0 0;