BlenderLoader.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2010, ASSIMP Development 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 Development 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 BlenderLoader.h
  34. * @brief Declaration of the Blender 3D (*.blend) importer class.
  35. */
  36. #ifndef INCLUDED_AI_BLEND_LOADER_H
  37. #define INCLUDED_AI_BLEND_LOADER_H
  38. #include "BaseImporter.h"
  39. namespace Assimp {
  40. // TinyFormatter.h
  41. namespace Formatter {
  42. template <typename T,typename TR, typename A> class basic_formatter;
  43. typedef class basic_formatter< char, std::char_traits<char>, std::allocator<char> > format;
  44. }
  45. // BlenderDNA.h
  46. namespace Blender {
  47. class FileDatabase;
  48. struct ElemBase;
  49. }
  50. // BlenderScene.h
  51. namespace Blender {
  52. struct Scene;
  53. struct Object;
  54. struct Mesh;
  55. struct Camera;
  56. struct Lamp;
  57. struct MTex;
  58. struct Image;
  59. struct Material;
  60. }
  61. // BlenderIntermediate.h
  62. namespace Blender {
  63. struct ConversionData;
  64. template <template <typename,typename> class TCLASS, typename T> struct TempArray;
  65. }
  66. // BlenderModifier.h
  67. namespace Blender {
  68. class BlenderModifierShowcase;
  69. class BlenderModifier;
  70. }
  71. enum aiLoaderFlags
  72. {
  73. aiLoaderFlags_SupportAsciiFlavour = 0x1,
  74. aiLoaderFlags_SupportBinaryFlavour = 0x2,
  75. aiLoaderFlags_SupportCompressedFlavour = 0x4,
  76. aiLoaderFlags_LimitedSupport = 0x8,
  77. aiLoaderFlags_Experimental = 0x10,
  78. aiLoaderFlags_Testing = 0x20,
  79. aiLoaderFlags_Production = 0x40,
  80. };
  81. struct aiLoaderDesc
  82. {
  83. const char* mName;
  84. const char* mAuthor;
  85. const char* mMaintainer;
  86. const char* mComments;
  87. unsigned int mFlags;
  88. unsigned int mMinMajor;
  89. unsigned int mMinMinor;
  90. unsigned int mMaxMajor;
  91. unsigned int mMaxMinor;
  92. };
  93. // -------------------------------------------------------------------------------------------
  94. /** Load blenders official binary format. The actual file structure (the `DNA` how they
  95. * call it is outsourced to BlenderDNA.cpp/BlenderDNA.h. This class only performs the
  96. * conversion from intermediate format to aiScene. */
  97. // -------------------------------------------------------------------------------------------
  98. class BlenderImporter : public BaseImporter
  99. {
  100. friend class Importer;
  101. protected:
  102. /** Constructor to be privately used by Importer */
  103. BlenderImporter();
  104. /** Destructor, private as well */
  105. ~BlenderImporter();
  106. public:
  107. // --------------------
  108. bool CanRead( const std::string& pFile,
  109. IOSystem* pIOHandler,
  110. bool checkSig
  111. ) const;
  112. protected:
  113. // --------------------
  114. const aiLoaderDesc& GetInfo () const;
  115. // --------------------
  116. void GetExtensionList(std::set<std::string>& app);
  117. // --------------------
  118. void SetupProperties(const Importer* pImp);
  119. // --------------------
  120. void InternReadFile( const std::string& pFile,
  121. aiScene* pScene,
  122. IOSystem* pIOHandler
  123. );
  124. // --------------------
  125. void ParseBlendFile(Blender::FileDatabase& out,
  126. boost::shared_ptr<IOStream> stream
  127. );
  128. // --------------------
  129. void ExtractScene(Blender::Scene& out,
  130. const Blender::FileDatabase& file
  131. );
  132. // --------------------
  133. void ConvertBlendFile(aiScene* out,
  134. const Blender::Scene& in,
  135. const Blender::FileDatabase& file
  136. );
  137. private:
  138. // --------------------
  139. aiNode* ConvertNode(const Blender::Scene& in,
  140. const Blender::Object* obj,
  141. Blender::ConversionData& conv_info
  142. );
  143. // --------------------
  144. void ConvertMesh(const Blender::Scene& in,
  145. const Blender::Object* obj,
  146. const Blender::Mesh* mesh,
  147. Blender::ConversionData& conv_data,
  148. Blender::TempArray<std::vector,aiMesh>& temp
  149. );
  150. // --------------------
  151. aiLight* ConvertLight(const Blender::Scene& in,
  152. const Blender::Object* obj,
  153. const Blender::Lamp* mesh,
  154. Blender::ConversionData& conv_data
  155. );
  156. // --------------------
  157. aiCamera* ConvertCamera(const Blender::Scene& in,
  158. const Blender::Object* obj,
  159. const Blender::Camera* mesh,
  160. Blender::ConversionData& conv_data
  161. );
  162. // --------------------
  163. void BuildMaterials(
  164. Blender::ConversionData& conv_data
  165. ) ;
  166. // --------------------
  167. void ResolveTexture(
  168. MaterialHelper* out,
  169. const Blender::Material* mat,
  170. const Blender::MTex* tex,
  171. Blender::ConversionData& conv_data
  172. );
  173. // --------------------
  174. void ResolveImage(
  175. MaterialHelper* out,
  176. const Blender::Material* mat,
  177. const Blender::MTex* tex,
  178. const Blender::Image* img,
  179. Blender::ConversionData& conv_data
  180. );
  181. void AddSentinelTexture(
  182. MaterialHelper* out,
  183. const Blender::Material* mat,
  184. const Blender::MTex* tex,
  185. Blender::ConversionData& conv_data
  186. );
  187. private: // static stuff, mostly logging and error reporting.
  188. // --------------------
  189. static void CheckActualType(const Blender::ElemBase* dt,
  190. const char* check
  191. );
  192. // --------------------
  193. static void NotSupportedObjectType(const Blender::Object* obj,
  194. const char* type
  195. );
  196. // -------------------------------------------------------------------
  197. /** Prepend 'BLEND: ' and throw msg.*/
  198. static void ThrowException(const std::string& msg);
  199. // -------------------------------------------------------------------
  200. /** @defgroup blog Prepend 'BLEND: ' and write @c message to log.*/
  201. static void LogWarn (const Formatter::format& message); //! @ingroup blog
  202. static void LogError (const Formatter::format& message); //! @ingroup blog
  203. static void LogInfo (const Formatter::format& message); //! @ingroup blog
  204. static void LogDebug (const Formatter::format& message); //! @ingroup blog
  205. private:
  206. Blender::BlenderModifierShowcase* modifier_cache;
  207. }; // !class BlenderImporter
  208. } // end of namespace Assimp
  209. #endif // AI_UNREALIMPORTER_H_INC