]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/picomodel/pm_fm.h
allow undo “make detail/structural”, <3 @SpiKe, thanks @Garux, fix #76
[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 #ifndef byte
80         #define byte unsigned char
81 #endif
82
83
84 //
85 //      Generic header on every chunk
86 //
87 #define FM_MAXCHUNKIDENT    32L
88 typedef struct
89 {
90         char ident[FM_MAXCHUNKIDENT];
91         unsigned int version;
92         unsigned int size;
93 } fm_chunk_header_t;
94
95 //
96 //      The format of the "header" chunk
97 //
98 #define FM_HEADERCHUNKNAME  "header"
99 #define FM_HEADERCHUNKVER   2
100 #define FM_HEADERCHUNKSIZE  40
101 typedef struct
102 {
103         int skinWidth;              // in pixels
104         int skinHeight;             // in pixels
105         int frameSize;              // size of each frame (in bytes)
106         int numSkins;               // number of skins
107         int numXYZ;                 // number of unique vertices in 3D space
108         int numST;                  // number of unique vertices in texture space
109         int numTris;                // number of unique triangles
110         int numGLCmds;              // # 32-bit elements in strip/fan command list
111         int numFrames;              // number of animation frames
112         int numMeshNodes;               // number of mesh nodes
113 } fm_header_t;
114
115 //
116 //      The format of an entry in the "skin" chunk.
117 //      The number of entries is given in the fmheader chunk
118 //
119 #define FM_SKINCHUNKNAME    "skin"
120 #define FM_SKINCHUNKVER     1
121 #define FM_MAXPATHLENGTH    64L
122 #define FM_SKINPATHSIZE ( FM_MAXPATHLENGTH )
123 typedef struct
124 {
125         char path[FM_SKINPATHSIZE];                 //  path, relative to 'base'
126 } fm_skinpath_t;
127
128 //
129 //      The format of the "st coord" chunk. This is a list
130 //      of unique skin texture (u, v) coordinates to be mapped
131 //      to verteces of the model
132 //
133 #define FM_STCOORDCHUNKNAME "st coord"
134 #define FM_STCOORDCHUNKVER  1
135 #define FM_STCOORDUVSIZE    ( 2L + 2L )
136
137 typedef struct
138 {
139         short s;
140         short t;
141 } fm_st_t;
142
143 //
144 //      The format of the "tris" chunk. This is a list of vertex indeces
145 //      in 3D space, and the corresponding vertex indeces in texture space.
146 //
147 #define FM_TRISCHUNKNAME    "tris"
148 #define FM_TRISCHUNKVER     1
149 #define FM_TRISINFOSIZE     ( 2L * 3 + 2L * 3 )
150
151 typedef struct
152 {
153         short index_xyz[3];
154         short index_st[3];
155 } fm_xyz_st_t;
156
157
158 //
159 //      The format of the "frames" chunk. This is a list of animation
160 //      frames, each specifying the coordinates and "light normal" index
161 //      of every vertex of the model in 3D space.
162 //
163 #define FM_FRAMESCHUNKNAME  "frames"
164 #define FM_FRAMESCHUNKVER   1
165
166 #define FM_NUMVERTEXNORMALS 162
167
168 // Frame info
169 typedef struct
170 {
171         byte v[3];                          //  scaled by header info
172         byte lightnormalindex;              //  index in canned table of closest vertex normal
173 } fm_vert_normal_t;
174
175 typedef struct
176 {
177         float scale[3];                     //  multiply byte verts by this
178         float translate[3];                 //  then add this
179         char name[16];                      //  frame name
180 } fm_framehdr_t;
181
182 typedef struct
183 {
184         fm_framehdr_t header;                   //      One header per frame
185         fm_vert_normal_t verts[1];              //      variable number of these
186 } fm_frame_t;
187
188 typedef struct
189 {
190         fm_chunk_header_t   *fm_header_hdr;
191         fm_header_t     *fm_header;
192         fm_chunk_header_t   *fm_skin_hdr;
193         fm_skinpath_t       *fm_skin;
194         fm_chunk_header_t   *fm_st_hdr;
195         fm_st_t         *fm_st;
196         fm_chunk_header_t   *fm_tri_hdr;
197         fm_xyz_st_t     *fm_tri;
198         fm_chunk_header_t   *fm_frame_hdr;
199         fm_frame_t      *fm_frame;
200 } fm_t;
201
202 float fm_normals[FM_NUMVERTEXNORMALS][3] = {
203         {-0.525731f, 0.000000f, 0.850651f},
204         {-0.442863f, 0.238856f, 0.864188f},
205         {-0.295242f, 0.000000f, 0.955423f},
206         {-0.309017f, 0.500000f, 0.809017f},
207         {-0.162460f, 0.262866f, 0.951056f},
208         {0.000000f, 0.000000f, 1.000000f},
209         {0.000000f, 0.850651f, 0.525731f},
210         {-0.147621f, 0.716567f, 0.681718f},
211         {0.147621f, 0.716567f, 0.681718f},
212         {0.000000f, 0.525731f, 0.850651f},
213         {0.309017f, 0.500000f, 0.809017f},
214         {0.525731f, 0.000000f, 0.850651f},
215         {0.295242f, 0.000000f, 0.955423f},
216         {0.442863f, 0.238856f, 0.864188f},
217         {0.162460f, 0.262866f, 0.951056f},
218         {-0.681718f, 0.147621f, 0.716567f},
219         {-0.809017f, 0.309017f, 0.500000f},
220         {-0.587785f, 0.425325f, 0.688191f},
221         {-0.850651f, 0.525731f, 0.000000f},
222         {-0.864188f, 0.442863f, 0.238856f},
223         {-0.716567f, 0.681718f, 0.147621f},
224         {-0.688191f, 0.587785f, 0.425325f},
225         {-0.500000f, 0.809017f, 0.309017f},
226         {-0.238856f, 0.864188f, 0.442863f},
227         {-0.425325f, 0.688191f, 0.587785f},
228         {-0.716567f, 0.681718f, -0.147621f},
229         {-0.500000f, 0.809017f, -0.309017f},
230         {-0.525731f, 0.850651f, 0.000000f},
231         {0.000000f, 0.850651f, -0.525731f},
232         {-0.238856f, 0.864188f, -0.442863f},
233         {0.000000f, 0.955423f, -0.295242f},
234         {-0.262866f, 0.951056f, -0.162460f},
235         {0.000000f, 1.000000f, 0.000000f},
236         {0.000000f, 0.955423f, 0.295242f},
237         {-0.262866f, 0.951056f, 0.162460f},
238         {0.238856f, 0.864188f, 0.442863f},
239         {0.262866f, 0.951056f, 0.162460f},
240         {0.500000f, 0.809017f, 0.309017f},
241         {0.238856f, 0.864188f, -0.442863f},
242         {0.262866f, 0.951056f, -0.162460f},
243         {0.500000f, 0.809017f, -0.309017f},
244         {0.850651f, 0.525731f, 0.000000f},
245         {0.716567f, 0.681718f, 0.147621f},
246         {0.716567f, 0.681718f, -0.147621f},
247         {0.525731f, 0.850651f, 0.000000f},
248         {0.425325f, 0.688191f, 0.587785f},
249         {0.864188f, 0.442863f, 0.238856f},
250         {0.688191f, 0.587785f, 0.425325f},
251         {0.809017f, 0.309017f, 0.500000f},
252         {0.681718f, 0.147621f, 0.716567f},
253         {0.587785f, 0.425325f, 0.688191f},
254         {0.955423f, 0.295242f, 0.000000f},
255         {1.000000f, 0.000000f, 0.000000f},
256         {0.951056f, 0.162460f, 0.262866f},
257         {0.850651f, -0.525731f, 0.000000f},
258         {0.955423f, -0.295242f, 0.000000f},
259         {0.864188f, -0.442863f, 0.238856f},
260         {0.951056f, -0.162460f, 0.262866f},
261         {0.809017f, -0.309017f, 0.500000f},
262         {0.681718f, -0.147621f, 0.716567f},
263         {0.850651f, 0.000000f, 0.525731f},
264         {0.864188f, 0.442863f, -0.238856f},
265         {0.809017f, 0.309017f, -0.500000f},
266         {0.951056f, 0.162460f, -0.262866f},
267         {0.525731f, 0.000000f, -0.850651f},
268         {0.681718f, 0.147621f, -0.716567f},
269         {0.681718f, -0.147621f, -0.716567f},
270         {0.850651f, 0.000000f, -0.525731f},
271         {0.809017f, -0.309017f, -0.500000f},
272         {0.864188f, -0.442863f, -0.238856f},
273         {0.951056f, -0.162460f, -0.262866f},
274         {0.147621f, 0.716567f, -0.681718f},
275         {0.309017f, 0.500000f, -0.809017f},
276         {0.425325f, 0.688191f, -0.587785f},
277         {0.442863f, 0.238856f, -0.864188f},
278         {0.587785f, 0.425325f, -0.688191f},
279         {0.688191f, 0.587785f, -0.425325f},
280         {-0.147621f, 0.716567f, -0.681718f},
281         {-0.309017f, 0.500000f, -0.809017f},
282         {0.000000f, 0.525731f, -0.850651f},
283         {-0.525731f, 0.000000f, -0.850651f},
284         {-0.442863f, 0.238856f, -0.864188f},
285         {-0.295242f, 0.000000f, -0.955423f},
286         {-0.162460f, 0.262866f, -0.951056f},
287         {0.000000f, 0.000000f, -1.000000f},
288         {0.295242f, 0.000000f, -0.955423f},
289         {0.162460f, 0.262866f, -0.951056f},
290         {-0.442863f, -0.238856f, -0.864188f},
291         {-0.309017f, -0.500000f, -0.809017f},
292         {-0.162460f, -0.262866f, -0.951056f},
293         {0.000000f, -0.850651f, -0.525731f},
294         {-0.147621f, -0.716567f, -0.681718f},
295         {0.147621f, -0.716567f, -0.681718f},
296         {0.000000f, -0.525731f, -0.850651f},
297         {0.309017f, -0.500000f, -0.809017f},
298         {0.442863f, -0.238856f, -0.864188f},
299         {0.162460f, -0.262866f, -0.951056f},
300         {0.238856f, -0.864188f, -0.442863f},
301         {0.500000f, -0.809017f, -0.309017f},
302         {0.425325f, -0.688191f, -0.587785f},
303         {0.716567f, -0.681718f, -0.147621f},
304         {0.688191f, -0.587785f, -0.425325f},
305         {0.587785f, -0.425325f, -0.688191f},
306         {0.000000f, -0.955423f, -0.295242f},
307         {0.000000f, -1.000000f, 0.000000f},
308         {0.262866f, -0.951056f, -0.162460f},
309         {0.000000f, -0.850651f, 0.525731f},
310         {0.000000f, -0.955423f, 0.295242f},
311         {0.238856f, -0.864188f, 0.442863f},
312         {0.262866f, -0.951056f, 0.162460f},
313         {0.500000f, -0.809017f, 0.309017f},
314         {0.716567f, -0.681718f, 0.147621f},
315         {0.525731f, -0.850651f, 0.000000f},
316         {-0.238856f, -0.864188f, -0.442863f},
317         {-0.500000f, -0.809017f, -0.309017f},
318         {-0.262866f, -0.951056f, -0.162460f},
319         {-0.850651f, -0.525731f, 0.000000f},
320         {-0.716567f, -0.681718f, -0.147621f},
321         {-0.716567f, -0.681718f, 0.147621f},
322         {-0.525731f, -0.850651f, 0.000000f},
323         {-0.500000f, -0.809017f, 0.309017f},
324         {-0.238856f, -0.864188f, 0.442863f},
325         {-0.262866f, -0.951056f, 0.162460f},
326         {-0.864188f, -0.442863f, 0.238856f},
327         {-0.809017f, -0.309017f, 0.500000f},
328         {-0.688191f, -0.587785f, 0.425325f},
329         {-0.681718f, -0.147621f, 0.716567f},
330         {-0.442863f, -0.238856f, 0.864188f},
331         {-0.587785f, -0.425325f, 0.688191f},
332         {-0.309017f, -0.500000f, 0.809017f},
333         {-0.147621f, -0.716567f, 0.681718f},
334         {-0.425325f, -0.688191f, 0.587785f},
335         {-0.162460f, -0.262866f, 0.951056f},
336         {0.442863f, -0.238856f, 0.864188f},
337         {0.162460f, -0.262866f, 0.951056f},
338         {0.309017f, -0.500000f, 0.809017f},
339         {0.147621f, -0.716567f, 0.681718f},
340         {0.000000f, -0.525731f, 0.850651f},
341         {0.425325f, -0.688191f, 0.587785f},
342         {0.587785f, -0.425325f, 0.688191f},
343         {0.688191f, -0.587785f, 0.425325f},
344         {-0.955423f, 0.295242f, 0.000000f},
345         {-0.951056f, 0.162460f, 0.262866f},
346         {-1.000000f, 0.000000f, 0.000000f},
347         {-0.850651f, 0.000000f, 0.525731f},
348         {-0.955423f, -0.295242f, 0.000000f},
349         {-0.951056f, -0.162460f, 0.262866f},
350         {-0.864188f, 0.442863f, -0.238856f},
351         {-0.951056f, 0.162460f, -0.262866f},
352         {-0.809017f, 0.309017f, -0.500000f},
353         {-0.864188f, -0.442863f, -0.238856f},
354         {-0.951056f, -0.162460f, -0.262866f},
355         {-0.809017f, -0.309017f, -0.500000f},
356         {-0.681718f, 0.147621f, -0.716567f},
357         {-0.681718f, -0.147621f, -0.716567f},
358         {-0.850651f, 0.000000f, -0.525731f},
359         {-0.688191f, 0.587785f, -0.425325f},
360         {-0.587785f, 0.425325f, -0.688191f},
361         {-0.425325f, 0.688191f, -0.587785f},
362         {-0.425325f, -0.688191f, -0.587785f},
363         {-0.587785f, -0.425325f, -0.688191f},
364         {-0.688191f, -0.587785f, -0.425325f},
365 };
366
367 #endif