PDA

View Full Version : getting the object under the mouse


AlanW1980
03-14-2007, 03:13 PM
Hi I need to be able to get the object directly under the mouse when a user clicks the mouse button. I don't want to select the object so this rules out a scriptCtx (AFAIK) because that requires you to select before the script executes.

So how do I get the script to execute when the button is pressed? I was thinking about a draggerCtx but I come back to the problem of actually figuring out what's under the mouse when it's clicked.

Is this going to be a case of getting into ray - mesh intersection coding and projecting my 2d mouse position as a ray into the scene and testing what it collides with first? Because that to me seems overkill... what does maya do to make a selection when you click? What code is run to select the object that it finds because that code is what I want just I want to change what happens before the object is selected....


A

tfall
03-21-2007, 08:53 PM
You can just restore the previous selection after you select what is under the mouse:

// Get the list of selected items
MGlobal::getActiveSelectionList(list);

// Select what is under the mouse
MGlobal::selectFromScreen( x1, y1, x2, y2, MGlobal::kReplaceList );

// Restore previous selection
MGlobal::setActiveSelectionList(list, MGlobal::kReplaceList);

- Terry

CGTalk Moderation
03-21-2007, 08:53 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.