Hello All-
First off thank very much for this great forum. Seems like it will soon become a great wealth of knowledge. Being new to the industry, I very much enjoyed the tech artist roundtables at GDC, and look forward to many more discussions with you all.
Now…on to my question. I’m just getting into writing nodes and plug-ins for Maya(using c++) and I basically want to create something like the current plusMinusAverage node in Maya, which can accept unlimited number of input attributes, and each time you connect one attribute to the input, it generates a deafult slot for the next one.
I’ve been playing with the setArray(true) call, but I can’t get it to generate that next input attribute after I input the first one. If anyone has any ideas and could point me in the right direction, it would be greatly appreciated.
Thanks,
Josh
[QUOTE=uberHuber;3130]
Now…on to my question. I’m just getting into writing nodes and plug-ins for Maya(using c++) and I basically want to create something like the current plusMinusAverage node in Maya, which can accept unlimited number of input attributes, and each time you connect one attribute to the input, it generates a deafult slot for the next one.[/QUOTE]
Are you also setting setIndexMatters?
Sorry for the delay, and thanks for the reply. Got stuck on some side projects here at work since I posted first on this. I hadn’t planned on using the setIndexMatters, but that’s mainly because I still don’t know much of the functionality of the API yet.
Right now I’m just setting the matrix attribute as an array and that seems to be sufficient for what I need to it do.
My new hurdle is that I’m trying to select one of the arrays based on another input attribute. For example, if I input 5 matrices, and have an int attr on a control somewhere that goes from 1-5, how can I output the proper matrix based on that value. I was trying the logical and physical indexes but it doesn’t seem to be giving me the same values as what’s in the matrix.
[QUOTE=uberHuber;3368]Sorry for the delay, and thanks for the reply. Got stuck on some side projects here at work since I posted first on this. I hadn’t planned on using the setIndexMatters, but that’s mainly because I still don’t know much of the functionality of the API yet.
[/QUOTE]
In general, if you’re thinking of an attribute that lets you set a connection using:
connectAttr -na
you need to:
MFnAttribute.setIndexMatters( False )
MFnAttribute.setReadable( False )
for each attribute you’re concerned with.
[QUOTE=uberHuber;3368]
My new hurdle is that I’m trying to select one of the arrays based on another input attribute.[/QUOTE]
Can you illustrate the problem a little more in detail? It seems like it should be pretty straightforward to have your compute method just pass out an array element based on an input. Maybe you need to throw an attributeAffects()? Just guessing here, i’d have to look at your code to be more certain.
So I’m trying to input ‘x’ amount of matrices into an attribute array, and also input an integer value. Based on what value that integer has, it would output the matrix corresponding to that index value in the array of matrices.
Here’s my code…keep in mind this is my first plug-in besides tutorials, so excuse any ugliness
/static/ MObject multiMatrix::input1;
/static/ MObject multiMatrix::input3;
/static/ MObject multiMatrix::output;
MStatus multiMatrix::initialize()
{
//- Create attributes
MFnNumericAttribute nAttr;
MFnMatrixAttribute mAttr;
MFnMatrixAttribute m2Attr;
input1 = mAttr.create(“matrix1”, “m1”, MFnMatrixAttribute::kFloat);
mAttr.setStorable(true);
mAttr.setReadable(false);
mAttr.setIndexMatters(false);
mAttr.setArray(true);
input3 = nAttr.create("switch", "sw", MFnNumericData::kInt);
nAttr.setStorable(true);
//- Initialize output
output = m2Attr.create( "output", "out", MFnMatrixAttribute::kFloat);
m2Attr.setStorable(false);
//- Add the attributes to the node
addAttribute( input1 );
addAttribute( input3 );
addAttribute( output );
attributeAffects( input1, output );
attributeAffects( input3, output );
attributeAffects( input3, input1 );
//- Return success to Maya
return MS::kSuccess;
}
MStatus multiMatrix::compute( const MPlug& plug, MDataBlock& data )
{
MStatus returnStatus;
MObject multiMatrix = thisMObject();
MS::kUnknownParameter.
if( plug == output )
{
// get the plug associated with the matrix input
MFnDependencyNode depFn(multiMatrix, &returnStatus);
MString attrName = ("input1");
MPlug multiMatrixPlug = depFn.findPlug(attrName, &returnStatus);
// Find the proper matrix in the plug, based on an integer "switch" val
MDataHandle inputData3 = data.inputValue( input3, &returnStatus );
int index = inputData3.asInt();
MPlug elementPlug = multiMatrixPlug.elementByLogicalIndex(index, &returnStatus);
// convert the plug to a matrix
MObject objMat;
elementPlug.getValue(objMat);
MFnMatrixData fnMat(objMat);
MMatrix mat = fnMat.matrix();
//- send the matrix to the output attribute
MDataHandle outputHandle = data.outputValue( multiMatrix::output );
outputHandle.set(mat);.
//- Tell Maya the plug is now clean
data.setClean(plug);
//- Return success to Maya
return MS::kSuccess;
}
return MS::kUnknownParameter;
}
Ah cool! thanks for sharing, i’ll give this a once over tonight. I have some ideas, i remember running into multi attribute api issues myself about a year or so ago, might be the same thing.