#include <math.h>
#include <maya/MPxCommand.h>
#include <maya/MStatus.h>
#include <maya/MArgList.h>
#include <maya/MFnPlugin.h>
#include <maya/MObject.h>
#include <maya/MGlobal.h>
#include <maya/MDagPath.h>
#include <maya/MItSelectionList.h>
#include <maya/MSelectionList.h>
#include <maya/MFloatArray.h>
#include <maya/MObjectArray.h>
#include <maya/MItDependencyNodes.h>
#include <maya/MItGeometry.h>
#include <maya/MFnWeightGeometryFilter.h>
#include <maya/MFnGeometryFilter.h>
#include <maya/MItGeometry.h>
#include <maya/MPlug.h>
#include <maya/MPlugArray.h>
#include <maya/MFnSet.h>
#include <maya/MIOStream.h>
#define CheckError(stat,msg) \
if ( MS::kSuccess != stat ) { \
displayError(msg); \
continue; \
}
{
public:
exportJointClusterData();
virtual ~exportJointClusterData();
static void* creator();
private:
FILE* file;
};
exportJointClusterData::exportJointClusterData():
file(NULL)
{
}
exportJointClusterData::~exportJointClusterData() {}
void* exportJointClusterData::creator()
{
return new exportJointClusterData;
}
bool exportJointClusterData::isUndoable() const
{
return false;
}
MStatus exportJointClusterData::undoIt()
{
}
{
const MString fileFlagLong (
"-file");
for (
unsigned int i = 0; i < args.
length(); i++ ) {
if (!stat)
continue;
if ( arg == fileFlag || arg == fileFlagLong ) {
arg += ": must specify a file name";
displayError(arg);
}
i++;
}
else {
arg += ": unknown argument";
displayError(arg);
}
}
file = fopen(fileName.
asChar(),
"wb");
if (!file) {
MString openError(
"Could not open: ");
openError += fileName;
displayError(openError);
}
return stat;
}
MObject exportJointClusterData::jointForCluster(
MObject& jointCluster)
const
{
MObject attrJoint = fnNode.attribute(
"matrix");
MPlug pJointPlug(jointCluster,attrJoint);
if (pJointPlug.connectedTo(conns,true,false)) {
result = conns[0].node();
}
return result;
}
{
return stat;
}
unsigned int jcCount = 0;
for ( ; !iter.isDone(); iter.next() ) {
MObject joint = jointForCluster(
object);
displayError("Joint is not attached to cluster.");
continue;
}
MObject deformSet = jointCluster.deformerSet(&stat);
CheckError(stat,"Error getting deformer set.");
MFnSet setFn(deformSet, &stat);
CheckError(stat,"Error getting deformer set fn.");
stat = setFn.getMembers(clusterSetList, true);
CheckError(stat,"Could not make member list with getMembers.");
fprintf(file,"%s %u\n",fnJoint.name().asChar(),
for (
unsigned int kk = 0; kk < clusterSetList.
length(); ++kk) {
clusterSetList.
getDagPath(kk,skinpath,components);
jointCluster.getWeights(skinpath,components,weights);
fprintf(file,
unsigned counter =0;
for ( ; !gIter.isDone() &&
counter < weights.
length(); gIter.next()) {
fprintf(file,"%d %f\n",gIter.index(),weights[counter]);
counter++;
}
}
jcCount++;
}
fclose(file);
if (0 == jcCount) {
displayError("No jointClusters found in this scene.");
}
}
MStatus exportJointClusterData::redoIt()
{
clearResult();
setResult( (int) 1);
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"3.0",
"Any");
status = plugin.registerCommand( "exportJointClusterData", exportJointClusterData::creator );
if (!status) {
status.
perror(
"registerCommand");
return status;
}
return status;
}
{
status = plugin.deregisterCommand( "exportJointClusterData" );
if (!status) {
status.
perror(
"deregisterCommand");
}
return status;
}