void SceneEditorScreenMain::AutoSaveLevel(BaseObject *, void *, void *) { time_t now = time(0); tm* utcTime = localtime(&now); String folderPath = EditorSettings::Instance()->GetDataSourcePath() + "Autosave"; bool folderExcists = FileSystem::Instance()->IsDirectory(folderPath); if(!folderExcists) { FileSystem::Instance()->CreateDirectory(folderPath); } String pathToFile = folderPath + Format("/AutoSave_%04d.%02d.%02d_%02d_%02d.sc2", utcTime->tm_year + 1900, utcTime->tm_mon + 1, utcTime->tm_mday, utcTime->tm_hour, utcTime->tm_min); BodyItem *iBody = bodies[0]; Scene * scene = iBody->bodyControl->GetScene(); SceneFileV2 * file = new SceneFileV2(); file->EnableDebugLog(false); file->SaveScene(pathToFile, scene); SafeRelease(file); SetupAnimation(); }
void CommandConvertScene::Execute() { DVASSERT(CheckExtension(String(".dae")) && "Wrong extension"); SceneValidator::Instance()->CreateDefaultDescriptors(EditorSettings::Instance()->GetDataSourcePath()); eColladaErrorCodes code = ConvertDaeToSce(filePathname); if(code == COLLADA_OK) { // load sce to scene object String path = FileSystem::Instance()->ReplaceExtension(filePathname, ".sce"); Scene * scene = new Scene(); Entity *rootNode = scene->GetRootNode(path); scene->AddNode(rootNode); scene->BakeTransforms(); // Export to *.sc2 path = FileSystem::Instance()->ReplaceExtension(path, ".sc2"); SceneFileV2 * file = new SceneFileV2(); file->EnableDebugLog(true); file->SaveScene(path.c_str(), scene); SafeRelease(file); SafeRelease(scene); } else if(code == COLLADA_ERROR_OF_ROOT_NODE) { ShowErrorDialog(String("Can't convert from DAE. Looks like one of materials has same name as root node.")); } else { ShowErrorDialog(String("Can't convert from DAE.")); } }
void SceneSaver::SaveScene(Scene *scene, const FilePath &fileName, Set<String> &errorLog) { DVASSERT(0 == texturesForSave.size()) String relativeFilename = fileName.GetRelativePathname(sceneUtils.dataSourceFolder); sceneUtils.workingFolder = fileName.GetDirectory().GetRelativePathname(sceneUtils.dataSourceFolder); FileSystem::Instance()->CreateDirectory(sceneUtils.dataFolder + sceneUtils.workingFolder, true); scene->Update(0.1f); FilePath oldPath = SceneValidator::Instance()->SetPathForChecking(sceneUtils.dataSourceFolder); SceneValidator::Instance()->ValidateScene(scene, errorLog); texturesForSave.clear(); SceneDataManager::EnumerateTextures(scene, texturesForSave); CopyTextures(scene, errorLog); ReleaseTextures(); Landscape *landscape = EditorScene::GetLandscape(scene); if (landscape) { sceneUtils.CopyFile(landscape->GetHeightmapPathname(), errorLog); } CopyReferencedObject(scene, errorLog); CopyEffects(scene, errorLog); CopyCustomColorTexture(scene, fileName.GetDirectory(), errorLog); //save scene to new place FilePath tempSceneName = sceneUtils.dataSourceFolder + relativeFilename; tempSceneName.ReplaceExtension(".saved.sc2"); SceneFileV2 * outFile = new SceneFileV2(); outFile->EnableSaveForGame(true); outFile->EnableDebugLog(false); outFile->SaveScene(tempSceneName, scene); SafeRelease(outFile); bool moved = FileSystem::Instance()->MoveFile(tempSceneName, sceneUtils.dataFolder + relativeFilename, true); if(!moved) { errorLog.insert(Format("Can't move file %s", fileName.GetAbsolutePathname().c_str())); } SceneValidator::Instance()->SetPathForChecking(oldPath); }
void SceneEditorScreenMain::SaveSceneToFile(const String &pathToFile) { BodyItem *iBody = FindCurrentBody(); iBody->bodyControl->SetFilePath(pathToFile); iBody->bodyControl->PushDebugCamera(); Scene * scene = iBody->bodyControl->GetScene(); uint64 startTime = SystemTimer::Instance()->AbsoluteMS(); SceneFileV2 * file = new SceneFileV2(); file->EnableDebugLog(false); file->SaveScene(pathToFile, scene); SafeRelease(file); uint64 endTime = SystemTimer::Instance()->AbsoluteMS(); Logger::Info("[SAVE SCENE TIME] %d ms", (endTime - startTime)); iBody->bodyControl->PopDebugCamera(); }
void SceneSaver::ResaveFile(const String &fileName, Set<String> &errorLog) { DVASSERT(0); //TODO: check save Logger::Info("[SceneSaver::ResaveFile] %s", fileName.c_str()); FilePath sc2Filename = sceneUtils.dataSourceFolder + fileName; //Load scene with *.sc2 Scene *scene = new Scene(); Entity *rootNode = scene->GetRootNode(sc2Filename); if(rootNode) { int32 count = rootNode->GetChildrenCount(); Vector<Entity*> tempV; tempV.reserve((count)); for(int32 i = 0; i < count; ++i) { tempV.push_back(rootNode->GetChild(i)); } for(int32 i = 0; i < count; ++i) { scene->AddNode(tempV[i]); } scene->Update(0.f); SceneFileV2 * outFile = new SceneFileV2(); outFile->EnableDebugLog(false); outFile->SaveScene(sc2Filename, scene); SafeRelease(outFile); } else { errorLog.insert(Format("[SceneSaver::ResaveFile] Can't open file %s", fileName.c_str())); } SafeRelease(scene); }