TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WMOGroup Class Reference

#include <wmo.h>

Public Member Functions

 WMOGroup (std::string const &filename)
 
 ~WMOGroup ()
 
bool open ()
 
int ConvertToVMAPGroupWmo (FILE *output, WMORoot *rootWMO, bool preciseVectorData)
 

Public Attributes

char * MOPY
 
uint16MOVI
 
uint16MoviEx
 
float * MOVT
 
uint16MOBA
 
int * MobaEx
 
WMOLiquidHeaderhlq
 
WMOLiquidVertLiquEx
 
char * LiquBytes
 
int groupName
 
int descGroupName
 
int mogpFlags
 
float bbcorn1 [3]
 
float bbcorn2 [3]
 
uint16 moprIdx
 
uint16 moprNItems
 
uint16 nBatchA
 
uint16 nBatchB
 
uint32 nBatchC
 
uint32 fogIdx
 
uint32 liquidType
 
uint32 groupWMOID
 
int mopy_size
 
int moba_size
 
int LiquEx_size
 
unsigned int nVertices
 
int nTriangles
 
uint32 liquflags
 

Private Attributes

std::string filename
 

Constructor & Destructor Documentation

WMOGroup::WMOGroup ( std::string const filename)
141  :
142  filename(filename), MOPY(0), MOVI(0), MoviEx(0), MOVT(0), MOBA(0), MobaEx(0),
143  hlq(0), LiquEx(0), LiquBytes(0), groupName(0), descGroupName(0), mogpFlags(0),
144  moprIdx(0), moprNItems(0), nBatchA(0), nBatchB(0), nBatchC(0), fogIdx(0),
146  nVertices(0), nTriangles(0), liquflags(0)
147 {
148  memset(bbcorn1, 0, sizeof(bbcorn1));
149  memset(bbcorn2, 0, sizeof(bbcorn2));
150 }
int * MobaEx
Definition: wmo.h:93
int groupName
Definition: wmo.h:97
int mopy_size
Definition: wmo.h:107
uint32 groupWMOID
Definition: wmo.h:105
int descGroupName
Definition: wmo.h:97
uint16 * MOVI
Definition: wmo.h:89
uint16 nBatchA
Definition: wmo.h:103
uint16 moprNItems
Definition: wmo.h:102
float bbcorn2[3]
Definition: wmo.h:100
char * MOPY
Definition: wmo.h:88
uint16 nBatchB
Definition: wmo.h:104
uint32 liquidType
Definition: wmo.h:105
WMOLiquidVert * LiquEx
Definition: wmo.h:95
uint16 * MoviEx
Definition: wmo.h:90
uint16 moprIdx
Definition: wmo.h:101
char * LiquBytes
Definition: wmo.h:96
int nTriangles
Definition: wmo.h:110
WMOLiquidHeader * hlq
Definition: wmo.h:94
int LiquEx_size
Definition: wmo.h:108
float bbcorn1[3]
Definition: wmo.h:99
unsigned int nVertices
Definition: wmo.h:109
uint32 liquflags
Definition: wmo.h:111
std::string filename
Definition: wmo.h:84
float * MOVT
Definition: wmo.h:91
uint32 nBatchC
Definition: wmo.h:105
int mogpFlags
Definition: wmo.h:98
uint32 fogIdx
Definition: wmo.h:105
int moba_size
Definition: wmo.h:107
uint16 * MOBA
Definition: wmo.h:92
WMOGroup::~WMOGroup ( )
478 {
479  delete [] MOPY;
480  delete [] MOVI;
481  delete [] MOVT;
482  delete [] MOBA;
483  delete hlq;
484  delete [] LiquEx;
485  delete [] LiquBytes;
486 }
uint16 * MOVI
Definition: wmo.h:89
char * MOPY
Definition: wmo.h:88
WMOLiquidVert * LiquEx
Definition: wmo.h:95
char * LiquBytes
Definition: wmo.h:96
WMOLiquidHeader * hlq
Definition: wmo.h:94
float * MOVT
Definition: wmo.h:91
uint16 * MOBA
Definition: wmo.h:92

Member Function Documentation

