Hi everybody! (Hi Dr Nick!)
I'm having trouble with compound Attrs
I added some simple code of a dummy plugin 'lls_DirtTrouble' to illustrate my problem.
//
// lls_DirtTrouble
//
#include <maya/MGlobal.h>
#include <maya/MPxNode.h>
#include <maya/MPlug.h>
#include <maya/MFnPlugin.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnMatrixAttribute.h>
#include <maya/MFnCompoundAttribute.h>
#include <maya/MString.h>
#include <maya/MPlug.h>
#include <maya/MPoint.h>
#include <maya/MMatrix.h>
#include <maya/MFloatPoint.h>
#include <maya/MTypeId.h>
#ifndef _lls_DirtTroubleNode
#define _lls_DirtTroubleNode
class lls_DirtTrouble : public MPxNode
{
public:
lls_DirtTrouble();
virtual ~lls_DirtTrouble();
virtual MStatus compute( const MPlug& plug, MDataBlock& data );
static void* creator();
static MStatus initialize();
//Plugin
static MString pluginName;
static MTypeId id;
//Attrs
static MObject aWorldMatrix;
static MObject aCompounds;
static MObject aWeight;
static MObject aOutTranslate;
};
#endif
//Plugin
MString lls_DirtTrouble::pluginName="lls_DirtTrouble";
MTypeId lls_DirtTrouble::id( 0x123456 );
// Attrs
MObject lls_DirtTrouble::aWorldMatrix;
MObject lls_DirtTrouble::aCompounds;
MObject lls_DirtTrouble::aWeight;
MObject lls_DirtTrouble::aOutTranslate;
lls_DirtTrouble::lls_DirtTrouble() {}
lls_DirtTrouble::~lls_DirtTrouble() {}
MStatus lls_DirtTrouble::compute( const MPlug& plug, MDataBlock& data )
{
MStatus stat = MStatus::kSuccess;
if( plug == aOutTranslate) //if( plug == aCompounds)
{
//Get Compound
MArrayDataHandle hCompounds = data.outputArrayValue (aCompounds);
double compoundCount=double(hCompounds.elementCount());
//Iterate compounds
for ( int compoundID = 0 ; compoundID < int(compoundCount) ; compoundID++)
{
//Get Compound Child Attrs
hCompounds.jumpToArrayElement(compoundID);
MMatrix worldMatrix = hCompounds.inputValue().child(aWorldMatrix).asMatrix();
double weight = hCompounds.inputValue().child(aWeight).asDouble();
// Some useless calcs
MFloatPoint result= MFloatPoint((float)worldMatrix[3][0], (float)worldMatrix[3][1], (float)worldMatrix[3][2]);
result = result*(float)weight;
//Set outTranslate
MDataHandle hOutTranslate = hCompounds.outputValue().child(aOutTranslate);
hOutTranslate.set(result.x, result.y, result.z);
hOutTranslate.setClean();
}
data.setClean(plug);
}else{
return MS::kUnknownParameter;
}
data.setClean(plug);
return MS::kSuccess;
}
void* lls_DirtTrouble::creator()
{
return new lls_DirtTrouble();
}
MStatus lls_DirtTrouble::initialize()
{
MFnNumericAttribute nAttr;
MFnMatrixAttribute mAttr;
MFnCompoundAttribute cAttr;
aWorldMatrix = mAttr.create( "myWorldMatrix", "mwm" );
mAttr.setStorable(false);
mAttr.setConnectable(true);
mAttr.setHidden(true);
addAttribute(aWorldMatrix);
aWeight = nAttr.create("weight","w",MFnNumericData::kDouble,0);
nAttr.setStorable(true);
nAttr.setKeyable(true);
nAttr.setMin(0.0);
nAttr.setMax(1.0);
nAttr.setDefault(1.0);
addAttribute(aWeight);
aOutTranslate = nAttr.createPoint( "outTranslate", "ot" );
nAttr.setStorable(false);
nAttr.setWritable(false);
addAttribute(aOutTranslate);
aCompounds= cAttr.create("compounds","cmps");
cAttr.addChild(aWorldMatrix);
cAttr.addChild(aWeight);
cAttr.addChild(aOutTranslate);
cAttr.setArray(true);
cAttr.setStorable(true);
addAttribute(aCompounds);
/*
attributeAffects( aWorldMatrix , aCompounds );
attributeAffects( aWeight , aCompounds );
*/
attributeAffects( aWorldMatrix , aOutTranslate );
attributeAffects( aWeight , aOutTranslate );
return MS::kSuccess;
}
MStatus initializePlugin( MObject obj )
{
MStatus status;
MFnPlugin plugin( obj, "xxx", "2013", "Any");
status = plugin.registerNode( lls_DirtTrouble::pluginName , lls_DirtTrouble::id, lls_DirtTrouble::creator, lls_DirtTrouble::initialize );
if (!status)
{
status.perror("registerNode");
return status;
}
return status;
}
MStatus uninitializePlugin(MObject obj)
{
MStatus status;
MFnPlugin plugin( obj );
status = plugin.deregisterNode( lls_DirtTrouble::id );
if (!status)
{
status.perror("deregisterNode");
return status;
}
return status;
}
I structured my attrs in an array of compound attrs because this seems the most logical approach to me.
(and I'd like to keep it that way)
aCompounds= cAttr.create("compounds","cmps");
cAttr.addChild(aWorldMatrix);
cAttr.addChild(aWeight);
cAttr.addChild(aOutTranslate);
cAttr.setArray(true);
cAttr.setStorable(true);
addAttribute(aCompounds);
The dummy plug works as expected but I keep getting loads of
Cycle on 'lls_DirtTrouble1.compounds[id].outTranslate' may not evaluate as expected.
Must be something wrong. Probably has to do with dirty plugs or something... ????
Do I need setDependentsDirty and how do I set it up in this case?
Could someone help me out please?
Thanx in advance