Accessing Camera Data [MEL]



 

 

Cameras in maya are stored as MFn::kCamera nodes. In the hypergraph view above, the transform is "persp" and the camera itself is "perspShape". In order to access the Camera information, we can use the MFnCamera function set.

 

In maya you can have one of two camera types, an orthographic camera or a perspective camera.

 

 

 

 

Finding all Cameras
in a Scene

To iterate through all of the cameras within a scene you can simply use an MItDependencyNode to iterate through the MFn::kCamera nodes in the scene.

 

 

 

 


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

// create an iterator to go through all curves
MItDag it(MFn::kCamera);

while(!it.isDone())
{
 

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

// print camera name
cout
<<"Camera "<< fn.name().asChar() <<endl;

// get next curve
it.next();

}




 

Camera Data

 

The MFnCamera function set provides you with access to all of the cameras attributes. The function listed here extracts common camera attributes for a perspective camera.

It is possible to extract orthographic cameras as well if you wish (possibly useful for user interfaces); However i will leave that as an excersice for the reader ;)

 

 

 

 

 

 


#include<maya/MFnDependencyNode.h>
#include<maya/MFnCamera.h>

void OutputCamera(MObject& obj)
{
 

// attach a function set to the camera
MFnCamera fn(obj);

// ignore orthographic cameras
if(fn.isOrtho())

  return;

// attach a function set to the parent transform
MFnDependencyNode fnParent( fn.parent(0) );

// output some info about the camera

cout




cout
cout

cout


cout
<< "CAMERA " << fn.name().asChar()
<< "\n\tparent "
<< fnParent.name().asChar()
<< endl;

<< "\taspect " << fn.aspectRatio() << endl;
<< "\tnear " << fn.nearClippingPlane()
<< endl;
<< "\tfar " << fn.farClippingPlane() << endl;
<< "\taspect "
<< fn.horizontalFieldOfView() << endl;
<< "\tvert_aspect "
<< fn.verticalFieldOfView() << endl;

}


 

 

What Next?

Transformation Data

Animation Data

Animation Curves

index

Rob Bateman [2004]

[HOME] [MEL] [API]