int WMOGroup::ConvertToVMAPGroupWmo ( FILE *  output,
WMORoot rootWMO,
bool  preciseVectorData 
)
249 {
250  fwrite(&mogpFlags,sizeof(uint32),1,output);
251  fwrite(&groupWMOID,sizeof(uint32),1,output);
252  // group bound
253  fwrite(bbcorn1, sizeof(float), 3, output);
254  fwrite(bbcorn2, sizeof(float), 3, output);
255  fwrite(&liquflags,sizeof(uint32),1,output);
256  int nColTriangles = 0;
257  if (preciseVectorData)
258  {
259  char GRP[] = "GRP ";
260  fwrite(GRP,1,4,output);
261 
262  int k = 0;
263  int moba_batch = moba_size/12;
264  MobaEx = new int[moba_batch*4];
265  for(int i=8; i<moba_size; i+=12)
266  {
267  MobaEx[k++] = MOBA[i];
268  }
269  int moba_size_grp = moba_batch*4+4;
270  fwrite(&moba_size_grp,4,1,output);
271  fwrite(&moba_batch,4,1,output);
272  fwrite(MobaEx,4,k,output);
273  delete [] MobaEx;
274 
275  uint32 nIdexes = nTriangles * 3;
276 
277  if(fwrite("INDX",4, 1, output) != 1)
278  {
279  printf("Error while writing file nbraches ID");
280  exit(0);
281  }
282  int wsize = sizeof(uint32) + sizeof(unsigned short) * nIdexes;
283  if(fwrite(&wsize, sizeof(int), 1, output) != 1)
284  {
285  printf("Error while writing file wsize");
286  // no need to exit?
287  }
288  if(fwrite(&nIdexes, sizeof(uint32), 1, output) != 1)
289  {
290  printf("Error while writing file nIndexes");
291  exit(0);
292  }
293  if(nIdexes >0)
294  {
295  if(fwrite(MOVI, sizeof(unsigned short), nIdexes, output) != nIdexes)
296  {
297  printf("Error while writing file indexarray");
298  exit(0);
299  }
300  }
301 
302  if(fwrite("VERT",4, 1, output) != 1)
303  {
304  printf("Error while writing file nbraches ID");
305  exit(0);
306  }
307  wsize = sizeof(int) + sizeof(float) * 3 * nVertices;
308  if(fwrite(&wsize, sizeof(int), 1, output) != 1)
309  {
310  printf("Error while writing file wsize");
311  // no need to exit?
312  }
313  if(fwrite(&nVertices, sizeof(int), 1, output) != 1)
314  {
315  printf("Error while writing file nVertices");
316  exit(0);
317  }
318  if(nVertices >0)
319  {
320  if(fwrite(MOVT, sizeof(float)*3, nVertices, output) != nVertices)
321  {
322  printf("Error while writing file vectors");
323  exit(0);
324  }
325  }
326 
327  nColTriangles = nTriangles;
328  }
329  else
330  {
331  char GRP[] = "GRP ";
332  fwrite(GRP,1,4,output);
333  int k = 0;
334  int moba_batch = moba_size/12;
335  MobaEx = new int[moba_batch*4];
336  for(int i=8; i<moba_size; i+=12)
337  {
338  MobaEx[k++] = MOBA[i];
339  }
340 
341  int moba_size_grp = moba_batch*4+4;
342  fwrite(&moba_size_grp,4,1,output);
343  fwrite(&moba_batch,4,1,output);
344  fwrite(MobaEx,4,k,output);
345  delete [] MobaEx;
346 
347  //-------INDX------------------------------------
348  //-------MOPY--------
349  MoviEx = new uint16[nTriangles*3]; // "worst case" size...
350  int *IndexRenum = new int[nVertices];
351  memset(IndexRenum, 0xFF, nVertices*sizeof(int));
352  for (int i=0; i<nTriangles; ++i)
353  {
354  // Skip no collision triangles
355  if (MOPY[2*i]&WMO_MATERIAL_NO_COLLISION ||
357  continue;
358  // Use this triangle
359  for (int j=0; j<3; ++j)
360  {
361  IndexRenum[MOVI[3*i + j]] = 1;
362  MoviEx[3*nColTriangles + j] = MOVI[3*i + j];
363  }
364  ++nColTriangles;
365  }
366 
367  // assign new vertex index numbers
368  int nColVertices = 0;
369  for (uint32 i=0; i<nVertices; ++i)
370  {
371  if (IndexRenum[i] == 1)
372  {
373  IndexRenum[i] = nColVertices;
374  ++nColVertices;
375  }
376  }
377 
378  // translate triangle indices to new numbers
379  for (int i=0; i<3*nColTriangles; ++i)
380  {
381  assert(MoviEx[i] < nVertices);
382  MoviEx[i] = IndexRenum[MoviEx[i]];
383  }
384 
385  // write triangle indices
386  int INDX[] = {0x58444E49, nColTriangles*6+4, nColTriangles*3};
387  fwrite(INDX,4,3,output);
388  fwrite(MoviEx,2,nColTriangles*3,output);
389 
390  // write vertices
391  int VERT[] = {0x54524556, nColVertices*3*static_cast<int>(sizeof(float))+4, nColVertices};// "VERT"
392  int check = 3*nColVertices;
393  fwrite(VERT,4,3,output);
394  for (uint32 i=0; i<nVertices; ++i)
395  if(IndexRenum[i] >= 0)
396  check -= fwrite(MOVT+3*i, sizeof(float), 3, output);
397 
398  assert(check==0);
399 
400  delete [] MoviEx;
401  delete [] IndexRenum;
402  }
403 
404  //------LIQU------------------------
405  if (LiquEx_size != 0)
406  {
407  int LIQU_h[] = {0x5551494C, static_cast<int>(sizeof(WMOLiquidHeader) + LiquEx_size) + hlq->xtiles*hlq->ytiles};// "LIQU"
408  fwrite(LIQU_h, 4, 2, output);
409 
410  // according to WoW.Dev Wiki:
411  uint32 liquidEntry;
412  if (rootWMO->liquidType & 4)
413  liquidEntry = liquidType;
414  else if (liquidType == 15)
415  liquidEntry = 0;
416  else
417  liquidEntry = liquidType + 1;
418 
419  if (!liquidEntry)
420  {
421  int v1; // [email protected]
422  int v2; // [email protected]
423 
424  v1 = hlq->xtiles * hlq->ytiles;
425  v2 = 0;
426  if (v1 > 0)
427  {
428  while ((LiquBytes[v2] & 0xF) == 15)
429  {
430  ++v2;
431  if (v2 >= v1)
432  break;
433  }
434 
435  if (v2 < v1 && (LiquBytes[v2] & 0xF) != 15)
436  liquidEntry = (LiquBytes[v2] & 0xF) + 1;
437  }
438  }
439 
440  if (liquidEntry && liquidEntry < 21)
441  {
442  switch ((liquidEntry - 1) & 3)
443  {
444  case 0:
445  liquidEntry = ((mogpFlags & 0x80000) != 0) + 13;
446  break;
447  case 1:
448  liquidEntry = 14;
449  break;
450  case 2:
451  liquidEntry = 19;
452  break;
453  case 3:
454  liquidEntry = 20;
455  break;
456  }
457  }
458 
459  hlq->type = liquidEntry;
460 
461  /* std::ofstream llog("Buildings/liquid.log", ios_base::out | ios_base::app);
462  llog << filename;
463  llog << ":\nliquidEntry: " << liquidEntry << " type: " << hlq->type << " (root:" << rootWMO->liquidType << " group:" << liquidType << ")\n";
464  llog.close(); */
465 
466  fwrite(hlq, sizeof(WMOLiquidHeader), 1, output);
467  // only need height values, the other values are unknown anyway
468  for (uint32 i = 0; i<LiquEx_size/sizeof(WMOLiquidVert); ++i)
469  fwrite(&LiquEx[i].height, sizeof(float), 1, output);
470  // todo: compress to bit field
471  fwrite(LiquBytes, 1, hlq->xtiles*hlq->ytiles, output);
472  }
473 
474  return nColTriangles;
475 }
int * MobaEx
Definition: wmo.h:93
int ytiles
Definition: wmo.h:63
#define WMO_MATERIAL_NO_COLLISION
Definition: wmo.h:32
uint32 groupWMOID
Definition: wmo.h:105
uint16 * MOVI
Definition: wmo.h:89
Definition: wmo.h:72
float bbcorn2[3]
Definition: wmo.h:100
char * MOPY
Definition: wmo.h:88
#define output
Definition: wire_format_lite.h:381
uint32 liquidType
Definition: wmo.h:105
#define WMO_MATERIAL_COLLIDE_HIT
Definition: wmo.h:35
WMOLiquidVert * LiquEx
Definition: wmo.h:95
uint16 * MoviEx
Definition: wmo.h:90
uint32_t uint32
Definition: Define.h:150
uint16_t uint16
Definition: Define.h:151
char * LiquBytes
Definition: wmo.h:96
int nTriangles
Definition: wmo.h:110
WMOLiquidHeader * hlq
Definition: wmo.h:94
#define WMO_MATERIAL_HINT
Definition: wmo.h:33
int LiquEx_size
Definition: wmo.h:108
uint32 liquidType
Definition: wmo.h:51
float bbcorn1[3]
Definition: wmo.h:99
unsigned int nVertices
Definition: wmo.h:109
uint32 liquflags
Definition: wmo.h:111
int xtiles
Definition: wmo.h:63
short type
Definition: wmo.h:67
float * MOVT
Definition: wmo.h:91
uint32_t uint32
Definition: g3dmath.h:168
int mogpFlags
Definition: wmo.h:98
int moba_size
Definition: wmo.h:107
T check(T value)
Definition: format.h:305
Definition: wmo.h:61
uint16 * MOBA
Definition: wmo.h:92
bool preciseVectorData
Definition: vmapexport.cpp:76
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool WMOGroup::open ( )
153 {
154  MPQFile f(CascStorage, filename.c_str());
155  if(f.isEof ())
156  {
157  printf("No such file.\n");
158  return false;
159  }
160  uint32 size;
161  char fourcc[5];
162  while (!f.isEof())
163  {
164  f.read(fourcc,4);
165  f.read(&size, 4);
166  flipcc(fourcc);
167  if (!strcmp(fourcc,"MOGP"))//Fix sizeoff = Data size.
168  {
169  size = 68;
170  }
171  fourcc[4] = 0;
172  size_t nextpos = f.getPos() + size;
173  LiquEx_size = 0;
174  liquflags = 0;
175 
176  if (!strcmp(fourcc,"MOGP"))//header
177  {
178  f.read(&groupName, 4);
179  f.read(&descGroupName, 4);
180  f.read(&mogpFlags, 4);
181  f.read(bbcorn1, 12);
182  f.read(bbcorn2, 12);
183  f.read(&moprIdx, 2);
184  f.read(&moprNItems, 2);
185  f.read(&nBatchA, 2);
186  f.read(&nBatchB, 2);
187  f.read(&nBatchC, 4);
188  f.read(&fogIdx, 4);
189  f.read(&liquidType, 4);
190  f.read(&groupWMOID,4);
191 
192  }
193  else if (!strcmp(fourcc,"MOPY"))
194  {
195  MOPY = new char[size];
196  mopy_size = size;
197  nTriangles = (int)size / 2;
198  f.read(MOPY, size);
199  }
200  else if (!strcmp(fourcc,"MOVI"))
201  {
202  MOVI = new uint16[size/2];
203  f.read(MOVI, size);
204  }
205  else if (!strcmp(fourcc,"MOVT"))
206  {
207  MOVT = new float[size/4];
208  f.read(MOVT, size);
209  nVertices = (int)size / 12;
210  }
211  else if (!strcmp(fourcc,"MONR"))
212  {
213  }
214  else if (!strcmp(fourcc,"MOTV"))
215  {
216  }
217  else if (!strcmp(fourcc,"MOBA"))
218  {
219  MOBA = new uint16[size/2];
220  moba_size = size/2;
221  f.read(MOBA, size);
222  }
223  else if (!strcmp(fourcc,"MLIQ"))
224  {
225  liquflags |= 1;
226  hlq = new WMOLiquidHeader();
227  f.read(hlq, 0x1E);
228  LiquEx_size = sizeof(WMOLiquidVert) * hlq->xverts * hlq->yverts;
230  f.read(LiquEx, LiquEx_size);
231  int nLiquBytes = hlq->xtiles * hlq->ytiles;
232  LiquBytes = new char[nLiquBytes];
233  f.read(LiquBytes, nLiquBytes);
234 
235  /* std::ofstream llog("Buildings/liquid.log", ios_base::out | ios_base::app);
236  llog << filename;
237  llog << "\nbbox: " << bbcorn1[0] << ", " << bbcorn1[1] << ", " << bbcorn1[2] << " | " << bbcorn2[0] << ", " << bbcorn2[1] << ", " << bbcorn2[2];
238  llog << "\nlpos: " << hlq->pos_x << ", " << hlq->pos_y << ", " << hlq->pos_z;
239  llog << "\nx-/yvert: " << hlq->xverts << "/" << hlq->yverts << " size: " << size << " expected size: " << 30 + hlq->xverts*hlq->yverts*8 + hlq->xtiles*hlq->ytiles << std::endl;
240  llog.close(); */
241  }
242  f.seek((int)nextpos);
243  }
244  f.close();
245  return true;
246 }
HANDLE CascStorage
Definition: System.cpp:69
int groupName
Definition: wmo.h:97
void flipcc(char *fcc)
Definition: mpqfile.h:57
int ytiles
Definition: wmo.h:63
int mopy_size
Definition: wmo.h:107
uint32 groupWMOID
Definition: wmo.h:105
int descGroupName
Definition: wmo.h:97
uint16 * MOVI
Definition: wmo.h:89
uint16 nBatchA
Definition: wmo.h:103
uint16 moprNItems
Definition: wmo.h:102
Definition: wmo.h:72
float bbcorn2[3]
Definition: wmo.h:100
char * MOPY
Definition: wmo.h:88
uint16 nBatchB
Definition: wmo.h:104
uint32 liquidType
Definition: wmo.h:105
Definition: mpqfile.h:32
int yverts
Definition: wmo.h:63
WMOLiquidVert * LiquEx
Definition: wmo.h:95
uint16 moprIdx
Definition: wmo.h:101
uint32_t uint32
Definition: Define.h:150
uint16_t uint16
Definition: Define.h:151
char * LiquBytes
Definition: wmo.h:96
int nTriangles
Definition: wmo.h:110
WMOLiquidHeader * hlq
Definition: wmo.h:94
int LiquEx_size
Definition: wmo.h:108
float bbcorn1[3]
Definition: wmo.h:99
unsigned int nVertices
Definition: wmo.h:109
uint32 liquflags
Definition: wmo.h:111
int xtiles
Definition: wmo.h:63
std::string filename
Definition: wmo.h:84
float * MOVT
Definition: wmo.h:91
uint32 nBatchC
Definition: wmo.h:105
int mogpFlags
Definition: wmo.h:98
uint32 fogIdx
Definition: wmo.h:105
int moba_size
Definition: wmo.h:107
Definition: wmo.h:61
uint16 * MOBA
Definition: wmo.h:92
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083
int xverts
Definition: wmo.h:63

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

float WMOGroup::bbcorn1[3]
float WMOGroup::bbcorn2[3]
int WMOGroup::descGroupName
std::string WMOGroup::filename
private
uint32 WMOGroup::fogIdx
int WMOGroup::groupName
uint32 WMOGroup::groupWMOID
WMOLiquidHeader* WMOGroup::hlq
char* WMOGroup::LiquBytes
WMOLiquidVert* WMOGroup::LiquEx
int WMOGroup::LiquEx_size
uint32 WMOGroup::liquflags
uint32 WMOGroup::liquidType
uint16* WMOGroup::MOBA
int WMOGroup::moba_size
int* WMOGroup::MobaEx
int WMOGroup::mogpFlags
uint16 WMOGroup::moprIdx
uint16 WMOGroup::moprNItems
char* WMOGroup::MOPY
int WMOGroup::mopy_size
uint16* WMOGroup::MOVI
uint16* WMOGroup::MoviEx
float* WMOGroup::MOVT
uint16 WMOGroup::nBatchA
uint16 WMOGroup::nBatchB
uint32 WMOGroup::nBatchC
int WMOGroup::nTriangles
unsigned int WMOGroup::nVertices

The documentation for this class was generated from the following files: