Saturday, April 21, 2012

Rigging IK FK snapping with Maya Api Node


I'm new to the Maya api but I think it will come incredibly handy with ik fk snapping.
I'm thinking if we had a node that we could connect to the matching object and also connect to the animator control,
then a mel script could quickly access the node connected to the animator control and find out where to snap to.

I had quite some trouble trying to figure out how to build a Mac plugin, but when I just googled Makefile maya plugin the examples that came up were incredibly useful for me to then try to figure out the things I needed to add.

Definitely where the sources are with .cpp those would need to be changed to whatever source file.
And whether or not headers are needed.

Part of the more confusing areas had to do with architecture. I was constantly finding unknown architecture.
With a mac book, I tried ppc, and ppc64 and was getting errors, then i tried i386 and it worked i'm not exactly sure why but it did.

Another thing that is important was knowing the exact path to the . This is needed to find all the "MSimple.h", "MGlobal.h" .. and all the other cool things we can use in our plugins. I think similar to Mel sourcing a mel file, by including these we can use any functions (like procs) they have.

I also had a bit of trouble not knowing why there was a .o file, I still don't completely understand it but from reading a bit on Wikibooks I think the object file is kind of the really back-end of the computer with the zeroes and 1's. I think in making this .o file the compiler needs to know the architecture of your computer.

To make it a little easier for Maya to find the plugin after its built I think the Maya.env file is incredibly useful.
Also check out the mel getEnv command (we could use this to find out whether Maya is looking for plugin at where we need)

Finding my Maya.env file was a little tricky, it looked like.
Changing the env file was easier just putting in the name Maya needs, and whatever path you have your plugins
MAYA_PLUG_IN_PATH = /Users/you/Documents/api/maya-plugins

Some other things I think may be useful is keeping the source and version control hierarchy separate from the build that way can easily remove builds and code.

Also I think its a good idea to add bundle to the Maya plugin path only when it looks like compile errors and stuff like that were figured out already, that way if Maya started up it won't go trying to load bundles that were'nt ready yet.

To get started with a plugin check out the
DeclareSimpleCommand. Its really short to write in c++.

All the c I wrote for this simple simple trial was:
/**intro to learn c for maya api for rigging

#include <maya/MSimple.h>
#include <maya/MGlobal.h>

DeclareSimpleCommand( hello, "world", "8.0");

MStatus hello::doIt( const MArgList& )
MGlobal::displayInfo("great day it built okay\n");
return MS::kSuccess;

But I think there is alot going on here that I still haven't mastered. Like the kSucess looks to be a variable we can directly access from an object we haven't even instanced (i think it has to do with static).

Also in the DeclareSimpleCommand i think there is quite alot of invisible stuff going on like that --hello-- I think is an object we have created which is an instance of a class (a command). I think that is why we can use the function doIt. doIt is i think a virtual function that we inherited from the invisible class hidden in the text file MSimple. I think virtual means we can make it anything we want as long as it takes the right thing and returns the right thing.

So there is quite a bit going on here, but lots of similarities with Mel though. Like we have functions (like procs but use two colons to call them). We have code we can get included automatically (like source but we use #include and possibly < >. And lots of powerful stuff like we can use variables without creating instance of object (kind of like a semi-global mel variable), not to mention that & in MArgList which I think says we know how to find the users arguments when they type hello; in Mel. Making one instance of a class and having access to thousands of tools using one instance.

Hope this is helpful.

Inspired by Jason Schleifer's Animator Friendly Rigging (jasonschleifer dot com)
Inspired by Erwin Coumans amazing make file examples for Maya plugins on Mac link

Inspired by Jason Parks wonderful examples of the getEnv (www dot jason - parks dot com)
Inspired by wikibooks dot org link