PDA

View Full Version : get camera attributes from an existing camera in the scene


daviddoria
01-31-2008, 08: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?

MFnDagNode dagNodCam;
args.get(1,strCamera);
MObject CamObjectParent, CamObjectChild;
MSelectionList activeListCam;
activeListCam.add(strCamera);
MFnCamera fnCamera;
MItSelectionList iterCam(activeListCam);
iterCam.getDependNode(CamObjectParent);
dagNodCam.setObject(CamObjectParent);
CamObjectChild = dagNodCam.child(0);
MDagPath pathToCamera;
MDagPath::getAPathTo(CamObjectChild, pathToCamera);
fnCamera.setObject(pathToCamera);
MMatrix CameraMatrix = fnCamera.transformationMatrix();
MObject MatrixObject = fnCamera.attribute( "matrix" );
MFnMatrixData worldMatrixData(MatrixObject);
MMatrix worldMatrix = worldMatrixData.matrix();
fout_Info << worldMatrix << endl;


Thanks!

David

rxgeez
01-31-2008, 09:23 PM
getAttr camera1.matrix

daviddoria
01-31-2008, 10: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?

tbaypaul
02-01-2008, 03: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 )

{

MStatus stat;

// Get a list of currently selected objects

MSelectionList selection;

MGlobal::getActiveSelectionList( selection );

MDagPath dagPath;

MFnTransform transformFn;

MString name;



// 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" ) );

}

return redoIt();

}

daviddoria
02-01-2008, 04: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.


MFnTransform CameraTransform(CamObjectParent);
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....

MFnCamera fnCamera(CamObjectChild);
fout_Info << "Camera Name: " << fnCamera.name() << endl;

the name is cameraShape1!!! This has much different attributes than camera1

Why is it giving me cameraShape1??

Thanks,

Dave

daviddoria
02-01-2008, 04:42 PM
bahhh scratch that... the kTransform IS the camera1 that i'm looking for!!

CGTalk Moderation
02-01-2008, 04: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.