/** * ファイルロード[拡張子自動判別] * @param filepath ファイルフルパス * @retval true 成功 * @retval false 失敗 */ bool Load(const char* filename) { bool result = false; m_image.Clear(); std::string path(filename); std::string::size_type pos = path.rfind('.'); if (pos != std::string::npos) { const std::string ext = make_lowercase(path.substr(pos+1)); if (ext == "png") { result = LoadPNG(path); } else if (ext == "jpg" || ext == "jpeg") { result = LoadJPG(path); } else if (ext == "tga") { result = LoadTGA(path); } else if (ext == "hdr") { result = LoadHDR(path); } else if (ext == "exr" || ext == "EXR") { result = LoadEXR(path); } } return result; }
//============================================================== // Alex Alex Alex Alex Alex Alex Alex Alex Alex Alex Alex Alex //============================================================== void ExampleFunction() { HANDLE fp; int c, d, FileType; int Domain, Class; char szFile[512]; int DXL_Offset = 0, DXL_size = 0, DXL_Processing_Type = 0; sprintf(szFile, "%sKoreaObj.hdr", KoreaObjFolder); fp = fopen(szFile,"rb+"); LoadHDR(fp); fclose(fp); LoadCT(); //... // Open KO.lod sprintf(szFile, "%sKoreaObj.lod", KoreaObjFolder); fp = fopen(szFile,"rb+"); for (c = 0; c < hdr.nLOD; c++) { //... // Get Domain, Class and File Type, if LOD has a CT record // if no CT record, then Domain = Class = FileType = 0 FileType = LODUsedByCT((int) c, (int*) &Domain, (int*) &Class); if (Domain < 0) { // a shadow BSP model //... Domain = -Domain; } //... // hdrLOD[c].uint[3] = offset into KO.lod // hdrLOD[c].uint[4] = size of lod (bytes) // Seek to start of this LOD in KO.lod fseek (fp, hdrLOD[c].uint[3], SEEK_SET); // Read LOD for (d = 0; d < hdrLOD[c].uint[4]; d++) { //... } //... // Put DXL file offset and size in KO.hdr hdrLOD[c].uint[0] = DXL_Offset; hdrLOD[c].uint[1] = DXL_size; hdrLOD[c].uint[1] = DXL_Processing_Type; // not required...may be useful // your code for Air Vehicles, Land Vehicles, Weapons, etc. // I may be able to add 2D and 3D cockpit code. } //... sprintf(szFile, "%sKoreaObj.hdr", KoreaObjFolder); fp = fopen(szFile,"wb"); SaveHDR(fp); fclose(fp); return; }
BOOL CDBConverter::Convert(CString path) { CFile fp,fOut,fModel; CStdioFile fLog; int c, d, FileType; int Domain, Class, Type, CTNumber; char szFile[512]; int DXL_Offset = 0, DXL_size = 0, DXL_Processing_Type = 0; DWORD FileOffset,FileSize; strcpy(KoreaObjFolder, path); sprintf(szFile, "%sKoreaObj.hdr", KoreaObjFolder); fp.Open(szFile, CFile::modeRead); LoadHDR(fp); fp.Close(); LoadCT(); DWORD LODSize; DWORD TagCount; char *NodeTreeData; BRoot *Root; BNodeType *TagList,*TagRoot; void *LODBuffer; Converter *cvt; CString s,k; CString DirName; BYTE *Buffer; Encoder *ecd; DrawDisable=true; DBConvert=false; ReBoot=false; Abort=false; FragIt=false; AssembleIt=false; TagRoot=TagList=(BNodeType*)malloc(MAX_TAGS*sizeof(BNodeType)); LODBuffer=malloc(LOD_BUFFER_SIZE); ObjectInstance *TestObj=new ObjectInstance(1); m_ConvProgress.SetRange(0, hdr.nLOD); //... // Open KO.lod sprintf(szFile, "%sKoreaObj.lod", KoreaObjFolder); fp.Open(szFile, CFile::modeRead); void *FileBuffer=malloc(16384*1024); Restart: // Open the Saving File if(DBConvert){ m_ExitKey.EnableWindow(false); m_GotoKey.EnableWindow(false); m_NextKey.EnableWindow(false); m_PrevKey.EnableWindow(false); sprintf(szFile, "%s"OBJECTS_DATABASE_NAME, KoreaObjFolder); DirName.Format("%s\\Models", KoreaObjFolder); DirName+='\\'; if(!FragIt){ fOut.Open(szFile, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary); } else { CFileFind File; int OnList=File.FindFile(DirName); while(OnList){ OnList=File.FindNextFile(); if(File.IsDirectory())goto ok; } File.Close(); char Buffer[128]; strcpy(Buffer,DirName); _mkdir(Buffer); } ok: _asm nop sprintf(szFile, "%sDXL.Log", KoreaObjFolder); fLog.Open(szFile, CFile::modeCreate|CFile::modeWrite|CFile::typeText); } FileOffset=0; FileSize=0; c=0; while(c < hdr.nLOD) { m_ConvProgress.SetPos(c); TagList=TagRoot; //... // Get Domain, Class and File Type, if LOD has a CT record // if no CT record, then Domain = Class = FileType = 0 FileType = LODUsedByCT((int) c, (int*) &Domain, (int*) &Class, (int*)&Type, (int*)&CTNumber); if (Domain < 0) { // a shadow BSP model //... Domain = -Domain; } //... // hdrLOD[c].uint[3] = offset into KO.lod // hdrLOD[c].uint[4] = size of lod (bytes) if(!hdrLOD[c].uint[4]) _asm nop; // ONLY IF IT HAS A SIZE... if(hdrLOD[c].uint[4] && (c<4804 || c>4805)){ ///////////////// ONLY DO IF NOT REASSEMBLING FROM SEPARATED MODELS /////////////////////// if(!AssembleIt){ // Seek to start of this LOD in KO.lod fp.Seek(hdrLOD[c].uint[3], CFile::begin); // Read LOD fp.Read(FileBuffer, hdrLOD[c].uint[4]); gClass=Class; gDomain=Domain; gType=Type; s.Format("LOD %d Class %d Type %d \n Parent %d",c, Class, Type, CTNumber); m_ConvText.SetWindowText(s); // TRANSFORMATION OF THE OBJECT ecd =new Encoder("temp.DXL"); IdleMode(); cvt=CV=new Converter(); IdleMode(); // Upadtes BSP Objects TagCount=*(int*)FileBuffer; memcpy((void*)TagList,(int*)FileBuffer+1,TagCount*sizeof(*TagList)); IdleMode(); LODSize=hdrLOD[c].uint[4]-sizeof(int)-TagCount*sizeof(*TagList); memcpy(LODBuffer,(char*)FileBuffer+sizeof(int)+TagCount*sizeof(*TagList),LODSize); IdleMode(); //Root=(BRoot*)BNode::RestorePointers((BYTE*)LODBuffer, 0, &TagList); DWORD VBClass; VBClass=VB_CLASS_FEATURES; if(Class==7) VBClass=VB_CLASS_DOMAIN_GROUND; if(Class==7 && Domain==2) VBClass=VB_CLASS_DOMAIN_AIR; GlobalBias=0.0f; cvt->Init(); TheStateStack.pvtDrawObject(Root); cvt->Statistics(); ecd->Initialize(cvt); ecd->Encode(c, VBClass, CTNumber); Buffer=ecd->GetModelBuffer(); FileSize=ecd->GetModelSize(); } if(AssembleIt){ CString ModelName; ModelName.Format("%s\\%05d.DXM",DirName,c); CFileStatus Stat; FileSize=0; if(fModel.GetStatus(ModelName, Stat)){ if(fModel.Open(ModelName, CFile::modeRead|CFile::typeBinary)){ FileSize=(DWORD)Stat.m_size; Buffer=(BYTE*)malloc(FileSize); fModel.Read((void*)(Buffer), FileSize); fModel.Close(); } } } // Write out the Model if(DBConvert){ // Assign the Model Class k.Format("LOD %04d, Offset: %08x, Size %06x\n", c, FileOffset, FileSize); fLog.WriteString(k); // Single models saving if(FragIt){ CString ModelName; ModelName.Format("%s\\%05d.DXM",DirName,c); fModel.Open(ModelName, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary); fModel.Write((void*)(Buffer), FileSize); fModel.Close(); } else { fOut.Write((void*)(Buffer), FileSize); } } NextLOD=PrevLOD=NewLOD=false; m_NextKey.EnableWindow(false); if(!DBConvert){ TestObj->id=c; TestObj->DOFValues=DOFs; TestObj->SwitchValues=SWITCHes; TestObj->ParentObject->nTextureSets=1; DxDbHeader *Head=(DxDbHeader*)ecd->GetModelBuffer(); TheVbManager.SetupModel(TestObj->id, (BYTE*)Head, Head->VBClass); TheDXEngine.LoadTextures(Head->Id); TheVbManager.AssertValidModel(TestObj->id); DX->Draw(TestObj); DrawDisable=false; m_NextKey.EnableWindow(true); while((!NextLOD) && (!ReBoot)){ if(PrevLOD){ c-=2; NextLOD=true; } if(NewLOD){ char x[10]; M_gotovALUE.GetWindowText(x,5); c=atoi(x); c--; NextLOD=true; } if(Abort) return true; IdleMode(); } m_NextKey.EnableWindow(false); DrawDisable=true; Delay(100); DX->UnDraw(TestObj); TheDXEngine.UnLoadTextures(TestObj->id); TheVbManager.ReleaseModel(TestObj->id); } if(!AssembleIt){ delete ecd; delete cvt; } if(ReBoot && (!DBConvert)){ DBConvert=true; ReBoot=false; goto Restart; } // Set Up New Pointers in the HDR File if(DBConvert){ hdrLOD[c].uint[3] = FileOffset; hdrLOD[c].uint[4] = FileSize; FileOffset+=FileSize; } } else { // MODELS WITH NO SIZE !!!! CString z; z.Format("LOD %04d -------------------------\n", c); fLog.WriteString(z); } Skip: //Delay(10); IdleMode(); c++; } fLog.Close(); fp.Close(); free(FileBuffer); free(TagRoot); //... if(DBConvert){ if(!FragIt) fOut.Close(); m_ConvText.SetWindowText("Writing HDR File....."); sprintf(szFile, "%s"OBJECTS_HEADER_NAME, KoreaObjFolder); fp.Open(szFile, CFile::modeCreate|CFile::modeWrite); SaveHDR(fp); fp.Close(); } // release File Buffer DrawDisable=false; return true; }
void CDBConverter::AssembleDB() { char szFile[256]; CFile fp,fOut,fModel; CStdioFile fLog; sprintf(szFile,"%s\Models\\KoreaObj.dxh", KoreaObjFolder); fp.Open(szFile, CFile::modeRead); LoadHDR(fp, true); fp.Close(); LoadCT(); CString DirName; CString ModelName,Log; DirName.Format("%sModels\\", KoreaObjFolder); sprintf(szFile,"%s"OBJECTS_DATABASE_NAME, DirName); fOut.Open(szFile, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary); sprintf(szFile,"%sDXL.Log", DirName); fLog.Open(szFile, CFile::modeCreate|CFile::modeWrite|CFile::typeText); DWORD FileOffset=0; DWORD FileSize=0; DWORD NewLODIndex=0; for(DWORD a=0; a<MAX_LOD; a++) LODNames[a]=""; m_ConvProgress.SetRange(0, hdr.nParent); bool EndIt=false; DWORD idx=0, p; for(idx=0; idx<hdr.nParent; idx++){ m_ConvProgress.SetPos(idx); IdleMode(); for(p=0; p<10; p++){ if(hdrLODRes[idx].LODName[p][0]){ DWORD OldIndex=(hdrLODRes[idx].lodind[p]-1)/2; DWORD Index=GetLODIndex(hdrLODRes[idx].LODName[p]); if(Index!=-1) hdrLODRes[idx].lodind[p]=Index*2+1; else { ModelName.Format("%s%s.DXM",DirName,hdrLODRes[idx].LODName[p]); CFileStatus Stat; FileSize=0; BYTE *Buffer; if(fModel.GetStatus(ModelName, Stat) && fModel.Open(ModelName, CFile::modeRead|CFile::typeBinary)){ FileSize=(DWORD)Stat.m_size; Buffer=(BYTE*)malloc(FileSize); fModel.Read((void*)(Buffer), FileSize); fModel.Close(); ((DxDbHeader*)Buffer)->Id=NewLODIndex; fOut.Write(Buffer,FileSize); free(Buffer); Log.Format("%-32s : #%05d -> #%05d @ %08x x %07x \n", hdrLODRes[idx].LODName[p], OldIndex, NewLODIndex, FileOffset, FileSize); fLog.WriteString(Log); LODNames[NewLODIndex]=hdrLODRes[idx].LODName[p]; hdrLODRes[idx].lodind[p]=NewLODIndex*2+1; hdrLOD[NewLODIndex].uint[3] = FileOffset; hdrLOD[NewLODIndex].uint[4] = FileSize; FileOffset+=FileSize; NewLODIndex++; } else{ CString Error; Error.Format("%s Failed to load!",hdrLODRes[idx].LODName[p]); MessageBox(Error); } } } } } fOut.Close(); fLog.Close(); sprintf(szFile,"%s"OBJECTS_HEADER_NAME,DirName); fp.Open(szFile, CFile::modeCreate|CFile::modeWrite); SaveHDR(fp, true); fp.Close(); }