Accessing Light Data [MEL]



 

 

Finding all Lights in a Scene

There are a number of light types available in Maya, all of them are derived from MFn::kLight. They are :

  • MFn::kAmbientLight
  • MFn::kDirectionalLight
  • MFn::kSpotLight
  • MFn::kPointLight
  • MFn::kAreaLight

 

 

 

 


#include<maya/MFnLight.h>
#include<maya/MItDag.h>

// create an iterator to go through all lights
MItDag it(MFn::kLight);

while(!it.isDone())
{
 

// attach the function set to the object
MFnLight
fn(it.item());

// print light name
cout
<<"Light "<< fn.name().asChar() <<endl;

outputLight(it.item());

// get next light
it.next();

}




 

Getting the light data

 

A general function set MFnLight exists to access most of the common attributes shared between the various light types.

 

In addition the class MFnPointLight, MFnAmbientLight, MFnSpotLight, MFnDirectionalLight and MFnAreaLight can be used to access more specialised attributes on other light types.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


#include<maya/MFnLight.h>
#include<maya/MFnDagNode.h>
#include<maya/MColor.h>
#include<maya/MFnPointLight.h>
#include<maya/MFnAmbientLight.h>
#include<maya/MFnDirectionalLight.h>
#include<maya/MFnSpotLight.h>
#include<maya/MFnAreaLight.h>

void outputLight(MObject& obj)
{
 

// attach a light function set to the object
MFnLight fn(obj);

MFnDagNode fnParent(fn.parent(0));

// get light color
MColor color(0.0f,0.0f,0.0f);
color = fnLight.color();

// output some light info

cout << "parent " << fnParent.name().asChar()
<< "\ntype " << obj.apiTypeStr()
<< "\nColor "
<< color.r << " "
<< color.g << " "
<< color.b << "\n"
<< "intensity " << fn.intensity()
<< endl;


// if you need to get specific attributes associated
// with specific light types then use something
// like this....

switch(obj.apiType())
{

  // output pointlight only attributes
case MFn
::kPointLight:
{
MFnPointLight fnPoint(obj);
}
break;
// output ambientlight only attributes
case MFn::kAmbientLight:
{
MFnAmbientLight fnAmbient(obj);
}
break;
// output spotlight only attributes
case MFn::kSpotLight:
{
MFnSpotLight fnSpot(obj);
}
break;
// output directional light only attributes
case MFn::kDirectionalLight:
{
MFnDirectionalLight fnDir(obj);
}
break;
// output arealight only attributes
case MFn::kAreaLight:
{
MFnAreaLight fnArea(obj);
}
break;

default:
break;

}

}


 

 

 

What Next?

Transformation Data

Animation Data

Animation Curves

index

Rob Bateman [2004]


[HOME] [MEL] [API]