1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2017, assimp team
6 
7 All rights reserved.
8 
9 Redistribution and use of this software in source and binary forms,
10 with or without modification, are permitted provided that the
11 following conditions are met:
12 
13 * Redistributions of source code must retain the above
14   copyright notice, this list of conditions and the
15   following disclaimer.
16 
17 * Redistributions in binary form must reproduce the above
18   copyright notice, this list of conditions and the
19   following disclaimer in the documentation and/or other
20   materials provided with the distribution.
21 
22 * Neither the name of the assimp team, nor the names of its
23   contributors may be used to endorse or promote products
24   derived from this software without specific prior
25   written permission of the assimp team.
26 
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 
39 ----------------------------------------------------------------------
40 */
41 
42 /** @file  MD2FileData.h
43  *  @brief Defines helper data structures for importing MD2 files
44  *  http://linux.ucla.edu/~phaethon/q3/formats/md2-schoenblum.html
45  */
46 #ifndef AI_MD2FILEHELPER_H_INC
47 #define AI_MD2FILEHELPER_H_INC
48 
49 #include <assimp/types.h>
50 #include <stdint.h>
51 
52 #include <assimp/Compiler/pushpack1.h>
53 
54 namespace Assimp    {
55 namespace MD2   {
56 
57 // to make it easier for us, we test the magic word against both "endianesses"
58 #define AI_MD2_MAGIC_NUMBER_BE  AI_MAKE_MAGIC("IDP2")
59 #define AI_MD2_MAGIC_NUMBER_LE  AI_MAKE_MAGIC("2PDI")
60 
61 // common limitations
62 #define AI_MD2_VERSION          15
63 #define AI_MD2_MAXQPATH         64
64 #define AI_MD2_MAX_FRAMES       512
65 #define AI_MD2_MAX_SKINS        32
66 #define AI_MD2_MAX_VERTS        2048
67 #define AI_MD2_MAX_TRIANGLES    4096
68 
69 // ---------------------------------------------------------------------------
70 /** \brief Data structure for the MD2 main header
71  */
72 struct Header
73 {
74     uint32_t magic;
75     uint32_t version;
76     uint32_t skinWidth;
77     uint32_t skinHeight;
78     uint32_t frameSize;
79     uint32_t numSkins;
80     uint32_t numVertices;
81     uint32_t numTexCoords;
82     uint32_t numTriangles;
83     uint32_t numGlCommands;
84     uint32_t numFrames;
85     uint32_t offsetSkins;
86     uint32_t offsetTexCoords;
87     uint32_t offsetTriangles;
88     uint32_t offsetFrames;
89     uint32_t offsetGlCommands;
90     uint32_t offsetEnd;
91 
92 } PACK_STRUCT;
93 
94 // ---------------------------------------------------------------------------
95 /** \brief Data structure for a MD2 OpenGl draw command
96  */
97 struct GLCommand
98 {
99    float s, t;
100    uint32_t vertexIndex;
101 } PACK_STRUCT;
102 
103 // ---------------------------------------------------------------------------
104 /** \brief Data structure for a MD2 triangle
105  */
106 struct Triangle
107 {
108     uint16_t vertexIndices[3];
109     uint16_t textureIndices[3];
110 } PACK_STRUCT;
111 
112 // ---------------------------------------------------------------------------
113 /** \brief Data structure for a MD2 vertex
114  */
115 struct Vertex
116 {
117     uint8_t vertex[3];
118     uint8_t lightNormalIndex;
119 } PACK_STRUCT;
120 
121 // ---------------------------------------------------------------------------
122 /** \brief Data structure for a MD2 frame
123  */
124 struct Frame
125 {
126     float scale[3];
127     float translate[3];
128     char name[16];
129     Vertex vertices[1];
130 } PACK_STRUCT;
131 
132 // ---------------------------------------------------------------------------
133 /** \brief Data structure for a MD2 texture coordinate
134  */
135 struct TexCoord
136 {
137     uint16_t s;
138     uint16_t t;
139 } PACK_STRUCT;
140 
141 // ---------------------------------------------------------------------------
142 /** \brief Data structure for a MD2 skin
143  */
144 struct Skin
145 {
146     char name[AI_MD2_MAXQPATH];              /* texture file name */
147 } PACK_STRUCT;
148 
149 #include <assimp/Compiler/poppack1.h>
150 
151 
152 // ---------------------------------------------------------------------------
153 //! Lookup a normal vector from Quake's normal lookup table
154 //! \param index Input index (0-161)
155 //! \param vOut Receives the output normal
156 void LookupNormalIndex(uint8_t index,aiVector3D& vOut);
157 
158 
159 }
160 }
161 
162 #endif // !! include guard
163 
164