/
gl_model.h
224 lines (189 loc) · 5.26 KB
/
gl_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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* DE1: $Id$
* Copyright (C) 2003, 2004 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not: http://www.opensource.org/
*/
/*
* gl_model.h: 3D Model Constants and Data Structures
*
* Supported model formats: MD2 and DMD2.
*/
#ifndef __DOOMSDAY_MODEL_H__
#define __DOOMSDAY_MODEL_H__
#include "dd_types.h"
#include "r_data.h"
#define MD2_MAGIC 0x32504449
#define NUMVERTEXNORMALS 162
#define MAX_MODELS 768
// "DMDM" = Doomsday/Detailed MoDel Magic
#define DMD_MAGIC 0x4D444D44
#define MAX_LODS 4
typedef struct {
int magic;
int version;
int skinWidth;
int skinHeight;
int frameSize;
int numSkins;
int numVertices;
int numTexCoords;
int numTriangles;
int numGlCommands;
int numFrames;
int offsetSkins;
int offsetTexCoords;
int offsetTriangles;
int offsetFrames;
int offsetGlCommands;
int offsetEnd;
} md2_header_t;
typedef struct {
byte vertex[3];
byte lightNormalIndex;
} md2_triangleVertex_t;
typedef struct {
float scale[3];
float translate[3];
char name[16];
md2_triangleVertex_t vertices[1];
} md2_packedFrame_t;
typedef struct {
float vertex[3];
byte lightNormalIndex;
} md2_modelVertex_t;
// Translated frame (vertices in model space).
typedef struct {
char name[16];
md2_modelVertex_t *vertices;
} md2_frame_t;
typedef struct {
char name[256];
int id;
} md2_skin_t;
typedef struct {
short vertexIndices[3];
short textureIndices[3];
} md2_triangle_t;
typedef struct {
short s, t;
} md2_textureCoordinate_t;
typedef struct {
float s, t;
int vertexIndex;
} md2_glCommandVertex_t;
//===========================================================================
// DMD (Detailed/Doomsday Models)
//===========================================================================
typedef struct {
int magic;
int version;
int flags;
} dmd_header_t;
// Chunk types.
enum {
DMC_END, // Must be the last chunk.
DMC_INFO // Required; will be expected to exist.
};
typedef struct {
int type;
int length; // Next chunk follows...
} dmd_chunk_t;
typedef struct // DMC_INFO
{
int skinWidth;
int skinHeight;
int frameSize;
int numSkins;
int numVertices;
int numTexCoords;
int numFrames;
int numLODs;
int offsetSkins;
int offsetTexCoords;
int offsetFrames;
int offsetLODs;
int offsetEnd;
} dmd_info_t;
typedef struct {
int numTriangles;
int numGlCommands;
int offsetTriangles;
int offsetGlCommands;
} dmd_levelOfDetail_t;
#pragma pack(1)
typedef struct {
byte vertex[3];
unsigned short normal; // Yaw and pitch.
} dmd_packedVertex_t;
typedef struct {
float scale[3];
float translate[3];
char name[16];
dmd_packedVertex_t vertices[1];
} dmd_packedFrame_t;
#pragma pack()
/*typedef struct
{
float vertex[3];
float normal[3];
} dmd_vertex_t;
// Translated frame (vertices in model space).
typedef struct
{
char name[16];
dmd_vertex_t *vertices;
} dmd_frame_t; */
typedef struct {
char name[256];
int id;
} dmd_skin_t;
typedef struct {
short vertexIndices[3];
short textureIndices[3];
} dmd_triangle_t;
typedef struct {
short s, t;
} dmd_textureCoordinate_t;
typedef struct {
float s, t;
int vertexIndex;
} dmd_glCommandVertex_t;
typedef struct {
//dmd_triangle_t *triangles;
int *glCommands;
} dmd_lod_t;
typedef struct model_vertex_s {
float xyz[3];
} model_vertex_t;
typedef struct model_frame_s {
char name[16];
model_vertex_t *vertices;
model_vertex_t *normals;
} model_frame_t;
typedef struct model_s {
boolean loaded;
char fileName[256]; // Name of the md2 file.
dmd_header_t header;
dmd_info_t info;
dmd_skin_t *skins;
//dmd_textureCoordinate_t *texCoords;
model_frame_t *frames;
dmd_levelOfDetail_t lodInfo[MAX_LODS];
dmd_lod_t lods[MAX_LODS];
char *vertexUsage; // Bitfield for each vertex.
boolean allowTexComp; // Allow texture compression with this.
} model_t;
extern model_t *modellist[MAX_MODELS];
extern float avertexnormals[NUMVERTEXNORMALS][3];
#endif