PDA

View Full Version : API Custom Node creation


dbsmith
08-31-2006, 10:10 PM
Okay, I want to build my own node that stores some custom data. Essentially I have a File Translator that imports my own file format (essentially vertex data for a mesh). Now I want to store this data as my own custom struct inside a Maya node.

So when I import my file format, I get the plugin to create my node, but how do I give that node my custom data? The node should hold this data internally and it shouldn't change, so I'd like to give the node the data upon its creation, rather than through an input connection. Im guessing that I couldn't really get it as an input connection anyway since its my own data format and nothing Maya knows about.

So how do I give my node custom data on creation? By putting parameters on its creation() method? If I do that, I get compilation errors registering my node
eg

status = plugin.registerNode( "CustomDataNode", CustomDataNode::id,

CustomDataNode::creator(CustomDataStruct cds), CustomDataNode::initialize );

where my node creator method is something like:

void* CustomDataNode::creator(CustomDataStruct cds)

{

//Make cds a private variable of node...
...

return new CustomDataNode();
}

dbsmith
08-31-2006, 10:25 PM
Upon further research, it looks like I may have to create my own data class, derived from MPxData, which is fine(?). But still the question remains how I get this data into the node...

Robert Bateman
09-01-2006, 09:50 AM
I think you want MPxNode tbh, MPxData is only used to pass data between attributes in the DG, and example would be connections to outMesh and outNurbs attributes. Basically though, in theory you can store data in your own format internally within a node, but it has to talk to maya correctly. The best way, is to add an output typed attribute that can output a mesh. Within your compute you will have to copy this data into a mesh structure and return it via a connection. You'd then have to connect that output attr to a mesh node to display and render it.

Alternatively, you could use MPxSurfaceShape, or - do what i think is probably the best solution - just put the data into a normal mesh node......

To actually fill an MPxNode derived class, look for MFnDepenencyNode::userNode() and cast to the correct type. But yeah, MPxData isn't what you want.

dbsmith
09-03-2006, 10:48 PM
Thanks Rob, you are a god!
That worked great (using userNode() and casting to my own Node type)
It still seems a bit strange to me, I mean on one hand Maya wants input data to only come in from other DG nodes and be stored internally, but surely there are circumstances like mine where data comes in from another source and should be stored internally in the DG node upon its creation. In other words, I find it strange that Maya hasnt made support for node creation with parameters (perhaps with strong warnings about the way it should be used)? As long as this data is input ONCE upon creation, and stays there inside the node to be used as a constant value, I don't see too much of a problem. Perhaps they are just playing it safe.
Agree/disagree?

Robert Bateman
09-04-2006, 03:38 AM
put simply, if you want to store data internally within the DG, then since maya owns the DG (not you, or your plugin), you have to pass responsibility of that data to Maya (ie, store in it's attributes that Maya can interpret). You can use your proxy class (MPx nodes) to store your own data, but maya will not be able to communicate with that data (ergo, createNode would never know how to set it - if it did, you would have even more restrictions that Maya currently has - take a look at the max SDK if you want to see how grim that can be). A custom mel command can still access your proxy data (via userNode), since Maya assumes that if it is your proxy, and it is your command, you alone know how to safely handle the data.

At the end of the day, creation with parameters is supported in maya - but only with your own custom commands. Take any geometry primitive in Maya - the mel command not only handles the parameters and creation of the nodes (polyCube -> mesh; parented under a transform), but also handles undo and redo etc.

Generally speaking though, you don't often want data that gets created and never modified being stored internally in your own nodes - Maya cannot actually save or load that data with the Maya Ascii/Binary files. Ideally, try to get the data to be re-producable in some way from one or more input attributes to the node. The inputs will after all be saved to the files, and your internal data can be re-loaded. In your case though, since you are importing vertex data - i'd still suggest that writing an MPxFileTranslator that either creates a mesh or your own node (and stores stuff as attributes) would be the best way of doing this.....

dbsmith
09-14-2006, 11:17 PM
OK I have a big problem and am pretty confused.

Well heres my setup:
I have a MPxFileTranslator that loads in custom mesh data from an external file. This is stored in a custom struct format, the main bulk of it in an unsigned short*. The file translator then creates a custom node (which extends MPxNode)

//structData = getStructDataFromFile(filename);

MObject tempNodeObj = depNodeFn.create("HeightFieldNode");
customNode *myNode = (customNode*)( MFnDependencyNode(tempNodeObj).userNode() );

myNode->initData(structData);


initData then copies the data passed in as a parameter to a local struct defined inside my customNode.


The node uses this stored data to output a geometry mesh at different detail levels depending on a slider attribute. I really want this data to be stored ONCE inside a node so I can access it on the fly in Maya without having to re-import it in from a file every time i use it.

So if I import one mesh, it creates a customNode attached to a polygon mesh and everything works great.
If I import another mesh, it creates a second customNode attached to a separate polygon mesh and everything works great. There are no connections between the two different networks.

However, as soon as I modify the detail slider of one of these nodes, it somehow gets data form the other node and uses that instead. So different instances of the node are somehow sharing data.

I know there is something wrong with my fundamental understanding of instances of nodes and their data, can anyone shed some light on
A) why is this behaviour occuring and
B) how I can work around it.

dbsmith
09-19-2006, 09:14 PM
Anyone???????

CGTalk Moderation
09-19-2006, 09:14 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.