DG Node update logic

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 11 November 2012   #1
DAG Node update logic

I'm confused how DAG nodes actually updates. So here's simple code, almost directly from Maya pluginWizard.


#include "DGUpdateNode.h"

#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>

#include <maya/MGlobal.h>

MTypeId     DGUpdate::id( 0x00011 );

MObject     DGUpdate::input;        
MObject     DGUpdate::output;       

DGUpdate::DGUpdate() {}
DGUpdate::~DGUpdate() {}

MStatus DGUpdate::compute( const MPlug& plug, MDataBlock& data )
{
	MStatus returnStatus;
 
	if( plug == output )
	{
		MDataHandle inputData = data.inputValue( input, &returnStatus );

		if( returnStatus != MS::kSuccess )
			MGlobal::displayError( "Node DGUpdate cannot get value\n" );
		else
		{
			MGlobal::displayInfo( "Updated\n" );
			float result = inputData.asFloat();
			MDataHandle outputHandle = data.outputValue( DGUpdate::output );
			outputHandle.set( result );
			data.setClean(plug);
		}
	} else {
		return MS::kUnknownParameter;
	}

	return MS::kSuccess;
}

void* DGUpdate::creator()
{
	return new DGUpdate();
}

MStatus DGUpdate::initialize()
{
	MFnNumericAttribute nAttr;
	MStatus				stat;

	input = nAttr.create( "input", "in", MFnNumericData::kFloat, 0.0 );
 	nAttr.setStorable(true);
 	nAttr.setKeyable(true);

	output = nAttr.create( "output", "out", MFnNumericData::kFloat, 0.0 );
	nAttr.setWritable(false);
	nAttr.setStorable(false);

	stat = addAttribute( input );
		if (!stat) { stat.perror("addAttribute"); return stat;}
	stat = addAttribute( output );
		if (!stat) { stat.perror("addAttribute"); return stat;}

	stat = attributeAffects( input, output );
		if (!stat) { stat.perror("attributeAffects"); return stat;}

	return MS::kSuccess;

}


Now when I change input value. I should get "Updated" print right? However I'm not getting any prints so what I'm doing wrong?

As far as I understand update process it goes like this.
When ever input plug changes output plugs which are specified to be affected by input plug are marked dirty and all plugs where output plugs are connected. When Maya next time updates all dirty plugs get re-evaluated from child first order.

Can someone clear this up for me, please?
__________________
http://www.verajankorva.com

Last edited by xcx : 11 November 2012 at 08:51 AM.
 
Old 11 November 2012   #2
First off, DAG and DG are two distinct types of nodes. All nodes in Maya are DG (dependency graph) nodes. DAG (directed acyclic graph) nodes are a subset of DG nodes that represent scene hierarchy.

You almost have the process correct:

1. When an input on a node is updated, the first process is the DG dirty stage. In the DG dirty stage, it will look at attributeAffects relationships on your node and dirty dependents. Similarly it does the same for connections downstream.

2. Next, is the DG evaluation stage. Maya uses a lazy evaluation. It is a pull based scheme. So it will only attempt to update a dirty value if it is requested. That's the key. So it won't just update because you've changed the input. It will only update if you change the input (to dirty the output) and then request the output (a getAttr works just fine).
 
Old 11 November 2012   #3
Thanks for your help. It makes more sense now.
__________________
http://www.verajankorva.com
 
Old 11 November 2012   #4
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 10:51 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.