62 boost::system::error_code ec;
66 printf(
"Failed to open input %s/dir_bin: %s\n",
iSrcDir.string().c_str(), ec.message().c_str());
70 if (!boost::filesystem::create_directories(
iDestDir, ec))
72 boost::system::error_code existsErr;
73 if (!boost::filesystem::exists(
iDestDir, existsErr))
75 printf(
"Failed to create output directory %s: %s\n",
iDestDir.string().c_str(), ec.message().c_str());
84 std::once_flag abortedFlag;
85 auto abortThreads = [&threadPool, &aborted, &abortedFlag]
87 std::call_once(abortedFlag, [&] { threadPool.
Stop(); aborted =
true; });
91 std::atomic<std::size_t> workerIndexGen;
92 std::vector<std::set<std::string>> spawnedModelFilesByThread(
iThreads);
94 std::atomic<std::size_t> mapsToProcess;
96 for (boost::filesystem::directory_entry
const& directoryEntry : dirBin)
98 if (!boost::filesystem::is_regular_file(directoryEntry))
102 threadPool.
PostWork([
this, file = directoryEntry.path(), &abortThreads, &workerIndexGen, &spawnedModelFilesByThread, &mapsToProcess]
104 thread_local std::size_t workerIndex = workerIndexGen++;
109 printf(
"Could not read dir_bin file!\n");
110 return abortThreads();
113 Optional<uint32> mapId = Trinity::StringTo<uint32>(file.filename().string());
116 printf(
"Invalid Map ID %s\n", file.filename().string().c_str());
117 return abortThreads();
120 printf(
"spawning Map %u\n", *mapId);
125 return abortThreads();
128 return abortThreads();
135 while (mapsToProcess && !aborted)
136 std::this_thread::sleep_for(1s);
141 for (std::set<std::string>& modelsForThread : spawnedModelFilesByThread)
147 printf(
"\nConverting Model Files\n");
152 printf(
"Converting %s\n", spawnedModelFile.c_str());
155 printf(
"error converting %s\n", spawnedModelFile.c_str());
171 float constexpr invTileSize = 1.0f / 533.33333f;
174 std::vector<ModelSpawn*> mapSpawns;
176 printf(
"Calculating model bounds for map %u...\n", data.
MapId);
184 mapSpawns.push_back(&spawn);
188 G3D::AABox
const& bounds = spawn.iBound;
189 G3D::Vector2int16 low(
int16(bounds.low().x * invTileSize),
int16(bounds.low().y * invTileSize));
190 G3D::Vector2int16 high(
int16(bounds.high().x * invTileSize),
int16(bounds.high().y * invTileSize));
191 for (
int x = low.x; x <= high.x; ++x)
192 for (
int y = low.y; y <= high.y; ++y)
196 printf(
"Creating map tree for map %u...\n", data.
MapId);
201 pTree.
build(mapSpawns, BoundsTrait<ModelSpawn*>());
203 catch (std::exception& e)
205 printf(R
"(Exception "%s" when calling pTree.build)", e.what());
209 std::unordered_map<uint32, uint32> modelNodeIdx;
210 for (
uint32 i = 0; i < mapSpawns.size(); ++i)
211 modelNodeIdx.try_emplace(mapSpawns[i]->ID, i);
215 boost::system::error_code ec;
216 boost::filesystem::create_directory(mapDestDir, ec);
220 auto mapfile =
OpenFile(mapfilename,
"wb");
223 printf(
"Cannot open %s\n", mapfilename.string().c_str());
228 if (fwrite(
VMAP_MAGIC, 1, 8, mapfile.get()) != 8)
231 if (fwrite(
"NODE", 4, 1, mapfile.get()) != 1)
241 for (
auto const& [tileId, spawns] : data.
TileEntries)
247 if (tileFile && tileSpawnIndicesFile)
251 uint32 nSpawns = spawns.size() + parentTileEntries.size();
254 if (fwrite(
VMAP_MAGIC, 1, 8, tileFile.get()) != 8)
256 if (fwrite(
VMAP_MAGIC, 1, 8, tileSpawnIndicesFile.get()) != 8)
260 if (fwrite(&nSpawns,
sizeof(
uint32), 1, tileFile.get()) != 1)
262 if (fwrite(&nSpawns,
sizeof(
uint32), 1, tileSpawnIndicesFile.get()) != 1)
266 for (
uint32 spawnId : spawns)
270 if (fwrite(&modelNodeIdx[spawnId],
sizeof(
uint32), 1, tileSpawnIndicesFile.get()) != 1)
274 for (
uint32 spawnId : parentTileEntries)
278 if (fwrite(&modelNodeIdx[spawnId],
sizeof(
uint32), 1, tileSpawnIndicesFile.get()) != 1)
292 if (tileSpawnIndicesFile)
294 uint32 nSpawns = spawns.size();
297 if (fwrite(
VMAP_MAGIC, 1, 8, tileSpawnIndicesFile.get()) != 8)
301 if (fwrite(&nSpawns,
sizeof(
uint32), 1, tileSpawnIndicesFile.get()) != 1)
305 for (
uint32 spawnId : spawns)
306 if (fwrite(&modelNodeIdx[spawnId],
sizeof(
uint32), 1, tileSpawnIndicesFile.get()) != 1)
416 if (!model_list_copy)
421 uint32 name_length, displayId;
430 || name_length >=
sizeof(buff)
431 || fread(&buff,
sizeof(
char), name_length,
model_list.get()) != name_length)
433 printf(
"\nFile 'temp_gameobject_models' seems to be corrupted\n");
437 std::string model_name(buff, name_length);
444 G3D::AABox bounds = G3D::AABox::empty();
446 for (G3D::Vector3
const& vertice : groupModel.vertexArray)
447 bounds.merge(vertice);
449 if (bounds.isEmpty())
451 printf(
"\nModel %s has empty bounding box\n", model_name.c_str());
455 if (!bounds.isFinite())
457 printf(
"\nModel %s has invalid bounding box\n", model_name.c_str());
461 fwrite(&displayId,
sizeof(
uint32), 1, model_list_copy.get());
462 fwrite(&name_length,
sizeof(
uint32), 1, model_list_copy.get());
463 fwrite(&buff,
sizeof(
char), name_length, model_list_copy.get());
464 fwrite(&bounds.low(),
sizeof(G3D::Vector3), 1, model_list_copy.get());
465 fwrite(&bounds.high(),
sizeof(G3D::Vector3), 1, model_list_copy.get());
484 G3D::Vector3 vec1, vec2;
498 for (
uint32 b = 0; b < branches; ++b)
513 std::unique_ptr<uint32[]> indexarray = std::make_unique<uint32[]>(nindexes);
516 for (
uint32 i = 0; i < nindexes; i += 3)
517 triangles.push_back({ .idx0 = indexarray[i], .idx1 = indexarray[i + 1], .idx2 = indexarray[i + 2] });
529 std::unique_ptr<float[]> vectorarray = std::make_unique<float[]>(nvectors * 3);
531 for (
uint32 i = 0; i < nvectors; ++i)
532 vertexArray.push_back(G3D::Vector3(&vectorarray[3 * i]));