-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model.h
169 lines (127 loc) · 4.03 KB
/
Model.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#define GL_GLEXT_PROTOTYPES
/***
Model: Defines a collection of faces, vertexs, and texture coordiants to form a 3d model
***/
#ifndef MODEL_H
#define MODEL_H
#include "Metrics.h"
#include "Face.h"
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_Mixer.h"
#include "SDL_ttf.h"
#include "SDL_opengl.h"
#include "StringFunctions.h"
#include "Math.h"
#include "GL_Debug.h"
#include "GLTextureContainer.h"
#include "MaterialContainer.h"
#include "Utilities.h"
#include "OctTree.h"
#include <string>
#include <vector>
#include <fstream>
// The bone class container any bone information about the model
class Bone
{
public:
std::string name;
std::vector<Vertex*> effectedVerts;
private:
};
// Contains a per-vertex package of information for vertex arrays
// -Used to provide faster rendering
class RenderPacket
{
public:
Point3F position;
Vector3F normal;
Point2F texture;
Color4F color;
GLubyte padding[12];
RenderPacket( );
RenderPacket( Point3F position, Vector3F normal, Point2F texture, Color4F color );
};
class Model
{
private:
// Vbos and Ibos
std::map<std::string, GLuint> VBOs;
std::map<std::string, GLuint> IBOs;
// Map of vertex positions in their array
std::map<Vertex*,GLuint> vertexMap;
// Indices for vertex arrays
GLuint* indices;
// Packages of information for rendering
bool renderPackagesSetup;
std::map<std::string, RenderPacket*> RenderPackages;
std::map<std::string, int> RenderPackagesSize;
std::map<std::string, GLuint*> RenderPackagesIndices;
// Material
Material* material;
// Texture coordinates
Point2D* textures;
int amountOfTextures;
// Bones related to the model
Bone* bones;
int amountOfBones;
// True is the model has been suscessfully loaded
bool loaded;
// Size of the model in world coordinates
Size3D size;
// Will calculate the size of the model and center the verts
void calcSizeAndCenter( bool center = true );
// Alternative size calculation function
void CalcSize();
// Allocates memory for the render packages
void setupRenderPackages();
// Name of the model
std::string name;
// Allocated memory for the model
void allocateMemory();
// True if the memory for the model has been allocated
bool memoryAllocated;
// True if the model has been changed since load time
bool hasBeenAlteredSinceLoad;
public:
// Friend class to allow DynamicMesh to alter the verts
friend class DynamicMesh;
// Faces in the model
Face* faces;
int amountOfFaces;
// Vertex positions
int amountOfVerts;
Vertex* verts;
Model();
~Model();
void ClearVBO_IBOs();
// Updates the render packages
void updateRenderPackages();
// Loads a .obj file at path location
// -allowIncompleteLoad will allow a model to load without having the associated texture files
bool load( std::string path, bool allowIncompleteLoad = false, bool sizeAndCenter = true );
// Loads a model with supplied vertex, texture, face, and bone data
// -allowIncompleteLoad will allow a model to load without having the associated texture files
bool load( std::vector<Vertex*>& verts, std::vector<Point2D*>& textures, std::vector<Face*>& faces, std::vector<Bone*>& bones, bool allowIncompleteLoad = false );
// Saves a .obj file to path
bool save( std::string path );
void exportRenderPackets( std::string path );
// Unloads the models data
void unload();
// Returns true if the model has loaded correctly
bool hasLoaded();
// Draws the model at the specified position, scale, and rotation *refactor*
void draw( Point3D position, Size3D scale, Rotation3D rotation, Color4F color, GLuint overrideTexture = 0 );
// Calculates the vertex normals for the entire model
void calcNormals( bool force = false);
// Draws the normal vector for each vertex
void drawNormals( Point3D position, Size3D scale, Rotation3D rotation, double length );
// Draws the position of each vertex
void drawPoints( Point3D position, Size3D scale, Rotation3D rotation, double length );
// Returns the size of the model
Size3D getSize();
// Gets / Sets the name of the model
std::string Name();
void Name( std::string name );
};
#endif // !MODEL_H