View Full Version : Visibility On if Mesh intersection is true

Yoann Lemoine
07 July 2007, 02:54 AM
hey everyone,
I have a sphere and a cube on my scene, i'd like the cube to be visible ONLY if the sphere intersects it, how should i proceed ? I want this to be checked out every frame of my animation, so that i can move the sphere around and if the mesh touches the cube, then the cube appears, then disapears if the sphere goes away.
I tried using an expression on pCube1.visibility, but i can't find anywhere the attribute or piece of code that returns 1 if the cube and sphere interpenetrate.

Any idea ?


07 July 2007, 03:33 AM
This would be alittle annoying, at least from what I know. It would need to find every face and see if they cross through. That takes of alot of proccessing power and time. If you need it to be exact, maybe someone else can help but I'd say just get the locations of both the cube and sphere and find the distance between them to determine weither it will be on or off.

You can do this with mag -

//distance between the sphere and cube to make the cube visible
float $maxDist=5;

vector $sphereLoc=`getAttr pSphere1.translate`;
vector $cubeLoc=`getAttr pCube1.translate`;

//finds the distance between the sphere and cube
float $magDistance=mag($sphereLoc-$cubeLoc);

if ($magDistance <= $maxDist){
setAttr pCube1.visibility 1;
setAttr pCube1.visibility 0;

I don't have maya open, can't test it, but it should work. You're $maxDist is the maximum distance away from each other that the visibility will still be on. If the distance is below that number will keep the cube visible.

edit - added comments in the code

Yoann Lemoine
07 July 2007, 03:49 AM
Hey thanx
Actually, i really need to calculate interpenetration, because my sphere will be deformed and i will have a bunch of cubes at the end, anyone have an idea ?
I don't think it's really complex, it's pretty easy for maya to know if two objects are intersecting (boolean operations, toon shading)... I thought there would have a simple function to detect this and return like a boolean, true or false

07 July 2007, 04:00 AM
You could always echo all commands and see what booleans does behind the scenes in the script editor. Make your script based off that.

07 July 2007, 12:14 PM
The simulation tools also know about collisions. You might look into using rigid body collisions to do the testing for you.

There was also a tutorial on the gnomon online site about spawning particles at the location that two objects intersect. You might check that out to see if it offers any insights.

Yoann Lemoine
07 July 2007, 12:12 AM
mmmh i tried to look at this but it doesnt seem to be what i need, i don't know dynamics very well though...
Anyone can help me ?

CGTalk Moderation
07 July 2007, 12:12 AM
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.