From 79e557eb4dc1d5a997f75390fa55bd3ccb993c7e Mon Sep 17 00:00:00 2001 From: iamsleepy Date: Mon, 12 Dec 2016 14:43:21 +0800 Subject: [PATCH 1/2] Fix callback not triggering during the animation playback Replace attribute change message with node plug dirty --- affectsNode.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/affectsNode.cpp b/affectsNode.cpp index 1e9377d..1772a01 100644 --- a/affectsNode.cpp +++ b/affectsNode.cpp @@ -83,10 +83,7 @@ class affects : public MPxNode void setProjectionMatrixDirty(); - friend void cameraAttributeChanged(MNodeMessage::AttributeMessage msg, - MPlug & plug, - MPlug & otherPlug, - void* userData ); + friend void cameraNodePlugDirty(MObject &node, MPlug &plug, void *clientData); friend void cameraWorldMatrixChangeCallback(MObject &transformNode, MDagMessage::MatrixModifiedFlags &modified, @@ -151,7 +148,7 @@ MStatus affects::connectionMade( const MPlug& plug, const MPlug& otherPlug, bool MFnCamera fnCam(cameraNode); projectionMatrixValue = fnCam.projectionMatrix(); setProjectionMatrixDirty(); - cameraCallbackId = MNodeMessage::addAttributeChangedCallback(cameraNode, cameraAttributeChanged, this); + cameraCallbackId = MNodeMessage::addNodeDirtyPlugCallback(cameraNode, cameraNodePlugDirty, this); // Add world transform matrix MSelectionList sel; @@ -211,8 +208,8 @@ MStatus affects::initialize() // Use for projection matrix projectionMatrix = matAttr.create(PROJECTION_MATRIX_LN, PROJECTION_MATRIX_SN, MFnMatrixAttribute::kFloat); - //matAttr.setInternal(true); - + + // Message attribute inputCamera = msgAttr.create(INPUT_CAMERA_LN, INPUT_CAMERA_SN); // For attributeAffects @@ -227,13 +224,10 @@ MStatus affects::initialize() return( MS::kSuccess ); } -// Attribute change callback -void cameraAttributeChanged(MNodeMessage::AttributeMessage msg, - MPlug & plug, - MPlug & otherPlug, - void* userData ) +// Node plug dirty change callback +void cameraNodePlugDirty(MObject &node, MPlug &plug, void *clientData) { - affects* affectNode = (affects*)userData; + affects* affectNode = (affects*)clientData; if(affectNode->isCameraSet) { From 87f09a398338364147598989c36bcb358e3de23e Mon Sep 17 00:00:00 2001 From: cxli Date: Mon, 12 Dec 2016 15:02:06 +0800 Subject: [PATCH 2/2] Update affectsNode.cpp Comments correction --- affectsNode.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affectsNode.cpp b/affectsNode.cpp index 1772a01..74d9327 100644 --- a/affectsNode.cpp +++ b/affectsNode.cpp @@ -129,7 +129,7 @@ MStatus affects::compute( const MPlug& plug, MDataBlock& data ) return MStatus::kSuccess; } -// Create an attribute change callback on the camera when connection is made +// Create a node plug dirty callback on the camera when connection is made MStatus affects::connectionMade( const MPlug& plug, const MPlug& otherPlug, bool asSrc ) { if(plug == inputCamera) @@ -163,7 +163,7 @@ MStatus affects::connectionMade( const MPlug& plug, const MPlug& otherPlug, bool return MPxNode::connectionMade(plug, otherPlug, asSrc); } -// Remove callback when connection is broken. +// Remove callbacks when connection is broken. MStatus affects::connectionBroken( const MPlug& plug, const MPlug& otherPlug, bool asSrc ) { if(plug == inputCamera)