/* ===================== idModelExport::ConvertMayaToMD5 Checks if a Maya model should be converted to an MD5, and converts if if the time/date or version number has changed. ===================== */ bool idModelExport::ConvertMayaToMD5( void ) { ID_TIME_T sourceTime; ID_TIME_T destTime; int version; idToken cmdLine; idStr path; // check if our DLL got loaded if( initialized && !Maya_ConvertModel ) { Maya_Error = "MayaImport dll not loaded."; return false; } // if idAnimManager::forceExport is set then we always reexport Maya models if( idAnimManager::forceExport ) { force = true; } // get the source file's time if( fileSystem->ReadFile( src, NULL, &sourceTime ) < 0 ) { // source file doesn't exist return true; } // get the destination file's time if( !force && ( fileSystem->ReadFile( dest, NULL, &destTime ) >= 0 ) ) { idParser parser( LEXFL_ALLOWPATHNAMES | LEXFL_NOSTRINGESCAPECHARS ); parser.LoadFile( dest ); // read the file version if( parser.CheckTokenString( MD5_VERSION_STRING ) ) { version = parser.ParseInt(); // check the command line if( parser.CheckTokenString( "commandline" ) ) { parser.ReadToken( &cmdLine ); // check the file time, scale, and version if( ( destTime >= sourceTime ) && ( version == MD5_VERSION ) && ( cmdLine == commandLine ) ) { // don't convert it return true; } } } } // if this is the first time we've been run, check if Maya is installed and load our DLL if( !initialized ) { initialized = true; if( !CheckMayaInstall() ) { Maya_Error = "Maya not installed in registry."; return false; } LoadMayaDll(); // check if our DLL got loaded if( !Maya_ConvertModel ) { Maya_Error = "Could not load MayaImport dll."; return false; } } // we need to make sure we have a full path, so convert the filename to an OS path src = fileSystem->RelativePathToOSPath( src ); dest = fileSystem->RelativePathToOSPath( dest ); dest.ExtractFilePath( path ); if( path.Length() ) { fileSystem->CreateOSPath( path ); } // get the os path in case it needs to create one path = fileSystem->RelativePathToOSPath( "" ); common->SetRefreshOnPrint( true ); Maya_Error = Maya_ConvertModel( path, commandLine ); common->SetRefreshOnPrint( false ); if( Maya_Error != "Ok" ) { return false; } // conversion succeded return true; }
/* ===================== idModelExport::LoadMayaDll Checks to see if we can load the Maya export dll ===================== */ void idModelExport::LoadMayaDll( void ) { exporterDLLEntry_t dllEntry; char dllPath[ MAX_OSPATH ]; fileSystem->FindDLL( "MayaImport", dllPath, false ); if ( !dllPath[ 0 ] ) { return; } importDLL = sys->DLL_Load( dllPath ); if ( !importDLL ) { return; } // look up the dll interface functions dllEntry = ( exporterDLLEntry_t )sys->DLL_GetProcAddress( importDLL, "dllEntry" ); Maya_ConvertModel = ( exporterInterface_t )sys->DLL_GetProcAddress( importDLL, "Maya_ConvertModel" ); Maya_Shutdown = ( exporterShutdown_t )sys->DLL_GetProcAddress( importDLL, "Maya_Shutdown" ); if ( !Maya_ConvertModel || !dllEntry || !Maya_Shutdown ) { Maya_ConvertModel = NULL; Maya_Shutdown = NULL; sys->DLL_Unload( importDLL ); importDLL = 0; gameLocal.Error( "Invalid interface on export DLL." ); return; } // initialize the DLL // RAVEN BEGIN // rhummer: unify allocation strategy to try to fix some of our crashes #ifdef RV_UNIFIED_ALLOCATOR if ( !dllEntry( MD5_VERSION, common, sys, Memory::Allocate, Memory::Free, Memory::MSize ) ) { #else if ( !dllEntry( MD5_VERSION, common, sys ) ) { #endif // RAVEN END // init failed Maya_ConvertModel = NULL; Maya_Shutdown = NULL; sys->DLL_Unload( importDLL ); importDLL = 0; gameLocal.Error( "Export DLL init failed." ); return; } // RAVEN BEGIN // jscott: maya needs the source control in the tools dll common->LoadToolsDLL(); // RAVEN END } /* ===================== idModelExport::ConvertMayaToMD5 Checks if a Maya model should be converted to an MD5, and converts if if the time/date or version number has changed. ===================== */ bool idModelExport::ConvertMayaToMD5( void ) { unsigned sourceTime; unsigned destTime; int version; idToken cmdLine; idStr path; // check if our DLL got loaded if ( initialized && !Maya_ConvertModel ) { Maya_Error = "MayaImport dll not loaded."; return false; } // if idAnimManager::forceExport is set then we always reexport Maya models if ( idAnimManager::forceExport ) { force = true; } // RAVEN BEGIN // bdube: fs_import path // we need to make sure we have a full path, so convert the filename to an OS path path.AppendPath( cvarSystem->GetCVarString ("fs_importpath")); path.AppendPath(src); idFile* f = fileSystem->OpenExplicitFileRead ( path ); if ( !f ) { Maya_Error = "could not open source file"; return false; } sourceTime = f->Timestamp ( ); fileSystem->CloseFile ( f ); /* // get the source file's time if ( fileSystem->ReadFile( src, NULL, &sourceTime ) < 0 ) { // source file doesn't exist return true; } */ // RAVEN END // get the destination file's time if ( !force && ( fileSystem->ReadFile( dest, NULL, &destTime ) >= 0 ) ) { idParser parser( LEXFL_ALLOWPATHNAMES | LEXFL_NOSTRINGESCAPECHARS ); parser.LoadFile( dest ); // read the file version if ( parser.CheckTokenString( MD5_VERSION_STRING ) ) { version = parser.ParseInt(); // check the command line if ( parser.CheckTokenString( "commandline" ) ) { parser.ReadToken( &cmdLine ); // check the file time, scale, and version if ( ( destTime >= sourceTime ) && ( version == MD5_VERSION ) && ( cmdLine == commandLine ) ) { // don't convert it return true; } } } } // if this is the first time we've been run, check if Maya is installed and load our DLL if ( !initialized ) { initialized = true; if ( !CheckMayaInstall() ) { Maya_Error = "Maya not installed in registry."; return false; } LoadMayaDll(); // check if our DLL got loaded if ( !Maya_ConvertModel ) { Maya_Error = "Could not load MayaImport dll."; return false; } } // we need to make sure we have a full path, so convert the filename to an OS path src = fileSystem->RelativePathToOSPath( src ); dest = fileSystem->RelativePathToOSPath( dest ); dest.ExtractFilePath( path ); if ( path.Length() ) { fileSystem->CreateOSPath( path ); } // get the os path in case it needs to create one path = fileSystem->RelativePathToOSPath( "" ); common->SetRefreshOnPrint( true ); // RAVEN BEGIN // scork: if this assert ever triggers it means there's a call to ConvertMayaToMD5() that doesn't have a 'MayaConversionCleaner' object above it. Go and put one in. Now. assert( g_bMayaConversionCleanerRunning ); // bdube: support src and dest ospath Maya_Error = Maya_ConvertModel( cvarSystem->GetCVarString ( "fs_importpath" ), path, commandLine ); // RAVEN END common->SetRefreshOnPrint( false ); if ( Maya_Error != "Ok" ) { return false; } // conversion succeded return true; }