Feedback

What's your question?

By: Asked from India

closestPointCmd

MMeshIntersector::getClosestPoint function gets closest point between a pointlight and a mesh. How is it possible to get closest distance between 2 mesh objects.

EDIT

string $closestPoint = eval("createNode nearestPointOnMesh -n cpom1"); 
connectAttr -f pPlane1.worldMesh ($closestPoint + ".inMesh"); 
connectAttr -f pSphere1.translateX cpom1.inPositionX; 
connectAttr -f pSphere1.translateY cpom1.inPositionY; 
connectAttr -f pSphere1.translateZ cpom1.inPositionZ; 
int $selectedFaces = getAttr cpom1.closestFaceIndex; 

this is half the solution. presume a sphere at (0,6,0) - "freeze transformed",now (0,0,0). and plane at (0,0,0). how is it possible to snap sphere to plane on the face index gotten by the above code.

Add comment viewed 193 times Latest activity 11 months ago

or Cancel

1 answer

  • 0

julian [ Admin ]

I'm not sure if there is anything in the maya API that will find the closest point between 2 meshes. If not you will need to test every triangle in one mesh against every triangle in the other mesh (theoretically). The code to get the closest point between two triangles is a little bit complex. Best to find a library with the function you need. There is a triangle-triangle closest distance function in WildMagic - scroll down to Wm5DistTriangle3Triangle3.h

And then you will want to optimize the number of tests somehow. One way to do this is to store all the triangles from one mesh in bounding boxes in a a kdTree. Then loop through the triangles of the other mesh querying the kdTree as you go. Again kdTree code is not trivial, but there are libraries you can use. Search for AABB kdTree (AABB means Axis Aligned Bounding Box).

What you are trying to sounds pretty similar to collision detection, so you might be able to use functions in a collision detection library and avoid the need to think about the search or the tests specifically. Have a look in the physics section of WildMagic or other libraries. You can find a lot of info about geometric tests and efficient data structures in this book It has lots of code on the CD, which you might also be able to find online.

NN comments
knishua
-

string \$closestPoint = eval(“createNode nearestPointOnMesh -n cpom1”);

connectAttr -f pPlane1.worldMesh (\$closestPoint + “.inMesh”);

connectAttr -f pSphere1.translateX cpom1.inPositionX; connectAttr -f pSphere1.translateY cpom1.inPositionY; connectAttr -f pSphere1.translateZ cpom1.inPositionZ;

int \$selectedFaces = getAttr cpom1.closestFaceIndex;

this is half the solution. presume a sphere at (0,6,0) – “freeze transformed”,now (0,0,0). and plane at (0,0,0). how is it possible to snap sphere to plane on the face index gotten by the above code.

julian
-

I’ll add this to the original Q for syntax hilighting.

or Cancel