Mouse Over Mesh with Python ?

Hi,

How could I calculate if the mouse button is pressed over the mesh in 3DView ?

The script is ran every time the refresh is done, and always the first commad is Blender.Windows.CameraView(0), which sets the view point to the active camera.

There will be few button kind of mesh objects in the camera view which I would like to use to make some functionality through python scripting.

I think I could use all those View Matrices to calculate the mouse over object thingie, but at the moment my math skills are not that good I could do that. If somebody has some nice easy way, or ready script I would appreciate a lot for those :slight_smile:

Thank you very much,
-Mika

Hmm, this could be done directly from the script, but it requires a bit of work.
You need to project polygons of the object on an imaginary x-y plane that matches what you see on screen, and then determine if the x-y coordinates of the mouse fall within or without the mesh border you are examining. Also you need to check statring from the mesh closest to the camera/viewer to end with the furthest. The hard part here is that you need to determine if a point falls within or without the borders of a triangle. Also, if you have several faces and/or several meshes this could be incredibly slow. The best way would be to check against the mesh bounding boxes first, and if the hit is positive confirm this by checking against the triangles that compose each single face. That’s a lot of mathematics, anyone up for the challenge?

What is it exactly you try to accomplish ? If you just want to have interactive buttons in the 3d view, you should really just draw them in 2d on top of the view. Check the MakeHuman interface script to see how it is done.

Or does your idea depend on the buttons being actual meshes ? If so, how complex are these meshes and how many are there ? If the total face count of the meshes isn’t too big I could write up a quick and dirty script for you…


Don’t feed your ego, feed the duckies…