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)
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4c11c70e-d13b-4931-9a21-ca1262cbd6f7%40googlegroups.com.--
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/zGdhBD6SuUE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
then the matrix passed to create() should provide the mapping from world space to the mesh's object space.
--
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/zGdhBD6SuUE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/82d9cdd0-b19f-4da4-b36d-883ef7f86deb%40googlegroups.com.
Hi,as for the missing Matrix parameter, there is this thread: https://groups.google.com/forum/#!topic/python_inside_maya/axX7W8imeEUI have the same problems as described there, if I pass the matrix I will get this error: More keyword list entries (4) than format specifiers (2)But you are right, there has to be a Matrix parameter as the documentation says:.....then the matrix passed to create() should provide the mapping from world space to the mesh's object space.So for me the MMeshIntersector is not working....
2018-08-01 23:47 GMT+02:00 Luiz Amaral <amara...@gmail.com>:
Hey there,
“ ‘Point’ Specifies the location for which to evaluate the closest point on the mesh. `point' is transformed using the matrix parameter passed to the create() method, so for example if your matrix maps world to object space, then `point' should be specified in world space.”
You should either pass the cube’s world matrix on creation or pass the point localized to the cube’s space on get closest point.
Since you created the MMeshIntercector without passing a matrix to it the get closest point function expects a localized position.
That’s why you are getting a “random” point instead of the closest point to locator2.
If you pass the cube’s world matrix to the create just multiply the result of the get closest point by the same matrix and your locator will snap to the expected place.
Or you can keep create the way it is and multiply the point by the inverse of the cube’s world matrix before passing it to the get closest point and then multiply the result by the world matrix again.
Cheers,
Luiz
--
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/zGdhBD6SuUE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsubscribe@googlegroups.com.
matr = om2.MMatrix(dag.inclusiveMatrix())
meshIntersect.create(mesh, matr)
meshIntersect.create(mesh, om2.MMatrix.identity)
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, matr)
meshIntersect.create(mesh, om2.MMatrix(matr))
import maya.OpenMaya as om
selList = om.MSelectionList()
selList.add("pCube1")
dagCube = om.MDagPath()
selList.getDagPath(0, dagCube)
mesh = dagCube.child(0)
trFn = om.MFnTransform(dagCube)
matrCube = trFn.transformationMatrix()
######
mesh.apiTypeStr() # should be kMesh
######
intersector = om.MMeshIntersector()
intersector.create(mesh, matrCube) # no error in API 1.0...Yeah ;)
selListLoc1 = om.MSelectionList()
selListLoc1.add("locator1")
dagLoc1 = om.MDagPath()
selListLoc1.getDagPath(0, dagLoc1)
trFnLoc1 = om.MFnTransform(dagLoc1)
vecLoc1 = trFnLoc1.translation(4)
pointLoc1 = om.MPoint(vecLoc1.x, vecLoc1.y, vecLoc1.z)
mPointOnMesh = om.MPointOnMesh()
intersector.getClosestPoint(pointLoc1,mPointOnMesh, 1000)
resultPoint = mPointOnMesh.getPoint()
# first I create vector
resultVector = om.MVector(resultPoint.x, resultPoint.y,resultPoint.z)
# then I convert to matrix
matrTrans = om.MTransformationMatrix()
matrTrans.setTranslation(resultVector,4)
localMatrix = matrTrans.asMatrix(1)
# this is the important step to get the world matrix, multiply child/local with the parent Matrix
worldMatr = localMatrix*matrCube
worldMatrTrans = om.MTransformationMatrix(worldMatr)
selListLoc2 = om.MSelectionList()
selListLoc2.add("locator2")
dagLoc2 = om.MDagPath()
selListLoc2.getDagPath(0, dagLoc2)
trFnLoc2 = om.MFnTransform(dagLoc2)
trFnLoc2.set(worldMatrTrans)
--
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/zGdhBD6SuUE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/02874409-af3c-4fc9-afa2-083f3cf40a95%40googlegroups.com.