View Full Version : get camera attributes from an existing camera in the scene
01-31-2008, 09:03 PM
I am trying to get the camera1.matrix attribute from an existing camera in a scene.
I thought this would do it (although it seems like a ridiculous amount of code to get that), but it just keeps giving me back an identity matrix (I'm assuming the default return?). Anything blatantly wrong here?
MObject CamObjectParent, CamObjectChild;
CamObjectChild = dagNodCam.child(0);
MMatrix CameraMatrix = fnCamera.transformationMatrix();
MObject MatrixObject = fnCamera.attribute( "matrix" );
MMatrix worldMatrix = worldMatrixData.matrix();
fout_Info << worldMatrix << endl;
01-31-2008, 10:23 PM
01-31-2008, 11:44 PM
right, that is if I do it from maya... but i need to get it in a c++ api command.
i can run "executeCommand(" ... ")"
but I don't know how to store the result.
any other tips?
02-01-2008, 04:41 PM
If your intersectCmd is just a mel command you could write a script to query the selected camera and use that as parameters passed to your command call. mel and the api have their respective places in maya. Don't confuse them.
If your intersectCmd can become a node here is how you would connect the cam to your node.
here is a brief sample of an example of the api attaching a custom node to selected transform objs using a mel command created with c++. It is from David Gould's Complete Maya Programming 1...I recommend it....your two week struggle would probably be over now if you had it as a reference. Remember that a transform is part of the dag, which is unique...most nodes are dependency graph nodes, so you may have to use a different method then MDagPath.
MStatus GoRollingCmd::doIt ( const MArgList &args )
// Get a list of currently selected objects
MGlobal::getActiveSelectionList( selection );
// Iterate over all the transforms
MItSelectionList iter( selection, MFn::kTransform );
for ( ; !iter.isDone(); iter.next() )
iter.getDagPath( dagPath );
transformFn.setObject( dagPath );
MObject rollNodeObj = dgMod.createNode( "RollingNode" );
MFnDependencyNode depNodeFn( rollNodeObj );
dgMod.connect( transformFn.findPlug( "translateX" ), depNodeFn.findPlug( "distance") );
dgMod.connect( transformFn.findPlug( "translateY" ), depNodeFn.findPlug( "radius" ) );
dgMod.connect( depNodeFn.findPlug( "rotation" ), transformFn.findPlug( "rotateZ" ) );
02-01-2008, 05:32 PM
I actually have David Gould's book right here! However its sometimes tough to get what I want out of it.
I think I found the problem, but I'm not sure why its happening.
fout_Info << "Parent type: " << CamObjectParent.apiTypeStr() << endl;
CamObjectChild = CameraTransform.child(0);
fout_Info << "Child type: " << CamObjectChild.apiTypeStr() << endl;
CamObjectParent is type kTransform
CamObjectChild is type kCamera
so far so good....
fout_Info << "Camera Name: " << fnCamera.name() << endl;
the name is cameraShape1!!! This has much different attributes than camera1
Why is it giving me cameraShape1??
02-01-2008, 05:42 PM
bahhh scratch that... the kTransform IS the camera1 that i'm looking for!!
02-01-2008, 05:42 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.