View Full Version : attributeAffects dirty propagation via matrix attributes
07-12-2012, 01:31 AM
Hello! I've built a tool that I would like to run the compute for whenever it moves in world space. I've tried setting up an attribute with a kMatrix type that has setWorldSpace(true). I then set this to affect my main data attr. Using pymel/mel's isDirty command with datablock set to true I found that the worldspace matrix attribute indeed does get set to dirty but my attr does not.
I google'd this problem and found another wayward soul who found the workaround of having a setWorldSpace attr connected to ANOTHER dummy attribute that should then propagate my dirty flag. So, I made another kMatrix attr, wrote a script to hook up my inWorldSpace to my dummyWSMatrix attr and continued my attributeAffects chain from dummyWSMatrix to my fieldData attr. Unfortunately, both of the matrix attr's are now dirty but the fieldData is indeed still clean.
Does anyone have any tips or tricks to force computes based off of transforms in world space?
07-12-2012, 11:17 AM
Difficult to read the purpose of your node, but generally you don't have to force compute. It will be called when input changes and output needs to be computed. What's your compute calculating for output?
07-12-2012, 02:56 PM
In short, please provide a code for a small demo plugin which reproduces your problem.
07-12-2012, 05:02 PM
Small test code from an esteemed colleague who really took a liking to this puzzle:
We were making a custom locator to show force lines from a field. Fields take an inputData input (a compound attribute of positions, current velocity, mass and a delta time) and in return give us outputForce.
We created a worldspace attribute and set it to affect our outputData for the field. We wiggled the locator around, the worldspace attr was dirty and then our outputData attribute was not dirty in turn (aka, our force lines never update).
if pluginInfo('PymelTestNode.py', q=1, loaded=1):
tn = createNode('PymelTestNode')
myT = pm.createNode('transform')
print "initial output get:", getAttr('PymelTestNode1.output')
print "set parent tx..."
print pm.isDirty('PymelTestNode1.worldIn', d=1)
print pm.isDirty('PymelTestNode1.output', d=1)
print "final output get:", getAttr('PymelTestNode1.output')
import pymel.api.plugins as plugins
import maya.OpenMaya as om
'''Test plugin node
_typeId = om.MTypeId(0x9000F)
_name = 'PymelTestNode'
nAttr = om.MFnNumericAttribute()
mAttr = om.MFnMatrixAttribute()
cAttr = om.MFnCompoundAttribute()
cls.input = nAttr.create( "input", "in", om.MFnNumericData.kFloat, 0.0 )
cls.addAttribute( cls.input )
cls.outputFloat = nAttr.create( "outputFloat", "of", om.MFnNumericData.kFloat, 0.0 )
cls.addAttribute( cls.outputFloat )
cls.outputInt = nAttr.create( "outputInt", "oi", om.MFnNumericData.kInt, 0.0 )
cls.addAttribute( cls.outputInt )
cls.output = cAttr.create( "output", "out")
cls.addAttribute( cls.output )
#cls.worldFloat = nAttr.create("worldFloat", "wf", om.MFnNumericData.kFloat, 0.0 )
#cls.addAttribute( cls.worldFloat )
#cls.dummyWorldDest = nAttr.create("dummyWorldDest", "d", om.MFnNumericData.kFloat, 0.0 )
#cls.addAttribute( cls.dummyWorldDest )
cls.worldIn = mAttr.create("worldIn", "wi")
cls.addAttribute( cls.worldIn )
# set attribute affects
cls.attributeAffects( cls.input, cls.output )
#cls.attributeAffects( cls.dummyWorldDest, cls.output )
cls.attributeAffects( cls.worldIn, cls.output )
def compute(self, plug, dataBlock):
print "compute called for:", plug.name()
if ( plug == self.output ):
## initialize the script plug-in
# uninitialize the script plug-in
07-18-2012, 10:04 PM
I'm having a similar problem with the API (C++). I have matrices coming into a compound set to array, and outputing position vectors in an output compound set to be an array. If I do a simple inputData affects outputData my plug does not update. My workaround was to create a time attr. The time attr affects the outputData attr. I connect the time1 node to my time attr and then check if the individual child attrs where set to dirty as opposed to the compound parent.
ex; if( (plug == childPosA) || (plug == childPosB) || (plug == childPosC) )
The problem that I am now having is that my plug does not update in batch render mode. :hmm: :banghead:
07-18-2012, 10:18 PM
Sorry, somehow I missed your previous post. I'll take a look later on.
07-19-2012, 08:27 AM
I missed the post as well.
I think the main problem is that you are dirtying a compound attribute which will not cause a compute since you don't really connect compound attribute as output. Maya will not automatically mark children attributes dirty when you mark compound attribute dirty. You have to do that yourself.
Here are some pointers that I learned:
1. Mark output plug dirty that will be calculated/updated in compute and which is requested by other nodes via connections.
2. You have to connect or request output in some way to tell Maya to compute a node.
07-19-2012, 08:27 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2014, Jelsoft Enterprises Ltd.