I corrected few things. Now it loads properly, but i didn't check if it is working properly. Will leave this to you :)
import math, sys
import maya.OpenMaya as OM
import maya.OpenMayaMPx as MPx
kNodeName = "circusTransformNode"
kNodeID = OM.MTypeId(0x00032236)
kMatrixID = OM.MTypeId(0x00032235)
class circusTransformMatrix(MPx.MPxTransformationMatrix):
def __init__(self):
MPx.MPxTransformationMatrix.__init__()
kTrackingDictionary[MPx.asHashable(self)] = self
self.parentMatrix = OM.MObject()
def __del__(self):
del kTrackingDictionary[MPx.asHashable(self)]
def setParentMatrix(self,pm):
self.parentMatrix = pm
def getParentMatrix(self):
return self.parentMatrix
def asMatrix(self):
matrix = MPx.MPxTransformationMatrix.asMatrix(self)
tm = OM.MTransformationMatrix(matrix)
parent = self.getParentMatrix()
parentM = OM.MTransformationMatrix.asMatrix(parent)
resultMatrix = OM.MTransformationMatrix(parent * tm)
return resultMatrix.asMatrix()
class circusTransform(MPx.MPxTransform):
aParentArray = OM.MObject()
aParentSelector = OM.MObject()
aParentWeight = OM.MObject()
def __init__(self, transform=None):
if transform is None:
MPx.MPxTransform.__init__(self)
else:
MPx.MPxTransform.__init__(self, transform)
self.parentMatrix = OM.MObject()
self.mustCallValidateAndSet(self.aParentArray)
self.mustCallValidateAndSet(self.aParentSelector)
self.mustCallValidateAndSet(self.aParentWeight)
def createTransformationMatrix(self):
return MPx.asMPxPtr(circusTransformMatrix())
def validateAndSetValue(self,plug,handle,context):
stat = OM.MStatus()
data = OM.MDataHandle()
if plug == self.aParentArray:
weightValue = data.inputValue(self.aParentWeight)
weight = weightValue.asBool()
if weight == False:
return stat
elif weight == True:
parentArray = OM.MArrayDataHandle(self.aParentArray)
parentSelector = data.inputValue(self.aParentSelector)
finalParent = parentSelector.asInt()
if parentSelector in parentArray.elementCount():
parElem = parentArray.elementByLogicalIndex(parentSelector)
parentMatrix = plug.getvalue(parElem)
ltm = self.getCircusTransformationMatrix()
ltm.setParentMatrix(parentMatrix)
else: return stat
else: return stat.kUnknownParameter()
return stat.kSuccess()
def getCircusTransformationMatrix(self):
baseXform = self.transformationMatrixPtr()
return kTrackingDictionary[MPx.asHashable(baseXform)]
def matrixCreator():
return MPx.asMPxPtr( circusTransformMatrix() )
def nodeCreator():
return MPx.asMPxPtr( circusTransform() )
def nodeInitializer():
numFn = OM.MFnNumericAttribute()
matFn = OM.MFnMatrixAttribute()
wtFn = OM.MFnNumericAttribute()
circusTransform.aParentArray = matFn.create("inParentMatrices","ipm")
matFn.setArray(True)
# matFn.setIndexMatters(True)
circusTransform.aParentSelector = numFn.create("parentSelector","ps", OM.MFnNumericData.kInt,0)
numFn.setWritable(True)
numFn.setStorable(True)
numFn.setKeyable(True)
circusTransform.aParentWeight = wtFn.create("weight","w",OM.MFnNumericData.kBoolean,0)
wtFn.setKeyable(True)
wtFn.setStorable(True)
circusTransform.addAttribute(circusTransform.aParentWeight)
circusTransform.addAttribute(circusTransform.aParentSelector)
circusTransform.addAttribute(circusTransform.aParentArray)
return
def initializePlugin(mobject):
mplugin = MPx.MFnPlugin(mobject)
try:
mplugin.registerTransform(kNodeName,kNodeID,nodeCreator,nodeInitializer,matrixCreator,kMatrixID)
except:
sys.stderr.write('could not register Transform: %s\n' %kNodeName)
raise
def uninitializePlugin(mobject):
mplugin = MPx.MFnPlugin(mobject)
try:
mplugin.deregisterNode(kNodeID)
except:
sys.stderr.write('could not deregister Transform: %s\n' %kNodeName)
raise