array compound attribute calling compute() on change

array compound attribute calling compute() on change

muir.j
Contributor Contributor
567 Views
2 Replies
Message 1 of 3

array compound attribute calling compute() on change

muir.j
Contributor
Contributor

I'm writing a MPxParticleAttributeMapperNode to color particles arbitrarily and have an array compound attribute that controls the coloring parameters.

 

However, I can't seem to get the compute() method executing when I make a change to a child attribute with attributeAffects(). How can I ensure this executes each time a child in the array is changed?

 

e.g. the user changes colorMod[2].color (its an array compound attribute) and hence I would like compute() to be called.

 

MFnCompoundAttribute cmpAttr;
colorMod = cmpAttr.create("colorMod", "cm", &status);

cmpAttr.setArray(true);

cmpAttr.addChild(startParticle);
cmpAttr.addChild(endParticle);
cmpAttr.addChild(color);

cmpAttr.setReadable(true);
cmpAttr.setUsesArrayDataBuilder(true);

addAttribute(colorMod);


attributeAffects(startParticle, colorMod);
attributeAffects(endParticle, colorMod);
attributeAffects(color, colorMod);

attributeAffects( colorMod, outColorPP);

 

0 Likes
568 Views
2 Replies
Replies (2)
Message 2 of 3

stuzzz
Collaborator
Collaborator

your need to use MPxNode::setDependentsDirty()

 

MStatus ziPatchNode::setDependentsDirty(const MPlug &dirtyPlug, MPlugArray &affectedPlugs) {

	MStatus stat;
	MObject thisNode = thisMObject();
	MFnDependencyNode fnThisNode(thisNode);

	if (dirtyPlug== MYATTR ) {

		MPlug toupdate = fnThisNode.findPlug(ATTRTOUPDATE, &stat);
		if (stat) { affectedPlugs.append(toupdate); }

	}

	return stat;
}
0 Likes
Message 3 of 3

muir.j
Contributor
Contributor

I tried setDependantsDirty but it didn't seem to make a difference.

 

Possibly I am stating the problem wrong?

If I change my color Attribute in the attribute editor or via python, the compute method is not called, but is if I change the animation frame it does evaluate. Possibly missing a callback?

 

I was hoping just

attributeAffects( colorMod, outColorPP);

would do everything.

 

 

 

0 Likes