Showing posts with label API. Show all posts
Showing posts with label API. Show all posts

05 January, 2012

MPoint '=' assignment operator and float[3]

All 3d packages define a 3D point as (x,y,z,w). Last property 'w' is included based on how homogeneous coordinate system works. And this 'w' always needs to be 1 when we do calculations. Maya's implementation of this 3D point is done in MPoint class. This class also defines '=' operator which will copy the values of a float[3] to the given point. But it's really not a good idea to do the following.

float myPt[3] = {1,1,1};
MPoint mayaPt = myPt;

The problem here is that Maya will assign values to x,y,z from myPt but not to 'w' leaving it 0. This is an invalid homogeneous coordinate as w=0 means the point is at infinity! So keep in mind that 'w' is important :)

02 August, 2010

MSyntax Flag Definition & Invalid Flag Error

I had some frustrating moments in making flags work for a command using MSyntax. A part of it was my ignorance in reading the function detail, but the other one I am not sure is mentioned in docs. Here is what it says in the doc. for MSyntax::addFlag(const char* shortFlag, const char* longFlag, ......)

shortName  the string representing the short (< 4 character) version of the flag
longName   the string representing the int (> 3 character) version of the flag


=> Short flag name should always be < 4 characters.
=> I defined one flag name like this:  syntax.addFlag("-it", "-infType", MSyntax::kDouble);
and used it with my command like this: myCmd -infType 2 Maya gave me an error, "invalid flag -infType"!

Then I changed the flag long name from -infType to -influenceType it all worked fine. So I wonder there is a problem with defining a long flag name beginning with three lower case characters, followed by an upper case character.

08 March, 2010

Dirty Bit Propagation

I have been looking for more information on how and when Maya marks nodes dirty. First thing I have come to understand is that for an attribute two dirty bits can be set, connection and datablock. See isDirty command for these two options. I am still not clear how using these two flags Maya decides to call compute method. And what has confused me more is that if I don't mark a datablock clean then the compute method does not get called after first compute call.
Here is an interesting discussion about dirty propagation,
http://forums.cgsociety.org/showthread.php?t=119449

07 March, 2010

compute Method and Dirty Bit

Working at the lower level functioning of Maya, is a very different experience as there are lots of obvious elements to consider. Basic rule of Maya is that a node is computed only if there is a need of new output from that node. So if there is no output attribute or if it's not connected  then the node is not computed. There has to be another node dependent on output of our node for Maya to call compute method of our node. And we have to explicitly mark a plug clean to tell maya that the output is latest.

edit:
Technically not entirely correct post. I will be posting a new elaborated post explaining this matter.

12 February, 2010

API: Node start and end functions

Following are what I call startup and ending functions that are called during some kind of (un)initializing process. I have also described at what event they are called in Maya.

-initializePlugin()
-uninitializePlugin()
-Constructor
-Destructor
-MPxNode::initialize()

Sequence in which these functions are called:

MPxNode::initialize()
When a node plugin is loaded this is the first function to be called.

initializePlugin()
After above function is called during loading of the plugin.

Constructor
When a node is created, e.g. using createNode.

Destructor
When node is deleted and it is not referenced by undo queue (imp).

uninitializePlugin()
When a node plugin is unloaded from Maya.