SplitLargeMeshes.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 Defines a post processing step to split large meshes into sub-meshes
  34. */
  35. #ifndef AI_SPLITLARGEMESHES_H_INC
  36. #define AI_SPLITLARGEMESHES_H_INC
  37. #include <vector>
  38. #include "Common/BaseProcess.h"
  39. #include <assimp/mesh.h>
  40. #include <assimp/scene.h>
  41. // Forward declarations
  42. class SplitLargeMeshesTest;
  43. namespace Assimp {
  44. class SplitLargeMeshesProcess_Triangle;
  45. class SplitLargeMeshesProcess_Vertex;
  46. // NOTE: If you change these limits, don't forget to change the
  47. // corresponding values in all Assimp ports
  48. // **********************************************************
  49. // Java: ConfigProperty.java,
  50. // ConfigProperty.DEFAULT_VERTEX_SPLIT_LIMIT
  51. // ConfigProperty.DEFAULT_TRIANGLE_SPLIT_LIMIT
  52. // **********************************************************
  53. // default limit for vertices
  54. #if (!defined AI_SLM_DEFAULT_MAX_VERTICES)
  55. # define AI_SLM_DEFAULT_MAX_VERTICES 1000000
  56. #endif
  57. // default limit for triangles
  58. #if (!defined AI_SLM_DEFAULT_MAX_TRIANGLES)
  59. # define AI_SLM_DEFAULT_MAX_TRIANGLES 1000000
  60. #endif
  61. // ---------------------------------------------------------------------------
  62. /** Post-processing filter to split large meshes into sub-meshes
  63. *
  64. * Applied BEFORE the JoinVertices-Step occurs.
  65. * Returns NON-UNIQUE vertices, splits by triangle number.
  66. */
  67. class ASSIMP_API SplitLargeMeshesProcess_Triangle : public BaseProcess
  68. {
  69. friend class SplitLargeMeshesProcess_Vertex;
  70. public:
  71. SplitLargeMeshesProcess_Triangle();
  72. ~SplitLargeMeshesProcess_Triangle();
  73. public:
  74. // -------------------------------------------------------------------
  75. /** Returns whether the processing step is present in the given flag.
  76. * @param pFlags The processing flags the importer was called with. A
  77. * bitwise combination of #aiPostProcessSteps.
  78. * @return true if the process is present in this flag fields,
  79. * false if not.
  80. */
  81. bool IsActive( unsigned int pFlags) const;
  82. // -------------------------------------------------------------------
  83. /** Called prior to ExecuteOnScene().
  84. * The function is a request to the process to update its configuration
  85. * basing on the Importer's configuration property list.
  86. */
  87. virtual void SetupProperties(const Importer* pImp);
  88. //! Set the split limit - needed for unit testing
  89. inline void SetLimit(unsigned int l)
  90. {LIMIT = l;}
  91. //! Get the split limit
  92. inline unsigned int GetLimit() const
  93. {return LIMIT;}
  94. public:
  95. // -------------------------------------------------------------------
  96. /** Executes the post processing step on the given imported data.
  97. * At the moment a process is not supposed to fail.
  98. * @param pScene The imported data to work at.
  99. */
  100. void Execute( aiScene* pScene);
  101. // -------------------------------------------------------------------
  102. //! Apply the algorithm to a given mesh
  103. void SplitMesh (unsigned int a, aiMesh* pcMesh,
  104. std::vector<std::pair<aiMesh*, unsigned int> >& avList);
  105. // -------------------------------------------------------------------
  106. //! Update a node in the asset after a few of its meshes
  107. //! have been split
  108. static void UpdateNode(aiNode* pcNode,
  109. const std::vector<std::pair<aiMesh*, unsigned int> >& avList);
  110. public:
  111. //! Triangle limit
  112. unsigned int LIMIT;
  113. };
  114. // ---------------------------------------------------------------------------
  115. /** Post-processing filter to split large meshes into sub-meshes
  116. *
  117. * Applied AFTER the JoinVertices-Step occurs.
  118. * Returns UNIQUE vertices, splits by vertex number.
  119. */
  120. class ASSIMP_API SplitLargeMeshesProcess_Vertex : public BaseProcess
  121. {
  122. public:
  123. SplitLargeMeshesProcess_Vertex();
  124. ~SplitLargeMeshesProcess_Vertex();
  125. public:
  126. // -------------------------------------------------------------------
  127. /** Returns whether the processing step is present in the given flag field.
  128. * @param pFlags The processing flags the importer was called with. A bitwise
  129. * combination of #aiPostProcessSteps.
  130. * @return true if the process is present in this flag fields, false if not.
  131. */
  132. bool IsActive( unsigned int pFlags) const;
  133. // -------------------------------------------------------------------
  134. /** Called prior to ExecuteOnScene().
  135. * The function is a request to the process to update its configuration
  136. * basing on the Importer's configuration property list.
  137. */
  138. virtual void SetupProperties(const Importer* pImp);
  139. //! Set the split limit - needed for unit testing
  140. inline void SetLimit(unsigned int l)
  141. {LIMIT = l;}
  142. //! Get the split limit
  143. inline unsigned int GetLimit() const
  144. {return LIMIT;}
  145. public:
  146. // -------------------------------------------------------------------
  147. /** Executes the post processing step on the given imported data.
  148. * At the moment a process is not supposed to fail.
  149. * @param pScene The imported data to work at.
  150. */
  151. void Execute( aiScene* pScene);
  152. // -------------------------------------------------------------------
  153. //! Apply the algorithm to a given mesh
  154. void SplitMesh (unsigned int a, aiMesh* pcMesh,
  155. std::vector<std::pair<aiMesh*, unsigned int> >& avList);
  156. // NOTE: Reuse SplitLargeMeshesProcess_Triangle::UpdateNode()
  157. public:
  158. //! Triangle limit
  159. unsigned int LIMIT;
  160. };
  161. } // end of namespace Assimp
  162. #endif // !!AI_SPLITLARGEMESHES_H_INC