Mel Script - Bump Maps [API]

 

 

 

 

Bump mapping uses a grey-scale file texture which is connected as an input to a bump 2D node. The bump 2D node calculates an output normal vector which it supplies to the "normalCamera" attribute of a material.

It is this normal camera attribute that provides the Maya renderer with the surface normal for the lighting calcuation.

 

 

 

 

Finding All Bump Maps in a Scene

To find all of the camera nodes, we can simply use ls.

 

 


		// get a list of all bump map nodes in the scene
		$maps = `ls -type "bump2d"`;

		// loop through each bump map
		for( $bump in $maps )
		{
			// print the name of the bump 2d node
			print( $bump + "\n" );
		}
		

 

 

Accessing the Bump Map Data

The data contained on the bump 2d node is nothing more than a depth value for the effect of the bump. More importantly, we need to be able to access the connected material and file texture nodes since which material(s) use the bump map and which texture is used for the bump map is fairly important. To do this we can simply use getAttr to get the bump depth, and listConnections for the connected nodes.

 

 

		// get a list of all bump map nodes in the scene
		$maps = `ls -type "bump2d"`;

		// loop through each bump map
		for( $bump in $maps )
		{
			// print the name of the bump 2d node
			print( $bump + "\n" );

			// get the file used for the bump map. This is always a connection
			// between the "bumpValue" attribute of the bump2d node, and the 
			// "outAlpha" attribute of the file texture
			$files = `listConnections -s 1 -d 0 ($bump+".bumpValue")`;
			print( "file: " + $files[0] + "\n" );
			print( "filename: " + `getAttr($files[0]+".ftn")` + "\n" );

			// get the connected material (there is always a connection
			// between the "normalCamera" attribute of the material, and
			// the bump2d nodes "outNormal" attribute. 
			$materials = `listConnections -s 0 -d 1 ($bump+".outNormal")`;
			for( $material in $materials )
			{
				print( "connectedTo: "+$material+"\n" );
			}
			
			// finally print the bump depth
			print( "depth: " + `getAttr ($bump+".bumpDepth")` + "\n" );
		}