Maya API 2 Node Camera

Maya API 2 Node Camera

SimonJWakley
Contributor Contributor
1,712 Views
6 Replies
Message 1 of 7

Maya API 2 Node Camera

SimonJWakley
Contributor
Contributor

 

Is there a way to create a 2 Node camera simply in the API using MfnCamera or is it simply easier to use a Mel Command with MGlobal::executeCommand.  Somehow it feels bad form to be using MEL commands from within the API but maybe that is not a bad thing?

 

Is there a significent overhead in terms of speed for using a MEL comand ("xform -ws") as opposed to using an API comand such as getTranslation().

 

I have an API that creates a 1 or 2 node camera, I can easily make the single node, but I don't see how to immediately do it with the API unless I have to create the locator and set it as the interest point etc etc.

 

Thanks,

 

Simon

 

 

0 Likes
Accepted solutions (1)
1,713 Views
6 Replies
Replies (6)
Message 2 of 7

cheng_xi_li
Autodesk Support
Autodesk Support
Accepted solution

Hi Simon,

 

There won't be a significent overhead to call mel in your plug-in and I don't think MFnCamera supports creating a two-node camera.  Calling mel should be simplier than creating transform and locators and plug them properly in this case.

 

Yours,

Li

0 Likes
Message 3 of 7

SimonJWakley
Contributor
Contributor
Thanks. I will try that.
0 Likes
Message 4 of 7

SimonJWakley
Contributor
Contributor


So using the mel Command worked and I can create the camera with MFnCamera, then get  the Dag Node, then get the partial name and plug that into a Mel string.  Then I get the name of the _aim so created, then I iterate throught the Dags to find it, so I can get the Dag so that I can animate it using setTranslation.

 

It seems like a horrible mix of API and MEL and having to convert back and forth between what the API uses and what MEL uses, but it works and I can drive the camera with my API.

 

Now I notice that my API runs during the OnIdle. so if the scene is being moved around, then the camera motion stutters.  Is there a way to ensure that I get my API code called more in time with the update.  If you drag the time slider, sometime the camera stops moving from my API command until you release the slider.

 

 

0 Likes
Message 5 of 7

cheng_xi_li
Autodesk Support
Autodesk Support

Hi Simon,

 

I don't know how you update your camera. 

 

 

Is it a command or node? 

 

Yours,

Li

0 Likes
Message 6 of 7

SimonJWakley
Contributor
Contributor

I get the DagPath of the camera, store it and then in the OnIdle API routine I get the new camera position xv, yv, zv and..

 

MVector vPoint;
MEulerRotation rotation;
MFnTransform xform(m_CameraDagPath);

vPoint[0] = xv;
vPoint[1] = yv;
vPoint[2] = zv;

xform.setTranslation(vPoint, MSpace::kTransform);

 

Simon

0 Likes
Message 7 of 7

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

When the animation is playing back, the idle event won't be triggered always. 

 

What kind of plugin are you trying to create? Maybe a node connected to camera transform and time1 would be better in this case.

 

Yours,

Li

 

 

0 Likes