igo rov
2018-07-31 07:53:19 UTC
Hi,
I utilized the MMeshintersector.getClosestPoint() to get closest point on
a cube. my problem is, that I can`t make use of it (e.g. set the world
position of a locator) because its in local space.
- MMeshIntersector.getClosestPoint gives me a MPointOnMesh
- MPointOnMesh.point gives me a MFloatPoint
I have less knowledge of Matrix, I guess if i would have a child matrix I
could multiply with the parent. Her is the full code:
import maya.api.OpenMaya as om2
selList = om2.MGlobal.getActiveSelectionList()
dag = selList.getDagPath(0)
matr = dag.inclusiveMatrix()
mesh = dag.child(0)
meshIntersect = om2.MMeshIntersector()
meshIntersect.create(mesh) # documentation says, mesh and matrix as
parametres, ...
# but matrix throws me an error, without Matrix
it works I guess
selLoc = om2.MSelectionList()
selLoc.add("locator1")
dagLoc = selLoc.getDagPath(0)
trLoc = om2.MFnTransform(dagLoc)
vec = trLoc.translation(4)
point = om2.MPoint(vec)
pOnMesh = meshIntersect.getClosestPoint(point,1000)
pos3d = pOnMesh.point #this gives the local translation of the mesh`s
transform as MFloatPoint()
# the following is kind of a mess... trying to get the world position of
the point in object space. But it gives me wrong results
XVal = pos3d.x
YVal = pos3d.y
ZVal = pos3d.z
childMatr = om2.MMatrix()
childMatr.setToIdentity()
childMatr.setElement(3,0,XVal)
childMatr.setElement(3,1,YVal)
childMatr.setElement(3,2,ZVal)
worldM = childMatr * matr
targetX = worldM.getElement(3,0)
targetY = worldM.getElement(3,1)
targetZ = worldM.getElement(3,2)
newVec = om2.MVector(targetX, targetY, targetZ)
selLoc2 = om2.MSelectionList()
selLoc2.add("locator2")
dagLoc2 = selLoc2.getDagPath(0)
trLoc2 = om2.MFnTransform(dagLoc2)
trLoc2.setTranslation(newVec, 4)
I utilized the MMeshintersector.getClosestPoint() to get closest point on
a cube. my problem is, that I can`t make use of it (e.g. set the world
position of a locator) because its in local space.
- MMeshIntersector.getClosestPoint gives me a MPointOnMesh
- MPointOnMesh.point gives me a MFloatPoint
I have less knowledge of Matrix, I guess if i would have a child matrix I
could multiply with the parent. Her is the full code:
import maya.api.OpenMaya as om2
selList = om2.MGlobal.getActiveSelectionList()
dag = selList.getDagPath(0)
matr = dag.inclusiveMatrix()
mesh = dag.child(0)
meshIntersect = om2.MMeshIntersector()
meshIntersect.create(mesh) # documentation says, mesh and matrix as
parametres, ...
# but matrix throws me an error, without Matrix
it works I guess
selLoc = om2.MSelectionList()
selLoc.add("locator1")
dagLoc = selLoc.getDagPath(0)
trLoc = om2.MFnTransform(dagLoc)
vec = trLoc.translation(4)
point = om2.MPoint(vec)
pOnMesh = meshIntersect.getClosestPoint(point,1000)
pos3d = pOnMesh.point #this gives the local translation of the mesh`s
transform as MFloatPoint()
# the following is kind of a mess... trying to get the world position of
the point in object space. But it gives me wrong results
XVal = pos3d.x
YVal = pos3d.y
ZVal = pos3d.z
childMatr = om2.MMatrix()
childMatr.setToIdentity()
childMatr.setElement(3,0,XVal)
childMatr.setElement(3,1,YVal)
childMatr.setElement(3,2,ZVal)
worldM = childMatr * matr
targetX = worldM.getElement(3,0)
targetY = worldM.getElement(3,1)
targetZ = worldM.getElement(3,2)
newVec = om2.MVector(targetX, targetY, targetZ)
selLoc2 = om2.MSelectionList()
selLoc2.add("locator2")
dagLoc2 = selLoc2.getDagPath(0)
trLoc2 = om2.MFnTransform(dagLoc2)
trLoc2.setTranslation(newVec, 4)
--
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/405bdeae-e71d-43bd-a1f9-442ccbf5e586%40googlegroups.com.
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/405bdeae-e71d-43bd-a1f9-442ccbf5e586%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.