74 for (MapData::iterator map_iter =
mapData.begin(); map_iter !=
mapData.end() && success; ++map_iter)
77 std::vector<ModelSpawn*> mapSpawns;
78 UniqueEntryMap::iterator entry;
79 printf(
"Calculating model bounds for map %u...\n", map_iter->first);
80 for (entry = map_iter->second->UniqueEntries.begin(); entry != map_iter->second->UniqueEntries.end(); ++entry)
83 if (entry->second.flags &
MOD_M2)
92 entry->second.iBound = entry->second.iBound + Vector3(533.33333f*32, 533.33333f*32, 0.f);
94 mapSpawns.push_back(&(entry->second));
98 printf(
"Creating map tree for map %u...\n", map_iter->first);
103 pTree.
build(mapSpawns, BoundsTrait<ModelSpawn*>::getBounds);
105 catch (std::exception& e)
107 printf(
"Exception ""%s"" when calling pTree.build", e.what());
112 std::map<uint32, uint32> modelNodeIdx;
113 for (
uint32 i=0; i<mapSpawns.size(); ++i)
114 modelNodeIdx.insert(pair<uint32, uint32>(mapSpawns[i]->ID, i));
117 std::stringstream mapfilename;
118 mapfilename <<
iDestDir <<
'/' << std::setfill(
'0') << std::setw(3) << map_iter->first <<
".vmtree";
119 FILE* mapfile = fopen(mapfilename.str().c_str(),
"wb");
123 printf(
"Cannot open %s\n", mapfilename.str().c_str());
128 if (success && fwrite(
VMAP_MAGIC, 1, 8, mapfile) != 8) success =
false;
130 pair<TileMap::iterator, TileMap::iterator> globalRange = map_iter->second->TileEntries.equal_range(globalTileID);
131 char isTiled = globalRange.first == globalRange.second;
132 if (success && fwrite(&isTiled,
sizeof(
char), 1, mapfile) != 1) success =
false;
134 if (success && fwrite(
"NODE", 4, 1, mapfile) != 1) success =
false;
137 if (success && fwrite(
"GOBJ", 4, 1, mapfile) != 1) success =
false;
139 for (TileMap::iterator glob = globalRange.first; glob != globalRange.second && success; ++glob)
147 TileMap &tileEntries = map_iter->second->TileEntries;
148 TileMap::iterator tile;
149 for (tile = tileEntries.begin(); tile != tileEntries.end(); ++tile)
151 ModelSpawn const& spawn = map_iter->second->UniqueEntries[tile->second];
154 uint32 nSpawns = tileEntries.count(tile->first);
155 std::stringstream tilefilename;
156 tilefilename.fill(
'0');
157 tilefilename <<
iDestDir <<
'/' << std::setw(3) << map_iter->first <<
'_';
160 tilefilename << std::setw(2) << x <<
'_' << std::setw(2) << y <<
".vmtile";
161 if (FILE* tilefile = fopen(tilefilename.str().c_str(),
"wb"))
164 if (success && fwrite(
VMAP_MAGIC, 1, 8, tilefile) != 8) success =
false;
166 if (success && fwrite(&nSpawns,
sizeof(
uint32), 1, tilefile) != 1) success =
false;
168 for (
uint32 s=0; s<nSpawns; ++s)
172 ModelSpawn const& spawn2 = map_iter->second->UniqueEntries[tile->second];
175 std::map<uint32, uint32>::iterator nIdx = modelNodeIdx.find(spawn2.
ID);
176 if (success && fwrite(&nIdx->second,
sizeof(
uint32), 1, tilefile) != 1) success =
false;
187 std::cout <<
"\nConverting Model Files" << std::endl;
190 std::cout <<
"Converting " << spawnedModelFile << std::endl;
193 std::cout <<
"error converting " << spawnedModelFile << std::endl;
200 for (std::pair<uint32 const, MapSpawns*>& map_iter :
mapData)
201 delete map_iter.second;
352 FILE*
model_list = fopen((
iSrcDir +
"/" +
"temp_gameobject_models").c_str(),
"rb");
364 if (!model_list_copy)
372 uint32 name_length, displayId;
383 || name_length >=
sizeof(buff)
384 || fread(&buff,
sizeof(
char), name_length,
model_list) != name_length)
386 std::cout <<
"\nFile 'temp_gameobject_models' seems to be corrupted" << std::endl;
390 std::string model_name(buff, name_length);
393 if (!raw_model.
Read((
iSrcDir +
"/" + model_name).c_str()) )
398 bool boundEmpty =
true;
401 for (Vector3& v : g.vertexArray)
404 bounds = AABox(v, v), boundEmpty =
false;
410 if (bounds.isEmpty())
412 std::cout <<
"\nModel " << std::string(buff, name_length) <<
" has empty bounding box" << std::endl;
416 if (!bounds.isFinite())
418 std::cout <<
"\nModel " << std::string(buff, name_length) <<
" has invalid bounding box" << std::endl;
422 fwrite(&displayId,
sizeof(
uint32), 1, model_list_copy);
423 fwrite(&isWmo,
sizeof(
uint8), 1, model_list_copy);
424 fwrite(&name_length,
sizeof(
uint32), 1, model_list_copy);
425 fwrite(&buff,
sizeof(
char), name_length, model_list_copy);
426 fwrite(&bounds.low(),
sizeof(Vector3), 1, model_list_copy);
427 fwrite(&bounds.high(),
sizeof(Vector3), 1, model_list_copy);
431 fclose(model_list_copy);