You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

328 regels
9.0 KiB

  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2012, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file Md3Loader.h
  34. * @brief Declaration of the .MD3 importer class.
  35. */
  36. #ifndef AI_MD3LOADER_H_INCLUDED
  37. #define AI_MD3LOADER_H_INCLUDED
  38. #include "BaseImporter.h"
  39. #include "ByteSwap.h"
  40. #include "../include/assimp/types.h"
  41. #include "MD3FileData.h"
  42. namespace Assimp {
  43. using namespace MD3;
  44. namespace Q3Shader {
  45. // ---------------------------------------------------------------------------
  46. /** @brief Tiny utility data structure to hold the data of a .skin file
  47. */
  48. struct SkinData
  49. {
  50. //! A single entryin texture list
  51. struct TextureEntry : public std::pair<std::string,std::string>
  52. {
  53. // did we resolve this texture entry?
  54. bool resolved;
  55. // for std::find()
  56. bool operator == (const std::string& f) const {
  57. return f == first;
  58. }
  59. };
  60. //! List of textures
  61. std::list<TextureEntry> textures;
  62. // rest is ignored for the moment
  63. };
  64. // ---------------------------------------------------------------------------
  65. /** @brief Specifies cull modi for Quake shader files.
  66. */
  67. enum ShaderCullMode
  68. {
  69. CULL_NONE,
  70. CULL_CW,
  71. CULL_CCW
  72. };
  73. // ---------------------------------------------------------------------------
  74. /** @brief Specifies alpha blend modi (src + dest) for Quake shader files
  75. */
  76. enum BlendFunc
  77. {
  78. BLEND_NONE,
  79. BLEND_GL_ONE,
  80. BLEND_GL_ZERO,
  81. BLEND_GL_DST_COLOR,
  82. BLEND_GL_ONE_MINUS_DST_COLOR,
  83. BLEND_GL_SRC_ALPHA,
  84. BLEND_GL_ONE_MINUS_SRC_ALPHA
  85. };
  86. // ---------------------------------------------------------------------------
  87. /** @brief Specifies alpha test modi for Quake texture maps
  88. */
  89. enum AlphaTestFunc
  90. {
  91. AT_NONE,
  92. AT_GT0,
  93. AT_LT128,
  94. AT_GE128
  95. };
  96. // ---------------------------------------------------------------------------
  97. /** @brief Tiny utility data structure to hold a .shader map data block
  98. */
  99. struct ShaderMapBlock
  100. {
  101. ShaderMapBlock()
  102. : blend_src (BLEND_NONE)
  103. , blend_dest (BLEND_NONE)
  104. , alpha_test (AT_NONE)
  105. {}
  106. //! Name of referenced map
  107. std::string name;
  108. //! Blend and alpha test settings for texture
  109. BlendFunc blend_src,blend_dest;
  110. AlphaTestFunc alpha_test;
  111. //! For std::find()
  112. bool operator== (const std::string& o) const {
  113. return !ASSIMP_stricmp(o,name);
  114. }
  115. };
  116. // ---------------------------------------------------------------------------
  117. /** @brief Tiny utility data structure to hold a .shader data block
  118. */
  119. struct ShaderDataBlock
  120. {
  121. ShaderDataBlock()
  122. : cull (CULL_CW)
  123. {}
  124. //! Name of referenced data element
  125. std::string name;
  126. //! Cull mode for the element
  127. ShaderCullMode cull;
  128. //! Maps defined in the shader
  129. std::list<ShaderMapBlock> maps;
  130. //! For std::find()
  131. bool operator== (const std::string& o) const {
  132. return !ASSIMP_stricmp(o,name);
  133. }
  134. };
  135. // ---------------------------------------------------------------------------
  136. /** @brief Tiny utility data structure to hold the data of a .shader file
  137. */
  138. struct ShaderData
  139. {
  140. //! Shader data blocks
  141. std::list<ShaderDataBlock> blocks;
  142. };
  143. // ---------------------------------------------------------------------------
  144. /** @brief Load a shader file
  145. *
  146. * Generally, parsing is error tolerant. There's no failure.
  147. * @param fill Receives output data
  148. * @param file File to be read.
  149. * @param io IOSystem to be used for reading
  150. * @return false if file is not accessible
  151. */
  152. bool LoadShader(ShaderData& fill, const std::string& file,IOSystem* io);
  153. // ---------------------------------------------------------------------------
  154. /** @brief Convert a Q3Shader to an aiMaterial
  155. *
  156. * @param[out] out Material structure to be filled.
  157. * @param[in] shader Input shader
  158. */
  159. void ConvertShaderToMaterial(aiMaterial* out, const ShaderDataBlock& shader);
  160. // ---------------------------------------------------------------------------
  161. /** @brief Load a skin file
  162. *
  163. * Generally, parsing is error tolerant. There's no failure.
  164. * @param fill Receives output data
  165. * @param file File to be read.
  166. * @param io IOSystem to be used for reading
  167. * @return false if file is not accessible
  168. */
  169. bool LoadSkin(SkinData& fill, const std::string& file,IOSystem* io);
  170. } // ! namespace Q3SHader
  171. // ---------------------------------------------------------------------------
  172. /** @brief Importer class to load MD3 files
  173. */
  174. class MD3Importer : public BaseImporter
  175. {
  176. public:
  177. MD3Importer();
  178. ~MD3Importer();
  179. public:
  180. // -------------------------------------------------------------------
  181. /** Returns whether the class can handle the format of the given file.
  182. * See BaseImporter::CanRead() for details. */
  183. bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
  184. bool checkSig) const;
  185. // -------------------------------------------------------------------
  186. /** Called prior to ReadFile().
  187. * The function is a request to the importer to update its configuration
  188. * basing on the Importer's configuration property list.
  189. */
  190. void SetupProperties(const Importer* pImp);
  191. protected:
  192. // -------------------------------------------------------------------
  193. /** Return importer meta information.
  194. * See #BaseImporter::GetInfo for the details
  195. */
  196. const aiImporterDesc* GetInfo () const;
  197. // -------------------------------------------------------------------
  198. /** Imports the given file into the given scene structure.
  199. * See BaseImporter::InternReadFile() for details
  200. */
  201. void InternReadFile( const std::string& pFile, aiScene* pScene,
  202. IOSystem* pIOHandler);
  203. // -------------------------------------------------------------------
  204. /** Validate offsets in the header
  205. */
  206. void ValidateHeaderOffsets();
  207. void ValidateSurfaceHeaderOffsets(const MD3::Surface* pcSurfHeader);
  208. // -------------------------------------------------------------------
  209. /** Read a Q3 multipart file
  210. * @return true if multi part has been processed
  211. */
  212. bool ReadMultipartFile();
  213. // -------------------------------------------------------------------
  214. /** Try to read the skin for a MD3 file
  215. * @param fill Receives output information
  216. */
  217. void ReadSkin(Q3Shader::SkinData& fill) const;
  218. // -------------------------------------------------------------------
  219. /** Try to read the shader for a MD3 file
  220. * @param fill Receives output information
  221. */
  222. void ReadShader(Q3Shader::ShaderData& fill) const;
  223. // -------------------------------------------------------------------
  224. /** Convert a texture path in a MD3 file to a proper value
  225. * @param[in] texture_name Path to be converted
  226. * @param[in] header_path Base path specified in MD3 header
  227. * @param[out] out Receives the converted output string
  228. */
  229. void ConvertPath(const char* texture_name, const char* header_path,
  230. std::string& out) const;
  231. protected:
  232. /** Configuration option: frame to be loaded */
  233. unsigned int configFrameID;
  234. /** Configuration option: process multi-part files */
  235. bool configHandleMP;
  236. /** Configuration option: name of skin file to be read */
  237. std::string configSkinFile;
  238. /** Configuration option: name or path of shader */
  239. std::string configShaderFile;
  240. /** Configuration option: speed flag was set? */
  241. bool configSpeedFlag;
  242. /** Header of the MD3 file */
  243. BE_NCONST MD3::Header* pcHeader;
  244. /** File buffer */
  245. BE_NCONST unsigned char* mBuffer;
  246. /** Size of the file, in bytes */
  247. unsigned int fileSize;
  248. /** Current file name */
  249. std::string mFile;
  250. /** Current base directory */
  251. std::string path;
  252. /** Pure file we're currently reading */
  253. std::string filename;
  254. /** Output scene to be filled */
  255. aiScene* mScene;
  256. /** IO system to be used to access the data*/
  257. IOSystem* mIOHandler;
  258. };
  259. } // end of namespace Assimp
  260. #endif // AI_3DSIMPORTER_H_INC