PDA

View Full Version : MEL/Python Ray casting or sampling zbuffer?


jwvanderbeck
10-27-2011, 08:46 PM
Hey everyone,

I am hoping someone can help me. I've been doing some tool development in Maya using Python. Most of the work I have had to do up until now has essentially been building expressions and some custom UIs.

However now I need to dig deeper into whatever data I can grab from Maya. Essentially what I need to do is cast rays from a camera out to the scene in order to determine the distance from camera of the geometry that is visible to the camera. In a nutshell I need to determine what the nearest visible point is from the camera and what the farthest visible point is from the camera.

Unfortunately I don't even know where to start. This type of information doesn't seem readily accessible to MELScript or Python.

NaughtyNathan
10-27-2011, 09:48 PM
if you do actually need to do Ray Casting there are several existing ways to do it, all of which have been discussed here before; pure maths (MEL), mll plugin and python API class calls. Just do a search here on this forum for "rayIntersect". This sounds like it may not be a hugely efficient way of finding the closest point to the camera view though, as you'd have to fire off a lot of rays.. depends on how accurate you want it I guess. are you just checking for mesh geometry? becasue there's also the nearestPointOnMesh/closestPointOnMesh plug-in command. Which one depends on your version of Maya, and I think they may be API example plug-ins, but they come with Bonus Tools I think...?

:nathaN

jwvanderbeck
10-28-2011, 01:11 PM
if you do actually need to do Ray Casting there are several existing ways to do it, all of which have been discussed here before; pure maths (MEL), mll plugin and python API class calls. Just do a search here on this forum for "rayIntersect". This sounds like it may not be a hugely efficient way of finding the closest point to the camera view though, as you'd have to fire off a lot of rays.. depends on how accurate you want it I guess. are you just checking for mesh geometry? becasue there's also the nearestPointOnMesh/closestPointOnMesh plug-in command. Which one depends on your version of Maya, and I think they may be API example plug-ins, but they come with Bonus Tools I think...?

:nathaN

Thanks for the reply Nathan. I had physically looked through every page listed, because I wasn't quite sure how to search (ray casting gave me everything with mental ray for example). Apparently though, searching reveals MORE threads than show up normally which is interesting.

Anyways, yes ray casting may not be the best way of doing things. I'm just trying to wrap my head around the requirement and figure out what my options are in Maya from Python.

I have a custom camera that simply needs to be able to determine the closest point to the camera and the farthest point from the camera, as seen through the camera. This is required for some custom calculations. The geometry in the scene could be anything though, so I can't say it will always be polygons, or nurbs, or whatever. Just whatever is in the scene, but excluding some specific objects that the camera itself actually draws as visual aids.

Does that make sense?

earlyworm
10-28-2011, 02:13 PM
Does the viewClipPlane command do what you want?

It has an -autoClipPlane flag which sets the near and far clipping planes according to what geometry is visible in the camera view.

If you wanted to create your own version of viewClipPlane to just return the min and max depth values I'd say it's calculating the min and max depth by measuring the distance to the bounding box values of the objects within the frustum - be quicker than going over all the vertices or surface points in the view.

jwvanderbeck
10-28-2011, 02:45 PM
Does the viewClipPlane command do what you want?

It has an -autoClipPlane flag which sets the near and far clipping planes according to what geometry is visible in the camera view.

If you wanted to create your own version of viewClipPlane to just return the min and max depth values I'd say it's calculating the min and max depth by measuring the distance to the bounding box values of the objects within the frustum - be quicker than going over all the vertices or surface points in the view.

The problem with using the clipping planes as I understand it is that it will indicate the min and max inside the frustum with no regard for what is actually visible. For example if I have a scene of a house interior and exterior, and the camera is inside the house, the clipping plane will indicate extents that include outside the house, even if the camera is looking at a solid wall and thus nothing past it is actually visible to the camera.

If I am not understanding that properly, then please let me know :)

CGTalk Moderation
10-28-2011, 02:45 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.