Guest User

Untitled

a guest
Feb 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. def worldSpaceToScreenSpace(camera, worldPoint):
  2.  
  3. # get current resolution
  4. resWidth = mc.getAttr('defaultResolution.width')
  5. resHeight = mc.getAttr('defaultResolution.height')
  6.  
  7. # get the dagPath to the camera shape node to get the world inverse matrix
  8. selList = om.MSelectionList()
  9. selList.add(camera)
  10. dagPath = om.MDagPath()
  11. selList.getDagPath(0,dagPath)
  12. dagPath.extendToShape()
  13. camInvMtx = dagPath.inclusiveMatrix().inverse()
  14.  
  15. # use a camera function set to get projection matrix, convert the MFloatMatrix
  16. # into a MMatrix for multiplication compatibility
  17. fnCam = om.MFnCamera(dagPath)
  18. mFloatMtx = fnCam.projectionMatrix()
  19. projMtx = om.MMatrix(mFloatMtx.matrix)
  20.  
  21. # multiply all together and do the normalisation
  22. mPoint = om.MPoint(worldPoint[0],worldPoint[1],worldPoint[2]) * camInvMtx * projMtx;
  23. x = (mPoint[0] / mPoint[3] / 2 + .5) * resWidth
  24. y = (mPoint[1] / mPoint[3] / 2 + .5) * resHeight
  25.  
  26. return [x,y]
Add Comment
Please, Sign In to add comment