Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import maya.api.OpenMaya as om
- def maya_useNewAPI():
- pass
- # Plug-in information:
- kPluginNodeName = 'transformHistory'
- kPluginNodeClassify = 'utility/general'
- kPluginNodeId = om.MTypeId(0x29A)
- class TransformHistory(om.MPxNode):
- timeInputAttribute = om.MObject()
- matrixInputAttribute = om.MObject()
- matrixOutputAttribute = om.MObject()
- def __init__(self):
- # Constructor
- om.MPxNode.__init__(self)
- def compute(self, pPlug, pDataBlock):
- # Node computation method
- # - pPlug: Connection point related to on of our node attributes
- # - pDataBlock: Contains the data on which we will base our computations.
- if (pPlug == TransformHistory.matrixOutputAttribute):
- timeInDataHandle = pDataBlock.inputValue(TransformHistory.timeInputAttribute)
- matrixInDataHandle = pDataBlock.inputValue(TransformHistory.matrixInputAttribute)
- inputMatrix = om.MMatrix(matrixInDataHandle.asMatrix())
- matrixOutDataHandle = pDataBlock.outputValue(TransformHistory.matrixOutputAttribute)
- outMatrix = matrixOutDataHandle.asMatrix()
- timeInValue = timeInDataHandle.asFloat()
- matrixInValue = matrixInDataHandle.asMatrix()
- matrixOutDataHandle.setMMatrix(matrixInValue)
- matrixOutDataHandle.setClean()
- # Plug-in Init
- def nodeCreator():
- return TransformHistory()
- def nodeInitializer():
- numericAttributeFn = om.MFnNumericAttribute()
- matrixAttributeFn = om.MFnMatrixAttribute()
- matrixOutputAttribute = om.MFnMatrixAttribute()
- # Input Node Attributes
- # ---------------------
- global timeDefaultValue
- timeDefaultValue = 0
- TransformHistory.timeInputAttribute = numericAttributeFn.create('inTime', 'inTime', om.MFnNumericData.kFloat)
- numericAttributeFn.writable = True
- numericAttributeFn.storable = True
- numericAttributeFn.readable = False
- numericAttributeFn.hidden = False
- TransformHistory.addAttribute(TransformHistory.timeInputAttribute)
- global inMatrixDefaultValue
- inMatrixDefaultValue = om.MMatrix()
- TransformHistory.matrixInputAttribute = matrixAttributeFn.create('inMatrix', 'inMatrix', om.MFnMatrixData.kMatrix)
- matrixAttributeFn.writable = True
- matrixAttributeFn.storable = True
- matrixAttributeFn.hidden = False
- TransformHistory.addAttribute(TransformHistory.matrixInputAttribute)
- # Output Node Attribute
- # ---------------------
- TransformHistory.matrixOutputAttribute = matrixOutputAttribute.create('outMatrix', 'o', om.MFnMatrixData.kMatrix)
- matrixOutputAttribute.storable = False
- matrixOutputAttribute.writable = False
- matrixOutputAttribute.readable = True
- matrixOutputAttribute.hidden = False
- TransformHistory.addAttribute(TransformHistory.matrixOutputAttribute)
- # Node Attribute Dependencies
- # ---------------------------
- TransformHistory.attributeAffects(TransformHistory.timeInputAttribute, TransformHistory.matrixOutputAttribute)
- TransformHistory.attributeAffects(TransformHistory.matrixInputAttribute, TransformHistory.matrixOutputAttribute)
- def initializePlugin(mobject):
- # Initialize the plug-in
- mplugin = om.MFnPlugin(mobject)
- try:
- mplugin.registerNode(kPluginNodeName, kPluginNodeId, nodeCreator, nodeInitializer, om.MPxNode.kDependNode, kPluginNodeClassify)
- except:
- sys.stderr.write('Failed to register node: ' + kPluginNodeName)
- raise
- def uninitializePlugin(mobject):
- mplugin = om.MFnPlugin(mobject)
- try:
- mplugin.deregisterNode(kPluginNodeId)
- except:
- sys.stderr.write('Failed to deregister node: ' + kPluginNodeName)
- raise
Advertisement
Add Comment
Please, Sign In to add comment