WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
WoWModel.h
Go to the documentation of this file.
1#pragma once
2
3// C++ files
4#include <map>
5#include <set>
6#include <vector>
7//#include <stdlib.h>
8//#include <crtdbg.h>
9
10#include "animated.h"
11#include "AnimManager.h"
12#include "Bone.h"
13#include "CASCChunks.h"
14#include "CharDetails.h"
15#include "CharTexture.h"
16#include "displayable.h"
17#include "Model.h"
18#include "ModelAttachment.h"
19#include "ModelCamera.h"
20#include "ModelColor.h"
21#include "ModelEvent.h"
22#include "modelheaders.h"
23#include "ModelLight.h"
24#include "ModelTransparency.h"
25#include "particle.h"
26#include "TabardDetails.h"
27#include "TextureAnim.h"
28#include "TextureManager.h"
29#include "wow_enums.h"
30#include "WoWItem.h"
31
32#include "Container.h"
33
34#include "glm/glm.hpp"
35
36class CASCFile;
37class GameFile;
38class ModelRenderPass;
39
40enum
41{
42 TEXTURE_MAX = 32
43};
44
49class WoWModel : public ManagedItem, public Displayable, public Model, public Container<WoWItem>
50{
51 // VBO Data
52 GLuint vbuf, nbuf, tbuf;
53 size_t vbufsize;
54
55 // Non VBO Data
56 GLuint dlist;
58
59 // ===============================
60 // Texture data
61 // ===============================
62 std::vector<GLuint> textures;
63 std::vector<int> specialTextures;
64 std::vector<GLuint> replaceTextures;
65
66 inline void drawModel();
67 void initCommon();
68 bool isAnimated();
69 void initAnimated();
70 void initStatic();
71 void initRaceInfos();
72
73 void animate(ssize_t anim);
74 void calcBones(ssize_t anim, size_t time);
75
76 void lightsOn(GLuint lbase);
77 void lightsOff(GLuint lbase);
78
79 std::vector<uint16> boundTris;
80 std::vector<glm::vec3> bounds;
81
82 void refreshMerging();
83 std::set<WoWModel*> mergedModels;
84
85 // raw values read from file (useful for merging)
86 std::vector<ModelVertex> rawVertices;
87 std::vector<uint32> rawIndices;
88 std::vector<ModelRenderPass*> rawPasses;
89 std::vector<ModelGeosetHD*> rawGeosets;
90 std::vector<uint32> skinFileIDs;
91
92 void restoreRawGeosets();
93 static bool sortPasses(ModelRenderPass* mrp1, ModelRenderPass* mrp2);
94
95 std::vector<uint32> globalSequences;
96 std::vector<ParticleSystem> particleSystems;
97 std::vector<RibbonEmitter> ribbons;
98 std::vector<TextureAnim> texAnims;
99 std::vector<ModelColor> colors;
100 std::vector<ModelTransparency> transparency;
101 std::vector<ModelLight> lights;
102 std::vector<ModelEvent> events;
103
105
106 std::vector<AFID> readAFIDSFromFile(GameFile* f);
107 void readAnimsFromFile(GameFile* f, std::vector<AFID>& afids, modelAnimData& data, uint32 nAnimations,
108 uint32 ofsAnimation, uint32 nAnimationLookup, uint32 ofsAnimationLookup);
109 std::vector<TXID> readTXIDSFromFile(GameFile* f);
110
111public:
113
114 std::vector<uint> replacableParticleColorIDs;
116
117 int mergedModelType; // 1 for customization models (e.g. body parts) / -1 for gear (armour sections)
118
120 {
121 return static_cast<uint>(lights.size());
122 }
123
124 // Start, Mid and End colours, for cases where the model's particle colours are
125 // overridden by values from ParticleColor.dbc, indexed from CreatureDisplayInfo:
126 typedef std::vector<glm::vec4> particleColorSet;
127
128 // The particle will get its replacement colour set from 0, 1 or 2,
129 // depending on whether its ParticleColorIndex is set to 11, 12 or 13:
130 std::vector<particleColorSet> particleColorReplacements;
131 // Raw Data
132 std::vector<ModelVertex> origVertices;
133
134 typedef int GeosetNum;
135
136 glm::vec3* normals;
137 glm::vec2* texCoords;
138 glm::vec3* vertices;
139 std::vector<uint32> indices;
140
141 WoWModel(GameFile* file, bool forceAnim = false);
142 ~WoWModel();
143
144 std::vector<ModelCamera> cam;
145 std::string modelname;
146 std::string lodname;
147
148 std::vector<ModelRenderPass*> passes;
149 std::vector<ModelGeosetHD*> geosets;
150
151 // ===============================
152 // Toggles
159 float alpha_;
160 float scale_;
161
162 // Position and rotation vector
163 glm::vec3 pos_;
164 glm::vec3 rot_;
165
166 bool ok;
167 bool ind;
170 bool isWMO;
173
174 // Misc values
175 float rad;
176 float trans;
177
178 std::vector<ModelAnimation> anims;
179 std::vector<int16> animLookups;
181 std::vector<Bone> bones;
182
185 size_t anim, animtime;
186
187 void reset()
188 {
189 animcalc = false;
190 }
191
192 void update(int dt);
193
195
196 void drawBones();
197 void drawBoundingVolume();
198 void drawParticles();
199 void draw();
200
201 void updateEmitters(float dt);
202 void setLOD(int index);
203
204 void setupAtt(int id);
205 void setupAtt2(int id);
206
207 std::vector<ModelAttachment> atts;
208 static const size_t ATT_MAX = 60;
211
218 std::set<GeosetNum> creatureGeosetData;
222
223 friend class ModelRenderPass;
224
226 int getItemId(CharSlots slot);
227 bool isWearingARobe();
228
229 void updateTextureList(GameFile* tex, int special);
230 void displayHeader(ModelHeader& a_header);
231 bool canSetTextureFromFile(int texnum);
232
233 std::map<int, std::wstring> getAnimsMap();
234
235 void save(pugi::xml_node& parentNode);
236 void load(const std::string& filepath);
237
238 static std::string getCGGroupName(CharGeosets cg);
239
240 // @TODO use geoset id instead of geoset index in vector
241 void showGeoset(uint geosetindex, bool value);
242 void hideAllGeosets();
243 bool isGeosetDisplayed(uint geosetindex);
244 void setGeosetGroupDisplay(CharGeosets group, int val);
245 void setCreatureGeosetData(std::set<GeosetNum> cgd);
246
247 WoWModel* mergeModel(std::string name, int type = 1, bool noRefresh = false);
248 WoWModel* mergeModel(uint fileID, int type = 1, bool noRefresh = false);
249 WoWModel* mergeModel(WoWModel* model, int type = 1, bool noRefresh = false);
250 void unmergeModel(std::string name);
251 void unmergeModel(uint fileID);
252 void unmergeModel(WoWModel* model);
254
255 void refresh();
256
257 std::string getNameForTex(uint16 tex);
258 GLuint getGLTexture(uint16 tex) const;
259 void dumpTextureStatus();
260
261 friend std::ostream& operator<<(std::ostream& out, const WoWModel& m);
262
263 friend class ModelRenderPass; // to allow access to rendering elements (texAnims, etc.)
264};
@ TEXTURE_MAX
Maximum number of texture slots per model.
Definition WoWModel.h:42
Manages animation playback for a WoWModel, supporting up to 4 queued animations, a secondary (upper-b...
Definition AnimManager.h:24
GameFile implementation that reads from a CASC storage archive.
Definition CASCFile.h:20
Manages character customisation options (skin, face, hair, etc.).
Definition CharDetails.h:30
Composites multiple texture layers into a single character skin texture.
Definition CharTexture.h:49
std::string name() const
Definition Component.cpp:52
Generic typed container that manages a set of child Component pointers.
Definition Container.h:13
Interface for objects that can be drawn and animated in the scene.
Definition displayable.h:9
Abstract base class representing a file within the game data archive.
Definition GameFile.h:12
Reference-counted item stored in a Manager.
Definition manager.h:15
Represents a single render pass (material + geometry) for an M2 model geoset.
Abstract base interface for all 3D model types.
Definition Model.h:5
Stores per-race/sex metadata loaded from ChrRaces / ChrModel database tables.
Definition RaceInfos.h:11
Manages custom tabard design details (icon, border, colours) and provides texture lookup for renderin...
Represents an equipped item on a character model.
Definition WoWItem.h:39
Core WoW .m2 model: geometry, animation, textures, and character data.
Definition WoWModel.h:50
float alpha_
Definition WoWModel.h:159
std::vector< ModelAnimation > anims
Definition WoWModel.h:178
std::vector< uint16 > boundTris
Definition WoWModel.h:79
GLuint getGLTexture(uint16 tex) const
std::vector< GLuint > replaceTextures
Definition WoWModel.h:64
int16 attLookup[ATT_MAX]
Definition WoWModel.h:209
void calcBones(ssize_t anim, size_t time)
uint creatureGeosetDataID
Definition WoWModel.h:219
glm::vec2 * texCoords
Definition WoWModel.h:137
void animate(ssize_t anim)
size_t anim
Definition WoWModel.h:185
size_t currentAnim
Definition WoWModel.h:183
TabardDetails td
Definition WoWModel.h:216
WoWModel * mergeModel(std::string name, int type=1, bool noRefresh=false)
glm::vec3 * vertices
Definition WoWModel.h:138
WoWItem * getItem(CharSlots slot)
bool animBones
Definition WoWModel.h:104
GLuint vbuf
Definition WoWModel.h:52
bool ind
Definition WoWModel.h:167
std::map< int, std::wstring > getAnimsMap()
std::vector< TextureAnim > texAnims
Definition WoWModel.h:98
void displayHeader(ModelHeader &a_header)
Definition WoWModel.cpp:249
void readAnimsFromFile(GameFile *f, std::vector< AFID > &afids, modelAnimData &data, uint32 nAnimations, uint32 ofsAnimation, uint32 nAnimationLookup, uint32 ofsAnimationLookup)
Definition WoWModel.cpp:903
std::vector< ModelColor > colors
Definition WoWModel.h:99
bool showBones
Definition WoWModel.h:153
std::vector< uint32 > rawIndices
Definition WoWModel.h:87
void save(pugi::xml_node &parentNode)
int mergedModelType
Definition WoWModel.h:117
std::vector< glm::vec3 > bounds
Definition WoWModel.h:80
std::vector< ModelRenderPass * > rawPasses
Definition WoWModel.h:88
ModelType modelType
Definition WoWModel.h:212
std::vector< int > specialTextures
Definition WoWModel.h:63
std::vector< ModelEvent > events
Definition WoWModel.h:102
void initAnimated()
Definition WoWModel.cpp:965
int16 keyBoneLookup[BONE_MAX]
Definition WoWModel.h:210
void lightsOn(GLuint lbase)
void hideAllGeosets()
RaceInfos infos
Definition WoWModel.h:215
static const size_t ATT_MAX
Definition WoWModel.h:208
bool isWMO
Definition WoWModel.h:170
bool showTexture
Definition WoWModel.h:158
glm::vec3 pos_
Definition WoWModel.h:163
std::vector< glm::vec4 > particleColorSet
Definition WoWModel.h:126
int getItemId(CharSlots slot)
bool animated
Definition WoWModel.h:172
std::vector< uint32 > indices
Definition WoWModel.h:139
ModelHeader header
Definition WoWModel.h:217
uint nbLights() const
Definition WoWModel.h:119
bool replaceParticleColors
Definition WoWModel.h:115
GLuint tbuf
Definition WoWModel.h:52
void initRaceInfos()
Definition WoWModel.cpp:842
std::vector< AFID > readAFIDSFromFile(GameFile *f)
Definition WoWModel.cpp:885
bool canSetTextureFromFile(int texnum)
void updateTextureList(GameFile *tex, int special)
void drawBones()
int GeosetNum
Definition WoWModel.h:134
bool isMount
Definition WoWModel.h:171
void dumpTextureStatus()
Definition WoWModel.cpp:38
bool isWearingARobe()
bool hasParticles
Definition WoWModel.h:169
GLuint dlist
Definition WoWModel.h:56
void load(const std::string &filepath)
std::vector< Bone > bones
Definition WoWModel.h:181
bool isAnimated()
Definition WoWModel.cpp:323
std::vector< uint32 > skinFileIDs
Definition WoWModel.h:90
bool mirrored_
Definition WoWModel.h:221
std::vector< ModelVertex > rawVertices
Definition WoWModel.h:86
std::string modelname
Definition WoWModel.h:145
CharTexture tex
Definition WoWModel.h:194
std::vector< uint > replacableParticleColorIDs
Definition WoWModel.h:114
std::set< WoWModel * > mergedModels
Definition WoWModel.h:83
bool showParticles
Definition WoWModel.h:156
void setupAtt(int id)
bool forceAnim
Definition WoWModel.h:57
std::vector< ModelRenderPass * > passes
Definition WoWModel.h:148
std::vector< uint32 > globalSequences
Definition WoWModel.h:95
float rad
Definition WoWModel.h:175
std::string getNameForTex(uint16 tex)
void drawModel()
bool showWireframe
Definition WoWModel.h:155
float trans
Definition WoWModel.h:176
bool animGeometry
Definition WoWModel.h:104
static bool sortPasses(ModelRenderPass *mrp1, ModelRenderPass *mrp2)
std::vector< RibbonEmitter > ribbons
Definition WoWModel.h:97
void reset()
Definition WoWModel.h:187
std::vector< TXID > readTXIDSFromFile(GameFile *f)
Definition WoWModel.cpp:869
void setLOD(int index)
void setCreatureGeosetData(std::set< GeosetNum > cgd)
CharModelDetails charModelDetails
Definition WoWModel.h:213
GLuint nbuf
Definition WoWModel.h:52
bool ok
Definition WoWModel.h:166
glm::vec3 rot_
Definition WoWModel.h:164
std::vector< GLuint > textures
Definition WoWModel.h:62
void update(int dt)
bool isGeosetDisplayed(uint geosetindex)
void updateEmitters(float dt)
glm::vec3 * normals
Definition WoWModel.h:136
std::vector< int16 > animLookups
Definition WoWModel.h:179
void unmergeModel(std::string name)
float scale_
Definition WoWModel.h:160
std::vector< ModelGeosetHD * > rawGeosets
Definition WoWModel.h:89
static std::string getCGGroupName(CharGeosets cg)
void drawBoundingVolume()
bool showBounds
Definition WoWModel.h:154
void drawParticles()
friend std::ostream & operator<<(std::ostream &out, const WoWModel &m)
void refresh()
size_t animtime
Definition WoWModel.h:185
std::vector< ModelLight > lights
Definition WoWModel.h:101
void initCommon()
Definition WoWModel.cpp:411
bool showModel
Definition WoWModel.h:157
CharDetails cd
Definition WoWModel.h:214
std::vector< particleColorSet > particleColorReplacements
Definition WoWModel.h:130
bool bSheathe
Definition WoWModel.h:220
WoWModel * getMergedModel(uint fileID)
void restoreRawGeosets()
std::vector< ParticleSystem > particleSystems
Definition WoWModel.h:96
void lightsOff(GLuint lbase)
std::vector< ModelAttachment > atts
Definition WoWModel.h:207
void initStatic()
Definition WoWModel.cpp:825
void setupAtt2(int id)
std::vector< ModelGeosetHD * > geosets
Definition WoWModel.h:149
AnimManager * animManager
Definition WoWModel.h:180
std::set< GeosetNum > creatureGeosetData
Definition WoWModel.h:218
size_t vbufsize
Definition WoWModel.h:53
void draw()
std::string lodname
Definition WoWModel.h:146
bool hasCamera
Definition WoWModel.h:168
std::vector< ModelTransparency > transparency
Definition WoWModel.h:100
void setGeosetGroupDisplay(CharGeosets group, int val)
void refreshMerging()
std::vector< ModelVertex > origVertices
Definition WoWModel.h:132
bool animcalc
Definition WoWModel.h:184
void showGeoset(uint geosetindex, bool value)
std::vector< ModelCamera > cam
Definition WoWModel.h:144
GameFile * gamefile
Definition WoWModel.h:112
Holds per-model animation metadata: index-to-id mapping, external anim files, and global sequences.
Definition animated.h:18
Tracks character-specific model state (hand closure, character flag).
M2 model file header — offsets and counts for all data blocks.
unsigned int uint
Definition types.h:36
int16_t int16
Definition types.h:33
uint16_t uint16
Definition types.h:32
uint32_t uint32
Definition types.h:34
CharGeosets
Character geoset group identifiers (mesh IDs for body/armour regions).
Definition wow_enums.h:26
ModelType
Classification of model types.
Definition wow_enums.h:212
CharSlots
Character equipment slot indices.
Definition wow_enums.h:5
@ BONE_MAX
Definition wow_enums.h:207