]> git.xonotic.org Git - xonotic/darkplaces.git/blob - model_hlmdl.h
model: Create header for Half-Life MDL format
[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 /*
22  * The Half-Life MDL format is Valve's format for models in GoldSrc engine.
23  * 
24  * These headers were added based on information found at
25  * https://github.com/malortie/assimp/wiki/MDL:-Half-Life-1-file-format
26  */
27
28 #include "qtypes.h"
29 #include "qdefs.h"
30
31 #define HLPOLYHEADER (('T' << 24) + ('S' << 16) + ('D' << 8) + 'I')
32 #define HLMDLHEADER "IDST"
33 #define HLSEQHEADER "IDSQ"
34
35 // Flags
36 #define HLMDLFLAG_FLAT 0x1
37 #define HLMDLFLAG_CHROME 0x2
38 #define HLMDLFLAG_FULLBRIGHT 0x4
39
40 // Header
41 typedef struct dhlmdl_header_s
42 {
43         int32_t id; // Should be IDST
44         int32_t version; // Should be 10
45         int8_t name[64];
46         int32_t filesize;
47         vec3_t eyeposition;
48         vec3_t min, max;
49         vec3_t bbmin, bbmax;
50         int32_t flags;
51
52         int32_t num_bones;
53         int32_t ofs_bones;
54
55         int32_t num_bonecontrollers;
56         int32_t ofs_bonecontrollers;
57
58         int32_t num_hitboxes;
59         int32_t ofs_hitboxes;
60
61         int32_t num_seq;
62         int32_t ofs_seq;
63
64         int32_t num_seqgroups;
65         int32_t ofs_seqgroups;
66
67         int32_t num_textures;
68         int32_t ofs_textures;
69         int32_t ofs_texturedata;
70
71         int32_t num_skins;
72         int32_t num_skingroups;
73         int32_t ofs_skins;
74
75         int32_t num_bodyparts;
76         int32_t ofs_bodyparts;
77
78         int32_t num_attachments;
79         int32_t ofs_attachments;
80
81         int32_t soundtable;
82         int32_t soundindex;
83
84         int32_t num_soundgroups;
85         int32_t ofs_soundgroups;
86
87         int32_t num_transitions;
88         int32_t ofs_transitions;
89 } dhlmdl_header_t;
90
91 typedef struct dhlmdl_sequence_header_s
92 {
93         int32_t id; // Should be IDSQ
94         int32_t version; // Should be 10
95         int8_t name[64];
96         int32_t size;
97 } dhlmdl_sequence_header_t;
98
99 typedef struct dhlmdl_texture_s
100 {
101         int8_t name[64];
102         int32_t flags;
103         int32_t w, h;
104         int32_t ofs;
105 } dhlmdl_texture_t;
106
107 typedef struct dhlmdl_bone_s
108 {
109         int8_t name[32];
110         int32_t parent;
111         int32_t flags;
112         int32_t bonecontroller[6];
113         float value[6];
114         float scale[6];
115 } dhlmdl_bone_t;
116
117 typedef struct dhlmdl_bone_controller_s
118 {
119         int32_t bone;
120         int32_t type;
121         float start;
122         float end;
123         int32_t rest;
124         int32_t index;
125 } dhlmdl_bone_controller_t;
126
127 typedef struct dhlmdl_hitbox_s
128 {
129         int32_t bone;
130         int32_t group;
131         vec3_t bbmin, bbmax;
132 } dhlmdl_hitbox_t;
133
134 typedef struct dhlmdl_sequence_group_s
135 {
136         int8_t label[32];
137         int8_t name[64];
138         int64_t unused;
139 } dhlmdl_sequence_group_t;
140
141 typedef struct dhlmdl_sequence_description_s
142 {
143         int8_t label[32];
144         float fps;
145         int32_t flags;
146         int32_t activity;
147         int32_t actweight;
148
149         int32_t num_events;
150         int32_t ofs_events;
151
152         int32_t num_frames;
153         
154         int64_t unused0;
155         
156         int32_t motiontype;
157         int32_t motionbone;
158         vec3_t linearmovement;
159         int64_t unused1;
160         vec3_t bbmin, bbmax;
161
162         int32_t num_blends;
163
164         int32_t ofs_anim;
165
166         int32_t blendtype[2];
167         float blendstart[2], blendend[2];
168         int32_t unused2; // blendparent
169         int32_t seqgroup;
170         int32_t entrynode;
171         int32_t exitnode;
172         int32_t nodeflags;
173         int32_t unused3; // nextseq
174 } dhlmdl_sequence_description_t;
175
176 typedef uint16_t dhlmdl_animoffset_t[6];
177
178 typedef union dhlmdl_animvalue_s
179 {
180         struct {
181                 uint8_t valid;
182                 uint8_t total;
183         } num;
184         int16_t value;
185 } dhlmdl_animvalue_t;
186
187 typedef struct dhlmdl_animevent_s
188 {
189         int32_t frame;
190         int32_t event;
191         int32_t unused;
192         int8_t options[64];
193 } dhlmdl_animevent_t;
194
195 typedef struct dhlmdl_attachment_s
196 {
197         int8_t unused0[36];
198         int32_t type;
199         int32_t bone;
200         vec3_t org;
201         vec3_t unused1[3];
202 } dhlmdl_attachment_t;
203
204 typedef struct dhlmdl_bodypart_s
205 {
206         int8_t name[64];
207         int32_t num_models;
208         int32_t base;
209         int32_t ofs_models;
210 } dhlmdl_bodypart_t;
211
212 typedef struct dhlmdl_s
213 {
214         int8_t name[64];
215         int64_t unused0;
216
217         int32_t num_mesh;
218         int32_t ofs_mesh;
219
220         int32_t num_verts;
221         int32_t ofs_vertinfo;
222         int32_t ofs_verts;
223         
224         int32_t num_norms;
225         int32_t ofs_norminfo;
226         int32_t ofs_norms;
227         
228         int64_t unused1;
229 } dhlmdl_t;
230
231 typedef struct dhlmdl_mesh_s
232 {
233         int32_t num_tris;
234         int32_t ofs_tris;
235         int32_t ofs_skins;
236         int64_t unused;
237 } dhlmdl_mesh_t;
238
239 typedef struct dhlmdl_trivert_s
240 {
241         int16_t vertindex;
242         int16_t normindex;
243         int16_t s, t;
244 } dhlmdl_trivert_t;