So much has been happening, where to start? How about Maya’s API. So I decided to learn how to swim, and jumped into the deep end of Maya’s API last month. It was the deep end, because I decided to start with writing a deformer in Python. I thought that python would be the simpler language to do it in before trying C++, since the last time I touched C++ was more than a few years ago. Boy was I wrong.
So lets imagine this situation. There is a company out there that does the best work in their field. And that’s the company you want, since they’re the best. They are of course located in Japan, the mecha center of this industry. So you hire their most flexible agent. He shows up at your door, and the first words he says are, “Hello, me the name associated with subject Super Agent Man is.” Huh? The most flexible agent from the best company in the world speaks English with a Japanese grammatical structure? How does that make any sense? Well, it doesn’t. But that’s Maya’s Python API. You can write it in Python, but you’re still speaking C++. In any case, I muscled through and completed my goal. In no small part thanks to the Maya in Python Google Group (and some informative questions posed by none other than Jason Osipa), Chad Vernon’s little API walkthrough, and of course the best (and basically only) API book on the market Complete Maya Programming by David Gould.
The deformer I set out to write was a simple average verticies deformer, or in more accurate terms a mesh smoothing deformer. I wanted to write this deformer, since Maya’s default average verticies operation is nearly useless in rigging. Maya’s doesn’t have an envelope and it stops smoothing after 20 iterations. My smooth mesh deformer should be available to download now in the increasingly inaccurately named Scripts section. You can read about what it can do there.
On my way to writing this plugin, I decided I wanted it to maintain volume. First I attempted to research the subject. I found a few results, most of which contained math I was completely unable to understand at first glance. So I did what any questionably sane programmer would do. I tried to write my own!
I formed the assumption that maintaining the area of a triangle which is defined by three points along a 2D edge would more or less maintain the overall area of a 2D polygon. I wrote it in 3D for the first time since trying it in 2D seemed harder to do given my base code. After teaching myself Linear Algebra from the ever trusty Wikipedia, and one incredibly stupid mistake about the area of a triangle, I arrived at my solution!
At first, the results of my experiment appeared to be going quite well.
Well, at least until I tried it on the ubiquitous Standford Bunny and saw this…
Woah Nelly! What is that?! It looks like most of the volume was maintained, but at what cost? Now the Standford Bunny is a sad diseased little lump. It reminds me a bit like Fred from Splice. I think this was due to loss of the area of a triangle over time without referencing back to the original. Furthermore the lovely “warts” on that last one were happening because the algorithm was attempting to make every triangle a 60-60-60 – causing tiny pyramids to pop up. This effect might have gone unnoticed on the typical meshes that are used in animation, but it obviously wasn’t doing what I wanted. Oh well, it was nice to meet you, you strange sad little bunny mutation.
So back to the drawing board with research. I went back to studying the Taubin method of mesh smoothing with volume preservation. I actually did figure out the math correctly though I didn’t know it until I stumbled on this little gem of five different clear implementations of mesh smoothing in C++.
And that was the end of my Mesh Smoothing API Quest. At least for now. Later I may try again at a volume preservation technique closer to Blender’s Shrink Wrap and Smooth modifier put together, but for now on to other exciting things!