add IQM format support into lib/picomodel
[xonotic/netradiant.git] / libs / picomodel / pm_fm.h
1 /* -----------------------------------------------------------------------------
2
3    PicoModel Library
4
5    Copyright (c) 2002, Randy Reddig & seaw0lf
6    All rights reserved.
7
8    Redistribution and use in source and binary forms, with or without modification,
9    are permitted provided that the following conditions are met:
10
11    Redistributions of source code must retain the above copyright notice, this list
12    of conditions and the following disclaimer.
13
14    Redistributions in binary form must reproduce the above copyright notice, this
15    list of conditions and the following disclaimer in the documentation and/or
16    other materials provided with the distribution.
17
18    Neither the names of the copyright holders nor the names of its contributors may
19    be used to endorse or promote products derived from this software without
20    specific prior written permission.
21
22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
26    ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29    ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33    ----------------------------------------------------------------------------- */
34
35 // This header file is based from the following:
36
37 /*
38     FlexModel.H - Header file for FlexModel file structure
39
40     By Chris Burke
41     serotonin@earthlink.net
42  */
43
44 #ifndef __PM_FM_H__
45 #define __PM_FM_H__
46
47 #include "picointernal.h"
48
49
50 //
51 //      Absolute limits (from QData / QMView source)
52 //
53 #define MAX_FM_TRIANGLES    2048
54 #define MAX_FM_VERTS        2048
55 #define MAX_FM_FRAMES       2048
56 #define MAX_FM_SKINS        64
57 #define MAX_FM_SKINNAME     64
58 #define MAX_FM_MESH_NODES   16
59
60 #define DTRIVERTX_V0   0
61 #define DTRIVERTX_V1   1
62 #define DTRIVERTX_V2   2
63 #define DTRIVERTX_LNI  3
64 #define DTRIVERTX_SIZE 4
65
66 #define SKINPAGE_WIDTH 640
67 #define SKINPAGE_HEIGHT 480
68
69 #define ENCODED_WIDTH_X 92
70 #define ENCODED_WIDTH_Y 475
71 #define ENCODED_HEIGHT_X 128
72 #define ENCODED_HEIGHT_Y 475
73
74 #define SCALE_ADJUST_FACTOR 0.96
75
76 #define INFO_HEIGHT 5
77 #define INFO_Y ( SKINPAGE_HEIGHT - INFO_HEIGHT )
78
79
80 //
81 //      Generic header on every chunk
82 //
83 #define FM_MAXCHUNKIDENT    32L
84 typedef struct
85 {
86         char ident[FM_MAXCHUNKIDENT];
87         unsigned int version;
88         unsigned int size;
89 } fm_chunk_header_t;
90
91 //
92 //      The format of the "header" chunk
93 //
94 #define FM_HEADERCHUNKNAME  "header"
95 #define FM_HEADERCHUNKVER   2
96 #define FM_HEADERCHUNKSIZE  40
97 typedef struct
98 {
99         int skinWidth;              // in pixels
100         int skinHeight;             // in pixels
101         int frameSize;              // size of each frame (in bytes)
102         int numSkins;               // number of skins
103         int numXYZ;                 // number of unique vertices in 3D space
104         int numST;                  // number of unique vertices in texture space
105         int numTris;                // number of unique triangles
106         int numGLCmds;              // # 32-bit elements in strip/fan command list
107         int numFrames;              // number of animation frames
108         int numMeshNodes;               // number of mesh nodes
109 } fm_header_t;
110
111 //
112 //      The format of an entry in the "skin" chunk.
113 //      The number of entries is given in the fmheader chunk
114 //
115 #define FM_SKINCHUNKNAME    "skin"
116 #define FM_SKINCHUNKVER     1
117 #define FM_MAXPATHLENGTH    64L
118 #define FM_SKINPATHSIZE ( FM_MAXPATHLENGTH )
119 typedef struct
120 {
121         char path[FM_SKINPATHSIZE];                 //  path, relative to 'base'
122 } fm_skinpath_t;
123
124 //
125 //      The format of the "st coord" chunk. This is a list
126 //      of unique skin texture (u, v) coordinates to be mapped
127 //      to verteces of the model
128 //
129 #define FM_STCOORDCHUNKNAME "st coord"
130 #define FM_STCOORDCHUNKVER  1
131 #define FM_STCOORDUVSIZE    ( 2L + 2L )
132
133 typedef struct
134 {
135         short s;
136         short t;
137 } fm_st_t;
138
139 //
140 //      The format of the "tris" chunk. This is a list of vertex indeces
141 //      in 3D space, and the corresponding vertex indeces in texture space.
142 //
143 #define FM_TRISCHUNKNAME    "tris"
144 #define FM_TRISCHUNKVER     1
145 #define FM_TRISINFOSIZE     ( 2L * 3 + 2L * 3 )
146
147 typedef struct
148 {
149         short index_xyz[3];
150         short index_st[3];
151 } fm_xyz_st_t;
152
153
154 //
155 //      The format of the "frames" chunk. This is a list of animation
156 //      frames, each specifying the coordinates and "light normal" index
157 //      of every vertex of the model in 3D space.
158 //
159 #define FM_FRAMESCHUNKNAME  "frames"
160 #define FM_FRAMESCHUNKVER   1
161
162 #define FM_NUMVERTEXNORMALS 162
163
164 // Frame info
165 typedef struct
166 {
167         byte v[3];                          //  scaled by header info
168         byte lightnormalindex;              //  index in canned table of closest vertex normal
169 } fm_vert_normal_t;
170
171 typedef struct
172 {
173         float scale[3];                     //  multiply byte verts by this
174         float translate[3];                 //  then add this
175         char name[16];                      //  frame name
176 } fm_framehdr_t;
177
178 typedef struct
179 {
180         fm_framehdr_t header;                   //      One header per frame
181         fm_vert_normal_t verts[1];              //      variable number of these
182 } fm_frame_t;
183
184 typedef struct
185 {
186         fm_chunk_header_t   *fm_header_hdr;
187         fm_header_t     *fm_header;
188         fm_chunk_header_t   *fm_skin_hdr;
189         fm_skinpath_t       *fm_skin;
190         fm_chunk_header_t   *fm_st_hdr;
191         fm_st_t         *fm_st;
192         fm_chunk_header_t   *fm_tri_hdr;
193         fm_xyz_st_t     *fm_tri;
194         fm_chunk_header_t   *fm_frame_hdr;
195         fm_frame_t      *fm_frame;
196 } fm_t;
197
198 float fm_normals[FM_NUMVERTEXNORMALS][3] = {
199         {-0.525731f, 0.000000f, 0.850651f},
200         {-0.442863f, 0.238856f, 0.864188f},
201         {-0.295242f, 0.000000f, 0.955423f},
202         {-0.309017f, 0.500000f, 0.809017f},
203         {-0.162460f, 0.262866f, 0.951056f},
204         {0.000000f, 0.000000f, 1.000000f},
205         {0.000000f, 0.850651f, 0.525731f},
206         {-0.147621f, 0.716567f, 0.681718f},
207         {0.147621f, 0.716567f, 0.681718f},
208         {0.000000f, 0.525731f, 0.850651f},
209         {0.309017f, 0.500000f, 0.809017f},
210         {0.525731f, 0.000000f, 0.850651f},
211         {0.295242f, 0.000000f, 0.955423f},
212         {0.442863f, 0.238856f, 0.864188f},
213         {0.162460f, 0.262866f, 0.951056f},
214         {-0.681718f, 0.147621f, 0.716567f},
215         {-0.809017f, 0.309017f, 0.500000f},
216         {-0.587785f, 0.425325f, 0.688191f},
217         {-0.850651f, 0.525731f, 0.000000f},
218         {-0.864188f, 0.442863f, 0.238856f},
219         {-0.716567f, 0.681718f, 0.147621f},
220         {-0.688191f, 0.587785f, 0.425325f},
221         {-0.500000f, 0.809017f, 0.309017f},
222         {-0.238856f, 0.864188f, 0.442863f},
223         {-0.425325f, 0.688191f, 0.587785f},
224         {-0.716567f, 0.681718f, -0.147621f},
225         {-0.500000f, 0.809017f, -0.309017f},
226         {-0.525731f, 0.850651f, 0.000000f},
227         {0.000000f, 0.850651f, -0.525731f},
228         {-0.238856f, 0.864188f, -0.442863f},
229         {0.000000f, 0.955423f, -0.295242f},
230         {-0.262866f, 0.951056f, -0.162460f},
231         {0.000000f, 1.000000f, 0.000000f},
232         {0.000000f, 0.955423f, 0.295242f},
233         {-0.262866f, 0.951056f, 0.162460f},
234         {0.238856f, 0.864188f, 0.442863f},
235         {0.262866f, 0.951056f, 0.162460f},
236         {0.500000f, 0.809017f, 0.309017f},
237         {0.238856f, 0.864188f, -0.442863f},
238         {0.262866f, 0.951056f, -0.162460f},
239         {0.500000f, 0.809017f, -0.309017f},
240         {0.850651f, 0.525731f, 0.000000f},
241         {0.716567f, 0.681718f, 0.147621f},
242         {0.716567f, 0.681718f, -0.147621f},
243         {0.525731f, 0.850651f, 0.000000f},
244         {0.425325f, 0.688191f, 0.587785f},
245         {0.864188f, 0.442863f, 0.238856f},
246         {0.688191f, 0.587785f, 0.425325f},
247         {0.809017f, 0.309017f, 0.500000f},
248         {0.681718f, 0.147621f, 0.716567f},
249         {0.587785f, 0.425325f, 0.688191f},
250         {0.955423f, 0.295242f, 0.000000f},
251         {1.000000f, 0.000000f, 0.000000f},
252         {0.951056f, 0.162460f, 0.262866f},
253         {0.850651f, -0.525731f, 0.000000f},
254         {0.955423f, -0.295242f, 0.000000f},
255         {0.864188f, -0.442863f, 0.238856f},
256         {0.951056f, -0.162460f, 0.262866f},
257         {0.809017f, -0.309017f, 0.500000f},
258         {0.681718f, -0.147621f, 0.716567f},
259         {0.850651f, 0.000000f, 0.525731f},
260         {0.864188f, 0.442863f, -0.238856f},
261         {0.809017f, 0.309017f, -0.500000f},
262         {0.951056f, 0.162460f, -0.262866f},
263         {0.525731f, 0.000000f, -0.850651f},
264         {0.681718f, 0.147621f, -0.716567f},
265         {0.681718f, -0.147621f, -0.716567f},
266         {0.850651f, 0.000000f, -0.525731f},
267         {0.809017f, -0.309017f, -0.500000f},
268         {0.864188f, -0.442863f, -0.238856f},
269         {0.951056f, -0.162460f, -0.262866f},
270         {0.147621f, 0.716567f, -0.681718f},
271         {0.309017f, 0.500000f, -0.809017f},
272         {0.425325f, 0.688191f, -0.587785f},
273         {0.442863f, 0.238856f, -0.864188f},
274         {0.587785f, 0.425325f, -0.688191f},
275         {0.688191f, 0.587785f, -0.425325f},
276         {-0.147621f, 0.716567f, -0.681718f},
277         {-0.309017f, 0.500000f, -0.809017f},
278         {0.000000f, 0.525731f, -0.850651f},
279         {-0.525731f, 0.000000f, -0.850651f},
280         {-0.442863f, 0.238856f, -0.864188f},
281         {-0.295242f, 0.000000f, -0.955423f},
282         {-0.162460f, 0.262866f, -0.951056f},
283         {0.000000f, 0.000000f, -1.000000f},
284         {0.295242f, 0.000000f, -0.955423f},
285         {0.162460f, 0.262866f, -0.951056f},
286         {-0.442863f, -0.238856f, -0.864188f},
287         {-0.309017f, -0.500000f, -0.809017f},
288         {-0.162460f, -0.262866f, -0.951056f},
289         {0.000000f, -0.850651f, -0.525731f},
290         {-0.147621f, -0.716567f, -0.681718f},
291         {0.147621f, -0.716567f, -0.681718f},
292         {0.000000f, -0.525731f, -0.850651f},
293         {0.309017f, -0.500000f, -0.809017f},
294         {0.442863f, -0.238856f, -0.864188f},
295         {0.162460f, -0.262866f, -0.951056f},
296         {0.238856f, -0.864188f, -0.442863f},
297         {0.500000f, -0.809017f, -0.309017f},
298         {0.425325f, -0.688191f, -0.587785f},
299         {0.716567f, -0.681718f, -0.147621f},
300         {0.688191f, -0.587785f, -0.425325f},
301         {0.587785f, -0.425325f, -0.688191f},
302         {0.000000f, -0.955423f, -0.295242f},
303         {0.000000f, -1.000000f, 0.000000f},
304         {0.262866f, -0.951056f, -0.162460f},
305         {0.000000f, -0.850651f, 0.525731f},
306         {0.000000f, -0.955423f, 0.295242f},
307         {0.238856f, -0.864188f, 0.442863f},
308         {0.262866f, -0.951056f, 0.162460f},
309         {0.500000f, -0.809017f, 0.309017f},
310         {0.716567f, -0.681718f, 0.147621f},
311         {0.525731f, -0.850651f, 0.000000f},
312         {-0.238856f, -0.864188f, -0.442863f},
313         {-0.500000f, -0.809017f, -0.309017f},
314         {-0.262866f, -0.951056f, -0.162460f},
315         {-0.850651f, -0.525731f, 0.000000f},
316         {-0.716567f, -0.681718f, -0.147621f},
317         {-0.716567f, -0.681718f, 0.147621f},
318         {-0.525731f, -0.850651f, 0.000000f},
319         {-0.500000f, -0.809017f, 0.309017f},
320         {-0.238856f, -0.864188f, 0.442863f},
321         {-0.262866f, -0.951056f, 0.162460f},
322         {-0.864188f, -0.442863f, 0.238856f},
323         {-0.809017f, -0.309017f, 0.500000f},
324         {-0.688191f, -0.587785f, 0.425325f},
325         {-0.681718f, -0.147621f, 0.716567f},
326         {-0.442863f, -0.238856f, 0.864188f},
327         {-0.587785f, -0.425325f, 0.688191f},
328         {-0.309017f, -0.500000f, 0.809017f},
329         {-0.147621f, -0.716567f, 0.681718f},
330         {-0.425325f, -0.688191f, 0.587785f},
331         {-0.162460f, -0.262866f, 0.951056f},
332         {0.442863f, -0.238856f, 0.864188f},
333         {0.162460f, -0.262866f, 0.951056f},
334         {0.309017f, -0.500000f, 0.809017f},
335         {0.147621f, -0.716567f, 0.681718f},
336         {0.000000f, -0.525731f, 0.850651f},
337         {0.425325f, -0.688191f, 0.587785f},
338         {0.587785f, -0.425325f, 0.688191f},
339         {0.688191f, -0.587785f, 0.425325f},
340         {-0.955423f, 0.295242f, 0.000000f},
341         {-0.951056f, 0.162460f, 0.262866f},
342         {-1.000000f, 0.000000f, 0.000000f},
343         {-0.850651f, 0.000000f, 0.525731f},
344         {-0.955423f, -0.295242f, 0.000000f},
345         {-0.951056f, -0.162460f, 0.262866f},
346         {-0.864188f, 0.442863f, -0.238856f},
347         {-0.951056f, 0.162460f, -0.262866f},
348         {-0.809017f, 0.309017f, -0.500000f},
349         {-0.864188f, -0.442863f, -0.238856f},
350         {-0.951056f, -0.162460f, -0.262866f},
351         {-0.809017f, -0.309017f, -0.500000f},
352         {-0.681718f, 0.147621f, -0.716567f},
353         {-0.681718f, -0.147621f, -0.716567f},
354         {-0.850651f, 0.000000f, -0.525731f},
355         {-0.688191f, 0.587785f, -0.425325f},
356         {-0.587785f, 0.425325f, -0.688191f},
357         {-0.425325f, 0.688191f, -0.587785f},
358         {-0.425325f, -0.688191f, -0.587785f},
359         {-0.587785f, -0.425325f, -0.688191f},
360         {-0.688191f, -0.587785f, -0.425325f},
361 };
362
363 #endif