nuclear@0: /* nuclear@0: Open Asset Import Library (assimp) nuclear@0: ---------------------------------------------------------------------- nuclear@0: nuclear@0: Copyright (c) 2006-2012, assimp team nuclear@0: All rights reserved. nuclear@0: nuclear@0: Redistribution and use of this software in source and binary forms, nuclear@0: with or without modification, are permitted provided that the nuclear@0: following conditions are met: nuclear@0: nuclear@0: * Redistributions of source code must retain the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer. nuclear@0: nuclear@0: * Redistributions in binary form must reproduce the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer in the documentation and/or other nuclear@0: materials provided with the distribution. nuclear@0: nuclear@0: * Neither the name of the assimp team, nor the names of its nuclear@0: contributors may be used to endorse or promote products nuclear@0: derived from this software without specific prior nuclear@0: written permission of the assimp team. nuclear@0: nuclear@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS nuclear@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT nuclear@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR nuclear@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT nuclear@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, nuclear@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT nuclear@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, nuclear@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY nuclear@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT nuclear@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE nuclear@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. nuclear@0: nuclear@0: ---------------------------------------------------------------------- nuclear@0: */ nuclear@0: nuclear@0: /** @file Md3FileData.h nuclear@0: * nuclear@0: * @brief Defines helper data structures for importing MD3 files. nuclear@0: * http://linux.ucla.edu/~phaethon/q3/formats/md3format.html nuclear@0: */ nuclear@0: #ifndef AI_MD3FILEHELPER_H_INC nuclear@0: #define AI_MD3FILEHELPER_H_INC nuclear@0: nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: nuclear@0: #include "assimp/types.h" nuclear@0: #include "assimp/mesh.h" nuclear@0: #include "assimp/anim.h" nuclear@0: nuclear@0: #include "assimp/Compiler/pushpack1.h" nuclear@0: nuclear@0: namespace Assimp { nuclear@0: namespace MD3 { nuclear@0: nuclear@0: // to make it easier for us, we test the magic word against both "endianesses" nuclear@0: #define AI_MD3_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDP3") nuclear@0: #define AI_MD3_MAGIC_NUMBER_LE AI_MAKE_MAGIC("3PDI") nuclear@0: nuclear@0: // common limitations nuclear@0: #define AI_MD3_VERSION 15 nuclear@0: #define AI_MD3_MAXQPATH 64 nuclear@0: #define AI_MD3_MAXFRAME 16 nuclear@0: #define AI_MD3_MAX_FRAMES 1024 nuclear@0: #define AI_MD3_MAX_TAGS 16 nuclear@0: #define AI_MD3_MAX_SURFACES 32 nuclear@0: #define AI_MD3_MAX_SHADERS 256 nuclear@0: #define AI_MD3_MAX_VERTS 4096 nuclear@0: #define AI_MD3_MAX_TRIANGLES 8192 nuclear@0: nuclear@0: // master scale factor for all vertices in a MD3 model nuclear@0: #define AI_MD3_XYZ_SCALE (1.0f/64.0f) nuclear@0: nuclear@0: // ------------------------------------------------------------------------------- nuclear@0: /** @brief Data structure for the MD3 main header nuclear@0: */ nuclear@0: struct Header nuclear@0: { nuclear@0: //! magic number nuclear@0: uint32_t IDENT; nuclear@0: nuclear@0: //! file format version nuclear@0: uint32_t VERSION; nuclear@0: nuclear@0: //! original name in .pak archive nuclear@0: char NAME[ AI_MD3_MAXQPATH ]; nuclear@0: nuclear@0: //! unknown nuclear@0: int32_t FLAGS; nuclear@0: nuclear@0: //! number of frames in the file nuclear@0: uint32_t NUM_FRAMES; nuclear@0: nuclear@0: //! number of tags in the file nuclear@0: uint32_t NUM_TAGS; nuclear@0: nuclear@0: //! number of surfaces in the file nuclear@0: uint32_t NUM_SURFACES; nuclear@0: nuclear@0: //! number of skins in the file nuclear@0: uint32_t NUM_SKINS; nuclear@0: nuclear@0: //! offset of the first frame nuclear@0: uint32_t OFS_FRAMES; nuclear@0: nuclear@0: //! offset of the first tag nuclear@0: uint32_t OFS_TAGS; nuclear@0: nuclear@0: //! offset of the first surface nuclear@0: uint32_t OFS_SURFACES; nuclear@0: nuclear@0: //! end of file nuclear@0: uint32_t OFS_EOF; nuclear@0: } PACK_STRUCT; nuclear@0: nuclear@0: nuclear@0: // ------------------------------------------------------------------------------- nuclear@0: /** @brief Data structure for the frame header nuclear@0: */ nuclear@0: struct Frame nuclear@0: { nuclear@0: //! minimum bounds nuclear@0: aiVector3D min; nuclear@0: nuclear@0: //! maximum bounds nuclear@0: aiVector3D max; nuclear@0: nuclear@0: //! local origin for this frame nuclear@0: aiVector3D origin; nuclear@0: nuclear@0: //! radius of bounding sphere nuclear@0: float radius; nuclear@0: nuclear@0: //! name of frame nuclear@0: char name[ AI_MD3_MAXFRAME ]; nuclear@0: nuclear@0: } PACK_STRUCT; nuclear@0: nuclear@0: nuclear@0: // ------------------------------------------------------------------------------- nuclear@0: /** @brief Data structure for the tag header nuclear@0: */ nuclear@0: struct Tag nuclear@0: { nuclear@0: //! name of the tag nuclear@0: char NAME[ AI_MD3_MAXQPATH ]; nuclear@0: nuclear@0: //! Local tag origin and orientation nuclear@0: aiVector3D origin; nuclear@0: float orientation[3][3]; nuclear@0: nuclear@0: } PACK_STRUCT; nuclear@0: nuclear@0: nuclear@0: // ------------------------------------------------------------------------------- nuclear@0: /** @brief Data structure for the surface header nuclear@0: */ nuclear@0: struct Surface nuclear@0: { nuclear@0: //! magic number nuclear@0: int32_t IDENT; nuclear@0: nuclear@0: //! original name of the surface nuclear@0: char NAME[ AI_MD3_MAXQPATH ]; nuclear@0: nuclear@0: //! unknown nuclear@0: int32_t FLAGS; nuclear@0: nuclear@0: //! number of frames in the surface nuclear@0: uint32_t NUM_FRAMES; nuclear@0: nuclear@0: //! number of shaders in the surface nuclear@0: uint32_t NUM_SHADER; nuclear@0: nuclear@0: //! number of vertices in the surface nuclear@0: uint32_t NUM_VERTICES; nuclear@0: nuclear@0: //! number of triangles in the surface nuclear@0: uint32_t NUM_TRIANGLES; nuclear@0: nuclear@0: nuclear@0: //! offset to the triangle data nuclear@0: uint32_t OFS_TRIANGLES; nuclear@0: nuclear@0: //! offset to the shader data nuclear@0: uint32_t OFS_SHADERS; nuclear@0: nuclear@0: //! offset to the texture coordinate data nuclear@0: uint32_t OFS_ST; nuclear@0: nuclear@0: //! offset to the vertex/normal data nuclear@0: uint32_t OFS_XYZNORMAL; nuclear@0: nuclear@0: //! offset to the end of the Surface object nuclear@0: int32_t OFS_END; nuclear@0: } PACK_STRUCT; nuclear@0: nuclear@0: // ------------------------------------------------------------------------------- nuclear@0: /** @brief Data structure for a shader defined in there nuclear@0: */ nuclear@0: struct Shader nuclear@0: { nuclear@0: //! filename of the shader nuclear@0: char NAME[ AI_MD3_MAXQPATH ]; nuclear@0: nuclear@0: //! index of the shader nuclear@0: uint32_t SHADER_INDEX; nuclear@0: } PACK_STRUCT; nuclear@0: nuclear@0: nuclear@0: // ------------------------------------------------------------------------------- nuclear@0: /** @brief Data structure for a triangle nuclear@0: */ nuclear@0: struct Triangle nuclear@0: { nuclear@0: //! triangle indices nuclear@0: uint32_t INDEXES[3]; nuclear@0: } PACK_STRUCT; nuclear@0: nuclear@0: nuclear@0: // ------------------------------------------------------------------------------- nuclear@0: /** @brief Data structure for an UV coord nuclear@0: */ nuclear@0: struct TexCoord nuclear@0: { nuclear@0: //! UV coordinates nuclear@0: float U,V; nuclear@0: } PACK_STRUCT; nuclear@0: nuclear@0: nuclear@0: // ------------------------------------------------------------------------------- nuclear@0: /** @brief Data structure for a vertex nuclear@0: */ nuclear@0: struct Vertex nuclear@0: { nuclear@0: //! X/Y/Z coordinates nuclear@0: int16_t X,Y,Z; nuclear@0: nuclear@0: //! encoded normal vector nuclear@0: uint16_t NORMAL; nuclear@0: } PACK_STRUCT; nuclear@0: nuclear@0: #include "assimp/Compiler/poppack1.h" nuclear@0: nuclear@0: // ------------------------------------------------------------------------------- nuclear@0: /** @brief Unpack a Q3 16 bit vector to its full float3 representation nuclear@0: * nuclear@0: * @param p_iNormal Input normal vector in latitude/longitude form nuclear@0: * @param p_afOut Pointer to an array of three floats to receive the result nuclear@0: * nuclear@0: * @note This has been taken from q3 source (misc_model.c) nuclear@0: */ nuclear@0: inline void LatLngNormalToVec3(uint16_t p_iNormal, float* p_afOut) nuclear@0: { nuclear@0: float lat = (float)(( p_iNormal >> 8u ) & 0xff); nuclear@0: float lng = (float)(( p_iNormal & 0xff )); nuclear@0: lat *= 3.141926f/128.0f; nuclear@0: lng *= 3.141926f/128.0f; nuclear@0: nuclear@0: p_afOut[0] = cosf(lat) * sinf(lng); nuclear@0: p_afOut[1] = sinf(lat) * sinf(lng); nuclear@0: p_afOut[2] = cosf(lng); nuclear@0: return; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // ------------------------------------------------------------------------------- nuclear@0: /** @brief Pack a Q3 normal into 16bit latitute/longitude representation nuclear@0: * @param p_vIn Input vector nuclear@0: * @param p_iOut Output normal nuclear@0: * nuclear@0: * @note This has been taken from q3 source (mathlib.c) nuclear@0: */ nuclear@0: inline void Vec3NormalToLatLng( const aiVector3D& p_vIn, uint16_t& p_iOut ) nuclear@0: { nuclear@0: // check for singularities nuclear@0: if ( 0.0f == p_vIn[0] && 0.0f == p_vIn[1] ) nuclear@0: { nuclear@0: if ( p_vIn[2] > 0.0f ) nuclear@0: { nuclear@0: ((unsigned char*)&p_iOut)[0] = 0; nuclear@0: ((unsigned char*)&p_iOut)[1] = 0; // lat = 0, long = 0 nuclear@0: } nuclear@0: else nuclear@0: { nuclear@0: ((unsigned char*)&p_iOut)[0] = 128; nuclear@0: ((unsigned char*)&p_iOut)[1] = 0; // lat = 0, long = 128 nuclear@0: } nuclear@0: } nuclear@0: else nuclear@0: { nuclear@0: int a, b; nuclear@0: nuclear@0: a = int(57.2957795f * ( atan2f( p_vIn[1], p_vIn[0] ) ) * (255.0f / 360.0f )); nuclear@0: a &= 0xff; nuclear@0: nuclear@0: b = int(57.2957795f * ( acosf( p_vIn[2] ) ) * ( 255.0f / 360.0f )); nuclear@0: b &= 0xff; nuclear@0: nuclear@0: ((unsigned char*)&p_iOut)[0] = b; // longitude nuclear@0: ((unsigned char*)&p_iOut)[1] = a; // lattitude nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: #endif // !! AI_MD3FILEHELPER_H_INC nuclear@0: