Rigging with classes

I recently wrote a rigging module that used classes instead of free floating functions. I’ve never used oop for auto rigging before, and I ran into a set of problems that were unique to this process. I’m wondering if any of you have tackled these issues.

  1. Once the code is run, I lose the object’s instance. This is the big problem for me. I enjoyed taking advantage of inheritance, polymorphism, and composite patterns. But none of that matters if I lose the object immediately after running it. I could try to rebuild the instance based on connections, but that almost defeats the whole purpose. This makes it difficult to edit the rig with code after the initial run is done. I tinkered with trying to keep the instance in globals(), but good taste prevailed.

  2. Less of an issue, but it deals with using getters and setters. I wasn’t sure if it is cleaner to make the class getters and setters, also get/set the corresponding maya attributes. That way one can be sure that the two values are linked. Or is it better to have a separate one for the object than the actual node attr?

Thanks

If you’re worried about losing your instances you can do two things:

The simple option is just to keep them around – for example, storing them in a class-level dictionary so the never go out of scope.

More complex but maybe more robust to scene changes, you can store all of the information you need in attributes on the rigs themselves, so that you can recreate an instance by passing it a scene object and then traversing it using the data you have. That way the code object always reflects the state of the scene. Obviously though in this case the code has to deal with all the ways users can break your scene.

Thanks for the reply Theodox. Option two appears to be the way to go. It seems pretty heavy handed to have to write a bunch of code in order to reconstruct the rig as an instanced object. Maybe it won’t take as long as I’m fearing. Have you ever found it a burden to do so?

It will be worth the effort.

Here on the site there’s a link to David Hunt’s GDC talk on this subject from 2009:

Definitely worth it in the long run.
If I remember correctly Red9 has a Framework for setting up a metadata system which could be used for this (correct me if I’m wrong), it’s open source so that might save you some time?

I tend to make a get/set for the class separate from a get/set that interacts with Maya. This just adds a little robustness if you wanted to edit the classes outside of Maya.

Red9 does indeed, there’s a full MetaData API designed just for this kind of thing. The idea is that you have a node as a class representation and whenever that node is hit, it’s returned as your instantiated class. It’s kind of like Pymel in that respect but with a more dedicated api for walking networks and binding your own classes to node instances. It’s a framework that has specific applications for rigging and there’s a well supported ‘‘MetaRig’’ class that includes wrapping of a lot of the other Red9 animation tools such as mirror, pose store, attrMap and many more. The main API is in the StudioPack which is open source so I’d have a poke around in that. We also extend that API in the ProPack for clients and use it’s ability to find nodes in teh rig networks to expand the tools to things like characterPickers and animation libraries etc.

As a work in practice our production rig uses these metaNodes to inspect, retrieve and store all build data on the rig itself so it doesn’t mnatter at what stage you leave the file your build code still runs. There’s lots of help on the Vimeo channel or just ping me, always happy to help.

https://vimeo.com/user9491246

cheers

Mark