TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ LoadTextureDatabaseJ()

nlohmann::json TextureStore::LoadTextureDatabaseJ ( )
private

Definition at line 59 of file TextureStore.cpp.

60{
61 bool loadFromFile = true;
62
63 if(IsNetWorkConnected() && rand() % 2 == 0)
64 {
65 loadFromFile = false;
66 }
67
68 if(!FileExists(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "cache" PATH_SEPARATOR "texture_database.terr3d"))
69 {
70 loadFromFile = false;
71 }
72
73 if(loadFromFile)
74 {
75 Log("Loading texture database from file");
76 bool tmp = false;
77 std::string tmpStr = ReadShaderSourceFile(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "cache" PATH_SEPARATOR "texture_database.terr3d", &tmp);
78
79 if(tmp == false)
80 {
81 Log("Failed to load texture database from file");
82 return nlohmann::json();
83 }
84
85 try
86 {
87 return nlohmann::json::parse(tmpStr);
88 }
89
91 {
92 Log("Failed to parse texture database from file");
93 return nlohmann::json();
94 }
95 }
96
97 else
98 {
99 Log("Fetching texture database from web database.");
100 std::string tmp = FetchURL("https://api.polyhaven.com", "/assets?t=textures");
101
102 if (tmp.size() < 3)
103 {
104 Log("Failed to fetch texture database from web database.");
105 return nlohmann::json();
106 }
107
108 SaveToFile(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "cache" PATH_SEPARATOR "texture_database.terr3d", tmp);
109 return nlohmann::json::parse(tmp);
110 }
111}
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json parse(InputType &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
deserialize from a compatible input
Definition: json.hpp:24605
exception indicating a parse error
Definition: json.hpp:2788
basic_json<> json
default JSON class
Definition: json.hpp:3411