BlenderLoader.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2020, 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 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 <assimp/BaseImporter.h>
  39. #include <assimp/LogAux.h>
  40. #include <memory>
  41. struct aiNode;
  42. struct aiMesh;
  43. struct aiLight;
  44. struct aiCamera;
  45. struct aiMaterial;
  46. namespace Assimp {
  47. // TinyFormatter.h
  48. namespace Formatter {
  49. template <typename T,typename TR, typename A> class basic_formatter;
  50. typedef class basic_formatter< char, std::char_traits<char>, std::allocator<char> > format;
  51. }
  52. // BlenderDNA.h
  53. namespace Blender {
  54. class FileDatabase;
  55. struct ElemBase;
  56. }
  57. // BlenderScene.h
  58. namespace Blender {
  59. struct Scene;
  60. struct Object;
  61. struct Mesh;
  62. struct Camera;
  63. struct Lamp;
  64. struct MTex;
  65. struct Image;
  66. struct Material;
  67. }
  68. // BlenderIntermediate.h
  69. namespace Blender {
  70. struct ConversionData;
  71. template <template <typename,typename> class TCLASS, typename T> struct TempArray;
  72. }
  73. // BlenderModifier.h
  74. namespace Blender {
  75. class BlenderModifierShowcase;
  76. class BlenderModifier;
  77. }
  78. // -------------------------------------------------------------------------------------------
  79. /** Load blenders official binary format. The actual file structure (the `DNA` how they
  80. * call it is outsourced to BlenderDNA.cpp/BlenderDNA.h. This class only performs the
  81. * conversion from intermediate format to aiScene. */
  82. // -------------------------------------------------------------------------------------------
  83. class BlenderImporter : public BaseImporter, public LogFunctions<BlenderImporter>
  84. {
  85. public:
  86. BlenderImporter();
  87. ~BlenderImporter();
  88. public:
  89. // --------------------
  90. bool CanRead( const std::string& pFile,
  91. IOSystem* pIOHandler,
  92. bool checkSig
  93. ) const;
  94. protected:
  95. // --------------------
  96. const aiImporterDesc* GetInfo () const;
  97. // --------------------
  98. void GetExtensionList(std::set<std::string>& app);
  99. // --------------------
  100. void SetupProperties(const Importer* pImp);
  101. // --------------------
  102. void InternReadFile( const std::string& pFile,
  103. aiScene* pScene,
  104. IOSystem* pIOHandler
  105. );
  106. // --------------------
  107. void ParseBlendFile(Blender::FileDatabase& out,
  108. std::shared_ptr<IOStream> stream
  109. );
  110. // --------------------
  111. void ExtractScene(Blender::Scene& out,
  112. const Blender::FileDatabase& file
  113. );
  114. // --------------------
  115. void ConvertBlendFile(aiScene* out,
  116. const Blender::Scene& in,
  117. const Blender::FileDatabase& file
  118. );
  119. private:
  120. // --------------------
  121. aiNode* ConvertNode(const Blender::Scene& in,
  122. const Blender::Object* obj,
  123. Blender::ConversionData& conv_info,
  124. const aiMatrix4x4& parentTransform
  125. );
  126. // --------------------
  127. void ConvertMesh(const Blender::Scene& in,
  128. const Blender::Object* obj,
  129. const Blender::Mesh* mesh,
  130. Blender::ConversionData& conv_data,
  131. Blender::TempArray<std::vector,aiMesh>& temp
  132. );
  133. // --------------------
  134. aiLight* ConvertLight(const Blender::Scene& in,
  135. const Blender::Object* obj,
  136. const Blender::Lamp* mesh,
  137. Blender::ConversionData& conv_data
  138. );
  139. // --------------------
  140. aiCamera* ConvertCamera(const Blender::Scene& in,
  141. const Blender::Object* obj,
  142. const Blender::Camera* mesh,
  143. Blender::ConversionData& conv_data
  144. );
  145. // --------------------
  146. void BuildDefaultMaterial(
  147. Blender::ConversionData& conv_data
  148. );
  149. void AddBlendParams(
  150. aiMaterial* result,
  151. const Blender::Material* source
  152. );
  153. void BuildMaterials(
  154. Blender::ConversionData& conv_data
  155. );
  156. // --------------------
  157. void ResolveTexture(
  158. aiMaterial* out,
  159. const Blender::Material* mat,
  160. const Blender::MTex* tex,
  161. Blender::ConversionData& conv_data
  162. );
  163. // --------------------
  164. void ResolveImage(
  165. aiMaterial* out,
  166. const Blender::Material* mat,
  167. const Blender::MTex* tex,
  168. const Blender::Image* img,
  169. Blender::ConversionData& conv_data
  170. );
  171. void AddSentinelTexture(
  172. aiMaterial* out,
  173. const Blender::Material* mat,
  174. const Blender::MTex* tex,
  175. Blender::ConversionData& conv_data
  176. );
  177. private: // static stuff, mostly logging and error reporting.
  178. // --------------------
  179. static void CheckActualType(const Blender::ElemBase* dt,
  180. const char* check
  181. );
  182. // --------------------
  183. static void NotSupportedObjectType(const Blender::Object* obj,
  184. const char* type
  185. );
  186. private:
  187. Blender::BlenderModifierShowcase* modifier_cache;
  188. }; // !class BlenderImporter
  189. } // end of namespace Assimp
  190. #endif // AI_UNREALIMPORTER_H_INC