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

#include <model.h>

Public Member Functions

bool open ()
 
bool ConvertToVMAPModel (char const *outfilename)
 
 Model (std::string &filename)
 
 ~Model ()
 

Public Attributes

ModelHeader header
 
Vec3Dvertices
 
uint16indices
 

Private Member Functions

void _unload ()
 

Private Attributes

std::string filename
 

Constructor & Destructor Documentation

Model::Model ( std::string &  filename)
30 {
31  memset(&header, 0, sizeof(header));
32 }
Vec3D * vertices
Definition: model.h:43
ModelHeader header
Definition: model.h:42
std::string filename
Definition: model.h:40
uint16 * indices
Definition: model.h:44
Model::~Model ( )
inline
50 { _unload(); }
void _unload()
Definition: model.h:33

+ Here is the call graph for this function:

Member Function Documentation

void Model::_unload ( )
inlineprivate
34  {
35  delete[] vertices;
36  delete[] indices;
37  vertices = NULL;
38  indices = NULL;
39  }
arena_t NULL
Definition: jemalloc_internal.h:624
Vec3D * vertices
Definition: model.h:43
uint16 * indices
Definition: model.h:44

+ Here is the caller graph for this function:

bool Model::ConvertToVMAPModel ( char const outfilename)
73 {
74  int N[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
75  FILE* output=fopen(outfilename, "wb");
76  if (!output)
77  {
78  printf("Can't create the output file '%s'\n",outfilename);
79  return false;
80  }
81  fwrite(szRawVMAPMagic, 8, 1, output);
82  uint32 nVertices = header.nBoundingVertices;
83  fwrite(&nVertices, sizeof(int), 1, output);
84  uint32 nofgroups = 1;
85  fwrite(&nofgroups,sizeof(uint32), 1, output);
86  fwrite(N,4*3,1,output);// rootwmoid, flags, groupid
87  fwrite(N,sizeof(float),3*2,output);//bbox, only needed for WMO currently
88  fwrite(N,4,1,output);// liquidflags
89  fwrite("GRP ",4,1,output);
90  uint32 branches = 1;
91  int wsize;
92  wsize = sizeof(branches) + sizeof(uint32) * branches;
93  fwrite(&wsize, sizeof(int), 1, output);
94  fwrite(&branches,sizeof(branches), 1, output);
95  uint32 nIndexes = header.nBoundingTriangles;
96  fwrite(&nIndexes,sizeof(uint32), 1, output);
97  fwrite("INDX",4, 1, output);
98  wsize = sizeof(uint32) + sizeof(unsigned short) * nIndexes;
99  fwrite(&wsize, sizeof(int), 1, output);
100  fwrite(&nIndexes, sizeof(uint32), 1, output);
101  if (nIndexes > 0)
102  {
103  for (uint32 i = 0; i < nIndexes; ++i)
104  {
105  if ((i % 3) - 1 == 0 && i + 1 < nIndexes)
106  {
107  uint16 tmp = indices[i];
108  indices[i] = indices[i + 1];
109  indices[i + 1] = tmp;
110  }
111  }
112  fwrite(indices, sizeof(unsigned short), nIndexes, output);
113  }
114 
115  fwrite("VERT", 4, 1, output);
116  wsize = sizeof(int) + sizeof(float) * 3 * nVertices;
117  fwrite(&wsize, sizeof(int), 1, output);
118  fwrite(&nVertices, sizeof(int), 1, output);
119  if (nVertices >0)
120  {
121  for (uint32 vpos = 0; vpos < nVertices; ++vpos)
122  {
123  float tmp = vertices[vpos].y;
124  vertices[vpos].y = -vertices[vpos].z;
125  vertices[vpos].z = tmp;
126  }
127 
128  fwrite(vertices, sizeof(float)*3, nVertices, output);
129  }
130 
131  fclose(output);
132 
133  return true;
134 }
const char * szRawVMAPMagic
Definition: vmapexport.cpp:82
#define output
Definition: wire_format_lite.h:381
uint32 nBoundingTriangles
Definition: modelheaders.h:69
Vec3D * vertices
Definition: model.h:43
ModelHeader header
Definition: model.h:42
uint32_t uint32
Definition: Define.h:150
uint16_t uint16
Definition: Define.h:151
uint16 * indices
Definition: model.h:44
float z
Definition: vec3d.h:28
float y
Definition: vec3d.h:28
uint32_t uint32
Definition: g3dmath.h:168
uint32 nBoundingVertices
Definition: modelheaders.h:71
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 Model::open ( )
35 {
36  MPQFile f(CascStorage, filename.c_str());
37 
38  if (f.isEof())
39  {
40  f.close();
41  // Do not show this error on console to avoid confusion, the extractor can continue working even if some models fail to load
42  //printf("Error loading model %s\n", filename.c_str());
43  return false;
44  }
45 
46  _unload();
47 
48  memcpy(&header, f.getBuffer(), sizeof(ModelHeader));
49  if (header.nBoundingTriangles > 0)
50  {
51  f.seek(0);
52  f.seekRelative(header.ofsBoundingVertices);
55  for (uint32 i=0; i<header.nBoundingVertices; i++)
57  f.seek(0);
58  f.seekRelative(header.ofsBoundingTriangles);
61  f.close();
62  }
63  else
64  {
65  //printf("not included %s\n", filename.c_str());
66  f.close();
67  return false;
68  }
69  return true;
70 }
Definition: modelheaders.h:26
HANDLE CascStorage
Definition: System.cpp:69
void close()
Definition: mpqfile.cpp:81
Definition: mpqfile.h:32
uint32 nBoundingTriangles
Definition: modelheaders.h:69
Vec3D * vertices
Definition: model.h:43
ModelHeader header
Definition: model.h:42
std::string filename
Definition: model.h:40
uint32_t uint32
Definition: Define.h:150
uint16_t uint16
Definition: Define.h:151
uint32 ofsBoundingTriangles
Definition: modelheaders.h:70
uint32 ofsBoundingVertices
Definition: modelheaders.h:72
uint16 * indices
Definition: model.h:44
void _unload()
Definition: model.h:33
Definition: vec3d.h:25
uint32 nBoundingVertices
Definition: modelheaders.h:71
Vec3D fixCoordSystem(Vec3D v)
Definition: model.cpp:137

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::string Model::filename
private
ModelHeader Model::header
uint16* Model::indices
Vec3D* Model::vertices

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