295{
296 data = d;
297 std::cout << "Wating for remesh cycle to finish ...\n";
298
299 while (appState->states.remeshing);
300
301 std::cout << "Finished remesing." << std::endl;
302 TRY_CATCH_ERR_DESERIALIZE(
303
304 if (data["versionHash"] != MD5File(GetExecutablePath()).ToString())
305{
306 onError("The file you are tryng to open was made with a different version of TerraForge3D!\nTrying to check Serializer compatibility", false);
307 }
308 , "Failed to verify file version."
309 );
310 TRY_CATCH_ERR_DESERIALIZE_WITH_CODE(
311 int serializerVersion = data["serailizerVersion"];
312
313 if (serializerVersion < TERR3D_MIN_SERIALIZER_VERSION)
314{
315 onError("This file cannot be opened as it was serialized using serializer V" + std::to_string(serializerVersion) + " but the minimum serializer version required is V" + std::to_string(TERR3D_MIN_SERIALIZER_VERSION), false);
316 return nullptr;
317 }
318
319 if (serializerVersion > TERR3D_MAX_SERIALIZER_VERSION)
320{
321 onError("This file cannot be opened as it was serialized using serializer V" + std::to_string(serializerVersion) + " but the maximum serializer version supported is V" + std::to_string(TERR3D_MAX_SERIALIZER_VERSION), false);
322 return nullptr;
323 }
324 , "Failed to verify Serializer",
325 return nullptr;
326 );
327
328 if (data["type"] != "SAVEFILE")
329 {
330 onError("This file is not a savefile.", false);
331 return nullptr;
332 }
333
334 TRY_CATCH_ERR_DESERIALIZE(LoadThemeFromStr(data["styleData"]);, "Failed to load theme.");
335 TRY_CATCH_ERR_DESERIALIZE(appState->globals.appData = data["appData"];, "Failed to app data.");
336 TRY_CATCH_ERR_DESERIALIZE(appState->globals.appData = data["appData"];, "Failed to app data.");
337 TRY_CATCH_ERR_DESERIALIZE(appState->mode = data["mode"];, "Failed to app mode.");
338 TRY_CATCH_ERR_DESERIALIZE(appState->projectManager->SetId(data["projectID"]);, "Failed to load Project ID.");
339 TRY_CATCH_ERR_DESERIALIZE(appState->projectManager->SetDatabase(data["projectDatabase"]);, "Failed to load project database.");
340 std::cout << "Loaded Project ID : " << appState->projectManager->GetId() << std::endl;
341 TRY_CATCH_ERR_DESERIALIZE(appState->cameras.Load(data["camera"]);, "Failed to load camera.");
342 TRY_CATCH_ERR_DESERIALIZE(appState->windows.Load(data["windows"]);, "Failed to load windows.");
343 TRY_CATCH_ERR_DESERIALIZE(appState->states.Load(data["states"]);, "Failed to load states.");
344 TRY_CATCH_ERR_DESERIALIZE(appState->globals.Load(data["globals"]);, "Failed to load globals.");
345 TRY_CATCH_ERR_DESERIALIZE(appState->textureBaker->Load(data["textureBaker"]);, "Failed to load texture baker settings.");
346 TRY_CATCH_ERR_DESERIALIZE(appState->seaManager->Load(data["sea"]);, "Failed to load sea.");
347 TRY_CATCH_ERR_DESERIALIZE(appState->foliageManager->Load(data["foliage"]);, "Failed to load foliage.");
348 TRY_CATCH_ERR_DESERIALIZE(appState->lightManager->Load(data["lighting"]);, "Failed to load lighting.");
349 TRY_CATCH_ERR_DESERIALIZE(appState->meshGenerator->Load(data["generators"]);, "Failed to load generators.");
350 TRY_CATCH_ERR_DESERIALIZE(appState->shadingManager->Load(data["shading"]);, "Failed to load shading data.");
351 TRY_CATCH_ERR_DESERIALIZE_WITH_CODE(
352
353 if (appState->mode == ApplicationMode::CUSTOM_BASE)
354{
355 std::string baseHash = data["baseid"];
356 std::string projectAsset = appState->projectManager->GetAsset(baseHash);
357
358 if (projectAsset == "")
359 {
360 std::cout << "Failed to load base model from save file!\n";
361 appState->states.usingBase = true;
362 }
363
364 else
365 {
366 if (!appState->models.customBase)
367 {
368 delete appState->models.customBase;
369 delete appState->models.customBaseCopy;
370 }
371
372 appState->globals.currentBaseModelPath = appState->projectManager->GetResourcePath() + PATH_SEPARATOR + projectAsset;
373 appState->models.customBase = LoadModel(appState->globals.currentBaseModelPath);
374 appState->models.customBaseCopy = LoadModel(appState->globals.currentBaseModelPath);
375 appState->states.usingBase = false;
376 }
377 }
378 , "Failed to load custom base model. Falling back to plane.",
379
380 if (!appState->models.customBase)
381{
382 delete appState->models.customBase;
383 delete appState->models.customBaseCopy;
384}
385appState->states.usingBase = true;
386);
387 return appState;
388}