Hi, I'm new to the maya API environment. I've read David Gould's Complete Maya Programming, and am finding that some of the things I need to do are not explained in the book. Or, I completely read/passed over it.
At the moment I am looking to create a very simple node that contains a filename, and 2 vector arrays.
Eventually I will get maya's frame position, then read specific information from the file, then put that information into the vector Arrays, and output them to a particle shape.
My node is quite simple
class SimNode : public MPxNode
{
public:
[quote]
virtual MStatus compute( const MPlug& plug, MDataBlock& data );
static void *creator();
static MStatus initialize();[/quote]
public:
[quote]
static MObject filename;
static MObject position;
static MObject velocity;
static MTypeId id;[/quote]
};
In my Initialize function, how to I create my variables? Am I doing it correctly?
MStatus SimNode::initialize(){
[quote]
MFnNumericAttribute nAttr;
filename = nAttr.create("filename", "fn", MFnStringData::kString);
position = nAttr.create("position", "pos", MFnNumericData::kVectorArray);
velocity = nAttr.create("velocity", "vel", MFnNumericData::kVectorArray);
addAttribute( filename );
addAttribute( position );
addAttribute( velocity );
return MS::kSuccess;[/quote]
}
Im aware that the nAttr attribute is of type MFnNumericAttribute, should I create other variables of the Data types above( i.e. MFnStringData sAttr and MFnNumericData vaAttr ?) Or am I supposed to use MFnNumericAttributes .setArray function
position = nAttr.create("position", "pos", MFnNumericAttribute::kDouble);
nAttr.setArray(true);
In my compute function:
I'm not quite sure how to put the the newly created vector array into the outputArrayValue (This is what I will connect to the particle shape, i.e. position, velocity etc). Can I use MArrayDataHandles .set function in conjunction with an MPoint or MVectorArray, or do I need to use the MArrayDataBuilder? And if so How?
MStatus SimNode::compute(const MPlug &plug, MDataBlock &data){
[quote]
MStatus stat;
if(plug == position){
[quote]
MDataHandle hFilenameData = data.inputValue(filename, &stat);
string simFilename = hFilenameData.asString();
//Create 2 arbitrary points...info will eventually be read from a file)
MPointArray posArray;
posArray.append(MPoint(-5, 5, 0));
posArray.append(MPoint(-5, 10, 0));
MArrayDataHandle hPositionData = data.outputArrayValue(position, &stat);
//MArrayDataBuilder builder(position, 2, &stat);
hPositionData.set(posArray);
data.setClean( plug );[/quote]
} else
stat = MS::kUnknownParameter;
return stat;[/quote]
}
Any help would be greatly appreciated.
Justin