AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
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
 

Detailed Description

Constructor & Destructor Documentation

◆ Model()

Model::Model ( std::string &  filename)
28 : filename(filename), header(), vertices(nullptr), indices(nullptr)
29{
30}
Vec3D * vertices
Definition: model.h:45
ModelHeader header
Definition: model.h:44
uint16 * indices
Definition: model.h:46
std::string filename
Definition: model.h:42

◆ ~Model()

Model::~Model ( )
inline
52{ _unload(); }
void _unload()
Definition: model.h:35

References _unload().

Member Function Documentation

◆ _unload()

void Model::_unload ( )
inlineprivate
36 {
37 delete[] vertices;
38 delete[] indices;
39 vertices = nullptr;
40 indices = nullptr;
41 }

References indices, and vertices.

Referenced by open(), and ~Model().

◆ ConvertToVMAPModel()

bool Model::ConvertToVMAPModel ( char const *  outfilename)
71{
72 int N[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
73 FILE* output = fopen(outfilename, "wb");
74 if (!output)
75 {
76 printf("Can't create the output file '%s'\n", outfilename);
77 return false;
78 }
79 fwrite(VMAP::RAW_VMAP_MAGIC, 8, 1, output);
81 fwrite(&nVertices, sizeof(int), 1, output);
82 uint32 nofgroups = 1;
83 fwrite(&nofgroups, sizeof(uint32), 1, output);
84 fwrite(N, 4 * 3, 1, output); // rootwmoid, flags, groupid
85 fwrite(N, sizeof(float), 3 * 2, output); //bbox, only needed for WMO currently
86 fwrite(N, 4, 1, output); // liquidflags
87 fwrite("GRP ", 4, 1, output);
88 uint32 branches = 1;
89 int wsize;
90 wsize = sizeof(branches) + sizeof(uint32) * branches;
91 fwrite(&wsize, sizeof(int), 1, output);
92 fwrite(&branches, sizeof(branches), 1, output);
94 fwrite(&nIndexes, sizeof(uint32), 1, output);
95 fwrite("INDX", 4, 1, output);
96 wsize = sizeof(uint32) + sizeof(unsigned short) * nIndexes;
97 fwrite(&wsize, sizeof(int), 1, output);
98 fwrite(&nIndexes, sizeof(uint32), 1, output);
99 if (nIndexes > 0)
100 {
101 for (uint32 i = 0; i < nIndexes; ++i)
102 {
103 if ((i % 3) - 1 == 0 && i + 1 < nIndexes)
104 {
105 uint16 tmp = indices[i];
106 indices[i] = indices[i + 1];
107 indices[i + 1] = tmp;
108 }
109 }
110 fwrite(indices, sizeof(unsigned short), nIndexes, output);
111 }
112 fwrite("VERT", 4, 1, output);
113 wsize = sizeof(int) + sizeof(float) * 3 * nVertices;
114 fwrite(&wsize, sizeof(int), 1, output);
115 fwrite(&nVertices, sizeof(int), 1, output);
116 if (nVertices > 0)
117 {
118 for (uint32 vpos = 0; vpos < nVertices; ++vpos)
119 {
120 float tmp = vertices[vpos].y;
121 vertices[vpos].y = -vertices[vpos].z;
122 vertices[vpos].z = tmp;
123 }
124
125 fwrite(vertices, sizeof(float) * 3, nVertices, output);
126 }
127
128 fclose(output);
129
130 return true;
131}
std::uint32_t uint32
Definition: Define.h:108
std::uint16_t uint16
Definition: Define.h:109
const char RAW_VMAP_MAGIC[]
Definition: VMapDefinitions.h:27
uint32 nBoundingVertices
Definition: modelheaders.h:75
uint32 nBoundingTriangles
Definition: modelheaders.h:73
float y
Definition: vec3d.h:27
float z
Definition: vec3d.h:27

References header, indices, ModelHeader::nBoundingTriangles, ModelHeader::nBoundingVertices, VMAP::RAW_VMAP_MAGIC, vertices, Vec3D::y, and Vec3D::z.

Referenced by ExtractSingleModel().

◆ open()

bool Model::open ( )
33{
34 MPQFile f(filename.c_str());
35
36 if (f.isEof())
37 {
38 f.close();
39 // Do not show this error on console to avoid confusion, the extractor can continue working even if some models fail to load
40 //printf("Error loading model %s\n", filename.c_str());
41 return false;
42 }
43
44 _unload();
45
46 memcpy(&header, f.getBuffer(), sizeof(ModelHeader));
48 {
49 f.seek(0);
50 f.seekRelative(header.ofsBoundingVertices);
52 f.read(vertices, header.nBoundingVertices * 12);
53 for (uint32 i = 0; i < header.nBoundingVertices; i++)
55 f.seek(0);
56 f.seekRelative(header.ofsBoundingTriangles);
59 f.close();
60 }
61 else
62 {
63 //printf("not included %s\n", filename.c_str());
64 f.close();
65 return false;
66 }
67 return true;
68}
Vec3D fixCoordSystem(Vec3D const &v)
Definition: model.cpp:133
Definition: mpq_libmpq04.h:75
Definition: modelheaders.h:31
uint32 ofsBoundingVertices
Definition: modelheaders.h:76
uint32 ofsBoundingTriangles
Definition: modelheaders.h:74
Definition: vec3d.h:25

References _unload(), MPQFile::close(), filename, fixCoordSystem(), MPQFile::getBuffer(), header, indices, MPQFile::isEof(), ModelHeader::nBoundingTriangles, ModelHeader::nBoundingVertices, ModelHeader::ofsBoundingTriangles, ModelHeader::ofsBoundingVertices, MPQFile::read(), MPQFile::seek(), MPQFile::seekRelative(), and vertices.

Referenced by ExtractSingleModel().

Member Data Documentation

◆ filename

std::string Model::filename
private

Referenced by open().

◆ header

ModelHeader Model::header

Referenced by ConvertToVMAPModel(), and open().

◆ indices

uint16* Model::indices

Referenced by _unload(), ConvertToVMAPModel(), and open().

◆ vertices

Vec3D* Model::vertices

Referenced by _unload(), ConvertToVMAPModel(), and open().