vrshoot
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/MD3Loader.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,327 @@ 1.4 +/* 1.5 +Open Asset Import Library (assimp) 1.6 +---------------------------------------------------------------------- 1.7 + 1.8 +Copyright (c) 2006-2012, assimp team 1.9 +All rights reserved. 1.10 + 1.11 +Redistribution and use of this software in source and binary forms, 1.12 +with or without modification, are permitted provided that the 1.13 +following conditions are met: 1.14 + 1.15 +* Redistributions of source code must retain the above 1.16 + copyright notice, this list of conditions and the 1.17 + following disclaimer. 1.18 + 1.19 +* Redistributions in binary form must reproduce the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer in the documentation and/or other 1.22 + materials provided with the distribution. 1.23 + 1.24 +* Neither the name of the assimp team, nor the names of its 1.25 + contributors may be used to endorse or promote products 1.26 + derived from this software without specific prior 1.27 + written permission of the assimp team. 1.28 + 1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.40 + 1.41 +---------------------------------------------------------------------- 1.42 +*/ 1.43 + 1.44 +/** @file Md3Loader.h 1.45 + * @brief Declaration of the .MD3 importer class. 1.46 + */ 1.47 +#ifndef AI_MD3LOADER_H_INCLUDED 1.48 +#define AI_MD3LOADER_H_INCLUDED 1.49 + 1.50 +#include "BaseImporter.h" 1.51 +#include "ByteSwap.h" 1.52 + 1.53 +#include "assimp/types.h" 1.54 + 1.55 +#include "MD3FileData.h" 1.56 +namespace Assimp { 1.57 + 1.58 + 1.59 +using namespace MD3; 1.60 +namespace Q3Shader { 1.61 + 1.62 +// --------------------------------------------------------------------------- 1.63 +/** @brief Tiny utility data structure to hold the data of a .skin file 1.64 + */ 1.65 +struct SkinData 1.66 +{ 1.67 + //! A single entryin texture list 1.68 + struct TextureEntry : public std::pair<std::string,std::string> 1.69 + { 1.70 + // did we resolve this texture entry? 1.71 + bool resolved; 1.72 + 1.73 + // for std::find() 1.74 + bool operator == (const std::string& f) const { 1.75 + return f == first; 1.76 + } 1.77 + }; 1.78 + 1.79 + //! List of textures 1.80 + std::list<TextureEntry> textures; 1.81 + 1.82 + // rest is ignored for the moment 1.83 +}; 1.84 + 1.85 +// --------------------------------------------------------------------------- 1.86 +/** @brief Specifies cull modi for Quake shader files. 1.87 + */ 1.88 +enum ShaderCullMode 1.89 +{ 1.90 + CULL_NONE, 1.91 + CULL_CW, 1.92 + CULL_CCW 1.93 +}; 1.94 + 1.95 +// --------------------------------------------------------------------------- 1.96 +/** @brief Specifies alpha blend modi (src + dest) for Quake shader files 1.97 + */ 1.98 +enum BlendFunc 1.99 +{ 1.100 + BLEND_NONE, 1.101 + BLEND_GL_ONE, 1.102 + BLEND_GL_ZERO, 1.103 + BLEND_GL_DST_COLOR, 1.104 + BLEND_GL_ONE_MINUS_DST_COLOR, 1.105 + BLEND_GL_SRC_ALPHA, 1.106 + BLEND_GL_ONE_MINUS_SRC_ALPHA 1.107 +}; 1.108 + 1.109 +// --------------------------------------------------------------------------- 1.110 +/** @brief Specifies alpha test modi for Quake texture maps 1.111 + */ 1.112 +enum AlphaTestFunc 1.113 +{ 1.114 + AT_NONE, 1.115 + AT_GT0, 1.116 + AT_LT128, 1.117 + AT_GE128 1.118 +}; 1.119 + 1.120 +// --------------------------------------------------------------------------- 1.121 +/** @brief Tiny utility data structure to hold a .shader map data block 1.122 + */ 1.123 +struct ShaderMapBlock 1.124 +{ 1.125 + ShaderMapBlock() 1.126 + : blend_src (BLEND_NONE) 1.127 + , blend_dest (BLEND_NONE) 1.128 + , alpha_test (AT_NONE) 1.129 + {} 1.130 + 1.131 + //! Name of referenced map 1.132 + std::string name; 1.133 + 1.134 + //! Blend and alpha test settings for texture 1.135 + BlendFunc blend_src,blend_dest; 1.136 + AlphaTestFunc alpha_test; 1.137 + 1.138 + 1.139 + //! For std::find() 1.140 + bool operator== (const std::string& o) const { 1.141 + return !ASSIMP_stricmp(o,name); 1.142 + } 1.143 +}; 1.144 + 1.145 +// --------------------------------------------------------------------------- 1.146 +/** @brief Tiny utility data structure to hold a .shader data block 1.147 + */ 1.148 +struct ShaderDataBlock 1.149 +{ 1.150 + ShaderDataBlock() 1.151 + : cull (CULL_CW) 1.152 + {} 1.153 + 1.154 + //! Name of referenced data element 1.155 + std::string name; 1.156 + 1.157 + //! Cull mode for the element 1.158 + ShaderCullMode cull; 1.159 + 1.160 + //! Maps defined in the shader 1.161 + std::list<ShaderMapBlock> maps; 1.162 + 1.163 + 1.164 + //! For std::find() 1.165 + bool operator== (const std::string& o) const { 1.166 + return !ASSIMP_stricmp(o,name); 1.167 + } 1.168 +}; 1.169 + 1.170 +// --------------------------------------------------------------------------- 1.171 +/** @brief Tiny utility data structure to hold the data of a .shader file 1.172 + */ 1.173 +struct ShaderData 1.174 +{ 1.175 + //! Shader data blocks 1.176 + std::list<ShaderDataBlock> blocks; 1.177 +}; 1.178 + 1.179 +// --------------------------------------------------------------------------- 1.180 +/** @brief Load a shader file 1.181 + * 1.182 + * Generally, parsing is error tolerant. There's no failure. 1.183 + * @param fill Receives output data 1.184 + * @param file File to be read. 1.185 + * @param io IOSystem to be used for reading 1.186 + * @return false if file is not accessible 1.187 + */ 1.188 +bool LoadShader(ShaderData& fill, const std::string& file,IOSystem* io); 1.189 + 1.190 + 1.191 +// --------------------------------------------------------------------------- 1.192 +/** @brief Convert a Q3Shader to an aiMaterial 1.193 + * 1.194 + * @param[out] out Material structure to be filled. 1.195 + * @param[in] shader Input shader 1.196 + */ 1.197 +void ConvertShaderToMaterial(aiMaterial* out, const ShaderDataBlock& shader); 1.198 + 1.199 +// --------------------------------------------------------------------------- 1.200 +/** @brief Load a skin file 1.201 + * 1.202 + * Generally, parsing is error tolerant. There's no failure. 1.203 + * @param fill Receives output data 1.204 + * @param file File to be read. 1.205 + * @param io IOSystem to be used for reading 1.206 + * @return false if file is not accessible 1.207 + */ 1.208 +bool LoadSkin(SkinData& fill, const std::string& file,IOSystem* io); 1.209 + 1.210 +} // ! namespace Q3SHader 1.211 + 1.212 +// --------------------------------------------------------------------------- 1.213 +/** @brief Importer class to load MD3 files 1.214 +*/ 1.215 +class MD3Importer : public BaseImporter 1.216 +{ 1.217 +public: 1.218 + MD3Importer(); 1.219 + ~MD3Importer(); 1.220 + 1.221 + 1.222 +public: 1.223 + 1.224 + // ------------------------------------------------------------------- 1.225 + /** Returns whether the class can handle the format of the given file. 1.226 + * See BaseImporter::CanRead() for details. */ 1.227 + bool CanRead( const std::string& pFile, IOSystem* pIOHandler, 1.228 + bool checkSig) const; 1.229 + 1.230 + 1.231 + // ------------------------------------------------------------------- 1.232 + /** Called prior to ReadFile(). 1.233 + * The function is a request to the importer to update its configuration 1.234 + * basing on the Importer's configuration property list. 1.235 + */ 1.236 + void SetupProperties(const Importer* pImp); 1.237 + 1.238 +protected: 1.239 + 1.240 + // ------------------------------------------------------------------- 1.241 + /** Return importer meta information. 1.242 + * See #BaseImporter::GetInfo for the details 1.243 + */ 1.244 + const aiImporterDesc* GetInfo () const; 1.245 + 1.246 + // ------------------------------------------------------------------- 1.247 + /** Imports the given file into the given scene structure. 1.248 + * See BaseImporter::InternReadFile() for details 1.249 + */ 1.250 + void InternReadFile( const std::string& pFile, aiScene* pScene, 1.251 + IOSystem* pIOHandler); 1.252 + 1.253 + // ------------------------------------------------------------------- 1.254 + /** Validate offsets in the header 1.255 + */ 1.256 + void ValidateHeaderOffsets(); 1.257 + void ValidateSurfaceHeaderOffsets(const MD3::Surface* pcSurfHeader); 1.258 + 1.259 + // ------------------------------------------------------------------- 1.260 + /** Read a Q3 multipart file 1.261 + * @return true if multi part has been processed 1.262 + */ 1.263 + bool ReadMultipartFile(); 1.264 + 1.265 + // ------------------------------------------------------------------- 1.266 + /** Try to read the skin for a MD3 file 1.267 + * @param fill Receives output information 1.268 + */ 1.269 + void ReadSkin(Q3Shader::SkinData& fill) const; 1.270 + 1.271 + // ------------------------------------------------------------------- 1.272 + /** Try to read the shader for a MD3 file 1.273 + * @param fill Receives output information 1.274 + */ 1.275 + void ReadShader(Q3Shader::ShaderData& fill) const; 1.276 + 1.277 + // ------------------------------------------------------------------- 1.278 + /** Convert a texture path in a MD3 file to a proper value 1.279 + * @param[in] texture_name Path to be converted 1.280 + * @param[in] header_path Base path specified in MD3 header 1.281 + * @param[out] out Receives the converted output string 1.282 + */ 1.283 + void ConvertPath(const char* texture_name, const char* header_path, 1.284 + std::string& out) const; 1.285 + 1.286 +protected: 1.287 + 1.288 + /** Configuration option: frame to be loaded */ 1.289 + unsigned int configFrameID; 1.290 + 1.291 + /** Configuration option: process multi-part files */ 1.292 + bool configHandleMP; 1.293 + 1.294 + /** Configuration option: name of skin file to be read */ 1.295 + std::string configSkinFile; 1.296 + 1.297 + /** Configuration option: name or path of shader */ 1.298 + std::string configShaderFile; 1.299 + 1.300 + /** Configuration option: speed flag was set? */ 1.301 + bool configSpeedFlag; 1.302 + 1.303 + /** Header of the MD3 file */ 1.304 + BE_NCONST MD3::Header* pcHeader; 1.305 + 1.306 + /** File buffer */ 1.307 + BE_NCONST unsigned char* mBuffer; 1.308 + 1.309 + /** Size of the file, in bytes */ 1.310 + unsigned int fileSize; 1.311 + 1.312 + /** Current file name */ 1.313 + std::string mFile; 1.314 + 1.315 + /** Current base directory */ 1.316 + std::string path; 1.317 + 1.318 + /** Pure file we're currently reading */ 1.319 + std::string filename; 1.320 + 1.321 + /** Output scene to be filled */ 1.322 + aiScene* mScene; 1.323 + 1.324 + /** IO system to be used to access the data*/ 1.325 + IOSystem* mIOHandler; 1.326 + }; 1.327 + 1.328 +} // end of namespace Assimp 1.329 + 1.330 +#endif // AI_3DSIMPORTER_H_INC