I haven't tested this code, but I think it should be a simple matter of 
multiplying the point by the mesh's transform. Something like:
node = om.MFnDagNode(dag)
nodeTransform = loc.transformationMatrix()
worldPos = pos3d * nodeTransform 


On Tuesday, 31 July 2018 17:53:19 UTC+10, igo rov wrote:
>
> 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)
>
>
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/4c11c70e-d13b-4931-9a21-ca1262cbd6f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to