ACFred

Updated Plug-in Template

Nov 5th, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.73 KB | None | 0 0
  1. import sys
  2. import maya.api.OpenMaya as om
  3.  
  4. def maya_useNewAPI():
  5.     pass
  6.  
  7. # Plug-in information:
  8. kPluginNodeName = 'transformHistory'
  9. kPluginNodeClassify = 'utility/general'
  10. kPluginNodeId = om.MTypeId(0x29A)
  11.  
  12. class TransformHistory(om.MPxNode):
  13.     timeInputAttribute = om.MObject()
  14.     matrixInputAttribute = om.MObject()
  15.     matrixOutputAttribute = om.MObject()
  16.  
  17.     def __init__(self):
  18.         # Constructor
  19.         om.MPxNode.__init__(self)
  20.  
  21.     def compute(self, pPlug, pDataBlock):
  22.         # Node computation method
  23.         #   - pPlug: Connection point related to on of our node attributes
  24.         #   - pDataBlock: Contains the data on which we will base our computations.
  25.  
  26.         if (pPlug == TransformHistory.matrixOutputAttribute):
  27.             timeInDataHandle = pDataBlock.inputValue(TransformHistory.timeInputAttribute)
  28.             matrixInDataHandle = pDataBlock.inputValue(TransformHistory.matrixInputAttribute)
  29.             inputMatrix = om.MMatrix(matrixInDataHandle.asMatrix())
  30.  
  31.             matrixOutDataHandle = pDataBlock.outputValue(TransformHistory.matrixOutputAttribute)
  32.             outMatrix = matrixOutDataHandle.asMatrix()
  33.  
  34.             timeInValue = timeInDataHandle.asFloat()
  35.             matrixInValue = matrixInDataHandle.asMatrix()
  36.  
  37.  
  38.             matrixOutDataHandle.setMMatrix(matrixInValue)
  39.             matrixOutDataHandle.setClean()
  40.  
  41.  
  42.  
  43.  
  44. # Plug-in Init
  45. def nodeCreator():
  46.     return TransformHistory()
  47.  
  48. def nodeInitializer():
  49.     numericAttributeFn = om.MFnNumericAttribute()
  50.     matrixAttributeFn = om.MFnMatrixAttribute()
  51.     matrixOutputAttribute = om.MFnMatrixAttribute()
  52.  
  53.     # Input Node Attributes
  54.     # ---------------------
  55.     global timeDefaultValue
  56.     timeDefaultValue = 0
  57.     TransformHistory.timeInputAttribute = numericAttributeFn.create('inTime', 'inTime', om.MFnNumericData.kFloat)
  58.     numericAttributeFn.writable = True
  59.     numericAttributeFn.storable = True
  60.     numericAttributeFn.readable = False
  61.     numericAttributeFn.hidden = False
  62.     TransformHistory.addAttribute(TransformHistory.timeInputAttribute)
  63.  
  64.     global inMatrixDefaultValue
  65.     inMatrixDefaultValue = om.MMatrix()
  66.     TransformHistory.matrixInputAttribute = matrixAttributeFn.create('inMatrix', 'inMatrix', om.MFnMatrixData.kMatrix)
  67.     matrixAttributeFn.writable = True
  68.     matrixAttributeFn.storable = True
  69.     matrixAttributeFn.hidden = False
  70.     TransformHistory.addAttribute(TransformHistory.matrixInputAttribute)
  71.  
  72.     # Output Node Attribute
  73.     # ---------------------
  74.     TransformHistory.matrixOutputAttribute = matrixOutputAttribute.create('outMatrix', 'o', om.MFnMatrixData.kMatrix)
  75.     matrixOutputAttribute.storable = False
  76.     matrixOutputAttribute.writable = False
  77.     matrixOutputAttribute.readable = True
  78.     matrixOutputAttribute.hidden = False
  79.     TransformHistory.addAttribute(TransformHistory.matrixOutputAttribute)
  80.  
  81.     # Node Attribute Dependencies
  82.     # ---------------------------
  83.     TransformHistory.attributeAffects(TransformHistory.timeInputAttribute, TransformHistory.matrixOutputAttribute)
  84.     TransformHistory.attributeAffects(TransformHistory.matrixInputAttribute, TransformHistory.matrixOutputAttribute)
  85.  
  86. def initializePlugin(mobject):
  87.     # Initialize the plug-in
  88.     mplugin = om.MFnPlugin(mobject)
  89.     try:
  90.         mplugin.registerNode(kPluginNodeName, kPluginNodeId, nodeCreator, nodeInitializer, om.MPxNode.kDependNode, kPluginNodeClassify)
  91.     except:
  92.         sys.stderr.write('Failed to register node: ' + kPluginNodeName)
  93.         raise
  94.  
  95. def uninitializePlugin(mobject):
  96.     mplugin = om.MFnPlugin(mobject)
  97.     try:
  98.         mplugin.deregisterNode(kPluginNodeId)
  99.     except:
  100.         sys.stderr.write('Failed to deregister node: ' + kPluginNodeName)
  101.         raise
Advertisement
Add Comment
Please, Sign In to add comment