70 import maya.OpenMaya 
as OpenMaya
 
   71 import maya.OpenMayaUI 
as OpenMayaUI
 
   72 import maya.OpenMayaMPx 
as OpenMayaMPx
 
   73 import maya.OpenMayaAnim 
as OpenMayaAnim
 
   77 kSolverNodeName = 
"spSimpleSolverNode" 
   81 class simpleSolverNode(OpenMayaMPx.MPxIkSolverNode):
 
   83         OpenMayaMPx.MPxIkSolverNode.__init__(self)
 
   86     def solverTypeName(self):
 
   87         return kSolverNodeName
 
   94     def doSimpleSolver(self):
 
   96         Solve single joint in the x-y plane 
   97             - first it calculates the angle between the handle and the end-effector. 
   98             - then it determines which way to rotate the joint. 
  100         handle_group = self.handleGroup()
 
  101         handle = handle_group.handle(0)
 
  103         fnHandle = OpenMayaAnim.MFnIkHandle(handlePath)
 
  107         fnHandle.getEffector(end_effector)
 
  109         effector_position = tran.rotatePivot(OpenMaya.MSpace.kWorld)
 
  112         handle_position = fnHandle.rotatePivot(OpenMaya.MSpace.kWorld)
 
  116         fnHandle.getStartJoint(start_joint)
 
  118         start_position = start_transform.rotatePivot(OpenMaya.MSpace.kWorld)
 
  121         v1 = start_position - effector_position
 
  122         v2 = start_position - handle_position
 
  147         U = effector_position - start_position
 
  156         P = handle_position - effector_position
 
  159         PdotN = P[0]*N[0] + P[1]*N[1]
 
  168             self._getJointAngles(jointAngles)
 
  173             jointAngles.set(jointAngles[0] + rot, 0)
 
  174             self._setJointAngles(jointAngles)
 
  181     return OpenMayaMPx.asMPxPtr(simpleSolverNode())
 
  184 def nodeInitializer():
 
  190 def initializePlugin(mobject):
 
  191     mplugin = OpenMayaMPx.MFnPlugin(mobject, 
"Autodesk", 
"1.0", 
"Any")
 
  194         mplugin.registerNode(kSolverNodeName, kSolverNodeId, nodeCreator, nodeInitializer, OpenMayaMPx.MPxNode.kIkSolverNode)
 
  196         sys.stderr.write(
"Failed to register node: %s" % kSolverNodeName)
 
  201 def uninitializePlugin(mobject):
 
  202     mplugin = OpenMayaMPx.MFnPlugin(mobject)
 
  204         mplugin.deregisterNode(kSolverNodeId)
 
  206         sys.stderr.write(
"Failed to unregister node: %s" % kSolverNodeName)