BlenderIntermediate.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2025, 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 BlenderIntermediate.h
  34. * @brief Internal utility structures for the BlenderLoader. It also serves
  35. * as master include file for the whole (internal) Blender subsystem.
  36. */
  37. #ifndef INCLUDED_AI_BLEND_INTERMEDIATE_H
  38. #define INCLUDED_AI_BLEND_INTERMEDIATE_H
  39. #include "BlenderLoader.h"
  40. #include "BlenderDNA.h"
  41. #include "BlenderScene.h"
  42. #include <deque>
  43. #include <assimp/material.h>
  44. struct aiTexture;
  45. namespace Assimp {
  46. namespace Blender {
  47. // --------------------------------------------------------------------
  48. /** Mini smart-array to avoid pulling in even more boost stuff. usable with vector and deque */
  49. // --------------------------------------------------------------------
  50. template <template <typename,typename> class TCLASS, typename T>
  51. struct TempArray {
  52. typedef TCLASS< T*,std::allocator<T*> > mywrap;
  53. TempArray() = default;
  54. ~TempArray () {
  55. for(T* elem : arr) {
  56. delete elem;
  57. }
  58. }
  59. void dismiss() {
  60. arr.clear();
  61. }
  62. mywrap* operator -> () {
  63. return &arr;
  64. }
  65. operator mywrap& () {
  66. return arr;
  67. }
  68. operator const mywrap& () const {
  69. return arr;
  70. }
  71. mywrap& get () {
  72. return arr;
  73. }
  74. const mywrap& get () const {
  75. return arr;
  76. }
  77. T* operator[] (size_t idx) const {
  78. return arr[idx];
  79. }
  80. T*& operator[] (size_t idx) {
  81. return arr[idx];
  82. }
  83. private:
  84. // no copy semantics
  85. void operator= (const TempArray&) {
  86. }
  87. TempArray(const TempArray& /*arr*/) {
  88. }
  89. private:
  90. mywrap arr;
  91. };
  92. #ifdef _MSC_VER
  93. # pragma warning(disable:4351)
  94. #endif
  95. // As counter-intuitive as it may seem, a comparator must return false for equal values.
  96. // The C++ standard defines and expects this behavior: true if lhs < rhs, false otherwise.
  97. struct ObjectCompare {
  98. bool operator() (const Object* left, const Object* right) const {
  99. return ::strncmp(left->id.name, right->id.name, strlen( left->id.name ) ) < 0;
  100. }
  101. };
  102. // When keeping objects in sets, sort them by their name.
  103. typedef std::set<const Object*, ObjectCompare> ObjectSet;
  104. // --------------------------------------------------------------------
  105. /** ConversionData acts as intermediate storage location for
  106. * the various ConvertXXX routines in BlenderImporter.*/
  107. // --------------------------------------------------------------------
  108. struct ConversionData
  109. {
  110. ConversionData(const FileDatabase& db)
  111. : sentinel_cnt()
  112. , next_texture()
  113. , db(db)
  114. {}
  115. // As counter-intuitive as it may seem, a comparator must return false for equal values.
  116. // The C++ standard defines and expects this behavior: true if lhs < rhs, false otherwise.
  117. struct ObjectCompare {
  118. bool operator() (const Object* left, const Object* right) const {
  119. return ::strncmp( left->id.name, right->id.name, strlen( left->id.name ) ) < 0;
  120. }
  121. };
  122. ObjectSet objects;
  123. TempArray <std::vector, aiMesh> meshes;
  124. TempArray <std::vector, aiCamera> cameras;
  125. TempArray <std::vector, aiLight> lights;
  126. TempArray <std::vector, aiMaterial> materials;
  127. TempArray <std::vector, aiTexture> textures;
  128. // set of all materials referenced by at least one mesh in the scene
  129. std::deque< std::shared_ptr< Material > > materials_raw;
  130. // counter to name sentinel textures inserted as substitutes for procedural textures.
  131. unsigned int sentinel_cnt;
  132. // next texture ID for each texture type, respectively
  133. unsigned int next_texture[aiTextureType_UNKNOWN+1];
  134. // original file data
  135. const FileDatabase& db;
  136. };
  137. #ifdef _MSC_VER
  138. # pragma warning(default:4351)
  139. #endif
  140. // ------------------------------------------------------------------------------------------------
  141. inline const char* GetTextureTypeDisplayString(Tex::Type t)
  142. {
  143. switch (t) {
  144. case Tex::Type_CLOUDS : return "Clouds";
  145. case Tex::Type_WOOD : return "Wood";
  146. case Tex::Type_MARBLE : return "Marble";
  147. case Tex::Type_MAGIC : return "Magic";
  148. case Tex::Type_BLEND : return "Blend";
  149. case Tex::Type_STUCCI : return "Stucci";
  150. case Tex::Type_NOISE : return "Noise";
  151. case Tex::Type_PLUGIN : return "Plugin";
  152. case Tex::Type_MUSGRAVE : return "Musgrave";
  153. case Tex::Type_VORONOI : return "Voronoi";
  154. case Tex::Type_DISTNOISE : return "DistortedNoise";
  155. case Tex::Type_ENVMAP : return "EnvMap";
  156. case Tex::Type_IMAGE : return "Image";
  157. default:
  158. break;
  159. }
  160. return "<Unknown>";
  161. }
  162. } // ! Blender
  163. } // ! Assimp
  164. #endif // ! INCLUDED_AI_BLEND_INTERMEDIATE_H