vrshoot

view libs/assimp/MD3Loader.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +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 Md3Loader.h
42 * @brief Declaration of the .MD3 importer class.
43 */
44 #ifndef AI_MD3LOADER_H_INCLUDED
45 #define AI_MD3LOADER_H_INCLUDED
47 #include "BaseImporter.h"
48 #include "ByteSwap.h"
50 #include "assimp/types.h"
52 #include "MD3FileData.h"
53 namespace Assimp {
56 using namespace MD3;
57 namespace Q3Shader {
59 // ---------------------------------------------------------------------------
60 /** @brief Tiny utility data structure to hold the data of a .skin file
61 */
62 struct SkinData
63 {
64 //! A single entryin texture list
65 struct TextureEntry : public std::pair<std::string,std::string>
66 {
67 // did we resolve this texture entry?
68 bool resolved;
70 // for std::find()
71 bool operator == (const std::string& f) const {
72 return f == first;
73 }
74 };
76 //! List of textures
77 std::list<TextureEntry> textures;
79 // rest is ignored for the moment
80 };
82 // ---------------------------------------------------------------------------
83 /** @brief Specifies cull modi for Quake shader files.
84 */
85 enum ShaderCullMode
86 {
87 CULL_NONE,
88 CULL_CW,
89 CULL_CCW
90 };
92 // ---------------------------------------------------------------------------
93 /** @brief Specifies alpha blend modi (src + dest) for Quake shader files
94 */
95 enum BlendFunc
96 {
97 BLEND_NONE,
98 BLEND_GL_ONE,
99 BLEND_GL_ZERO,
100 BLEND_GL_DST_COLOR,
101 BLEND_GL_ONE_MINUS_DST_COLOR,
102 BLEND_GL_SRC_ALPHA,
103 BLEND_GL_ONE_MINUS_SRC_ALPHA
104 };
106 // ---------------------------------------------------------------------------
107 /** @brief Specifies alpha test modi for Quake texture maps
108 */
109 enum AlphaTestFunc
110 {
111 AT_NONE,
112 AT_GT0,
113 AT_LT128,
114 AT_GE128
115 };
117 // ---------------------------------------------------------------------------
118 /** @brief Tiny utility data structure to hold a .shader map data block
119 */
120 struct ShaderMapBlock
121 {
122 ShaderMapBlock()
123 : blend_src (BLEND_NONE)
124 , blend_dest (BLEND_NONE)
125 , alpha_test (AT_NONE)
126 {}
128 //! Name of referenced map
129 std::string name;
131 //! Blend and alpha test settings for texture
132 BlendFunc blend_src,blend_dest;
133 AlphaTestFunc alpha_test;
136 //! For std::find()
137 bool operator== (const std::string& o) const {
138 return !ASSIMP_stricmp(o,name);
139 }
140 };
142 // ---------------------------------------------------------------------------
143 /** @brief Tiny utility data structure to hold a .shader data block
144 */
145 struct ShaderDataBlock
146 {
147 ShaderDataBlock()
148 : cull (CULL_CW)
149 {}
151 //! Name of referenced data element
152 std::string name;
154 //! Cull mode for the element
155 ShaderCullMode cull;
157 //! Maps defined in the shader
158 std::list<ShaderMapBlock> maps;
161 //! For std::find()
162 bool operator== (const std::string& o) const {
163 return !ASSIMP_stricmp(o,name);
164 }
165 };
167 // ---------------------------------------------------------------------------
168 /** @brief Tiny utility data structure to hold the data of a .shader file
169 */
170 struct ShaderData
171 {
172 //! Shader data blocks
173 std::list<ShaderDataBlock> blocks;
174 };
176 // ---------------------------------------------------------------------------
177 /** @brief Load a shader file
178 *
179 * Generally, parsing is error tolerant. There's no failure.
180 * @param fill Receives output data
181 * @param file File to be read.
182 * @param io IOSystem to be used for reading
183 * @return false if file is not accessible
184 */
185 bool LoadShader(ShaderData& fill, const std::string& file,IOSystem* io);
188 // ---------------------------------------------------------------------------
189 /** @brief Convert a Q3Shader to an aiMaterial
190 *
191 * @param[out] out Material structure to be filled.
192 * @param[in] shader Input shader
193 */
194 void ConvertShaderToMaterial(aiMaterial* out, const ShaderDataBlock& shader);
196 // ---------------------------------------------------------------------------
197 /** @brief Load a skin file
198 *
199 * Generally, parsing is error tolerant. There's no failure.
200 * @param fill Receives output data
201 * @param file File to be read.
202 * @param io IOSystem to be used for reading
203 * @return false if file is not accessible
204 */
205 bool LoadSkin(SkinData& fill, const std::string& file,IOSystem* io);
207 } // ! namespace Q3SHader
209 // ---------------------------------------------------------------------------
210 /** @brief Importer class to load MD3 files
211 */
212 class MD3Importer : public BaseImporter
213 {
214 public:
215 MD3Importer();
216 ~MD3Importer();
219 public:
221 // -------------------------------------------------------------------
222 /** Returns whether the class can handle the format of the given file.
223 * See BaseImporter::CanRead() for details. */
224 bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
225 bool checkSig) const;
228 // -------------------------------------------------------------------
229 /** Called prior to ReadFile().
230 * The function is a request to the importer to update its configuration
231 * basing on the Importer's configuration property list.
232 */
233 void SetupProperties(const Importer* pImp);
235 protected:
237 // -------------------------------------------------------------------
238 /** Return importer meta information.
239 * See #BaseImporter::GetInfo for the details
240 */
241 const aiImporterDesc* GetInfo () const;
243 // -------------------------------------------------------------------
244 /** Imports the given file into the given scene structure.
245 * See BaseImporter::InternReadFile() for details
246 */
247 void InternReadFile( const std::string& pFile, aiScene* pScene,
248 IOSystem* pIOHandler);
250 // -------------------------------------------------------------------
251 /** Validate offsets in the header
252 */
253 void ValidateHeaderOffsets();
254 void ValidateSurfaceHeaderOffsets(const MD3::Surface* pcSurfHeader);
256 // -------------------------------------------------------------------
257 /** Read a Q3 multipart file
258 * @return true if multi part has been processed
259 */
260 bool ReadMultipartFile();
262 // -------------------------------------------------------------------
263 /** Try to read the skin for a MD3 file
264 * @param fill Receives output information
265 */
266 void ReadSkin(Q3Shader::SkinData& fill) const;
268 // -------------------------------------------------------------------
269 /** Try to read the shader for a MD3 file
270 * @param fill Receives output information
271 */
272 void ReadShader(Q3Shader::ShaderData& fill) const;
274 // -------------------------------------------------------------------
275 /** Convert a texture path in a MD3 file to a proper value
276 * @param[in] texture_name Path to be converted
277 * @param[in] header_path Base path specified in MD3 header
278 * @param[out] out Receives the converted output string
279 */
280 void ConvertPath(const char* texture_name, const char* header_path,
281 std::string& out) const;
283 protected:
285 /** Configuration option: frame to be loaded */
286 unsigned int configFrameID;
288 /** Configuration option: process multi-part files */
289 bool configHandleMP;
291 /** Configuration option: name of skin file to be read */
292 std::string configSkinFile;
294 /** Configuration option: name or path of shader */
295 std::string configShaderFile;
297 /** Configuration option: speed flag was set? */
298 bool configSpeedFlag;
300 /** Header of the MD3 file */
301 BE_NCONST MD3::Header* pcHeader;
303 /** File buffer */
304 BE_NCONST unsigned char* mBuffer;
306 /** Size of the file, in bytes */
307 unsigned int fileSize;
309 /** Current file name */
310 std::string mFile;
312 /** Current base directory */
313 std::string path;
315 /** Pure file we're currently reading */
316 std::string filename;
318 /** Output scene to be filled */
319 aiScene* mScene;
321 /** IO system to be used to access the data*/
322 IOSystem* mIOHandler;
323 };
325 } // end of namespace Assimp
327 #endif // AI_3DSIMPORTER_H_INC