geometryCacheConverter.cpp
#include <geometryCacheFile.h>
#include <maya/MSyntax.h>
#include <maya/MPxCommand.h>
#include <maya/MGlobal.h>
#include <maya/MArgList.h>
#include <maya/MArgDatabase.h>
#include <maya/MFnPlugin.h>
#define LFLAG_TOASCII "-toAscii"
#define SFLAG_TOASCII "-ta"
#define LFLAG_FILE "-file"
#define SFLAG_FILE "-f"
class convertGeometryCache : public MPxCommand
{
public:
convertGeometryCache();
virtual ~convertGeometryCache();
static void* creator();
virtual bool hasSyntax();
static MSyntax cmdSyntax();
virtual MStatus doIt( const MArgList& args );
};
convertGeometryCache::convertGeometryCache()
{
}
convertGeometryCache::~convertGeometryCache()
{
}
void* convertGeometryCache::creator()
{
return new convertGeometryCache();
}
bool convertGeometryCache::hasSyntax()
{
return true;
}
MSyntax convertGeometryCache::cmdSyntax()
{
MSyntax syntax;
syntax.addFlag( SFLAG_TOASCII, LFLAG_TOASCII, MSyntax::kNoArg );
syntax.addFlag( SFLAG_FILE, LFLAG_FILE, MSyntax::kString );
syntax.makeFlagMultiUse( SFLAG_FILE );
syntax.enableQuery( false );
syntax.enableEdit( false );
return syntax;
}
MStatus convertGeometryCache::doIt( const MArgList& args )
{
MStatus status = MS::kSuccess;
MArgDatabase argDb( syntax(), args, &status );
if( !status ) return status;
bool isToAscii = argDb.isFlagSet( SFLAG_TOASCII );
bool hasFile = argDb.isFlagSet( SFLAG_FILE );
if( !isToAscii || !hasFile )
{
MGlobal::displayError(
"Specify at least one file and format to convert to." );
return status;
}
MIffFile iffFilePtr;
uint numUses = argDb.numberOfFlagUses( SFLAG_FILE );
for( uint i = 0; i < numUses; i++ )
{
MArgList argList;
status = argDb.getFlagArgumentList( SFLAG_FILE, i, argList );
if( !status ) return status;
MString name = argList.asString( 0, &status );
if( !status ) return status;
geometryCacheFile cacheFile( name, &iffFilePtr);
bool readStatus = cacheFile.readCacheFiles();
if( !readStatus ) {
MGlobal::displayError( "Failed in reading file \"" + name + "\"" );
continue;
}
if( isToAscii ) {
bool convertStatus = cacheFile.convertToAscii();
if( !convertStatus )
{
MGlobal::displayError( "Failed in converting file \"" +
name +
"\" to ASCII");
}
}
}
return status;
}
MStatus initializePlugin( MObject obj )
{
MStatus status;
MFnPlugin plugin( obj, "Autodesk", "8.0", "Any");
status = plugin.registerCommand( "convertGeometryCache",
convertGeometryCache::creator,
convertGeometryCache::cmdSyntax );
if (!status) {
status.perror("registerCommand");
return status;
}
return status;
}
MStatus uninitializePlugin( MObject obj)
{
MStatus status;
MFnPlugin plugin( obj );
status = plugin.deregisterCommand( "convertGeometryCache" );
if (!status) {
status.perror("deregisterCommand");
return status;
}
return status;
}