Example #1
0
// *****************************************************************************
MStatus GtoIO::reader( const MFileObject &file, 
                       const MString &optionsString,
                       MPxFileTranslator::FileAccessMode mode )
{
    MString filename = file.fullName();
    bool readAsDifference = false;
    int fs = 0;
    int fe = 0;

    MStringArray args;
    optionsString.split( ';', args );
    for( size_t i = 0; i < args.length(); ++i )
    {
        MStringArray thisArg;
        args[i].split( '=', thisArg );
        MString argName( thisArg[0] );
        MString argValue( thisArg[1] );

        if( argName == "readDiff" && argValue == "1" )
        {
            readAsDifference = true;
        }
        else if( argName == "fs" )
        {
            fs = argValue.asInt();
        }
        else if( argName == "fe" )
        {
            fe = argValue.asInt();
        }
    }

    if( readAsDifference )
    {
        MGlobal::displayInfo( "PreMunge name: " + filename );

        if( filename.index( '#' ) < 0 )
        {
            // By this point, Maya will have already appended a 
            // ".gto" to the filename if the user didn't include it,
            // so we're guaranteed to find a '.' in the filename
            filename = filename.substring( 0, filename.index( '.' ) )
                       + "#.gto";
        }

        for( int f = fs; f <= fe; ++f )
        {
            MGlobal::viewFrame( MTime( double(f) ) );

            MString fname = replaceFrameCookies( filename, f );

            MGlobal::displayInfo( "Reading " + fname );

            DataBase dataBase;
            Set *set = dataBase.set( fname.asChar() );
            if( set == NULL )
            {
                MGlobal::displayError( "Unable to open file for some "
                                       "reason.  Permissions?" );
                return MS::kFailure;
            }

            set->computeLocalTransforms();

            set->declareMayaDiff();

            dataBase.destroyAll();
        }
    }
    else
    {
        DataBase dataBase;
        Set *set = dataBase.set( filename.asChar() );
        if( set == NULL )
        {
            MGlobal::displayError( "Unable to open file for some "
                                   "reason.  Permissions?" );
            return MS::kFailure;
        }

        set->computeLocalTransforms();

        set->declareMaya();

        set->reparentAll();

        dataBase.destroyAll();
    }

    return MS::kSuccess;
}