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 Md3Loader.h nuclear@0: * @brief Declaration of the .MD3 importer class. nuclear@0: */ nuclear@0: #ifndef AI_MD3LOADER_H_INCLUDED nuclear@0: #define AI_MD3LOADER_H_INCLUDED nuclear@0: nuclear@0: #include "BaseImporter.h" nuclear@0: #include "ByteSwap.h" nuclear@0: nuclear@0: #include "assimp/types.h" nuclear@0: nuclear@0: #include "MD3FileData.h" nuclear@0: namespace Assimp { nuclear@0: nuclear@0: nuclear@0: using namespace MD3; nuclear@0: namespace Q3Shader { nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** @brief Tiny utility data structure to hold the data of a .skin file nuclear@0: */ nuclear@0: struct SkinData nuclear@0: { nuclear@0: //! A single entryin texture list nuclear@0: struct TextureEntry : public std::pair nuclear@0: { nuclear@0: // did we resolve this texture entry? nuclear@0: bool resolved; nuclear@0: nuclear@0: // for std::find() nuclear@0: bool operator == (const std::string& f) const { nuclear@0: return f == first; nuclear@0: } nuclear@0: }; nuclear@0: nuclear@0: //! List of textures nuclear@0: std::list textures; nuclear@0: nuclear@0: // rest is ignored for the moment nuclear@0: }; nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** @brief Specifies cull modi for Quake shader files. nuclear@0: */ nuclear@0: enum ShaderCullMode nuclear@0: { nuclear@0: CULL_NONE, nuclear@0: CULL_CW, nuclear@0: CULL_CCW nuclear@0: }; nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** @brief Specifies alpha blend modi (src + dest) for Quake shader files nuclear@0: */ nuclear@0: enum BlendFunc nuclear@0: { nuclear@0: BLEND_NONE, nuclear@0: BLEND_GL_ONE, nuclear@0: BLEND_GL_ZERO, nuclear@0: BLEND_GL_DST_COLOR, nuclear@0: BLEND_GL_ONE_MINUS_DST_COLOR, nuclear@0: BLEND_GL_SRC_ALPHA, nuclear@0: BLEND_GL_ONE_MINUS_SRC_ALPHA nuclear@0: }; nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** @brief Specifies alpha test modi for Quake texture maps nuclear@0: */ nuclear@0: enum AlphaTestFunc nuclear@0: { nuclear@0: AT_NONE, nuclear@0: AT_GT0, nuclear@0: AT_LT128, nuclear@0: AT_GE128 nuclear@0: }; nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** @brief Tiny utility data structure to hold a .shader map data block nuclear@0: */ nuclear@0: struct ShaderMapBlock nuclear@0: { nuclear@0: ShaderMapBlock() nuclear@0: : blend_src (BLEND_NONE) nuclear@0: , blend_dest (BLEND_NONE) nuclear@0: , alpha_test (AT_NONE) nuclear@0: {} nuclear@0: nuclear@0: //! Name of referenced map nuclear@0: std::string name; nuclear@0: nuclear@0: //! Blend and alpha test settings for texture nuclear@0: BlendFunc blend_src,blend_dest; nuclear@0: AlphaTestFunc alpha_test; nuclear@0: nuclear@0: nuclear@0: //! For std::find() nuclear@0: bool operator== (const std::string& o) const { nuclear@0: return !ASSIMP_stricmp(o,name); nuclear@0: } nuclear@0: }; nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** @brief Tiny utility data structure to hold a .shader data block nuclear@0: */ nuclear@0: struct ShaderDataBlock nuclear@0: { nuclear@0: ShaderDataBlock() nuclear@0: : cull (CULL_CW) nuclear@0: {} nuclear@0: nuclear@0: //! Name of referenced data element nuclear@0: std::string name; nuclear@0: nuclear@0: //! Cull mode for the element nuclear@0: ShaderCullMode cull; nuclear@0: nuclear@0: //! Maps defined in the shader nuclear@0: std::list maps; nuclear@0: nuclear@0: nuclear@0: //! For std::find() nuclear@0: bool operator== (const std::string& o) const { nuclear@0: return !ASSIMP_stricmp(o,name); nuclear@0: } nuclear@0: }; nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** @brief Tiny utility data structure to hold the data of a .shader file nuclear@0: */ nuclear@0: struct ShaderData nuclear@0: { nuclear@0: //! Shader data blocks nuclear@0: std::list blocks; nuclear@0: }; nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** @brief Load a shader file nuclear@0: * nuclear@0: * Generally, parsing is error tolerant. There's no failure. nuclear@0: * @param fill Receives output data nuclear@0: * @param file File to be read. nuclear@0: * @param io IOSystem to be used for reading nuclear@0: * @return false if file is not accessible nuclear@0: */ nuclear@0: bool LoadShader(ShaderData& fill, const std::string& file,IOSystem* io); nuclear@0: nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** @brief Convert a Q3Shader to an aiMaterial nuclear@0: * nuclear@0: * @param[out] out Material structure to be filled. nuclear@0: * @param[in] shader Input shader nuclear@0: */ nuclear@0: void ConvertShaderToMaterial(aiMaterial* out, const ShaderDataBlock& shader); nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** @brief Load a skin file nuclear@0: * nuclear@0: * Generally, parsing is error tolerant. There's no failure. nuclear@0: * @param fill Receives output data nuclear@0: * @param file File to be read. nuclear@0: * @param io IOSystem to be used for reading nuclear@0: * @return false if file is not accessible nuclear@0: */ nuclear@0: bool LoadSkin(SkinData& fill, const std::string& file,IOSystem* io); nuclear@0: nuclear@0: } // ! namespace Q3SHader nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** @brief Importer class to load MD3 files nuclear@0: */ nuclear@0: class MD3Importer : public BaseImporter nuclear@0: { nuclear@0: public: nuclear@0: MD3Importer(); nuclear@0: ~MD3Importer(); nuclear@0: nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Returns whether the class can handle the format of the given file. nuclear@0: * See BaseImporter::CanRead() for details. */ nuclear@0: bool CanRead( const std::string& pFile, IOSystem* pIOHandler, nuclear@0: bool checkSig) const; nuclear@0: nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Called prior to ReadFile(). nuclear@0: * The function is a request to the importer to update its configuration nuclear@0: * basing on the Importer's configuration property list. nuclear@0: */ nuclear@0: void SetupProperties(const Importer* pImp); nuclear@0: nuclear@0: protected: nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Return importer meta information. nuclear@0: * See #BaseImporter::GetInfo for the details nuclear@0: */ nuclear@0: const aiImporterDesc* GetInfo () const; nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Imports the given file into the given scene structure. nuclear@0: * See BaseImporter::InternReadFile() for details nuclear@0: */ nuclear@0: void InternReadFile( const std::string& pFile, aiScene* pScene, nuclear@0: IOSystem* pIOHandler); nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Validate offsets in the header nuclear@0: */ nuclear@0: void ValidateHeaderOffsets(); nuclear@0: void ValidateSurfaceHeaderOffsets(const MD3::Surface* pcSurfHeader); nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Read a Q3 multipart file nuclear@0: * @return true if multi part has been processed nuclear@0: */ nuclear@0: bool ReadMultipartFile(); nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Try to read the skin for a MD3 file nuclear@0: * @param fill Receives output information nuclear@0: */ nuclear@0: void ReadSkin(Q3Shader::SkinData& fill) const; nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Try to read the shader for a MD3 file nuclear@0: * @param fill Receives output information nuclear@0: */ nuclear@0: void ReadShader(Q3Shader::ShaderData& fill) const; nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Convert a texture path in a MD3 file to a proper value nuclear@0: * @param[in] texture_name Path to be converted nuclear@0: * @param[in] header_path Base path specified in MD3 header nuclear@0: * @param[out] out Receives the converted output string nuclear@0: */ nuclear@0: void ConvertPath(const char* texture_name, const char* header_path, nuclear@0: std::string& out) const; nuclear@0: nuclear@0: protected: nuclear@0: nuclear@0: /** Configuration option: frame to be loaded */ nuclear@0: unsigned int configFrameID; nuclear@0: nuclear@0: /** Configuration option: process multi-part files */ nuclear@0: bool configHandleMP; nuclear@0: nuclear@0: /** Configuration option: name of skin file to be read */ nuclear@0: std::string configSkinFile; nuclear@0: nuclear@0: /** Configuration option: name or path of shader */ nuclear@0: std::string configShaderFile; nuclear@0: nuclear@0: /** Configuration option: speed flag was set? */ nuclear@0: bool configSpeedFlag; nuclear@0: nuclear@0: /** Header of the MD3 file */ nuclear@0: BE_NCONST MD3::Header* pcHeader; nuclear@0: nuclear@0: /** File buffer */ nuclear@0: BE_NCONST unsigned char* mBuffer; nuclear@0: nuclear@0: /** Size of the file, in bytes */ nuclear@0: unsigned int fileSize; nuclear@0: nuclear@0: /** Current file name */ nuclear@0: std::string mFile; nuclear@0: nuclear@0: /** Current base directory */ nuclear@0: std::string path; nuclear@0: nuclear@0: /** Pure file we're currently reading */ nuclear@0: std::string filename; nuclear@0: nuclear@0: /** Output scene to be filled */ nuclear@0: aiScene* mScene; nuclear@0: nuclear@0: /** IO system to be used to access the data*/ nuclear@0: IOSystem* mIOHandler; nuclear@0: }; nuclear@0: nuclear@0: } // end of namespace Assimp nuclear@0: nuclear@0: #endif // AI_3DSIMPORTER_H_INC