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 + "
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…