#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/MDagPathArray.h>
#include <maya/MItSelectionList.h>
#include <maya/MSelectionList.h>
#include <maya/MPlug.h>
#include <maya/MPlugArray.h>
#include <maya/MTransformationMatrix.h>
#include <maya/MMatrix.h>
#include <maya/MFnMatrixData.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MFnAttribute.h>
#include <maya/MIOStream.h>
#define CheckError(stat,msg) \
if ( MS::kSuccess != stat ) { \
displayError(msg); \
continue; \
}
{
public:
dagPoseInfo();
virtual ~dagPoseInfo();
static void* creator();
private:
void printDagPoseInfo(
MObject& dagPoseNode,
unsigned index);
bool findDagPose(
MObject& jointNode);
FILE* file;
};
dagPoseInfo::dagPoseInfo():
file(NULL)
{
}
dagPoseInfo::~dagPoseInfo() {}
void* dagPoseInfo::creator()
{
return new dagPoseInfo;
}
bool dagPoseInfo::isUndoable() const
{
return false;
}
{
}
{
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;
}
void dagPoseInfo::printDagPoseInfo(
MObject& dagPoseNode,
unsigned index)
{
fprintf(file,"%s\n",nDagPose.name().asChar());
MObject aWorldMatrix = nDagPose.attribute(
"worldMatrix");
MPlug pWorldMatrix(dagPoseNode,aWorldMatrix);
pWorldMatrix.selectAncestorLogicalIndex(index,aWorldMatrix);
MObject aMatrix = nDagPose.attribute(
"xformMatrix");
MPlug pMatrix(dagPoseNode,aMatrix);
pMatrix.selectAncestorLogicalIndex(index,aMatrix);
MStatus status = pWorldMatrix.getValue(worldMatrix);
displayError("Problem retrieving world matrix.");
} else {
bool foundMatrix = 0;
foundMatrix = 1;
unsigned jj,kk;
fprintf(file,"worldMatrix\n");
for (jj = 0; jj < 4; ++jj) {
for (kk = 0; kk < 4; ++kk) {
double val = wMatrix(jj,kk);
fprintf(file,"%f ",val);
}
fprintf(file,"\n");
}
}
if (!foundMatrix) {
displayError("Error getting world matrix data.");
}
}
status = pMatrix.getValue(xformMatrix);
displayError("Problem retrieving xform matrix.");
} else {
bool foundMatrix = 0;
if (dMatrix.isTransformation()) {
foundMatrix = 1;
unsigned jj,kk;
fprintf(file,"matrix\n");
for (jj = 0; jj < 4; ++jj) {
for (kk = 0; kk < 4; ++kk) {
double val = xformAsMatrix(jj,kk);
fprintf(file,"%f ",val);
}
fprintf(file,"\n");
}
}
}
if (!foundMatrix) {
displayError("Error getting local matrix data.");
}
}
}
bool dagPoseInfo::findDagPose(
MObject& jointNode)
{
bool rtn = 0;
MObject aBindPose = fnJoint.attribute(
"bindPose",&status);
unsigned connLength = 0;
MPlug pBindPose(jointNode,aBindPose);
pBindPose.connectedTo(connPlugs,false,true);
connLength = connPlugs.
length();
for (unsigned ii = 0; ii < connLength; ++ii) {
MObject aMember = connPlugs[ii].attribute();
if (fnAttr.name() == "worldMatrix") {
unsigned jointIndex = connPlugs[ii].logicalIndex();
fprintf(file,"%s\n",fnJoint.name().asChar());
MObject jointObject = connPlugs[ii].node();
printDagPoseInfo(jointObject,jointIndex);
rtn = 1;
}
}
}
}
return rtn;
}
{
return stat;
}
unsigned int count = 0;
for (; !itr.isDone(); itr.next() )
{
itr.getDependNode(depNode);
if (findDagPose(depNode)) {
count++;
}
}
}
fclose(file);
if (0 == count) {
displayError("No poses were found on the selected joints.");
}
}
{
clearResult();
setResult( (int) 1);
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"3.0",
"Any");
status = plugin.registerCommand( "dagPoseInfo", dagPoseInfo::creator );
if (!status) {
status.
perror(
"registerCommand");
return status;
}
return status;
}
{
status = plugin.deregisterCommand( "dagPoseInfo" );
if (!status) {
status.
perror(
"deregisterCommand");
}
return status;
}