misterwolfy

11-11-2010, 03: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.

http://www.mrwolfy.com/images2/npomScene1.png

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

http://www.mrwolfy.com/images2/npomScene2.png

What am I doing wrong, or misunderstanding?

import maya.cmds as mc

mc.polyCube(name='cube')

mc.move(0.5,1.25,0.5)

mc.polySphere(name='sg')

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))

mc.select(cl=True)

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

Thanks for reading this!!!

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.

http://www.mrwolfy.com/images2/npomScene1.png

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

http://www.mrwolfy.com/images2/npomScene2.png

What am I doing wrong, or misunderstanding?

import maya.cmds as mc

mc.polyCube(name='cube')

mc.move(0.5,1.25,0.5)

mc.polySphere(name='sg')

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))

mc.select(cl=True)

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

Thanks for reading this!!!