📄 ase2tgl.cpp
字号:
//===========================================================================//
// Copyright (C) Microsoft Corporation. All rights reserved. //
//===========================================================================//
#include "stdafx.h"
#include "version.h"
#include "../../ARM/Microsoft.Xna.Arm.h"
using namespace Microsoft::Xna::Arm;
HINSTANCE hInst = NULL;
DWORD gosResourceHandle = 0;
Stuff::MemoryStream *effectStream = NULL;
extern char CDInstallPath[];
bool hasGuardBand = false;
bool justResaveAllMaps = false;
Camera *eye = NULL;
enum { CPU_UNKNOWN, CPU_PENTIUM, CPU_MMX, CPU_KATMAI } Processor = CPU_PENTIUM; //Needs to be set when GameOS supports ProcessorID -- MECHCMDR2
float MaxMinUV = 8.0f;
DWORD BaseVertexColor = 0x00000000;
static LPCTSTR lpszAppName = "MechCmdr2";
UserHeapPtr systemHeap = NULL;
UserHeapPtr guiHeap = NULL;
float gosFontScale = 1.0f;
extern bool silentMode;
bool useLOSAngle = false;
static bool createARM = false;
IProviderEngine * armProvider = NULL;
unsigned long tglHeapSize = 16386000;
FastFile **fastFiles = NULL;
long numFastFiles = 0;
long maxFastFiles = 0;
HWND appWnd = NULL;
extern char* MechAnimationNames[MaxGestures];
long ObjectTextureSize = 128;
bool reloadBounds = false;
MidLevelRenderer::MLRClipper * theClipper = NULL;
HGOSFONT3D gosFontHandle = 0;
extern HGOSFONT3D FontHandle;
FloatHelpPtr globalFloatHelp = NULL;
unsigned long currentFloatHelp = 0;
char fileName[1024];
char listName[1024];
//----------------------------------------------------------------------------
// Same command line Parser as MechCommander
void ParseCommandLine(char *command_line)
{
int i;
int n_args = 0;
int index = 0;
char *argv[30];
char tempCommandLine[4096];
memset(tempCommandLine,0,4096);
strncpy(tempCommandLine,command_line,4095);
while (tempCommandLine[index] != '\0') // until we null out
{
argv[n_args] = tempCommandLine + index;
n_args++;
while (tempCommandLine[index] != ' ' && tempCommandLine[index] != '\0')
{
index++;
}
while (tempCommandLine[index] == ' ')
{
tempCommandLine[index] = '\0';
index++;
}
}
i=0;
while (i<n_args)
{
if (strcmpi(argv[i],"-file") == 0)
{
i++;
if (i < n_args)
{
if (argv[i][0] == '"')
{
// They typed in a quote, keep reading argvs
// until you find the close quote
strcpy(fileName,&(argv[i][1]));
bool scanName = true;
while (scanName && (i < n_args))
{
i++;
if (i < n_args)
{
strcat(fileName," ");
strcat(fileName,argv[i]);
if (strstr(argv[i],"\"") != NULL)
{
scanName = false;
fileName[strlen(fileName)-1] = 0;
}
}
else
{
//They put a quote on the line with no space.
//
scanName = false;
fileName[strlen(fileName)-1] = 0;
}
}
}
else
strcpy(fileName,argv[i]);
}
}
if (strcmpi(argv[i],"-list") == 0)
{
i++;
if (i < n_args)
{
if (argv[i][0] == '"')
{
// They typed in a quote, keep reading argvs
// until you find the close quote
strcpy(listName,&(argv[i][1]));
bool scanName = true;
while (scanName && (i < n_args))
{
i++;
if (i < n_args)
{
strcat(listName," ");
strcat(listName,argv[i]);
if (strstr(argv[i],"\"") != NULL)
{
scanName = false;
listName[strlen(listName)-1] = 0;
}
}
else
{
//They put a quote on the line with no space.
//
scanName = false;
listName[strlen(listName)-1] = 0;
}
}
}
else
strcpy(listName,argv[i]);
}
}
if (strcmpi(argv[i],"-arm") == 0)
{
createARM = true;
}
i++;
}
}
//-----------------------------
long convertASE2TGL (char *file)
{
//---------------------------------------------------
// Get all of the .ASE files in the tgl directory.
char findString[1024];
char armFileName[1024];
if( file[0] == '\0')
{
sprintf(findString,"%s*.ini",tglPath);
}
else
{
strcpy(findString,tglPath);
strcat(findString, file);
}
int count =0;
WIN32_FIND_DATA findResult;
HANDLE searchHandle = FindFirstFile(findString,&findResult);
do
{
if ((findResult.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
{
//-----------------------------------
// Search for TGLData
FullPathFileName iniName;
iniName.init(tglPath,findResult.cFileName,"");
FitIniFile iniFile;
long result = iniFile.open(iniName);
if (result != NO_ERR)
return result;
// ARM
IProviderAssetPtr iniAsset = armProvider->OpenAsset((char*)iniName, AssetType_Physical,
ProviderType_Primary);
iniAsset->AddProperty("Type", "Object Definition");
iniAsset->AddProperty("Version", "1.0");
TG_TypeMultiShape *shape = NULL;
result = iniFile.seekBlock("TGLData");
if (result == NO_ERR)
{
char fileName[1024];
result = iniFile.readIdString("FileName",fileName,1023);
if (result != NO_ERR)
{
//---------------------------------------------
// We have LODs -- handle differently
// We will get animation from LAST LOD loaded
long i=0;
char fileCheck[1024];
sprintf(fileCheck,"FileName%d",i);
result = iniFile.readIdString(fileCheck,fileName,1023);
while (result == NO_ERR)
{
if (shape)
{
delete shape;
shape = NULL;
}
char aseName[1024];
sprintf(aseName,"%s%s%s",tglPath,fileName,".ase");
//---------------------------------------------------------------------------------------------
// Load Base Shape or LOD 0 Shape.
shape = new TG_TypeMultiShape;
gosASSERT(shape != NULL);
printf( "Processing Main Shape %s\n", aseName );
char lodID[4];
sprintf(lodID, "%02d", count);
IProviderRelationshipPtr armLink = iniAsset->AddRelationship("LOD Shape", aseName);
armLink->AddProperty("LOD", lodID);
shape->LoadTGMultiShapeFromASE(aseName, true, armProvider);
i++;
sprintf(fileCheck,"FileName%d",i);
result = iniFile.readIdString(fileCheck,fileName,1023);
}
}
char aseName[1024];
sprintf(aseName,"%s%s%s",tglPath,fileName,".ase");
//---------------------------------------------------------------------------------------------
// Load Base Shape or LOD 0 Shape.
shape = new TG_TypeMultiShape;
gosASSERT(shape != NULL);
printf( "Processing Main Shape %s\n", aseName );
IProviderRelationshipPtr armLink = iniAsset->AddRelationship("Main Shape", aseName);
shape->LoadTGMultiShapeFromASE(aseName, true, armProvider);
//-------------------------------------------
// Gotta make the special shadow shape now!!
// MUST use its own shape or animation below
// will go straight to HELL!!
result = iniFile.readIdString("ShadowName",fileName,1023);
if (result == NO_ERR)
{
char aseName[1024];
sprintf(aseName,"%s%s%s",tglPath,fileName,".ase");
//---------------------------------------------------------------------------------------------
// Load Base Shape or LOD 0 Shape.
TG_TypeMultiShapePtr shadowShape = new TG_TypeMultiShape;
gosASSERT(shadowShape != NULL);
printf( "Processing Shadow Shape %s\n", aseName );
IProviderRelationshipPtr armLink = iniAsset->AddRelationship("Shadow Shape", aseName);
shadowShape->LoadTGMultiShapeFromASE(aseName, true, armProvider);
delete shadowShape;
shadowShape = NULL;
}
long i=0;
char animCheck[1024];
sprintf(animCheck,"Animation:%d",i);
result = iniFile.seekBlock(animCheck);
while (result == NO_ERR) //This thing has animations. Process them!
{
char fileName[1024];
result = iniFile.readIdString("AnimationName",fileName,1023);
if (result == NO_ERR)
{
FullPathFileName aseName;
aseName.init(tglPath,fileName,".ase");
TG_AnimateShape *anim = new TG_AnimateShape;
gosASSERT(mechAnim != NULL);
//-----------------------------------------------
// Skip this one if its already a binary file.
// Happens ALOT!
printf( "Processing Animation %s\n", aseName );
IProviderRelationshipPtr armLink = iniAsset->AddRelationship("Animation", (char*)aseName);
anim->LoadTGMultiShapeAnimationFromASE(aseName,shape,true);
delete anim;
anim = NULL;
}
i++;
sprintf(animCheck,"Animation:%d",i);
result = iniFile.seekBlock(animCheck);
}
if (!i) //No Animations, BUT they may mean we are a MECH!!!
{
if (iniFile.seekBlock("Gestures0") == NO_ERR)
{
//We ARE a mech. Load all of the animations for this mech and write 'em out.
for (long i=0;i<MaxGestures;i++)
{
char name[MAX_PATH];
_splitpath(findResult.cFileName,NULL,NULL,name,NULL);
char mechFileName[1024];
sprintf(mechFileName,"%s%s%s.ase",tglPath,name,MechAnimationNames[i]);
TG_AnimateShape *anim = new TG_AnimateShape;
gosASSERT(anim != NULL);
//-----------------------------------------------
// Skip this one if its already a binary file.
// Happens ALOT!
printf( "Processing Animation %s\n", mechFileName );
IProviderRelationshipPtr armLink = iniAsset->AddRelationship("Animation", mechFileName);
anim->LoadTGMultiShapeAnimationFromASE(mechFileName,shape,true);
delete anim;
anim = NULL;
}
}
}
if (!i) //No Animations, BUT they may mean we are a MECH!!!
{
if (iniFile.seekBlock("Gestures0") == NO_ERR)
{
//We ARE a mech. Load all of the destroyed shapes for this mech and write 'em out.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -