PDA

View Full Version : How to find the objects touched by another


aghawa
10-05-2010, 04:31 PM
Hey guys, today I'm gonna ask you a fancy question:
let's say I have some cubes in a row and a sphere.
I animate the sphere to pass through those cubes, and I want to know when the sphere touches each cube, via MEL or Python (the latter preferably)
I know there is a way to do it with Fields, but I'd like to avoid that if possible. Any idea?

Thanks,
Aghawa

nessus
10-05-2010, 06:43 PM
I think this involves collision detection, and there is only one way to enable that in Maya that I know of is to use rigidbody, then the rigidbody object will have attributes such as .contactCount and .contractNames to indicate a collision with another rigidbody. I dont know if there is a way to detect this with regular objects (e.g. meshes) unless you implement your own collision detection logic?

jojanpm
10-06-2010, 04:02 AM
fine. but rigidBody method ll take much time wen object count is big. and it wont work properly in all cases; dont knw y!

uiron
10-06-2010, 07:01 AM
if it's just sphere and cubes, then you could go for this kind of algorithm - the "closestPoint" is not a most optimal solution in the case of these primitives, but:


for each cube: find closest distance D from sphere center to cube surface (using MMeshIntersector::getClosestPoint is the fastest way to do that); if D<=sphere radius = you got intersection with that cube.

spiderman3
11-04-2010, 05:19 AM
i think under MFnMesh there is a option called intersect which uses the rayIntersect methodt to see the objects intersect or not....

also if you want really lower level you can check the bounding box intersection this also comes under MFnMesh in maya api

bendingiscool
11-04-2010, 05:51 PM
The simplest would be to get the boundingBox (xform has a flag for this) info of each cube, then write an expression to get the sphere boundingBox each frame, then if it is within the cube, do your thing.


float $ballPos[] = `xform -q -bb pSphere1`;
float $cubePos[] = `xform -q -bb pCube1`;

if ($ballPos[2] > $cubePos[2] && $ballPos[5] < $cubePos[5]){
if ($ballPos[0] > $cubePos[0] && $ballPos[3] < $cubePos[3]){
print "inside";
}
}

cheers,
Chris

CGTalk Moderation
11-04-2010, 05:51 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.