Project Locator away from camera until it Hits something?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 01 January 2008   #1
Project Locator away from camera until it Hits something?

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).
Thanks
Christian
__________________
 
Old 01 January 2008   #2
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[3], float $end[3])
 {
    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) )
 		   return 1;
 	  }
 
 	  print ("intersects " + $object + "\n");
 	  return 1;
    }
    return 0;
 }


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....


MGlobal::selectFromScreen(x_cam_space,y_cam_space)  ;
MSelectionList sl;
MGlobal::getActiveSelectionList(sl);

for(int i=0;i!=sl.length();++i)
{ 
   MDagPath path;
   sl.getDagPath(path); 
   if(path.node().apiType() == MFn::kMesh)
   { 
	 MFnMesh fn(path);

	 fn.closestIntersection( /*some params */ );
   }   
}


which is significantly easier than with mel...

Last edited by Robert Bateman : 01 January 2008 at 12:49 PM.
 
Old 01 January 2008   #3
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!
Christian
__________________
 
Old 01 January 2008   #4
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....
 
Old 01 January 2008   #5
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:12 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.