示例#1
0
/*
====================
idModelExport::ParseExportSection
====================
*/
int idModelExport::ParseExportSection( idParser &parser ) {
	idToken	command;
	idToken	token;
	idStr	defaultCommands;
	idLexer lex;
	idStr	temp;
	idStr	parms;
	int		count;
	// only export sections that match our export mask
	if( g_exportMask.GetString()[ 0 ] ) {
		if( parser.CheckTokenString( "{" ) ) {
			parser.SkipBracedSection( false );
			return 0;
		}
		parser.ReadToken( &token );
		if( token.Icmp( g_exportMask.GetString() ) ) {
			parser.SkipBracedSection();
			return 0;
		}
		parser.ExpectTokenString( "{" );
	} else if( !parser.CheckTokenString( "{" ) ) {
		// skip the export mask
		parser.ReadToken( &token );
		parser.ExpectTokenString( "{" );
	}
	count = 0;
	lex.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
	while( 1 ) {
		if( !parser.ReadToken( &command ) ) {
			parser.Error( "Unexpoected end-of-file" );
			break;
		}
		if( command == "}" ) {
			break;
		}
		if( command == "options" ) {
			parser.ParseRestOfLine( defaultCommands );
		} else if( command == "addoptions" ) {
			parser.ParseRestOfLine( temp );
			defaultCommands += " ";
			defaultCommands += temp;
		} else if( ( command == "mesh" ) || ( command == "anim" ) || ( command == "camera" ) ) {
			if( !parser.ReadToken( &token ) ) {
				parser.Error( "Expected filename" );
			}
			temp = token;
			parser.ParseRestOfLine( parms );
			if( defaultCommands.Length() ) {
				sprintf( temp, "%s %s", temp.c_str(), defaultCommands.c_str() );
			}
			if( parms.Length() ) {
				sprintf( temp, "%s %s", temp.c_str(), parms.c_str() );
			}
			lex.LoadMemory( temp, temp.Length(), parser.GetFileName() );
			Reset();
			if( ParseOptions( lex ) ) {
				const char *game = cvarSystem->GetCVarString( "fs_game" );
				if( strlen( game ) == 0 ) {
					game = BASE_GAMEDIR;
				}
				if( command == "mesh" ) {
					dest.SetFileExtension( MD5_MESH_EXT );
				} else if( command == "anim" ) {
					dest.SetFileExtension( MD5_ANIM_EXT );
				} else if( command == "camera" ) {
					dest.SetFileExtension( MD5_CAMERA_EXT );
				} else {
					dest.SetFileExtension( command );
				}
				idStr back = commandLine;
				sprintf( commandLine, "%s %s -dest %s -game %s%s", command.c_str(), src.c_str(), dest.c_str(), game, commandLine.c_str() );
				if( ConvertMayaToMD5() ) {
					count++;
				} else {
					parser.Warning( "Failed to export '%s' : %s", src.c_str(), Maya_Error.c_str() );
				}
			}
			lex.FreeSource();
		} else {
			parser.Error( "Unknown token: %s", command.c_str() );
			parser.SkipBracedSection( false );
			break;
		}
	}
	return count;
}