-
Notifications
You must be signed in to change notification settings - Fork 0
/
C3DModel.h
executable file
·154 lines (121 loc) · 3.8 KB
/
C3DModel.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
/*
C3DModel.h
Author: Tom Naughton
Description: <describe the C3DModel class here>
*/
#ifndef C3DModel_H
#define C3DModel_H
#include <iostream.h>
#include <string>
#include <map>
#include "CShader.h"
#include "CResourceManager.h"
#include "mathdefs.h"
#include "mathlib.h"
class CPakStream;
class CModelInstance;
class CFileArchive;
class CMd3AnimationInfo;
class CGLImage;
using std::string;
using std::map;
const double FAR_GL_PLANE = 10000.0;
const double NEAR_GL_PLANE = 0.1d;
//const double FAR_GL_PLANE = 512.0d;
//const double NEAR_GL_PLANE = 0.0; // 10.0;
typedef enum
{
INTERP_NONE = 0,
INTERP_LINEAR,
INTERP_CUBIC
} InterpMethodT;
typedef enum
{
WAVEFRONT_OBJ_FORMAT = 0,
AUTOCAD_DXF_FORMAT
} ExportFormatT;
typedef struct MDLVERTEX
{
float x,y,z;
} mdl_vertex_t;
typedef struct MDLMATRIX
{
float m[3][3];
} mdl_matrix_t;
typedef struct MD3TAG
{
char name[12];
char unknown[52];
Vec3 Position; // relative position of tag
Vec4 Rotation; // rotation quaternion
union {
struct {
UInt32 glName;
} info;
struct {
float pad[5];
} pad;
};
} md3_tag_t;
// used for animation
// determined by presence of tags
typedef enum ModelType {
unknown_model = 0,
upper_model,
lower_model,
head_model,
weapon_model,
barrel_model,
flash_model,
other_model
} ModelType;
#define NUMVERTEXNORMALS 162 // normals for MDLs and MD2s are taken from a lookup table
extern float avertexnormals[NUMVERTEXNORMALS][3];
class C3DModel
{
public:
C3DModel();
C3DModel(CResourceManager *resources);
virtual ~C3DModel();
virtual Boolean init(CPakStream *inItem) = 0;
virtual void Draw(CModelInstance *instance, renderingAttributes_t *renderingAttributes) = 0;
virtual void DrawLinks(CModelInstance *instance, renderingAttributes_t *rendering);
virtual Mat4 PushTagTransformMatrix(CModelInstance *instance, int tagindex);
virtual SInt16 frameCount();
virtual string frameName(SInt16 frame);
virtual UInt32 tagNum();
virtual UInt32 meshNum();
virtual ModelType modelType();
virtual Boolean shouldDraw(renderingAttributes_t *rendering, CShader *shader);
virtual Boolean needsNormals(renderingAttributes_t *rendering, CShader *shader);
virtual CMd3AnimationInfo *animationInfo();
virtual int tagIndexWithName(const char *name);
virtual string tagNameForFrameAtIndex(short frame, short index);
virtual md3_tag_t *tagForFrameAtIndex(short frame, short index);
virtual void loadMeshTextures(CModelInstance *instance);
CGLImage *textureWithName(string name, string skinnname="");
void setTextureWithName(CGLImage *texture, string name);
void addTexture(CGLImage* texture);
void dumpTextureCache();
string pathName() { return _pathname; };
// exporting
virtual Boolean canExportFormat(ExportFormatT format) = 0;
virtual void dxfExportMesh(CModelInstance *instance, LFileStream *file, Mat4 transform, int meshnum) = 0;
virtual void objExportMeshVertexData(CModelInstance *instance, LFileStream *file, Mat4 transform, int meshnum) = 0;
virtual void objExportMeshElementData(LFileStream *file, int meshnum, int &vertexCount, int &meshCount) = 0;
float Interpolate(float p[], float u, InterpMethodT method);
SInt16 textureCount() { return _textureCount; };
CResourceManager *resources() { return _resources; };
CFileArchive *pak() { return _resources->pak(); };
vector<CGLImage*> *_textures ;
protected:
typedef pair<string, CGLImage *> texture_pair_type;
typedef map<string, CGLImage *> texture_map_type;
typedef texture_map_type::value_type texture_entry_type;
typedef texture_map_type::iterator texture_iterator;
texture_map_type _textureMap; // stores all textures for model group (stored in root model)
CResourceManager *_resources;
SInt16 _textureCount;
string _pathname;
};
#endif // C3DModel_H