View Full Version : Project Locator away from camera until it Hits something?
01-22-2008, 10:47 AM
Hey, this is a little out of my depth to start scripting without some serious research...
I have some locators with XY info parented to my camera (2D points) I want to project these away from camera until they hit a polygon mesh. They should not appear to move looking through the camera, so keeping their XY coordinate. But in persp they'll all be at different Z depths...
Having a quick think about it, I would probably approach it by something like point on surface node, then using some trig get it's right XY etc...
But, if any of you have a better idea, please let me know (this must be scriptable).
01-22-2008, 12:36 PM
probably better off first running an intersection test against the bounding boxes of the objects in the scene first, and then using the more complex methods to locate the exact position. Since this test can be hierarchical, you only need to test the root transforms, and then recurse through their children. Basically you'd be doing a very efficient hierarchical culling on the scene... (look up OABB trees, and AABB trees for more info on why this is a good idea ;)) i.e.
proc int testForIntersect(string $object,float $start, float $end)
if $object is intersected by the line between $start and $end
// we know we have an intersect, so test any meshes this node has...
// but we might also find that a child node has an intersect as well...
$kids = `listRelatives -c $objects`;
for($k in $kids)
if( testForIntersect($k,$start,$end) )
print ("intersects " + $object + "\n");
It's a shame you can't use the Maya API really. In the api you can pass it a screen coordinate in (x,y) and it will select any objects it hits (MGlobal::selectFromScreen()) - which basically is doing what the code does above....
A quick depth test, then usage of the MMeshIntersector or MFnMesh class and you'd be more or less done.
basically you'd only need something like this....
if(path.node().apiType() == MFn::kMesh)
fn.closestIntersection( /*some params */ );
which is significantly easier than with mel...
01-22-2008, 01:20 PM
EEEEEk, thats complicated :)
I would love to learn the API, I plan on getting into Python soon, but I just don't have enough time to devote to this at the moment!
I'll try and figure out this in mel using your example and let you know how I did!
Thanks for the help!
01-22-2008, 03:58 PM
the mel psuedo code is very rough around the edges, and has a lot of gaps that would need to be filled (with some relatively complex maths). The API code on the other hand just needs a bit of additional boiler-plate code. I'd just go moan at one of your td's until it gets done....
01-22-2008, 03:58 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.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.