Discussion:
[Maya-Python] Find the closest point on mesh
illunara
2014-12-04 12:10:36 UTC
Permalink
Hi everybody
Maya already had closestPointOnMesh node to do it, but i don't know how it
working from inside. Any chance to read the source of this node?

Anyway, i try to write one using openMaya, but its not working either, here
is the code. Please tell me where it goes wrong. Thanks

https://gist.github.com/illunara/4a456d1407f9f60a1089
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/56641ac5-2e10-41b1-940b-5b8edc16614c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Eduardo Grana
2014-12-04 16:29:27 UTC
Permalink
Hello Illunara,

Haven't done this for a while, but i remember using
from MFnMesh the getClosestPoint function instead,
not sure if this is what you are after...

MStatus
<http://docs.autodesk.com/MAYAUL/2013/ENU/Maya-API-Documentation/cpp_ref/class_m_status.html>
getClosestPoint(const MPoint
<http://docs.autodesk.com/MAYAUL/2013/ENU/Maya-API-Documentation/cpp_ref/class_m_point.html>
& toThisPoint,MPoint
<http://docs.autodesk.com/MAYAUL/2013/ENU/Maya-API-Documentation/cpp_ref/class_m_point.html>
& theClosestPoint,MSpace::Space
<http://docs.autodesk.com/MAYAUL/2013/ENU/Maya-API-Documentation/cpp_ref/class_m_space.html#ab11a1dda34491acff014ddfc9e6bafb8>
space = MSpace::kObject,int * closestPolygon = NULL )const

