CBool CScene::Load( CChar * fileName, CBool reportWarningsAndErrors, CBool readFromBuffer ) { if ( fileName == NULL ) return CFalse; CChar * nameOnly = GetAfterPath( fileName ); SetName( nameOnly ); // Instantiate the reference implementation m_collada = new DAE; PrintInfo( "\n" ); PrintInfo( _T("\n========Importing new external scene========"), COLOR_BLUE ); numErrors = numWarnings = 0; domCOLLADA *dom; if( readFromBuffer ) { ///////////////////////////////////////////////////////////////// //zip path CChar zipPath[MAX_NAME_SIZE]; Cpy( zipPath, fileName ); GetWithoutDot( zipPath ); Append(zipPath, ".zip" ); //file name inside zip file CChar fileNameInZip[MAX_NAME_SIZE]; Cpy( fileNameInZip, GetAfterPath( fileName ) ); //Uncompress zip file std::string buffer = ReadZipFile( zipPath, fileNameInZip ); //res = m_collada->load( "", buffer.c_str() ); dom = m_collada->openFromMemory( "", buffer.c_str() ); /////////////////////////////////////////////////////////////// } else { // load with full path //res = m_collada->load( fileName ); dom = m_collada->open(fileName); } //if (res != DAE_OK) //{ // PrintInfo(_T("\nCScene::Load > Error loading the COLLADA file:") + CString(fileName), COLOR_RED ); // delete m_collada; // m_collada = NULL; //if( reportWarningsAndErrors ) //{ // char tempReport[MAX_NAME_SIZE];; // sprintf( tempReport, "%s - fatal error (s)", nameOnly ); // PrintInfo2( tempReport, COLOR_RED ); //} // return CFalse; //} PrintInfo( _T("\nCOLLADA_DOM Runtime database initialized from" ) ); PrintInfo( _T("'") + CString( fileName ), COLOR_RED_GREEN ); //PrintInfo( _T("nameOnly: '") + (CString)nameOnly + _T( "'\n" ) ); //domCOLLADA *dom = m_collada->getDom(nameOnly); //if ( !dom ) // dom = m_collada->getDom( fileName); if ( !dom ) { PrintInfo( _T("\nCScene::Load > COLLADA File loaded to the dom, but query for the dom assets failed "), COLOR_RED ); PrintInfo( _T("\nCScene::Load > COLLADA Load Aborted! "), COLOR_RED ); delete m_collada; m_collada = NULL; if( reportWarningsAndErrors ) { char tempReport[MAX_NAME_SIZE];; sprintf( tempReport, "\n%s - Fatal error (s)", nameOnly ); PrintInfo( tempReport, COLOR_RED ); } return CFalse; } CInt ret = 0; //PrintInfo("Begin Conditioning\n"); //ret = kmzcleanup(m_collada, true); //if (ret) // PrintInfo("kmzcleanup complete\n"); ret = Triangulate(m_collada); if (ret) PrintInfo("\nTriangulate complete"); //ret = deindexer(m_collada); //if (ret) // PrintInfo("deindexer complete\n"); //PrintInfo("Finish Conditioning\n"); // Need to now get the asset tag which will determine what vector x y or z is up. Typically y or z. if ( dom->getAsset()->getUp_axis() ) { domAsset::domUp_axis *up = dom->getAsset()->getUp_axis(); switch( up->getValue() ) { case UPAXISTYPE_X_UP: PrintInfo(_T("\nWarning!X is Up Data and Hiearchies must be converted!") ); PrintInfo(_T("\nConversion to X axis Up isn't currently supported!") ); PrintInfo(_T("\nCOLLADA defaulting to Y Up") ); numWarnings +=1; //CRender.SetUpAxis(eCYUp); break; case UPAXISTYPE_Y_UP: PrintInfo( _T("\nY Axis is Up for this file...COLLADA set to Y Up ") ); //CRender.SetUpAxis(eCYUp); break; case UPAXISTYPE_Z_UP: PrintInfo( _T("\nZ Axis is Up for this file ") ); PrintInfo( _T("\nAll Geometries and Hiearchies converted!"), COLOR_YELLOW ) ; numWarnings +=1; //CRender.SetUpAxis(eCZUp); break; default: break; } } strcpy( m_fileName, fileName ); strcpy( m_pureFileName, nameOnly ); // Load all the image libraries //for ( CUInt i = 0; i < dom->getLibrary_images_array().getCount(); i++) //{ // ReadImageLibrary( dom->getLibrary_images_array()[i] ); //} CBool success = CFalse; /* CChar *cfxBinFilename = ReadCfxBinaryFilename( dom->getExtra_array() ); if ( cfxBinFilename != NULL ) { cfxLoader::setBinaryLoadRemotePath( BasePath ); success = (CBool) cfxLoader::loadMaterialsAndEffectsFromBinFile(cfxBinFilename, cfxMaterials, cfxEffects, cgContext); assert(success); } else { */ //success = ( CBool ) cfxLoader::loadMaterialsAndEffects( m_collada, m_cfxMaterials, m_cfxEffects, m_cgContext ); //assert(success); /*}*/ // Load all the effect libraries //for ( CUInt i = 0; i < dom->getLibrary_effects_array().getCount(); i++) //{ // ReadEffectLibrary( dom->getLibrary_effects_array()[i] ); //} //// Load all the material libraries //for ( CUInt i = 0; i < dom->getLibrary_materials_array().getCount(); i++) //{ // ReadMaterialLibrary( dom->getLibrary_materials_array()[i] ); //} // Load all the animation libraries for ( CUInt i = 0; i < dom->getLibrary_animations_array().getCount(); i++) { ReadAnimationLibrary( dom->getLibrary_animations_array()[i] ); m_hasAnimation = CTrue; } //Load all animation clips for ( CUInt i = 0; i < dom->getLibrary_animation_clips_array().getCount(); i++) { ReadAnimationClipLibrary( dom->getLibrary_animation_clips_array()[i] ); } //If there's no clip in COLLADA file, try to create a default clip if( m_numClips == 0 && dom->getLibrary_animations_array().getCount() > 0 ) { //Create a default clip and attach all the animations to this clip PrintInfo( "\nAdding default animation clip..." ); CAnimationClip * newAnimClip = CNew(CAnimationClip); //CAssert("No memory\n", newAnimClip!=NULL); newAnimClip->SetName( "defaultClip" ); newAnimClip->SetIndex(0); newAnimClip->SetStart(0.0); CFloat endTime = 0.0; for(CUInt i=0; i<m_animations.size(); i++) { CAnimation * anim = m_animations[i]; PrintInfo( "\nAttaching animation ' ", COLOR_WHITE );PrintInfo( anim->GetName(), COLOR_RED_GREEN ); PrintInfo( " ' to the default animation clip", COLOR_WHITE ); anim->SetClipTarget( newAnimClip ); newAnimClip->m_animations.push_back( anim ); if( anim->GetEndTime() > endTime ) endTime = anim->GetEndTime(); } newAnimClip->SetEnd((CDouble)endTime); m_numClips = 1; m_animationClips.push_back( newAnimClip ); } // Find the scene we want daeElement* defaultScene = dom->getScene()->getInstance_visual_scene()->getUrl().getElement(); domAsset::domUp_axis *up = dom->getAsset()->getUp_axis(); switch( up->getValue() ) { case UPAXISTYPE_X_UP: upAxis = eCXUp; break; case UPAXISTYPE_Y_UP: upAxis = eCYUp; break; case UPAXISTYPE_Z_UP: upAxis = eCZUp; break; default: break; } if(defaultScene) ReadScene( (domVisual_scene *)defaultScene, upAxis ); if (m_collada) { delete m_collada; m_collada = 0; } if( reportWarningsAndErrors ) { char tempReport[MAX_NAME_SIZE]; COLORREF color; if( numErrors > 0 ) color = COLOR_RED; else if (numWarnings > 0 ) color = COLOR_YELLOW; else color = COLOR_GREEN; sprintf( tempReport, "\n%s - %i error (s), %i warning (s)", nameOnly, numErrors, numWarnings ); PrintInfo( tempReport, color ); totalErrors += numErrors; totalWarnings += numWarnings; } return CTrue; }
void CSetCurrentProject::OnOK() { int nSelected = -1; POSITION p = m_listAvailableProjects.GetFirstSelectedItemPosition(); while(p) { nSelected = m_listAvailableProjects.GetNextSelectedItem(p); } if( nSelected >= 0 ) { TCHAR szBuffer[1024]; DWORD cchBuf(1024); LVITEM lvi; lvi.iItem = nSelected; lvi.iSubItem = 0; lvi.mask = LVIF_TEXT; lvi.pszText = szBuffer; lvi.cchTextMax = cchBuf; m_listAvailableProjects.GetItem(&lvi); for( CUInt i = 0; i < g_projects.size(); i++ ) { if(g_projects[i]->m_isActive) { if( Cmp( szBuffer, g_projects[i]->m_name ) ) { return; // no need to switch projects } } } //switch projects //close curren open VScene if(!ex_pVandaEngine1Dlg->OnMenuClickedNew(CTrue)) return; //fist of all, mark all as inactive for( CUInt i = 0; i < g_projects.size(); i++ ) { g_projects[i]->m_isActive = CFalse; } //then find the selected project and mark it as active for( CUInt i = 0; i < g_projects.size(); i++ ) { if( Cmp( szBuffer, g_projects[i]->m_name ) ) { g_projects[i]->m_isActive = CTrue; break; } } //change current directory Cpy( g_currentProjectPath, g_projectsPath ); Append( g_currentProjectPath, szBuffer ); Append( g_currentProjectPath, "/" ); //clear VScene names g_VSceneNamesOfCurrentProject.clear(); //then fill it with the VScenes of the selected project for( CUInt i = 0; i < g_projects.size(); i++ ) { if( g_projects[i]->m_isActive ) { for( CUInt j = 0; j < g_projects[i]->m_sceneNames.size(); j++ ) { g_VSceneNamesOfCurrentProject.push_back( g_projects[i]->m_sceneNames[j].c_str() ); } } } CChar m_currentVSceneNameWithoutDot[MAX_NAME_SIZE]; if (Cmp(g_currentVSceneName, "\n")) Cpy(m_currentVSceneNameWithoutDot, "Untitled"); else { Cpy(m_currentVSceneNameWithoutDot, g_currentVSceneName); GetWithoutDot(m_currentVSceneNameWithoutDot); } CChar temp[256]; sprintf(temp, "%s%s%s%s%s", "Vanda Engine 1.4 (", szBuffer, " - ", m_currentVSceneNameWithoutDot, ")"); ex_pVandaEngine1Dlg->SetWindowTextA(temp); //save the changes to projects.dat FILE *ProjectsFilePtr; CChar DATPath[MAX_NAME_SIZE]; sprintf( DATPath, "%s%s", g_projectsPath, "projects.dat" ); DeleteFile( DATPath ); ProjectsFilePtr = fopen( DATPath, "wb" ); if( !ProjectsFilePtr ) { MessageBox( "Couldn't open 'assets/Projects/projects.dat' to save data!", "Vanda Engine Error", MB_OK | MB_ICONERROR); //return; } CInt numProjects = (CInt)g_projects.size(); fwrite(&numProjects, sizeof(CInt), 1, ProjectsFilePtr); fclose(ProjectsFilePtr); for (CInt i = 0; i < numProjects; i++) { CChar filePath[MAX_URI_SIZE]; sprintf(filePath, "%s%s%s%s", g_projectsPath, "PRJ/", g_projects[i]->m_name, ".prj"); ProjectsFilePtr = fopen(filePath, "wb"); fwrite(g_projects[i]->m_name, sizeof(CChar), MAX_NAME_SIZE, ProjectsFilePtr); CInt numScenes = (CInt)g_projects[i]->m_sceneNames.size(); fwrite(&numScenes, sizeof(CInt), 1, ProjectsFilePtr); for (CInt j = 0; j < numScenes; j++) { CChar vsceneName[MAX_NAME_SIZE]; Cpy(vsceneName, g_projects[i]->m_sceneNames[j].c_str()); fwrite(vsceneName, sizeof(CChar), MAX_NAME_SIZE, ProjectsFilePtr); } fwrite(&g_projects[i]->m_isActive, sizeof(CBool), 1, ProjectsFilePtr); fclose(ProjectsFilePtr); } CDialog::OnOK(); } else { MessageBoxA( "Please select a project" ); } }
void CPrefabDlg::OnBnClickedDelete() { int nSelected = -1; POSITION p = m_listPrefabPackages.GetFirstSelectedItemPosition(); while (p) { nSelected = m_listPrefabPackages.GetNextSelectedItem(p); } TCHAR szBuffer1[1024]; //package TCHAR szBuffer2[1024]; //prefab if (nSelected >= 0) { DWORD cchBuf(1024); LVITEM lvi; lvi.iItem = nSelected; lvi.iSubItem = 0; lvi.mask = LVIF_TEXT; lvi.pszText = szBuffer1; lvi.cchTextMax = cchBuf; m_listPrefabPackages.GetItem(&lvi); m_selectedPackageName = szBuffer1; } else { MessageBox("Please select a package!", "Vanda Engine Error", MB_OK | MB_ICONINFORMATION); return; } nSelected = -1; p = m_listPrefabs.GetFirstSelectedItemPosition(); while (p) { nSelected = m_listPrefabs.GetNextSelectedItem(p); } if (nSelected >= 0) { CInt packageIndex = -1; for (CUInt i = 0; i < g_prefabPackagesAndNames.size(); i++) { if (Cmp(g_prefabPackagesAndNames[i].front().c_str(), m_selectedPackageName.c_str())) { packageIndex = i; break; } } DWORD cchBuf(1024); LVITEM lvi; lvi.iItem = nSelected; lvi.iSubItem = 0; lvi.mask = LVIF_TEXT | LVIF_IMAGE; lvi.pszText = szBuffer2; lvi.cchTextMax = cchBuf; m_listPrefabs.GetItem(&lvi); m_selectedPrefabName = szBuffer2; CChar currentPackageAndPrefabName[MAX_NAME_SIZE]; sprintf(currentPackageAndPrefabName, "%s%s%s", szBuffer1, "_", szBuffer2); if (Cmp(g_currentPackageAndPrefabName, currentPackageAndPrefabName)) { MessageBox("This prefab is already open. Please close current prefab scene and try again.", "Vanda Engine Error", MB_OK | MB_ICONERROR); return; } for (CUInt i = 0; i < g_projects.size(); i++) { for (CUInt j = 0; j < g_projects[i]->m_sceneNames.size(); j++) { //find pkg file CChar pkgPath[MAX_NAME_SIZE]; CChar sceneWithoutDot[MAX_NAME_SIZE]; Cpy(sceneWithoutDot, g_projects[i]->m_sceneNames[j].c_str()); GetWithoutDot(sceneWithoutDot); sprintf(pkgPath, "%s%s%s%s%s", g_projectsPath, g_projects[i]->m_name, "/", sceneWithoutDot, "/packages.pkg"); //copy package names FILE *PackageFilePtr; PackageFilePtr = fopen(pkgPath, "rb"); if (!PackageFilePtr) { CChar temp[MAX_NAME_SIZE]; sprintf(temp, "%s%s%s", "Couldn't open the file '", pkgPath, "' to save data"); MessageBox(temp, "Vanda Engine Error", MB_OK); ReleaseCapture(); PrintInfo("Delete failed.", COLOR_RED); return; } CUInt size = -1; fread(&size, sizeof(CUInt), 1, PackageFilePtr); for (CUInt k = 0; k < size; k++) { CChar name[MAX_NAME_SIZE]; CChar package_name[MAX_NAME_SIZE]; CChar prefab_name[MAX_NAME_SIZE]; //write prefab data fread(name, sizeof(CChar), MAX_NAME_SIZE, PackageFilePtr); fread(package_name, sizeof(CChar), MAX_NAME_SIZE, PackageFilePtr); fread(prefab_name, sizeof(CChar), MAX_NAME_SIZE, PackageFilePtr); if (Cmp(prefab_name, m_selectedPrefabName.c_str())) { CChar preafbName[MAX_NAME_SIZE]; sprintf(preafbName, "This prefab is used by %s/%s.\nYou can not delete this prefab.", g_projects[i]->m_name, g_projects[i]->m_sceneNames[j].c_str()); MessageBox(preafbName, "Vanda Engine Error", MB_OK | MB_ICONERROR); fclose(PackageFilePtr); return; } } fclose(PackageFilePtr); } } if (MessageBox("Are you sure you want to delete this prefab?", "Warning", MB_YESNO) == IDYES) { //remove prefab directory CChar PackagePath[MAX_NAME_SIZE]; HRESULT doc_result_package = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, PackagePath); if (doc_result_package != S_OK) { PrintInfo("\nCouldn't get the documents folder to write data", COLOR_RED); return; } else { Append(PackagePath, "/Vanda/Packages/"); } CChar path[MAX_NAME_SIZE]; sprintf(path, "%s%s%s%s", PackagePath, szBuffer1, "/", szBuffer2); RemoveAllFilesAndFoldersInDirectory(path); for (CUInt i = 0; i < g_prefabPackagesAndNames[packageIndex].size(); i++) { if (i == 0) continue; if (Cmp(g_prefabPackagesAndNames[packageIndex][i].c_str(), m_selectedPrefabName.c_str())) { g_prefabPackagesAndNames[packageIndex].erase(g_prefabPackagesAndNames[packageIndex].begin() + i); } } m_prefabIndex = -1; //delete all items of prefab list for (int nItem = m_listPrefabs.GetItemCount() - 1; nItem >= 0; nItem--) { m_listPrefabs.DeleteItem(nItem); } for (CUInt i = 0; i < g_prefabPackagesAndNames[packageIndex].size(); i++) { if (i == 0) continue; CChar str[MAX_NAME_SIZE]; Cpy(str, g_prefabPackagesAndNames[packageIndex][i].c_str()); InsertItemToPrefabList(str); } m_listPrefabs.UpdateWindow(); } } else { MessageBox("Please select a prefab!", "Vanda Engine Error", MB_OK | MB_ICONINFORMATION); return; } }
void CPrefabDlg::OnBnClickedDeletePackage() { int nSelected = -1; POSITION p = m_listPrefabPackages.GetFirstSelectedItemPosition(); while (p) { nSelected = m_listPrefabPackages.GetNextSelectedItem(p); } if (nSelected >= 0) { TCHAR szBuffer[1024]; DWORD cchBuf(1024); LVITEM lvi; lvi.iItem = nSelected; lvi.iSubItem = 0; lvi.mask = LVIF_TEXT; lvi.pszText = szBuffer; lvi.cchTextMax = cchBuf; m_listPrefabPackages.GetItem(&lvi); m_selectedPackageName = szBuffer; if (Cmp(szBuffer, "Vanda_Basics")) { MessageBox("You cannot delete this package", "Vanda Engine Error", MB_OK | MB_ICONINFORMATION); return; } for (CUInt i = 0; i < g_projects.size(); i++) { for (CUInt j = 0; j < g_projects[i]->m_sceneNames.size(); j++) { //find pkg file CChar pkgPath[MAX_NAME_SIZE]; CChar sceneWithoutDot[MAX_NAME_SIZE]; Cpy(sceneWithoutDot, g_projects[i]->m_sceneNames[j].c_str()); GetWithoutDot(sceneWithoutDot); sprintf(pkgPath, "%s%s%s%s%s", g_projectsPath, g_projects[i]->m_name, "/", sceneWithoutDot, "/packages.pkg"); //copy package names FILE *PackageFilePtr; PackageFilePtr = fopen(pkgPath, "rb"); if (!PackageFilePtr) { CChar temp[MAX_NAME_SIZE]; sprintf(temp, "%s%s%s", "Couldn't open the file '", pkgPath, "' to save data"); MessageBox(temp, "Vanda Engine Error", MB_OK); ReleaseCapture(); PrintInfo("Delete failed.", COLOR_RED); return; } CUInt size = -1; fread(&size, sizeof(CUInt), 1, PackageFilePtr); for (CUInt k = 0; k < size; k++) { CChar name[MAX_NAME_SIZE]; CChar package_name[MAX_NAME_SIZE]; CChar prefab_name[MAX_NAME_SIZE]; //write prefab data fread(name, sizeof(CChar), MAX_NAME_SIZE, PackageFilePtr); fread(package_name, sizeof(CChar), MAX_NAME_SIZE, PackageFilePtr); fread(prefab_name, sizeof(CChar), MAX_NAME_SIZE, PackageFilePtr); if (Cmp(package_name, m_selectedPackageName.c_str())) { CChar packageName[MAX_NAME_SIZE]; sprintf(packageName, "This package is used by %s/%s.\nYou can not delete this package.", g_projects[i]->m_name, g_projects[i]->m_sceneNames[j].c_str()); MessageBox(packageName, "Vanda Engine Error", MB_OK | MB_ICONERROR); fclose(PackageFilePtr); return; } } fclose(PackageFilePtr); } } CChar currentPackageName[MAX_NAME_SIZE]; sprintf(currentPackageName, "%s", szBuffer); if (Cmp(g_currentPackageName, currentPackageName)) { MessageBox("current open prefab belongs to selected package. Please close current prefab scene and try again.", "Vanda Engine Error", MB_OK | MB_ICONERROR); return; } if (MessageBox("Are you sure you want to delete this package?", "Warning", MB_YESNO) == IDYES) { CChar PackagePath[MAX_NAME_SIZE]; HRESULT doc_result_package = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, PackagePath); if (doc_result_package != S_OK) { PrintInfo("\nCouldn't get the documents folder to write data", COLOR_RED); return; } else { Append(PackagePath, "/Vanda/Packages/"); } CChar path[MAX_NAME_SIZE]; sprintf(path, "%s%s", PackagePath, szBuffer); RemoveAllFilesAndFoldersInDirectory(path); //remove pkg file in PKG folder CChar PKG_old[MAX_URI_SIZE]; sprintf(PKG_old, "%s%s%s%s", PackagePath, "PKG/", szBuffer, ".pkg"); DeleteFile(PKG_old); //delete items from std::vector for (CUInt i = 0; i < g_prefabPackagesAndNames.size(); i++) { if (Cmp(g_prefabPackagesAndNames[i].front().c_str(), m_selectedPackageName.c_str())) { g_prefabPackagesAndNames[i].clear(); g_prefabPackagesAndNames.erase(g_prefabPackagesAndNames.begin() + i); break; } } m_listPrefabPackages.DeleteItem(nSelected); m_listPrefabPackages.UpdateWindow(); m_packageIndex--; } } else { MessageBox("Please select an item!", "Vanda Engine Error", MB_OK | MB_ICONINFORMATION); return; } }
void CPrefabDlg::OnBnClickedRenamePackage() { int nSelected = -1; TCHAR szBuffer[1024]; POSITION p = m_listPrefabPackages.GetFirstSelectedItemPosition(); while (p) { nSelected = m_listPrefabPackages.GetNextSelectedItem(p); } if (nSelected >= 0) { DWORD cchBuf(1024); LVITEM lvi; lvi.iItem = nSelected; lvi.iSubItem = 0; lvi.mask = LVIF_TEXT; lvi.pszText = szBuffer; lvi.cchTextMax = cchBuf; m_listPrefabPackages.GetItem(&lvi); m_selectedPackageName = szBuffer; if (Cmp(szBuffer, "Vanda_Basics")) { MessageBox("You cannot rename this package", "Vanda Engine Error", MB_OK | MB_ICONINFORMATION); return; } } else { MessageBox("Please select an item!", "Vanda Engine Error", MB_OK | MB_ICONINFORMATION); return; } CChar currentPackageName[MAX_NAME_SIZE]; sprintf(currentPackageName, "%s", szBuffer); if (Cmp(g_currentPackageName, currentPackageName)) { MessageBox("current open prefab belongs to selected package. Please close current prefab scene and try again.", "Vanda Engine Error", MB_OK | MB_ICONERROR); return; } //then fill it with the VScenes of the selected project for (CUInt i = 0; i < g_projects.size(); i++) { for (CUInt j = 0; j < g_projects[i]->m_sceneNames.size(); j++) { //find pkg file CChar pkgPath[MAX_NAME_SIZE]; CChar sceneWithoutDot[MAX_NAME_SIZE]; Cpy(sceneWithoutDot, g_projects[i]->m_sceneNames[j].c_str()); GetWithoutDot(sceneWithoutDot); sprintf(pkgPath, "%s%s%s%s%s", g_projectsPath, g_projects[i]->m_name, "/", sceneWithoutDot, "/packages.pkg"); //copy package names FILE *PackageFilePtr; PackageFilePtr = fopen(pkgPath, "rb"); if (!PackageFilePtr) { CChar temp[MAX_NAME_SIZE]; sprintf(temp, "%s%s%s", "Couldn't open the file '", pkgPath, "' to save data"); MessageBox(temp, "Vanda Engine Error", MB_OK); ReleaseCapture(); PrintInfo("Rename failed.", COLOR_RED); return; } CUInt size = -1; fread(&size, sizeof(CUInt), 1, PackageFilePtr); for (CUInt k = 0; k < size; k++) { CChar name[MAX_NAME_SIZE]; CChar package_name[MAX_NAME_SIZE]; CChar prefab_name[MAX_NAME_SIZE]; //write prefab data fread(name, sizeof(CChar), MAX_NAME_SIZE, PackageFilePtr); fread(package_name, sizeof(CChar), MAX_NAME_SIZE, PackageFilePtr); fread(prefab_name, sizeof(CChar), MAX_NAME_SIZE, PackageFilePtr); if (Cmp(package_name, m_selectedPackageName.c_str())) { CChar packageName[MAX_NAME_SIZE]; sprintf(packageName, "This package is used by %s/%s.\nYou can not rename this package.", g_projects[i]->m_name, g_projects[i]->m_sceneNames[j].c_str()); MessageBox(packageName, "Vanda Engine Error", MB_OK | MB_ICONERROR); fclose(PackageFilePtr); return; } } fclose(PackageFilePtr); } } m_prefabNameDlg = CNew(CPrefabNameDlg); m_prefabNameDlg->SetInitialData(m_selectedPackageName, "\n", CTrue, CTrue); if (IDOK == m_prefabNameDlg->DoModal()) { m_listPrefabPackages.SetItemText(nSelected, 0, m_prefabNameDlg->GetNewName()); CChar PackagePath[MAX_NAME_SIZE]; HRESULT doc_result_package = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, PackagePath); if (doc_result_package != S_OK) { PrintInfo("\nCouldn't get the documents folder to write data", COLOR_RED); return; } else { Append(PackagePath, "/Vanda/Packages/"); } CChar old_path[MAX_NAME_SIZE]; CChar new_path[MAX_NAME_SIZE]; sprintf(old_path, "%s%s", PackagePath, szBuffer); sprintf(new_path, "%s%s", PackagePath, m_prefabNameDlg->GetNewName()); rename(old_path, new_path); //rename vpf files for (CUInt i = 0; i < g_prefabPackagesAndNames.size(); i++) { if (Cmp(g_prefabPackagesAndNames[i].front().c_str(), m_prefabNameDlg->GetNewName())) { for (CUInt j = 0; j < g_prefabPackagesAndNames[i].size(); j++) { if (j == 0)continue; CChar vpfOldPath[MAX_NAME_SIZE]; sprintf(vpfOldPath, "%s%s%s%s%s%s%s%s%s", PackagePath, g_prefabPackagesAndNames[i].front().c_str(), "/", g_prefabPackagesAndNames[i][j].c_str(), "/", szBuffer, "_", g_prefabPackagesAndNames[i][j].c_str(), ".vpf"); CChar vpfNewPath[MAX_NAME_SIZE]; sprintf(vpfNewPath, "%s%s%s%s%s%s%s%s%s", PackagePath, g_prefabPackagesAndNames[i].front().c_str(), "/", g_prefabPackagesAndNames[i][j].c_str(), "/", g_prefabPackagesAndNames[i].front().c_str(), "_", g_prefabPackagesAndNames[i][j].c_str(), ".vpf"); rename(vpfOldPath, vpfNewPath); } break; } } //rename the contents of PKG folder as well CChar PKG_old[MAX_URI_SIZE]; CChar PKG_new[MAX_URI_SIZE]; sprintf(PKG_old, "%s%s%s%s", PackagePath, "PKG/", szBuffer, ".pkg"); sprintf(PKG_new, "%s%s%s%s", PackagePath, "PKG/", m_prefabNameDlg->GetNewName(), ".pkg"); rename(PKG_old, PKG_new); } CDelete(m_prefabNameDlg); }
//CBool CTexture::LoadTargaTexture( CImage * texObj, CChar* name, CChar* sceneFileName ) //{ // //attache the sceneFileName path( without the dea file ) to the texture name // CChar pathName[MAX_NAME_SIZE]; // // if( sceneFileName ) //To deal with COLLADA files. // { // CChar * texName = GetAfterPath( name ); //don't know if it's required? Maybe the name in collada file has no path // //strcpy( pathName , sceneFileName ); // //CChar *removeExtra = GetAfterPath( pathName ); // //removeExtra[0] = 0; // //strcat( pathName, texName ); // //save functions. it should be copies in WIN32 Project as well // CChar g_currentVSceneNameWithoutDot[MAX_NAME_SIZE]; // Cpy( g_currentVSceneNameWithoutDot, g_currentVSceneName ); // GetWithoutDot( g_currentVSceneNameWithoutDot ); // // sprintf( pathName, "%s%s%s%s", "assets/vscenes/", g_currentVSceneNameWithoutDot, "/Textures/", texName ); // // } // else //To load independent targa files(not specified in a collada file ) // strcpy( pathName, name ); // // ILuint imageId; // ilGenImages(1, &imageId); // ilBindImage(imageId); // // PrintInfo( _T( "\nReading Image : " ) ); // PrintInfo( _T( "'" ) + CString( pathName ) + _T("'"), COLOR_RED_GREEN ); // // // Read in the image file into DevIL. // if (!ilLoadImage(pathName)) { // // ERROR // ilDeleteImages(1, &imageId); // CChar temp[MAX_NAME_SIZE]; // sprintf( temp, "\nError! CTexture::LoadTargaTexture > Couldn't load the targa file: '%s'", pathName ); // PrintInfo( temp, COLOR_RED ); // numErrors += 1; // // return false; // } // else { // texObj->SetWidth( ilGetInteger(IL_IMAGE_WIDTH) ); // texObj->SetHeight( ilGetInteger(IL_IMAGE_HEIGHT) ); // // CUChar* imageData; // CInt imageSize; // // imageSize = ilGetInteger(IL_IMAGE_WIDTH) * ilGetInteger(IL_IMAGE_HEIGHT) * ilGetInteger(IL_IMAGE_CHANNELS); // imageData = (CUChar*)malloc( imageSize ); // // if( ilGetInteger(IL_IMAGE_CHANNELS) == 3 ) // texObj->SetFormat( TGA_TRUECOLOR_24 ); // else if ( ilGetInteger(IL_IMAGE_CHANNELS) == 4 ) // texObj->SetFormat( TGA_TRUECOLOR_32 ); // // memcpy( imageData , ilGetData() , imageSize ); // texObj->SetImageData( imageData ); // ilDeleteImages(1, &imageId); // } // PrintInfo( "\nCreating Texture '" ); // PrintInfo(pathName, COLOR_RED_GREEN); // PrintInfo( "' "); // // CreateTargaTexture( texObj ); // // return CTrue; //} // CBool CTexture::LoadDDSTexture( CImage * texObj, CChar* name, CChar* sceneFileName, CBool reportError ) { //attache the sceneFileName path( without the dea file ) to the texture name CChar pathName[MAX_NAME_SIZE]; if( sceneFileName ) //To deal with COLLADA files. { CChar * texName = NULL; if( g_useOriginalPathOfDAETextures || g_updateTextureViaEditor) { texName = CNewData(CChar,MAX_NAME_SIZE); Cpy( texName, name ); } else { texName = GetAfterPath( name ); } GetWithoutDot( texName); Append( texName, ".dds" ); //replace %20 with space using std::string std::string s(texName); size_t i = 0; for (;;) { i = s.find("%20", i); if (i == string::npos) { break; } s.replace(i, 3, " "); } if( g_useOriginalPathOfDAETextures || g_updateTextureViaEditor) { s.begin(); size_t i = 0; for (;;) { i = s.find("file:/", i); if (i == string::npos) { break; } s.replace(i, 6, ""); } } strcpy(texName, s.c_str()); if( g_useOriginalPathOfDAETextures || g_updateTextureViaEditor) { strcpy( pathName, texName ); CDelete(texName); } else { CChar g_currentVSceneNameWithoutDot[MAX_NAME_SIZE]; Cpy( g_currentVSceneNameWithoutDot, g_currentVSceneName ); GetWithoutDot( g_currentVSceneNameWithoutDot ); sprintf( pathName, "%s%s%s%s", g_VScenePath, g_currentVSceneNameWithoutDot, "/Textures/", texName ); } } else //To load independent dds files(not specified in a collada file ) strcpy( pathName, name ); ifstream file(pathName, ios::binary); if (! file ) { if( reportError ) { CChar temp[MAX_NAME_SIZE]; sprintf( temp, "\nError! CTexture::LoadDDSTexture > Couldn't load the dds file: '%s'", pathName ); PrintInfo( temp, COLOR_RED ); numErrors += 1; } return false; } CDDS *m_ddsImage = CNew( CDDS ); if (! m_ddsImage->LoadFile(file) ) { if( reportError ) { CChar temp[MAX_NAME_SIZE]; sprintf( temp, "\nError! CTexture::LoadDDSTexture > Couldn't load the dds file: '%s'", pathName ); PrintInfo( temp, COLOR_RED ); numErrors += 1; } return false; } texObj->SetWidth( (CInt32)m_ddsImage->GetWidth() ); texObj->SetHeight( (CInt32)m_ddsImage->GetHeight() ); if( m_ddsImage->m_alphaChannel) texObj->SetFormat(TGA_TRUECOLOR_32); else texObj->SetFormat(TGA_TRUECOLOR_24); PrintInfo( "\nCreating Texture ' " ); PrintInfo(pathName, COLOR_RED_GREEN); PrintInfo( " '"); CreateDDSTexture( texObj, m_ddsImage ); return CTrue; }