]> git.xonotic.org Git - xonotic/darkplaces.git/blob - model_hlmdl.h
Improve debug logging for render modules
[xonotic/darkplaces.git] / model_hlmdl.h
1 /*
2 Copyright (C) 2021 David Knapp (Cloudwalk)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #ifndef MODEL_HLMDL_H
22 #define MODEL_HLMDL_H
23
24 #include "qtypes.h"
25 #include "qdefs.h"
26
27 /*
28  * The Half-Life MDL format is Valve's format for models in GoldSrc engine.
29  * 
30  * These headers were added based on information found at
31  * https://github.com/malortie/assimp/wiki/MDL:-Half-Life-1-file-format
32  */
33
34 #define HLPOLYHEADER (('T' << 24) + ('S' << 16) + ('D' << 8) + 'I')
35 #define HLMDLHEADER "IDST"
36 #define HLSEQHEADER "IDSQ"
37
38 // Flags
39 #define HLMDLFLAG_FLAT 0x1
40 #define HLMDLFLAG_CHROME 0x2
41 #define HLMDLFLAG_FULLBRIGHT 0x4
42
43 // Header
44 typedef struct dhlmdl_header_s
45 {
46         int32_t id; // Should be IDST
47         int32_t version; // Should be 10
48         int8_t name[64];
49         int32_t filesize;
50         vec3_t eyeposition;
51         vec3_t min, max;
52         vec3_t bbmin, bbmax;
53         int32_t flags;
54
55         int32_t num_bones;
56         int32_t ofs_bones;
57
58         int32_t num_bonecontrollers;
59         int32_t ofs_bonecontrollers;
60
61         int32_t num_hitboxes;
62         int32_t ofs_hitboxes;
63
64         int32_t num_seq;
65         int32_t ofs_seq;
66
67         int32_t num_seqgroups;
68         int32_t ofs_seqgroups;
69
70         int32_t num_textures;
71         int32_t ofs_textures;
72         int32_t ofs_texturedata;
73
74         int32_t num_skins;
75         int32_t num_skingroups;
76         int32_t ofs_skins;
77
78         int32_t num_bodyparts;
79         int32_t ofs_bodyparts;
80
81         int32_t num_attachments;
82         int32_t ofs_attachments;
83
84         int32_t soundtable;
85         int32_t soundindex;
86
87         int32_t num_soundgroups;
88         int32_t ofs_soundgroups;
89
90         int32_t num_transitions;
91         int32_t ofs_transitions;
92 } dhlmdl_header_t;
93
94 typedef struct dhlmdl_sequence_header_s
95 {
96         int32_t id; // Should be IDSQ
97         int32_t version; // Should be 10
98         int8_t name[64];
99         int32_t size;
100 } dhlmdl_sequence_header_t;
101
102 typedef struct dhlmdl_texture_s
103 {
104         int8_t name[64];
105         int32_t flags;
106         int32_t w, h;
107         int32_t ofs;
108 } dhlmdl_texture_t;
109
110 typedef struct dhlmdl_bone_s
111 {
112         int8_t name[32];
113         int32_t parent;
114         int32_t flags;
115         int32_t bonecontroller[6];
116         float value[6];
117         float scale[6];
118 } dhlmdl_bone_t;
119
120 typedef struct dhlmdl_bone_controller_s
121 {
122         int32_t bone;
123         int32_t type;
124         float start;
125         float end;
126         int32_t rest;
127         int32_t index;
128 } dhlmdl_bone_controller_t;
129
130 typedef struct dhlmdl_hitbox_s
131 {
132         int32_t bone;
133         int32_t group;
134         vec3_t bbmin, bbmax;
135 } dhlmdl_hitbox_t;
136
137 typedef struct dhlmdl_sequence_group_s
138 {
139         int8_t label[32];
140         int8_t name[64];
141         int64_t unused;
142 } dhlmdl_sequence_group_t;
143
144 typedef struct dhlmdl_sequence_description_s
145 {
146         int8_t label[32];
147         float fps;
148         int32_t flags;
149         int32_t activity;
150         int32_t actweight;
151
152         int32_t num_events;
153         int32_t ofs_events;
154
155         int32_t num_frames;
156         
157         int64_t unused0;
158         
159         int32_t motiontype;
160         int32_t motionbone;
161         vec3_t linearmovement;
162         int64_t unused1;
163         vec3_t bbmin, bbmax;
164
165         int32_t num_blends;
166
167         int32_t ofs_anim;
168
169         int32_t blendtype[2];
170         float blendstart[2], blendend[2];
171         int32_t unused2; // blendparent
172         int32_t seqgroup;
173         int32_t entrynode;
174         int32_t exitnode;
175         int32_t nodeflags;
176         int32_t unused3; // nextseq
177 } dhlmdl_sequence_description_t;
178
179 typedef uint16_t dhlmdl_animoffset_t[6];
180
181 typedef union dhlmdl_animvalue_s
182 {
183         struct {
184                 uint8_t valid;
185                 uint8_t total;
186         } num;
187         int16_t value;
188 } dhlmdl_animvalue_t;
189
190 typedef struct dhlmdl_animevent_s
191 {
192         int32_t frame;
193         int32_t event;
194         int32_t unused;
195         int8_t options[64];
196 } dhlmdl_animevent_t;
197
198 typedef struct dhlmdl_attachment_s
199 {
200         int8_t unused0[36];
201         int32_t type;
202         int32_t bone;
203         vec3_t org;
204         vec3_t unused1[3];
205 } dhlmdl_attachment_t;
206
207 typedef struct dhlmdl_bodypart_s
208 {
209         int8_t name[64];
210         int32_t num_models;
211         int32_t base;
212         int32_t ofs_models;
213 } dhlmdl_bodypart_t;
214
215 typedef struct dhlmdl_s
216 {
217         int8_t name[64];
218         int64_t unused0;
219
220         int32_t num_mesh;
221         int32_t ofs_mesh;
222
223         int32_t num_verts;
224         int32_t ofs_vertinfo;
225         int32_t ofs_verts;
226         
227         int32_t num_norms;
228         int32_t ofs_norminfo;
229         int32_t ofs_norms;
230         
231         int64_t unused1;
232 } dhlmdl_t;
233
234 typedef struct dhlmdl_mesh_s
235 {
236         int32_t num_tris;
237         int32_t ofs_tris;
238         int32_t ofs_skins;
239         int64_t unused;
240 } dhlmdl_mesh_t;
241
242 typedef struct dhlmdl_trivert_s
243 {
244         int16_t vertindex;
245         int16_t normindex;
246         int16_t s, t;
247 } dhlmdl_trivert_t;
248
249 #endif