testNucleusNode.cpp
#include "testNucleusNode.h"
#include <maya/MIOStream.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MGlobal.h>
#include <maya/MTime.h>
#include <maya/MFnMesh.h>
#include <maya/MFnMeshData.h>
#include <maya/MFnUnitAttribute.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnTypedAttribute.h>
#include <maya/MFnIntArrayData.h>
#include <maya/MFnComponentListData.h>
#include <maya/MFnSingleIndexedComponent.h>
#include <maya/MDagPath.h>
#include <maya/MPoint.h>
#include <maya/MFloatPointArray.h>
#include <maya/MItMeshVertex.h>
#include <maya/MFnPlugin.h>
#include <math.h>
#include "stdio.h"
const MTypeId testNucleusNode::id( 0x85002 );
#include <maya/MFnNObjectData.h>
#include <maya/MnCloth.h>
MObject testNucleusNode::startState;
MObject testNucleusNode::currentState;
MObject testNucleusNode::nextState;
MObject testNucleusNode::currentTime;
inline void statCheck( MStatus stat, MString msg )
{
if ( !stat )
{
cout<<msg<<"\n";
}
}
MStatus testNucleusNode::compute(const MPlug &plug, MDataBlock &data)
{
MStatus stat;
if ( plug == nextState )
{
MTime currTime = data.inputValue(currentTime).asTime();
MObject inputData;
if(currTime.value() <= 0.0) {
MArrayDataHandle multiDataHandle = data.inputArrayValue(startState);
multiDataHandle.jumpToElement(0);
inputData =multiDataHandle.inputValue().data();
}
else {
MArrayDataHandle multiDataHandle = data.inputArrayValue(currentState);
multiDataHandle.jumpToElement(0);
inputData =multiDataHandle.inputValue().data();
}
MFnNObjectData inputNData(inputData);
MnCloth * nObj = NULL;
inputNData.getObjectPtr(nObj);
MFloatPointArray points;
nObj->getPositions(points);
unsigned int ii;
for(ii=0;ii<points.length();ii++) {
points[ii].y = (float) sin(points[ii].x + currTime.value()*4.0f*(3.1415f/180.0f));
}
nObj->setPositions(points);
delete nObj;
data.setClean(plug);
}
else if ( plug == currentState )
{
data.setClean(plug);
}
else if (plug == startState) {
data.setClean(plug);
}
else {
stat = MS::kUnknownParameter;
}
return stat;
}
MStatus testNucleusNode::initialize()
{
MStatus stat;
MFnTypedAttribute tAttr;
startState = tAttr.create("startState", "sst", MFnData::kNObject, MObject::kNullObj, &stat );
statCheck(stat, "failed to create startState");
tAttr.setWritable(true);
tAttr.setStorable(true);
tAttr.setHidden(true);
tAttr.setArray(true);
currentState = tAttr.create("currentState", "cst", MFnData::kNObject, MObject::kNullObj, &stat );
statCheck(stat, "failed to create currentState");
tAttr.setWritable(true);
tAttr.setStorable(true);
tAttr.setHidden(true);
tAttr.setArray(true);
nextState = tAttr.create("nextState", "nst", MFnData::kNObject, MObject::kNullObj, &stat );
statCheck(stat, "failed to create nextState");
tAttr.setWritable(true);
tAttr.setStorable(true);
tAttr.setHidden(true);
tAttr.setArray(true);
MFnUnitAttribute uniAttr;
currentTime = uniAttr.create( "currentTime", "ctm" , MFnUnitAttribute::kTime, 0.0, &stat );
addAttribute(startState);
addAttribute(currentState);
addAttribute(nextState);
addAttribute(currentTime);
attributeAffects(startState, nextState);
attributeAffects(currentState, nextState);
attributeAffects(currentTime, nextState);
return MStatus::kSuccess;
}
MStatus initializePlugin ( MObject obj )
{
MStatus status;
MFnPlugin plugin(obj, "Autodesk - nCloth Prototype 4", "8.5", "Any");
status = plugin.registerNode ( "testNucleusNode", testNucleusNode::id,testNucleusNode ::creator, testNucleusNode::initialize );
if ( !status )
{
status.perror("registerNode");
return status;
}
return status;
}
MStatus uninitializePlugin ( MObject obj )
{
MStatus status;
MFnPlugin plugin(obj);
status = plugin.deregisterNode(testNucleusNode::id);
if ( !status )
{
status.perror("deregisterNode");
return status;
}
return status;
}