Saturday, March 31, 2012

[Maya] Custom Shape Nodes

I've worked on building system with custom shape nodes in Maya for a while and truly learnt a lot from it.

Maya indeed provides great proxies for developers to make custom shape nodes with different level of complexity. Using MPxSurfaceShape (or MPxComponentShape), combined with  MPxSurfaceShapeUI & MPxGeometryIterator &MPxData, you can implement a "very complicated" shape node in Maya. This node can have developer-defined data structure. The data itself can be an attribute which is able to connect to other nodes. You can also define the shape node's behavior under Maya's tools, such as move, rotate, scale, even deformer (lattice, cluster, etc)!!!! And with context command, interacting with custom shape nodes with defined context tool outside becomes possible. This work flow and mechanism is really awesome!!! well... just a flash into my mind, can it support dynamic stuff? Or should I do it outside and write the result back to the shape nodes? hmmm I will figure that out. 

Because they are just proxies, which means you have to do the coding for the actual content. Maya gives you lots of flexibility, but meanwhile, you also have to follow its rules. It would take a while to realize those provided virtual functions of each proxy, like when they will be called and how to make Maya recognize your shape node (Oh Ya, this is the main point!! You have to make Maya recognize your shape node and be able to interact with it!!)

Looking at my system growing bigger and bigger is excited. The custom shape nodes and context tools are almost done. It's time for the official greeting to Renderman API!! Hello Renderman!! :)

Thursday, March 22, 2012

[QT] Signal & Slot

Recently because of the need at work for developing Maya plugin, I got a chance to dabble in Qt. Always excited about new things to learn!! :)

As the central feature of Qt, the first thing I started experimenting is the Signal & Slot mechanism. I found that there are some similarity  between Qt's Signal & Slot and Maya's Push & Pull model. Probably this is the reason why Maya chose Qt to rewrite the entire GUI from 2011 (just guessing :p)

Instead of using traditional callback functions, Qt adopts an alternative approach: Signal & Slot. When an event occurs (or object's internal state changed), it emit signals, objects interested in this event would use slot to respond to the signal. It doesn't know if anything receives the signals it emits; and the slot itself doesn't know if any signals connected to it. Loose Coupling!! Oh... and the signature of signal should match the signature of slot.

QObject::connect(&a, SIGNAL(valueChanged(int)), &b, SLOT(setValue(int)));

Don't you think the usage of Signal & Slot is kind of like the following in Maya when trying to build dependent relationship between attributes?

attributeAffects(width, area);
attributeAffects(height, area);

In Maya, each node just knows about itself, it doesn't know anything about node connection, not knowing which node connects to it and which node it connects to. It only knows which input attribute affects which output attribute of itself. It's just like a black box with a compute function inside to do the necessay calculation. With commands, we can connect nodes together. With Maya's Push & Pull model, we can get the most updated state of a particular node.

That's why I think that there are some common ideas between these two architectures. They all maintain truly independent components and provide ways to bind objects(nodes) together for communication.

Saturday, March 17, 2012

[Maya] Handle MouseMove Event

Maya doesn't have MouseMove event, only provide doPress, doDrag and doRelease. One way to deal with MouseHover would be using Qt which is available since Maya 2011.

We can get QWidget from Maya's M3dView, then use it to instantiate a QWidget object with EventFilter installed and MouseTracking enabled. With eventFilter method, MouseMove event can be detected.

Quite straightforward and good so far. However, here is the thing.
For some reasons, if I just passed my M3dView to QWidget, that M3dView would only be valid at that moment. When it gets into the eventFilter method, it wouldn't be valid anymore. But I need that view to handle the scene in Maya.

There is an alternative. Within eventFilter method, I can get the name of the model panel I'm working on in Maya (via watchedObject->objectName()). Given the name of the model panel, M3dView::getM3dViewFromModelPanel should return the valid M3dView. Then I can do what I want to do with Maya scene under MouseMove event captured in Qt.

Interesting huh...

Tuesday, March 13, 2012

Enthusiasm!!


I happened to watch this quite inspiring speech, given by Mike Jutan, R&D Engineer at ILM. He decided his career goal right after watching Terminator 2 with amazing special effects. It's that very moment that keeps driving his enthusiasm all the way from studying Computer Science, working at Alias, Pixar and now ILM. He is awesome!

Dare to be different!
Luck favors the prepared.
Strive to be happy!
Overnight Success is many years in making.