vrshoot

annotate libs/assimp/MD3Loader.h @ 1:e7ca128b8713

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