View Full Version : help with nearestPointOnMesh

11 November 2010, 04:23 AM
I'm trying to figure out nearestPointOnMesh.

I want to measure the distance between the transform, or center, of a cube, and the "nearest point" on a sphere. I have set this up as I think it's supposed to be. I am not sure if my results are correct or not. The fact that I don't know what i am looking for may be the problem.

I have connected my sphereShape.outMesh to nearestPointOnMesh.inMesh
and the cube.transform to nearestPointOnMesh.inPosition

The output result I think I am looking for is nearestPointOnMesh.position, which gives me:
[(0.33543354272842407, 0.87489151954650879, 0.33543354272842407)]

In the scene I created a measure tool that measures from the cube center to where I assume would be the nearest point on the sphere mesh.

I *think* what the .position should give me is the displacement, in 3D units, between these two points. Am I right? So 0.87489151954650879 would be the displacement in Y between the points. Whereas if I measure the distance between my locators in Y (from the measure tool) I get approximately 0.300

What am I doing wrong, or misunderstanding?

import maya.cmds as mc
mc.createNode('nearestPointOnMesh', name = 'npom1')
mc.connectAttr('sgShape.outMesh', 'npom1.inMesh', f =True)
mc.connectAttr('cube.translate', 'npom1.inPosition', f =True)
mc.distanceDimension(sp= (0.5,1.25,0.5), ep= (0.25,.95,.25))

print('nearestPointOnMesh.position is: ' + str(mc.getAttr('npom1.position')))

Thanks for reading this!!!

11 November 2010, 10:57 AM
The clue is in the name: .POSITION and also in the funtion name nearestPointOnMesh. The data you are getting back is the 3d coordinate that is the closest point on the mesh to your source point. This could be local or world space I don't know, but the node docs for this node should tell you all this stuff.


11 November 2010, 12:02 PM
Thanks Nathan,

That makes total sense now.

CGTalk Moderation
11 November 2010, 12:02 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.