BlenderLoader.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2021, 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. bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
  89. protected:
  90. const aiImporterDesc* GetInfo () const;
  91. void SetupProperties(const Importer* pImp);
  92. void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
  93. void ParseBlendFile(Blender::FileDatabase& out, std::shared_ptr<IOStream> stream);
  94. void ExtractScene(Blender::Scene& out, const Blender::FileDatabase& file);
  95. void ConvertBlendFile(aiScene* out, const Blender::Scene& in, const Blender::FileDatabase& file);
  96. private:
  97. aiNode* ConvertNode(const Blender::Scene& in,
  98. const Blender::Object* obj,
  99. Blender::ConversionData& conv_info,
  100. const aiMatrix4x4& parentTransform
  101. );
  102. // --------------------
  103. void ConvertMesh(const Blender::Scene& in,
  104. const Blender::Object* obj,
  105. const Blender::Mesh* mesh,
  106. Blender::ConversionData& conv_data,
  107. Blender::TempArray<std::vector,aiMesh>& temp
  108. );
  109. // --------------------
  110. aiLight* ConvertLight(const Blender::Scene& in,
  111. const Blender::Object* obj,
  112. const Blender::Lamp* mesh,
  113. Blender::ConversionData& conv_data
  114. );
  115. // --------------------
  116. aiCamera* ConvertCamera(const Blender::Scene& in,
  117. const Blender::Object* obj,
  118. const Blender::Camera* mesh,
  119. Blender::ConversionData& conv_data
  120. );
  121. // --------------------
  122. void BuildDefaultMaterial(
  123. Blender::ConversionData& conv_data
  124. );
  125. void AddBlendParams(
  126. aiMaterial* result,
  127. const Blender::Material* source
  128. );
  129. void BuildMaterials(
  130. Blender::ConversionData& conv_data
  131. );
  132. // --------------------
  133. void ResolveTexture(
  134. aiMaterial* out,
  135. const Blender::Material* mat,
  136. const Blender::MTex* tex,
  137. Blender::ConversionData& conv_data
  138. );
  139. // --------------------
  140. void ResolveImage(
  141. aiMaterial* out,
  142. const Blender::Material* mat,
  143. const Blender::MTex* tex,
  144. const Blender::Image* img,
  145. Blender::ConversionData& conv_data
  146. );
  147. void AddSentinelTexture(
  148. aiMaterial* out,
  149. const Blender::Material* mat,
  150. const Blender::MTex* tex,
  151. Blender::ConversionData& conv_data
  152. );
  153. private: // static stuff, mostly logging and error reporting.
  154. // --------------------
  155. static void CheckActualType(const Blender::ElemBase* dt,
  156. const char* check
  157. );
  158. // --------------------
  159. static void NotSupportedObjectType(const Blender::Object* obj,
  160. const char* type
  161. );
  162. private:
  163. Blender::BlenderModifierShowcase* modifier_cache;
  164. }; // !class BlenderImporter
  165. } // end of namespace Assimp
  166. #endif // AI_UNREALIMPORTER_H_INC