vrshoot

view libs/assimp/MD3FileData.h @ 3:c179c72369be

rename candy->vr
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 03 Feb 2014 08:52:13 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
21 * Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ----------------------------------------------------------------------
39 */
41 /** @file Md3FileData.h
42 *
43 * @brief Defines helper data structures for importing MD3 files.
44 * http://linux.ucla.edu/~phaethon/q3/formats/md3format.html
45 */
46 #ifndef AI_MD3FILEHELPER_H_INC
47 #define AI_MD3FILEHELPER_H_INC
49 #include <string>
50 #include <vector>
51 #include <sstream>
53 #include "assimp/types.h"
54 #include "assimp/mesh.h"
55 #include "assimp/anim.h"
57 #include "assimp/Compiler/pushpack1.h"
59 namespace Assimp {
60 namespace MD3 {
62 // to make it easier for us, we test the magic word against both "endianesses"
63 #define AI_MD3_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDP3")
64 #define AI_MD3_MAGIC_NUMBER_LE AI_MAKE_MAGIC("3PDI")
66 // common limitations
67 #define AI_MD3_VERSION 15
68 #define AI_MD3_MAXQPATH 64
69 #define AI_MD3_MAXFRAME 16
70 #define AI_MD3_MAX_FRAMES 1024
71 #define AI_MD3_MAX_TAGS 16
72 #define AI_MD3_MAX_SURFACES 32
73 #define AI_MD3_MAX_SHADERS 256
74 #define AI_MD3_MAX_VERTS 4096
75 #define AI_MD3_MAX_TRIANGLES 8192
77 // master scale factor for all vertices in a MD3 model
78 #define AI_MD3_XYZ_SCALE (1.0f/64.0f)
80 // -------------------------------------------------------------------------------
81 /** @brief Data structure for the MD3 main header
82 */
83 struct Header
84 {
85 //! magic number
86 uint32_t IDENT;
88 //! file format version
89 uint32_t VERSION;
91 //! original name in .pak archive
92 char NAME[ AI_MD3_MAXQPATH ];
94 //! unknown
95 int32_t FLAGS;
97 //! number of frames in the file
98 uint32_t NUM_FRAMES;
100 //! number of tags in the file
101 uint32_t NUM_TAGS;
103 //! number of surfaces in the file
104 uint32_t NUM_SURFACES;
106 //! number of skins in the file
107 uint32_t NUM_SKINS;
109 //! offset of the first frame
110 uint32_t OFS_FRAMES;
112 //! offset of the first tag
113 uint32_t OFS_TAGS;
115 //! offset of the first surface
116 uint32_t OFS_SURFACES;
118 //! end of file
119 uint32_t OFS_EOF;
120 } PACK_STRUCT;
123 // -------------------------------------------------------------------------------
124 /** @brief Data structure for the frame header
125 */
126 struct Frame
127 {
128 //! minimum bounds
129 aiVector3D min;
131 //! maximum bounds
132 aiVector3D max;
134 //! local origin for this frame
135 aiVector3D origin;
137 //! radius of bounding sphere
138 float radius;
140 //! name of frame
141 char name[ AI_MD3_MAXFRAME ];
143 } PACK_STRUCT;
146 // -------------------------------------------------------------------------------
147 /** @brief Data structure for the tag header
148 */
149 struct Tag
150 {
151 //! name of the tag
152 char NAME[ AI_MD3_MAXQPATH ];
154 //! Local tag origin and orientation
155 aiVector3D origin;
156 float orientation[3][3];
158 } PACK_STRUCT;
161 // -------------------------------------------------------------------------------
162 /** @brief Data structure for the surface header
163 */
164 struct Surface
165 {
166 //! magic number
167 int32_t IDENT;
169 //! original name of the surface
170 char NAME[ AI_MD3_MAXQPATH ];
172 //! unknown
173 int32_t FLAGS;
175 //! number of frames in the surface
176 uint32_t NUM_FRAMES;
178 //! number of shaders in the surface
179 uint32_t NUM_SHADER;
181 //! number of vertices in the surface
182 uint32_t NUM_VERTICES;
184 //! number of triangles in the surface
185 uint32_t NUM_TRIANGLES;
188 //! offset to the triangle data
189 uint32_t OFS_TRIANGLES;
191 //! offset to the shader data
192 uint32_t OFS_SHADERS;
194 //! offset to the texture coordinate data
195 uint32_t OFS_ST;
197 //! offset to the vertex/normal data
198 uint32_t OFS_XYZNORMAL;
200 //! offset to the end of the Surface object
201 int32_t OFS_END;
202 } PACK_STRUCT;
204 // -------------------------------------------------------------------------------
205 /** @brief Data structure for a shader defined in there
206 */
207 struct Shader
208 {
209 //! filename of the shader
210 char NAME[ AI_MD3_MAXQPATH ];
212 //! index of the shader
213 uint32_t SHADER_INDEX;
214 } PACK_STRUCT;
217 // -------------------------------------------------------------------------------
218 /** @brief Data structure for a triangle
219 */
220 struct Triangle
221 {
222 //! triangle indices
223 uint32_t INDEXES[3];
224 } PACK_STRUCT;
227 // -------------------------------------------------------------------------------
228 /** @brief Data structure for an UV coord
229 */
230 struct TexCoord
231 {
232 //! UV coordinates
233 float U,V;
234 } PACK_STRUCT;
237 // -------------------------------------------------------------------------------
238 /** @brief Data structure for a vertex
239 */
240 struct Vertex
241 {
242 //! X/Y/Z coordinates
243 int16_t X,Y,Z;
245 //! encoded normal vector
246 uint16_t NORMAL;
247 } PACK_STRUCT;
249 #include "assimp/Compiler/poppack1.h"
251 // -------------------------------------------------------------------------------
252 /** @brief Unpack a Q3 16 bit vector to its full float3 representation
253 *
254 * @param p_iNormal Input normal vector in latitude/longitude form
255 * @param p_afOut Pointer to an array of three floats to receive the result
256 *
257 * @note This has been taken from q3 source (misc_model.c)
258 */
259 inline void LatLngNormalToVec3(uint16_t p_iNormal, float* p_afOut)
260 {
261 float lat = (float)(( p_iNormal >> 8u ) & 0xff);
262 float lng = (float)(( p_iNormal & 0xff ));
263 lat *= 3.141926f/128.0f;
264 lng *= 3.141926f/128.0f;
266 p_afOut[0] = cosf(lat) * sinf(lng);
267 p_afOut[1] = sinf(lat) * sinf(lng);
268 p_afOut[2] = cosf(lng);
269 return;
270 }
273 // -------------------------------------------------------------------------------
274 /** @brief Pack a Q3 normal into 16bit latitute/longitude representation
275 * @param p_vIn Input vector
276 * @param p_iOut Output normal
277 *
278 * @note This has been taken from q3 source (mathlib.c)
279 */
280 inline void Vec3NormalToLatLng( const aiVector3D& p_vIn, uint16_t& p_iOut )
281 {
282 // check for singularities
283 if ( 0.0f == p_vIn[0] && 0.0f == p_vIn[1] )
284 {
285 if ( p_vIn[2] > 0.0f )
286 {
287 ((unsigned char*)&p_iOut)[0] = 0;
288 ((unsigned char*)&p_iOut)[1] = 0; // lat = 0, long = 0
289 }
290 else
291 {
292 ((unsigned char*)&p_iOut)[0] = 128;
293 ((unsigned char*)&p_iOut)[1] = 0; // lat = 0, long = 128
294 }
295 }
296 else
297 {
298 int a, b;
300 a = int(57.2957795f * ( atan2f( p_vIn[1], p_vIn[0] ) ) * (255.0f / 360.0f ));
301 a &= 0xff;
303 b = int(57.2957795f * ( acosf( p_vIn[2] ) ) * ( 255.0f / 360.0f ));
304 b &= 0xff;
306 ((unsigned char*)&p_iOut)[0] = b; // longitude
307 ((unsigned char*)&p_iOut)[1] = a; // lattitude
308 }
309 }
311 }
312 }
314 #endif // !! AI_MD3FILEHELPER_H_INC