I’ve been beating my head against the wall trying to use artUserPaintCtx for a custom Vert Painting tool, it’s just WAY overloaded and tied to internal Maya UI to use. All I need for the script is the world position of the mouse projected on the a surface.
draggerContext is almost there but it doesn’t project to a surface
Any thoughts?
Find mouse world position on surface?
I did something like this, but used the API. Not sure if this is transferrable to your situation but I basically:
- Captured a mouse click event within a Context command
- Ran a MGlobal::selectFromScreen on the mouse coords generated by the event
- Used M3dView::active3dView().viewToWorld to convert 2D screen coords to 3D world coords
This returns source and direction vectors - ran a MFnMesh.closestIntersection() using my vectors
- Grabbed the hitPoint generated by this method to get final 3D pos (remember to use MDistance::internalToUI() )
Alternatively, there are 3rd-party plugins available that give you a simple MEL raytracer
getting the projected click point on a surface (rayIntersect) for a vertex painting function seems like a little overkill, but if that is indeed what you’re ultimately after do a search here on this forum for rayIntersect. You should find several posts describing similar usage and techniques to what you’re suggesting, as well as links to the mll plugins, the C++ source code, python API examples and even a MEL version.
:nathaN
awesome! thanks guys, I did run across spPaint3d by Sebastien Paviot on creativecrash(highend3d) which is a raycasting object placement tool implemented in py using the api, have been looking through it and I think I get the flow. I’m curious though Nathan, what would you suggest other then raycasting?
well I guess it depends on exactly what you want to do… if you want a specific clicked point on a mesh then there is nothing better than rayIntersecting, but if what you want is actually a tool that gives you verts via some kind of paint selection method then artUserPaintCtx is probably the best approach. I agree though it is a bit finiky to use, but the advantages are that it allows use of the brush sizing controls. Using rayIntersect (the eqivalent of a laser-pointer
) to select lots of verts might be pretty annoying in practice…
What probs specifically did you find with artUserPaintCtx? I’ve done a tool using it and I remember it being a bit tricky in parts (don’t remember why) but it does work. Maybe I’ll post it on my blog as an example…
:nathaN
right on.
My idea was to revise the way the brush finds verts, so commands called once for every vert found by artUserPaintCtx was frustrating.
I did initially setup the tool using artUserPaintCtx, which was great to help proof the concept, but needed to modify the UI and/or integrate call backs from the brush controls, etc, which I also found frustrating.
Again thanks for the rayIntersect tip, seems like a popular topic here, knowing what to search for is apparently 99% of the battle:)
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.