PDA

View Full Version : Maya API: share an object between nodes (with pointer)


sleepyfox
04-15-2009, 03:52 PM
hi,

without having tried it (maybe I'm saving myself a lot of trouble and time). Has anybody tried to share an object with another node over a pointer or some kind of reference?

I have a MPxLocaterNode which holds some attributes and a non-maya object (array of floats - just some random vertex data). This pointarray get rendered to the viewport through some openGL calls by the draw() method of the MPxLocaterNode.

My question is: Is it possible to separate the rendering function and the data and share the vertex data between them?

I'd like to use the MPxLocaterNode just for the drawing purpose and use a MPxNode otherwise (for attributes and vertex data) without the need of copying the data. Can I pass the pointer of the non-maya object (in MPxNode) to another node (MPxLocatorNode)?

I can't pass it to the other node as an attribute (because it isn't an attribtue).

thanks

alex

Robert Bateman
04-15-2009, 04:29 PM
My question is: Is it possible to separate the rendering function and the data and share the vertex data between them?

Assuming the data is identical on each locator instance, you could just make the array static.


I'd like to use the MPxLocaterNode just for the drawing purpose and use a MPxNode otherwise (for attributes and vertex data) without the need of copying the data.

Why not just use 1 locator node?


Can I pass the pointer of the non-maya object (in MPxNode) to another node (MPxLocatorNode)?


You can do it, but don't be surprised to find it crash occasionally.

sleepyfox
04-15-2009, 05:11 PM
thanks for the quick answer:



Originally Posted by sleepyfox
My question is: Is it possible to separate the rendering function and the data and share the vertex data between them?

Assuming the data is identical on each locator instance, you could just make the array static.


Unfortunately it has to be dynamic due to size, unknown elements, threading etc. :-(




Originally Posted by sleepyfox
I'd like to use the MPxLocaterNode just for the drawing purpose and use a MPxNode otherwise (for attributes and vertex data) without the need of copying the data.

Why not just use 1 locator node?


I'm not sure if this won't lead to any problems later on. I want to be able to delete the display of the data in the viewport (the MPxLocatorNode) without deleting the data. I like the idea of having separate objects for special purposes instead one i-can-do-all node... but I think that's the only failsafe solution



Originally Posted by sleepyfox
Can I pass the pointer of the non-maya object (in MPxNode) to another node (MPxLocatorNode)?
You can do it, but don't be surprised to find it crash occasionally.


just for my understanding (I'm pretty new to the maya api):

I thought of the nodes as separate objects, without any reference to each other besides attributes and their connections.
How can I exchange data between them without the attribute-connection-thing (is there some dagNode.gimmePointer() method)?
Or do I have to delcare them as kind of global pointer in my plugins main module?

thanks a lot!

kind regards

alex

Robert Bateman
04-15-2009, 05:35 PM
Unfortunately it has to be dynamic due to size, unknown elements, threading etc. :-(

Then it must not be shared, and must be separate for each instance of the node.


I'm not sure if this won't lead to any problems later on. I want to be able to delete the display of the data in the viewport (the MPxLocatorNode) without deleting the data. I like the idea of having separate objects for special purposes instead one i-can-do-all node... but I think that's the only failsafe solution

visibility flag won't do then? Not sure why you are so against using attribute connections to be honest. It does exactly what you want (i.e. prevents the data being duplicated).


I thought of the nodes as separate objects, without any reference to each other besides attributes and their connections.

yup


How can I exchange data between them without the attribute-connection-thing (is there some dagNode.gimmePointer() method)?

The short answer is you can't, you must use attributes. The longer answer is that MFnDepencencyNode provides a pointer to the userNode which you can cast to your node type. However, for the ungodly abuse of the DG that you have in mind, it definitely is not a solution. Don't even go there. Just use an attribute connection.

CGTalk Moderation
04-15-2009, 05:35 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.