mtuttle
How does one force a computation for the output on a MPXNode when one of its attributes have changed, but not directly affected any of its other attributes?
Reply 0 0
mtuttle
Okay, I'll let you know how this works...
Reply 0 0
mtuttle
There is a small hangup with the plugin, it's not loading:
// Error: line 1: RuntimeError: file c:\buildforge\Maya_2012_Win64_Build\build\wrk\optim\runTime\Python\Lib\site-packages\maya\OpenMaya.py line 3921: (kInvalidParameter): Object is incompatible with this method //
// Warning: line 1: Failed to call script creator function //
// Error: line 1: TypeError: file c:\buildforge\Maya_2012_Win64_Build\build\wrk\optim\runTime\Python\Lib\site-packages\maya\OpenMayaMPx.py line 21: set() takes exactly 1 argument (2 given) //
// Warning: line 1: Failed to call script creator function //
Reply 0 0
pshipkov
Are you talking about the code you pasted in your previous emails or this is coming from the attempt to create your own transform node ?
Reply 0 0
mtuttle
This is the transform implementation you suggested, or an attempt at thereof. Sorry, here's the code:
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)
weFn.setStorable(True)
circusTransform.addAttribute(circusTransform.aParentWeight)
circusTransform.addAttribute(circusTransform.aParentSelector)
circusTransform.addAttribute(circusTransform.aParentArray)
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.deregisterTransform(kNodeID)
except:
sys.stderr.write('could not deregister Transform: %s\n' %kNodeName)
raise
Reply 0 0
silent.bullet

whoa!!! high level stuff... :crazy:

Reply 0 0
pshipkov
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

Reply 0 0
mtuttle
Hey, thanks! Though now that I'm starting to understand how callbacks work in Maya, I don't know if a custom transform is the right way to do this now. Especially since I'm interning at a gaming company and have to make sure my rigs export to Unity properly; a custom transform may make things too complicated, if not impossible. However, what about triggering the parentConstraint's own update offset's feature via a plugin that tells Maya to monitor a certain event? I don't know what the event should be, probably a MNodeMessage:addAttributeChangedCallback for whenever the target's transformation attributes change?
Reply 0 0
pshipkov
Yeah, game engines limit our freedom of how we create assets.
If you ask about my opinion - i wouldn't go API for triggering offset updates to constraints. These things are usually manually controlled by animators. Talk to them first if you can.

Reply 0 0
mtuttle
I guess I'm thinking mainly about animation tools for students more than studios. My classmates generally just keyframe and don't bother with anything else in Maya unless they really have to. They aren't really taught how to use or animate constraints, just how to make a strong pose and utilize the principles of Animation. So giving them an "advanced" rig where they have to control everything might be animator-friendly but not student-friendly, in this case. They expect a great deal of automation and ease of use. Space-switching was one of those concepts that I felt made rigs easier to use, but not if the students need to do anything other than change a attribute in the channel-box and key it...
Reply 0 0
pshipkov
Right, for a moment i forgot you are coding for students.

Reply 0 0
mtuttle
I've finally got something working (albeit something buggy still), but now I'm not sure that writing something for students would be acceptable as a showreel piece, because it doesn't fit within a standard pipeline:
https://github.com/esotericDisciple/CircusDev/blob/master/multiParentNode.py
The isPassiveOutput function is commented out because I think it's what's causing a crash when connecting the outputs to a transform, does anyone know how you're supposed to use it?
Reply 0 0
pshipkov
Can you provide a basic example scene ? I am not sure how to use the node.
Thanks.

Reply 0 0
mtuttle
I'm not entirely sure either. Basically you just add matrices to the node and connect any matrix attribute from a transform to them, then use the selector to switch between matrices which changes the output translate and rotate values...
Reply 0 0
mtuttle
I've switched back to c++ since python doesn't offer some of functions I thought I'd need, but still no success using callbacks. Perhaps instead I need a MCommandMessage callback that tells Maya to run the userCB function when the "move," "rotate," or "setAttr" command is executed?
https://github.com/esotericDisciple/CircusDev/blob/master/updateOffsets/updateOffsetsCmd.cpp
Reply 0 0
Reply