I cant find the code where i used it,
I'll keep looking...
Cheers,
Eduardo
Post by illunara
Hi everybody
Maya already had closestPointOnMesh node to do it, but i don't know how it
working from inside. Any chance to read the source of this node?
Anyway, i try to write one using openMaya, but its not working either,
here is the code. Please tell me where it goes wrong. Thanks
https://gist.github.com/illunara/4a456d1407f9f60a1089
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/56641ac5-2e10-41b1-940b-5b8edc16614c%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/56641ac5-2e10-41b1-940b-5b8edc16614c%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
Eduardo Graña
www.eduardograna.com.ar
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACt6GrmGmY%2Bdzeao0RF64knLJsM7_Knr_6wgVP3Zja1j%2BfzLaw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Tuan Nguyen
2014-12-04 17:45:03 UTC
Permalink
Hi Graña
I tried, and fail too. The result is on mesh's surface, but clearly not the
closest point :(
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMCvD%2BEazGE%2BFsSGfZiDZVjM5v3SZ-cFS9p%3D_bpQhzj8B5XS2Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Eduardo Grana
2014-12-04 18:31:16 UTC
Permalink
Hello,
I've made this simple test,

http://pastebin.com/6xtHkt7t

Hope its usefull, otherwise let me know.
Be aware that is with python api 2.0, and you cant mix it with regular
python api. I used it to avoid the pointers that are a little bit messy...
Cheers,
Eduardo
Post by Tuan Nguyen
Hi Graña
I tried, and fail too. The result is on mesh's surface, but clearly not
the closest point :(
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAMCvD%2BEazGE%2BFsSGfZiDZVjM5v3SZ-cFS9p%3D_bpQhzj8B5XS2Q%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAMCvD%2BEazGE%2BFsSGfZiDZVjM5v3SZ-cFS9p%3D_bpQhzj8B5XS2Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
Eduardo Graña
www.eduardograna.com.ar
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACt6GrkQhWFOWG3EjDqojzCmpM5OBT_gwKPMZHp9FVFSZapDYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Tuan Nguyen
2014-12-04 19:04:33 UTC
Permalink
First of all, it works, thanks a lots, and for telling me about python api
2 too :D

Just a little confuse about MSpace, i used MSpace::kObject, but lately,it
got multiply with mesh's matrix, so they should be identical, right?
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMCvD%2BFOc2M9F5qoHaUW4zjMp91gqGM98-21FvAOA2XOd7DS9w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Chad Vernon
2014-12-04 20:35:22 UTC
Permalink
If you are calculating many closest points, you should use MMeshIntersector
as it will be a lot faster.
Post by Tuan Nguyen
First of all, it works, thanks a lots, and for telling me about python api
2 too :D
Just a little confuse about MSpace, i used MSpace::kObject, but lately,it
got multiply with mesh's matrix, so they should be identical, right?
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5c3bb376-8a45-4932-8a81-4f208f1af8bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tuan Nguyen
2014-12-04 20:56:12 UTC
Permalink
Hi Chad
I attach the code using MMeshIntersector in the first post, but the result
gone wrong :(
can you take a quick look at it please?
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMCvD%2BHAJxUmYgfHBWv4ED7PwU6BXUAGA5wZFoPZKby4c20-aA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Chad Vernon
2014-12-04 23:40:23 UTC
Permalink
You're passing in the wrong matrix. You don't want the inverse you just
want the inclusive matrix :


mat = meshPath.inclusiveMatrix()
resultPoint = om.MPoint()
polyIntersect = om.MMeshIntersector()
polyIntersect.create(shape, mat)
ptON = om.MPointOnMesh()
polyIntersect.getClosestPoint(pt, ptON);
resultPoint = om.MPoint(ptON.getPoint().x, ptON.getPoint().y, ptON.getPoint().z)
Post by Tuan Nguyen
Hi Chad
I attach the code using MMeshIntersector in the first post, but the result
gone wrong :(
can you take a quick look at it please?
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/68f88735-8cb6-44db-8655-f93d7aff80a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tuan Nguyen
2014-12-05 04:42:13 UTC
Permalink
Thank Chad, it works beautifully :D
Post by Chad Vernon
You're passing in the wrong matrix. You don't want the inverse you just
mat = meshPath.inclusiveMatrix()
resultPoint = om.MPoint()
polyIntersect = om.MMeshIntersector()
polyIntersect.create(shape, mat)
ptON = om.MPointOnMesh()
polyIntersect.getClosestPoint(pt, ptON);
resultPoint = om.MPoint(ptON.getPoint().x, ptON.getPoint().y, ptON.getPoint().z)
Post by Tuan Nguyen
Hi Chad
I attach the code using MMeshIntersector in the first post, but the
result gone wrong :(
can you take a quick look at it please?
--
You received this message because you are subscribed to a topic in the
Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/python_inside_maya/EznnAtM0Hgw/unsubscribe
.
To unsubscribe from this group and all its topics, send an email to
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/68f88735-8cb6-44db-8655-f93d7aff80a1%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/68f88735-8cb6-44db-8655-f93d7aff80a1%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMCvD%2BHFJvbAXLJ_zGFRmr%3DUXEyh1p4FTuhvPxrtuYy2A60f5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
igo rov
2018-07-30 21:52:29 UTC
Permalink
Hi , I know its a old post...but how to you get the world position of the
point which is MFloatPoint, 3d Point in objects space?
Post by Tuan Nguyen
Thank Chad, it works beautifully :D
Post by Chad Vernon
You're passing in the wrong matrix. You don't want the inverse you just
mat = meshPath.inclusiveMatrix()
resultPoint = om.MPoint()
polyIntersect = om.MMeshIntersector()
polyIntersect.create(shape, mat)
ptON = om.MPointOnMesh()
polyIntersect.getClosestPoint(pt, ptON);
resultPoint = om.MPoint(ptON.getPoint().x, ptON.getPoint().y, ptON.getPoint().z)
Post by Tuan Nguyen
Hi Chad
I attach the code using MMeshIntersector in the first post, but the
result gone wrong :(
can you take a quick look at it please?
--
You received this message because you are subscribed to a topic in the
Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/python_inside_maya/EznnAtM0Hgw/unsubscribe
.
To unsubscribe from this group and all its topics, send an email to
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/68f88735-8cb6-44db-8655-f93d7aff80a1%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/68f88735-8cb6-44db-8655-f93d7aff80a1%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0de6a80f-a472-4acc-9970-1d2a92924bc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Eduardo Grana
2014-12-04 21:30:34 UTC
Permalink
Yes, it should be the same, although I don't know how MMeshIntersector
handles spaces.
Post by Tuan Nguyen
First of all, it works, thanks a lots, and for telling me about python api
2 too :D
Just a little confuse about MSpace, i used MSpace::kObject, but lately,it
got multiply with mesh's matrix, so they should be identical, right?
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAMCvD%2BFOc2M9F5qoHaUW4zjMp91gqGM98-21FvAOA2XOd7DS9w%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAMCvD%2BFOc2M9F5qoHaUW4zjMp91gqGM98-21FvAOA2XOd7DS9w%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
Eduardo Graña
www.eduardograna.com.ar
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACt6Grk4WSqEnWcN_YN2s%2BsgcdG-aFgxBenFos0akXdY66Bu1Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...