PDA

View Full Version : node to take locators as inputs


jhuangtw
03-28-2005, 06:23 AM
Hi all.
i'm trying to create some sort of a modifier node for polymesh, where it would take the inputs of multiple locators' world space as inputs, and based on them, recompute internal data and refresh the mesh.

i am having trouble trying to understand how to set it up so that the node is constantly watching these locators, and updating when the locators move.

also, the locators would be geometry-constrained to the mesh, and so far i dont have a clever way to find out which face of the polymesh the locator landed on. one (dumb) solution i thought of was to sort all the vertices and find the closest vert to the given locator position, then walk around the faces around the vert and find out which face the locator's position lie in. but that seems super inefficient to do on all locators. another possible way is maybe using the framebuffer somehow, where i could render the faceID into each pixel of the framebuffer, and then use the screenspace position of the locator to look up into the framebuffer and take the faceID. but i dont know how would be done in maya (set up and accessing the framebuffer) . i have a feeling that there should be a much easier way to do this (given worldspace, look up which face it lies in) with the maya API, could somebody point me in the right direction.

thank you for reading the long post, any help is deeply appreciated.
now i'm gonna go back and dig around the maya doc/devkit codes some more :)

playmesumch00ns
03-28-2005, 11:35 AM
For the inputs you'll need to use an array of compound attributes. These are just tuples of float attributes that can be grouped together, like a colour, or a position.

For doing the closest face calculation, i'd just do something like you suggested to start off with, to check the rest of the algorithm is working, then worry about optimizing it.

You could theoretically do the screen-space framebuffer thing. But what about faces on the back of the mesh? And what about aliasing?

Much better would be to use a data structure like a kd-tree to optimize your searching.

mummey
03-28-2005, 02:47 PM
hmmm... that username tooks familiar... ;)

jhuangtw
03-28-2005, 03:23 PM
mummey: wasup brian :P

playmesumch00ns: thanks for your reply, i didnt think about the aliasing/backface problem. i think for now i'll just use the more brute-force-ish approach to get the algorithm working first.

mummey
03-28-2005, 03:39 PM
Hi all.
i'm trying to create some sort of a modifier node for polymesh, where it would take the inputs of multiple locators' world space as inputs, and based on them, recompute internal data and refresh the mesh.

i am having trouble trying to understand how to set it up so that the node is constantly watching these locators, and updating when the locators move.

Look up the 'Observer' design pattern for possible ideas. This is an OO structure that refreshes when changes are made.

As for the rest of it, I don't know what Maya provides/restricts. Good luck figuring it out.

-b

playmesumch00ns
03-29-2005, 10:55 AM
You don't need to worry about handling updates since Maya's DAG will do that for you automatically.

If i remember correctly, Maya's MFnMesh class provides you with a closestPointOnMesh function, which is essentially what you want to write... beware that closestPointOnMesh is notoriously slow and buggy, but it should be enough to get you started while you get the rest of the plugin written, then you can replace it with your own optimized version later.

To be honest, the hardest part of this is probably going to be setting up and managing the connections between the mesh and you locators. Maya provides all the functionality you need to do that already, but it can be a pain in the arse to use sometimes. I'd concentrate on getting that part bulletproof first, then look at the closesPointOnMesh thing...

jhuangtw
03-29-2005, 05:38 PM
hi all, thanks for the suggestions. as suggested i'll look into the closestPointOnMesh function later. for now i'm reading up david gould's book again to try to figure out the array of compound attributes.

the life cycle of the node goes something like this:
- node created, it will modify a output mesh. no locator "hooked on" at this point
- command to create a new locator and the locator is hooked onto the node. the node takes the positions of the newly created locator and recomputes, then modify the output mesh accordingly.
- more locators are added/deleted as the session goes on.

i'm still not exactly sure how to do this yet. can i use MEL to create locators and plug their translate attributes into the node's array attribute, or should i also write a command plugin to create the locators and set up the attribute connections? i was thinking if i could use MEL because i have a mel GUI that would keep a scrolllist of these locators.

this is my first stab at the maya api, this is exciting stuff :) and thanks for all the helps, i really appreciate them.

CGTalk Moderation
03-29-2005, 05:38 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.