Mel Script - Material Data [API]

 

 

 

 

Materials within Maya are applied to surfaces to change the way that light interacts with the surface when rendering. There are a number of common material types in Maya namely, blinn, phong, lambert etc. Often materials are used in conjunction with textures to add extra levels of surface detail into the geometry.

 

 

 

 

 

 

Creating a Material

in order to create a material using mel you need to use the shadingNode mel command.

 

 

 



		// create an anisotropic material
		$anisotropic = `shadingNode -asShader anisotropic`;
		
		// create a blinn material
		$blinn = `shadingNode -asShader blinn`;
		
		// create a lambert material
		$lambert = `shadingNode -asShader lambert`;
		
		// create a phong material
		$phong = `shadingNode -asShader phong`;
		
		// create a phongE material
		$phongE = `shadingNode -asShader phongE`;

 

 

 

Finding All Materials in a Scene

The lambert shader node is common to all node types, ie; phng, blinn, anisotropic and phongE materials all extend the basic lambert node to add in specular lighting. This means that we can query all materials by simply listing all lambert nodes.

 

 


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

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