Beispiel #1
0
// ------------------------------------------------------------------------
// lta packer
// 
// open up the lta file parse it in, interpret into model, call model save 
// with export name... 
// ------------------------------------------------------------------------
int main(int argc, char* argv[])
{
	if (!TdGuard::Aegis::GetSingleton().Init() ||
		!TdGuard::Aegis::GetSingleton().DoWork())
	{
		return 1;
	}


	const bool bLoadChildModelsAsRefs = true ;
	LAllocCount AllocCount(&g_DefAlloc);
	EReturnValue RetVal = RET_SUCCESS; // Return value. Set to indicate error.
	bool bVerbose = false ;
	// default number of quad slots in a render patch (ps2)
    uint32 iMaxPatchMemory = 500; // quad slots 
	Model  *pNewModel;
	const char *pInFileName; char *pOutFileName ;

	g_cmdLine.SetCommandLine(argc,argv); 
	bool bInvalidParams = false;
	
	if (!g_cmdLine.GetProcessCmd())	
	{ 
		cerr << "No compile output format specified" << endl; 
		OutputDebugString("No compile output format specified"); 
		bInvalidParams = true; 
	}
	if (!g_cmdLine.GetInFile())		
	{  
		cerr << "No input file specified" << endl; 
		OutputDebugString("No input file specified"); 
		bInvalidParams = true; 
	}
	if (!g_cmdLine.InPlace() && !g_cmdLine.GetOutFile() )	
	{ 
		cerr << "No output file specified" << endl; 
		OutputDebugString("No output file specified"); 
		bInvalidParams = true; 
	}
	
	if (bInvalidParams) {
		RetVal = RET_INVALID_PARAMS;
		cout << "Usage:" << endl;
		cout << "Model_Packer CONVERSION_DIRECTIVE -input filename.lta -output outputfilename.ltb -verbose" << endl;
		cout << "Model_Packer CONVERSION_DIRECTIVE -inplace filename.lta -verbose" << endl;
		cout << "Packer Conversion Directives :" << endl;
		
		cout << "\nd3d : "<< endl;
		cout << "\tCompiles lta to an ltb with d3d (DirectX) optimizations."<<endl;
		cout << "\tOptions : " << endl;
		cout << "\tMaxBonesPerVert, MaxBonesPerTri,\n MinBoneWeight, ReIndexBones" << endl;
		cout << "\tUseMatrixPalettes " << endl;
		
			
		cout << "\t-inplace will change the lta/ltc into ltb as the out put name." << endl;
		cout << "\t-ac0     forces packer to not compress." << endl;
		cout << "\t-ac1     compress animations, saving only relevant info." << endl;
		cout << "\t-ac2     compress animations even more. Possibly losing float precision."<<endl;
		cout << "\t-acpv    animation compression 16 bit (for rotations only), plus rle. " <<endl;
		cout << "\t-nogeom  don't put geometry into ltb file. (space saving)."<<endl;

		cout << "\n\tnote: don't forget to convert child models as well." << endl;
		cout << endl;
		
		cout << endl<< __DATE__ << "\t\t" << LT_VERSION << endl;
		
		return RetVal; 
	}
	
	
	if( g_cmdLine.hasVerbose() )
	{
		CLTATranslStatus::SetLoadLogCB(VerboseOutputCB);
		bVerbose = true ;
	}

		// open input file 
	if( bVerbose ) {
		cout <<"processing : " << g_cmdLine.GetInFile() ;
		if( !g_cmdLine.InPlace() )
		 cout << " --> " << g_cmdLine.GetOutFile() << endl;
		else cout << endl;
	}

	pInFileName = g_cmdLine.GetInFile();
	if( g_cmdLine.InPlace() )
	{
		uint32 size = strlen(pInFileName);
		pOutFileName = strdup(pInFileName);
		pOutFileName[ size -1 ] = 'b';
	}
	else {
		pOutFileName = (char*)g_cmdLine.GetOutFile();
	}

	pNewModel = ltaModelLoad( pInFileName, AllocCount ,bLoadChildModelsAsRefs );
	if( pNewModel == NULL )
	{
		cerr << "could open or process " << g_cmdLine.GetInFile() << " exiting " << endl;
		RetVal = RET_FILE_READ_FAILED;
		return RetVal ;
	}

	// Go through the known process commands...
	if (stricmp(g_cmdLine.GetProcessCmd(),"compile_ltb_d3d")==0  ||
	   (stricmp(g_cmdLine.GetProcessCmd(),"d3d")==0)) 
	{
		// Get some params...
		int    iMaxBonesPerVert					= 4;
        int    iMaxBonesPerTri					= 99; 
		bool   bUseMatrixPalettes				= false;
		float  fMinWeightPerBone				= 0.05f;
		bool   bReIndexBones					= true;
		bool   bExportJustPieceLOD				= false;
		bool   bExportGeom						= g_cmdLine.ExportGeom();
		EANIMCOMPRESSIONTYPE AnimCompressionType= g_cmdLine.GetAnimCompressionType();

		// model over-rides.
		if(!g_cmdLine.GetAnimCompressionTypeOverride())
		{
			AnimCompressionType = (EANIMCOMPRESSIONTYPE)pNewModel->m_CompressionType ;
		}
		if(!g_cmdLine.ExportGeomOverride()) 
		{		
			bExportGeom         = !pNewModel->m_bExcludeGeom ;
		}
 
		string szPieceLODName;
		uint32 StreamData[4];

		if (g_cmdLine.GetParamVal("MaxBonesPerVert"))
            iMaxBonesPerVert   = atoi(g_cmdLine.GetParamVal("MaxBonesPerVert"));

		if (g_cmdLine.GetParamVal("MaxBonesPerTri"))
            iMaxBonesPerTri    = atoi(g_cmdLine.GetParamVal("MaxBonesPerTri"));

		if (g_cmdLine.GetParamVal("MinBoneWeight"))
            fMinWeightPerBone  = (float)atof(g_cmdLine.GetParamVal("MinBoneWeight"));

		if (g_cmdLine.GetParamVal("UseMatrixPalettes")) {
            bUseMatrixPalettes = atoi(g_cmdLine.GetParamVal("UseMatrixPalettes")) ?  true : false; }

		if (g_cmdLine.GetParamVal("ReIndexBones")) {
			bReIndexBones = atoi(g_cmdLine.GetParamVal("ReIndexBones")) ? true : false; }

		if (g_cmdLine.GetParamVal("ExportJustRenderObject")) {
			bExportJustPieceLOD = true;
			szPieceLODName = g_cmdLine.GetParamVal("ExportJustRenderObject"); 
		}
		


		if ( bUseMatrixPalettes ) iMaxBonesPerVert = MIN(iMaxBonesPerVert,4);	// Always force it - even if they say not to - because these are the real limits...
		else iMaxBonesPerTri  = MIN(iMaxBonesPerTri,4);

		for (uint32 i = 0; i < 4; ++i) { StreamData[i] = g_cmdLine.GetSteamFlags(i); }

		

		C_LTB_D3D_File MyFile;
		
		if (!MyFile.OpenFile(pOutFileName)) {
			cout << "Error opening file." << pOutFileName << endl; 
		}
		else 
		{
			if (bVerbose ) 
			{	
				cerr << "MaxBonesPerVert "<< iMaxBonesPerVert << endl;
				cerr << "MaxBonesPerTri "<< iMaxBonesPerTri << endl;
				cerr << "MinBoneWeight "<< fMinWeightPerBone << endl;
				cerr << "UseMatrixPalettes "<< bUseMatrixPalettes << endl; 
				cerr << "ReIndexBones" << bReIndexBones << endl; 
				if( !bExportGeom ) cerr << "Excluding Geometry"<< endl;
				cerr << "AnimCompressionType : " << szAnimCompressionType[ int(AnimCompressionType) ] << endl;
			}


			if (bExportJustPieceLOD) // export just the pieces.
			{
				if (!MyFile.ExportD3DFile_JustPieceLOD(
													pNewModel,
													szPieceLODName.c_str(),
													iMaxBonesPerVert,
													iMaxBonesPerTri,
													bUseMatrixPalettes,
													fMinWeightPerBone,
													bReIndexBones,
													StreamData)) 
				{
					cerr << "Error render object file." << endl; 
					RetVal = RET_FILE_OPEN_FAILED; 
				} 
				
			}
			else // export the whole file
			{
				if (!MyFile.ExportD3DFile(	pNewModel, 
											iMaxBonesPerVert,
											iMaxBonesPerTri,
											bUseMatrixPalettes,
											fMinWeightPerBone,
											bReIndexBones,
											StreamData,
											AnimCompressionType,
											bExportGeom)) 
				{
					cerr << "Error exporting file." << endl; 
					RetVal = RET_FILE_OPEN_FAILED; 
				} 
			} 
		}
	}
	else {
		cerr << g_cmdLine.GetProcessCmd() << " is an unknown command " << endl;
	}

	if( bVerbose )
	{
		extern void GetAnimOutputReport( ostream & );
		GetAnimOutputReport(cout);
	}
	
	// see if the user wants to stall ( this is for when ModelEdit calls 
	// the packer so that the user can see the output )
	if( g_cmdLine.hasStall() )
	{
		cout << endl << "Press Enter to continue." << endl;
		while( cin.peek() == EOF )
			;
	}

	return RetVal; 
}