Hi again,
I don`t know how much sense this code still makes, however for me its for
learning purposes and for me its one step towards my goal to learn c++ api.
Especially converting between vectors, MFloatPoint and Matrix type might be
horrible code...but I didn*t find a more direct way.....at least it works
for me.
If you have some hints for me, how to do things more clever, please don`t
hesitate
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 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/55ad67e8-62b9-48a5-8155-4bc90a7de78f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.