#include <assert.h>
#include <maya/MGlobal.h>
#include <maya/MString.h>
#include <maya/MPoint.h>
#include <maya/MVector.h>
#include <maya/MVectorArray.h>
#include <maya/MDoubleArray.h>
#include <maya/MArgList.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MSelectionList.h>
#include <maya/MPxCommand.h>
#include <maya/MFnDagNode.h>
#include <maya/MRenderLine.h>
#include <maya/MRenderLineArray.h>
#include <maya/MFnPfxGeometry.h>
#include <maya/MFnPlugin.h>
#define mCommandName "pfxInfo" // Command name
class pfxInfoCmd : public MPxCommand
{
public:
pfxInfoCmd();
virtual ~pfxInfoCmd();
virtual MStatus doIt ( const MArgList& args );
static void* creator();
private:
static MStatus nodeFromName(MString name, MObject & obj);
MStatus parseArgs ( const MArgList& args );
MStatus printDoubleArray( MDoubleArray &array, char *title );
MStatus printVectorArray( MVectorArray &array, char *title );
MStatus printRenderLine( MRenderLine &renderLine );
MStatus printRenderLineArray( MRenderLineArray &lineArray, char *title );
MString pfxName;
MObject pfxNode;
MString pfxOutput;
};
pfxInfoCmd::pfxInfoCmd()
{
}
pfxInfoCmd::~pfxInfoCmd()
{
}
MStatus pfxInfoCmd::nodeFromName(MString name, MObject & obj)
{
MSelectionList tempList;
tempList.add( name );
if ( tempList.length() > 0 )
{
tempList.getDependNode( 0, obj );
return MS::kSuccess;
}
return MS::kFailure;
}
MStatus pfxInfoCmd::parseArgs( const MArgList& args )
{
MStatus stat = MS::kSuccess;
pfxOutput = "none";
if( args.length() < 1 )
{
MGlobal::displayError( "Missing pfx node name argument(stroke or pfxHair)." );
return MS::kFailure;
}
else if( args.length() > 2 )
{
MGlobal::displayError( "Too many arguments." );
return MS::kFailure;
}
pfxName = args.asString( 0, &stat );
if (stat != MS::kSuccess)
{
MGlobal::displayError( "Failed to parse pfx node name argument." );
return MS::kFailure;
}
if(args.length() == 1) {
pfxOutput = "all";
} else {
pfxOutput = args.asString( 1, &stat );
if (stat != MS::kSuccess)
{
MGlobal::displayError( "Failed to parse num voxels to pribt argument." );
return MS::kFailure;
}
}
nodeFromName( pfxName, pfxNode );
if( pfxNode.isNull() )
{
MGlobal::displayError( "There is no pfx node with the given name." );
return MS::kFailure;
}
if( ! (pfxNode.hasFn( MFn::kPfxGeometry )
|| pfxNode.hasFn( MFn::kStroke )
|| pfxNode.hasFn( MFn::kPfxHair )) )
{
MGlobal::displayError( "The named node is not a stroke or pfxHair node." );
return MS::kFailure;
}
return MS::kSuccess;
}
MStatus pfxInfoCmd::printDoubleArray( MDoubleArray &array, char *title )
{
int i;
char buffer[256];
int len = array.length();
sprintf( buffer, " %s(%d entries):", title, len);
MGlobal::displayInfo( buffer );
for( i = 0; i < len; i++ ){
sprintf( buffer, " %f", array[i]);
MGlobal::displayInfo( buffer );
}
MGlobal::displayInfo( " " );
return MS::kSuccess;
}
MStatus pfxInfoCmd::printVectorArray( MVectorArray &array, char *title )
{
int i;
char buffer[256];
int len = array.length();
sprintf( buffer, " %s(%d entries):", title, len);
MGlobal::displayInfo( buffer );
for( i = 0; i < len; i++ ){
MVector vec = array[i];
sprintf( buffer, " (%f, %f, %f)", vec.x, vec.y, vec.z);
MGlobal::displayInfo( buffer );
}
MGlobal::displayInfo( " " );
return MS::kSuccess;
}
MStatus pfxInfoCmd::printRenderLine( MRenderLine &renderLine )
{
MVectorArray line = renderLine.getLine();
MVectorArray twist = renderLine.getTwist();
MDoubleArray width = renderLine.getWidth();
MDoubleArray flatness = renderLine.getFlatness();
MDoubleArray parameter = renderLine.getParameter();
MVectorArray color = renderLine.getColor();
MVectorArray incandescence = renderLine.getIncandescence();
MVectorArray transparency = renderLine.getTransparency();
if( line.length() > 0 ){
printVectorArray( line, "line" );
}
if( twist.length() > 0 ){
printVectorArray( twist, "twist" );
}
if( width.length() > 0 ){
printDoubleArray( width, "width" );
}
if( flatness.length() > 0 ){
printDoubleArray( flatness, "flatness" );
}
if( parameter.length() > 0 ){
printDoubleArray( parameter, "parameter" );
}
if( color.length() > 0 ){
printVectorArray( color, "color" );
}
if( incandescence.length() > 0 ){
printVectorArray( incandescence, "incandescence" );
}
if( transparency.length() > 0 ){
printVectorArray( transparency, "transparency" );
}
MGlobal::displayInfo( " " );
return MS::kSuccess;
}
MStatus pfxInfoCmd::printRenderLineArray( MRenderLineArray &lineArray, char *title )
{
char buffer[256];
int length = lineArray.length();
sprintf( buffer, "=%s (%d lines) =============================================", title, length);
MGlobal::displayInfo( buffer );
MStatus stat = MS::kSuccess;
for( int i = 0; i < length; i++ ){
sprintf( buffer, " LINE %d .......................", (i+1));
MGlobal::displayInfo( buffer );
MRenderLine renderLine = lineArray.renderLine( i, &stat );
if( stat == MS::kSuccess ){
printRenderLine( renderLine );
}
}
MGlobal::displayInfo( " " );
return MS::kSuccess;
}
MStatus pfxInfoCmd::doIt( const MArgList& args )
{
MStatus stat = parseArgs( args );
if( stat != MS::kSuccess ) {
return stat;
}
if( pfxOutput == "none" ){
return stat;
}
MFnPfxGeometry node( pfxNode );
MRenderLineArray mainLines, leafLines, flowerLines;
if( pfxOutput == "all" ){
stat = node.getLineData( mainLines, leafLines, flowerLines,
true, true, true, true,
true, true, true, true, true );
} else if( pfxOutput == "line" ){
stat = node.getLineData( mainLines, leafLines, flowerLines,
true, false, false, false,
false, false, false, false, true );
} else if( pfxOutput == "lineAndWidth" ){
stat = node.getLineData( mainLines, leafLines, flowerLines,
true, false, true, false,
false, false, false, false, true );
}
if( stat != MS::kSuccess ){
return stat;
}
stat = printRenderLineArray( mainLines, "MainLines" );
if( stat != MS::kSuccess ){
return stat;
}
stat = printRenderLineArray( leafLines, "LeafLines" );
if( stat != MS::kSuccess ){
return stat;
}
stat = printRenderLineArray( flowerLines, "FlowerLines" );
if( stat != MS::kSuccess ){
return stat;
}
mainLines.deleteArray();
leafLines.deleteArray();
flowerLines.deleteArray();
return MS::kSuccess;
}
void * pfxInfoCmd::creator() { return new pfxInfoCmd(); }
MStatus initializePlugin( MObject obj )
{
MFnPlugin plugin( obj, PLUGIN_COMPANY, "6.5", "Any");
MStatus status = plugin.registerCommand(mCommandName,
pfxInfoCmd::creator );
if (!status)
status.perror("registerCommand");
return status;
}
MStatus uninitializePlugin( MObject obj )
{
MFnPlugin plugin( obj );
MStatus status = plugin.deregisterCommand(mCommandName);
if (!status)
status.perror("deregisterCommand");
return status;
}