68 {
70 if (!success)
71 {
72 return false;
73 }
74
75
76 for (MapData::iterator map_iter =
mapData.begin(); map_iter !=
mapData.end() && success; ++map_iter)
77 {
78
79 std::vector<ModelSpawn*> mapSpawns;
80 UniqueEntryMap::iterator entry;
81 printf("Calculating model bounds for map %u...\n", map_iter->first);
82 for (entry = map_iter->second->UniqueEntries.begin(); entry != map_iter->second->UniqueEntries.end(); ++entry)
83 {
84
85 if (entry->second.flags &
MOD_M2)
86 {
88 {
89 break;
90 }
91 }
93 {
95
96 entry->second.iBound = entry->second.iBound + Vector3(533.33333f * 32, 533.33333f * 32, 0.f);
97 }
98 mapSpawns.push_back(&(entry->second));
100 }
101
102 printf("Creating map tree for map %u...\n", map_iter->first);
104
105 try
106 {
107 pTree.
build(mapSpawns, BoundsTrait<ModelSpawn*>::GetBounds);
108 }
109 catch (std::exception& e)
110 {
111 printf("Exception ""%s"" when calling pTree.build", e.what());
112 return false;
113 }
114
115
116 std::map<uint32, uint32> modelNodeIdx;
117 for (
uint32 i = 0; i < mapSpawns.size(); ++i)
118 {
119 modelNodeIdx.insert(pair<uint32, uint32>(mapSpawns[i]->ID, i));
120 }
121
122
123 std::stringstream mapfilename;
124 mapfilename <<
iDestDir <<
'/' << std::setfill(
'0') << std::setw(3) << map_iter->first <<
".vmtree";
125 FILE* mapfile = fopen(mapfilename.str().c_str(), "wb");
126 if (!mapfile)
127 {
128 success = false;
129 printf("Cannot open %s\n", mapfilename.str().c_str());
130 break;
131 }
132
133
134 if (success && fwrite(
VMAP_MAGIC, 1, 8, mapfile) != 8) { success =
false; }
136 pair<TileMap::iterator, TileMap::iterator> globalRange = map_iter->second->TileEntries.equal_range(globalTileID);
137 char isTiled = globalRange.first == globalRange.second;
138 if (success && fwrite(&isTiled, sizeof(char), 1, mapfile) != 1) { success = false; }
139
140 if (success && fwrite("NODE", 4, 1, mapfile) != 1) { success = false; }
141 if (success) { success = pTree.
writeToFile(mapfile); }
142
143 if (success && fwrite("GOBJ", 4, 1, mapfile) != 1) { success = false; }
144
145 for (TileMap::iterator glob = globalRange.first; glob != globalRange.second && success; ++glob)
146 {
148 }
149
150 fclose(mapfile);
151
152
153
154
155 TileMap& tileEntries = map_iter->second->TileEntries;
156 TileMap::iterator tile;
157 for (tile = tileEntries.begin(); tile != tileEntries.end(); ++tile)
158 {
159 const ModelSpawn& spawn = map_iter->second->UniqueEntries[tile->second];
161 {
162 continue;
163 }
164 uint32 nSpawns = tileEntries.count(tile->first);
165 std::stringstream tilefilename;
166 tilefilename.fill('0');
167 tilefilename <<
iDestDir <<
'/' << std::setw(3) << map_iter->first <<
'_';
170 tilefilename << std::setw(2) << x << '_' << std::setw(2) << y << ".vmtile";
171 if (FILE* tilefile = fopen(tilefilename.str().c_str(), "wb"))
172 {
173
174 if (success && fwrite(
VMAP_MAGIC, 1, 8, tilefile) != 8) { success =
false; }
175
176 if (success && fwrite(&nSpawns,
sizeof(
uint32), 1, tilefile) != 1) { success =
false; }
177
178 for (
uint32 s = 0; s < nSpawns; ++s)
179 {
180 if (s)
181 {
182 ++tile;
183 }
184 const ModelSpawn& spawn2 = map_iter->second->UniqueEntries[tile->second];
186
187 std::map<uint32, uint32>::iterator nIdx = modelNodeIdx.find(spawn2.ID);
188 if (success && fwrite(&nIdx->second,
sizeof(
uint32), 1, tilefile) != 1) { success =
false; }
189 }
190 fclose(tilefile);
191 }
192 }
193
194 }
195
196
198
199 std::cout << "\nConverting Model Files" << std::endl;
201 {
202 std::cout << "Converting " << *mfile << std::endl;
204 {
205 std::cout << "error converting " << *mfile << std::endl;
206 success = false;
207 break;
208 }
209 }
210
211
212 for (MapData::iterator map_iter =
mapData.begin(); map_iter !=
mapData.end(); ++map_iter)
213 {
214 delete map_iter->second;
215 }
216 return success;
217 }
const char VMAP_MAGIC[]
Definition: VMapDefinitions.h:25
std::multimap< uint32, uint32 > TileMap
Definition: TileAssembler.h:55
@ MOD_WORLDSPAWN
Definition: ModelInstance.h:37
@ MOD_M2
Definition: ModelInstance.h:36
Definition: BoundingIntervalHierarchy.h:67
bool writeToFile(FILE *wf) const
Definition: BoundingIntervalHierarchy.cpp:273
void build(const PrimArray &primitives, BoundsFunc &GetBounds, uint32 leafSize=3, bool printStats=false)
Definition: BoundingIntervalHierarchy.h:80
static uint32 packTileID(uint32 tileX, uint32 tileY)
Definition: MapTree.h:66
static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY)
Definition: MapTree.h:67
void exportGameobjectModels()
Definition: TileAssembler.cpp:374
bool readMapSpawns()
Definition: TileAssembler.cpp:219
MapData mapData
Definition: TileAssembler.h:98
bool convertRawFile(const std::string &pModelFilename)
Definition: TileAssembler.cpp:334
std::set< std::string > spawnedModelFiles
Definition: TileAssembler.h:99
bool calculateTransformedBound(ModelSpawn &spawn)
Definition: TileAssembler.cpp:267
static bool writeToFile(FILE *rw, const ModelSpawn &spawn)
Definition: ModelInstance.cpp:207