clothPaintAttrCmd.cpp
#include <maya/MFnPlugin.h>
#include <maya/MArgList.h>
#include <maya/MGlobal.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MItDependencyGraph.h>
#include <maya/MString.h>
#include <maya/MStringArray.h>
#include <maya/MDoubleArray.h>
#include <maya/MFnDoubleArrayData.h>
#include "clothPaintAttrCmd.h"
ClothPaintAttrCommand::ClothPaintAttrCommand()
{
}
ClothPaintAttrCommand::~ClothPaintAttrCommand()
{
}
void* ClothPaintAttrCommand::creator()
{
return new ClothPaintAttrCommand;
}
bool ClothPaintAttrCommand::isUndoable() const
{
return false;
}
MStatus ClothPaintAttrCommand::doIt(const MArgList& args)
{
MString pluginCheck = "pluginInfo -q -l CpClothPlugin.mll";
int pluginResult;
MGlobal::executeCommand(pluginCheck,pluginResult);
if(pluginResult != 1)
{
displayError("\"CpClothPlugin\" should be loaded to use this Plug-in!");
return MS::kFailure;
}
MString nodeName[2];
if (!args.length() || args.length() != 2)
{
displayError("Cloth Mesh node and Cloth paint attribute name must be specified as\n Command's first and second argument respectively!");
return MS::kFailure;
}
else
{
nodeName[0] = args.asString(0);
nodeName[1] = args.asString(1);
}
bool isFirstArg = false;
bool isSecondArg = false;
MString clothMesh = "isClothMesh "+ nodeName[0];
int result;
MGlobal::executeCommand(clothMesh, result);
if(result == 1)
{
isFirstArg = true;
}
if( nodeName[1] == "bendAngle" || nodeName[1] == "densityWeights" ||
nodeName[1] == "scaleWeights" || nodeName[1] == "bendRateWeights" ||
nodeName[1] == "thicknessWeights" || nodeName[1] == "airDampingWeights" ||
nodeName[1] == "clothDampingWeights" || nodeName[1] == "clothFrictionWeights" ||
nodeName[1] == "staticFrictionWeights" || nodeName[1] == "thicknessForceWeights" ||
nodeName[1] == "bendResistanceWeights" || nodeName[1] == "dynamicFrictionWeights" ||
nodeName[1] == "shearResistanceWeights" || nodeName[1] == "stretchResistanceWeights")
{
isSecondArg = true;
}
if(isFirstArg == false && isSecondArg == false)
{
displayError("Cloth Mesh node and Cloth paint attribute name must be specified as\n Command's first and second argument respectively!");
return MS::kFailure;
}
else if(isFirstArg == true && isSecondArg == false)
{
displayError("A cloth paint attribute name must be specified as command's second argument!");
return MS::kFailure;
}
else if(isFirstArg == false && isSecondArg == true)
{
displayError("A cloth Mesh node must be specified as command's first argument!");
return MS::kFailure;
}
MSelectionList nodeList;
nodeList.add(nodeName[0]);
MObject clothNode;
nodeList.getDependNode(0, clothNode);
MFnDependencyNode fnDN(clothNode);
MPlug paintAttrPlug = fnDN.findPlug(nodeName[1]);
MObject doubleArrayData;
paintAttrPlug.getValue(doubleArrayData);
MFnDoubleArrayData fnDAD(doubleArrayData);
MDoubleArray finalArray = fnDAD.array();
setResult(finalArray);
return MS::kSuccess;
}
MStatus initializePlugin(MObject obj)
{
MStatus status;
MFnPlugin plugin(obj, PLUGIN_COMPANY, MGlobal::mayaVersion().asChar(), "Any");
status = plugin.registerCommand("ClothPaintAttr", ClothPaintAttrCommand::creator);
if (!status)
{
status.perror("registerCommand");
return status;
}
return status;
}
MStatus uninitializePlugin(MObject obj)
{
MStatus status;
MFnPlugin plugin(obj);
status = plugin.deregisterCommand("ClothPaintAttr");
if (!status)
{
status.perror("deregisterCommand");
return status;
}
return status;
}