vrshoot

annotate libs/assimp/MD3FileData.h @ 2:334d17aed7de

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