PDA

View Full Version : how to find the inside of a object?


H3ro
04-02-2006, 12:30 PM
How can i find out if a object is inside an other one?

say I have a sphere and a Box and I want to make the box become visible only if it is inside the sphere

Thanks

tciny
04-02-2006, 02:17 PM
That depends... if you're just testing for spheres and boxes you could easily do that. But if it should work for any given mesh it's getting a lot more complicated.

Easiest case: Spheres. Just calculate the distance between the two and see if the distance + radius of the smaller sphere is smaller or equal than the bigger sphere's radius. If so, its inside.

So for what you were asking I'd say: represent the cube as a sphere (works well in this case. but only if its really a cube!) by measuing the distance from the center of the cube to any vertex. Then do the check as said above.

rokandic
04-02-2006, 03:03 PM
If you're only working with boxes and spheres then you can work distance and radius as tciny already wrote.

However for any shape things can be a bit messier. If you want to know for any given point whether it's inside another object you'll have to check objects nearest point/normal. Then check whether the normal is directing to point or away from it. If it's facing away you're inside provided all you objects normals are facing outwards.

-rok

H3ro
04-02-2006, 04:26 PM
I want to make it work for any given object. But, I am not sure on how to make it work.

Is there no pre-made comand to help user preform something like that?

tciny
04-02-2006, 05:01 PM
There unfortunately isnt.

The API provdes you with a closest point funtion (MFnMesh) that will also give you the normal. So you should be able to check for a vertex if its inside a mesh with like 4 loc...
If you want to check wether the entire mesh is occluded you'd have to perform that check for every single vertex. So its pretty costly to do.

What exactly are you trying to do? Maybe theres a different way that might be a lot easier in your case...

Bonedaddy
04-02-2006, 06:49 PM
From skimming it on the store shelf the other day, I beileve there's an example of how to do this in David Gould's second volume of working with the Maya API and C++. But it isn't easy.

tciny
04-02-2006, 06:56 PM
I was thinking about getting it but wasnt sure wether it'd actually cover stuff thats interesting for me. Do you know if theres more to it than just stuff about modeling tools?

rokandic
04-02-2006, 07:10 PM
If you want to check wether the entire mesh is occluded you'd have to perform that check for every single vertex. So its pretty costly to do.
Completely agree on this one. Especially if you have complex geometry to work with... might be a bit slow. For simple geometry it shouldn't be a problem though.

Luckily (if you're not used to writing plugins) you don't have to do any API for this (except compile/build closestPointOnMesh plugin that comes with Maya devkit if you're working with meshes). If you're working with NURBS you can use closestPointOnSurface and pointOnSurfaceInfo nodes to retrieve the normal. For mesh you only need the mentioned closestPointOnMesh node to get the normal.


David Gould wrote two books: Complete Maya Programming Vol. I and Vol. II, both highly recommended. The first one goes into both MEL and API in general but very well written. The second one goes more into transformations, matrices, how to work with meshes, NURBS,... in API in detail. If you wanna start learning Maya API I can definitely suggest Vol. I :thumbsup:

Cheers,
Rok

H3ro
04-02-2006, 07:48 PM
I dont know what i want to create, just wanted to try to write a script which say set viasbility of all objects inside the control object to zero.

But if this is really complicated, it is nothing for me:p

But an other question, how to i quary the number of vertexes in a object?
Edit : Sometimes it helps to search the forum, the polyEvaluate command was what i was looking for

CGTalk Moderation
04-02-2006, 07:48 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.