2
0

OptimizeGraph.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 OptimizeGraph.h
  34. * @brief Declares a post processing step to optimize the scenegraph
  35. */
  36. #ifndef AI_OPTIMIZEGRAPHPROCESS_H_INC
  37. #define AI_OPTIMIZEGRAPHPROCESS_H_INC
  38. #include "Common/BaseProcess.h"
  39. #include "PostProcessing/ProcessHelper.h"
  40. #include <assimp/types.h>
  41. #include <set>
  42. // Forward declarations
  43. struct aiMesh;
  44. class OptimizeGraphProcessTest;
  45. namespace Assimp {
  46. // -----------------------------------------------------------------------------
  47. /** @brief Postprocessing step to optimize the scenegraph
  48. *
  49. * The implementation tries to merge nodes, even if they use different
  50. * transformations. Animations are preserved.
  51. *
  52. * @see aiProcess_OptimizeGraph for a detailed description of the
  53. * algorithm being applied.
  54. */
  55. class OptimizeGraphProcess : public BaseProcess {
  56. public:
  57. // -------------------------------------------------------------------
  58. /// The default class constructor / destructor.
  59. OptimizeGraphProcess();
  60. ~OptimizeGraphProcess() override = default;
  61. // -------------------------------------------------------------------
  62. bool IsActive( unsigned int pFlags) const override;
  63. // -------------------------------------------------------------------
  64. void Execute( aiScene* pScene) override;
  65. // -------------------------------------------------------------------
  66. void SetupProperties(const Importer* pImp) override;
  67. // -------------------------------------------------------------------
  68. /** @brief Add a list of node names to be locked and not modified.
  69. * @param in List of nodes. See #AI_CONFIG_PP_OG_EXCLUDE_LIST for
  70. * format explanations.
  71. */
  72. inline void AddLockedNodeList(std::string& in) {
  73. ConvertListToStrings (in,locked_nodes);
  74. }
  75. // -------------------------------------------------------------------
  76. /** @brief Add another node to be locked and not modified.
  77. * @param name Name to be locked
  78. */
  79. inline void AddLockedNode(std::string& name) {
  80. locked_nodes.push_back(name);
  81. }
  82. // -------------------------------------------------------------------
  83. /** @brief Remove a node from the list of locked nodes.
  84. * @param name Name to be unlocked
  85. */
  86. inline void RemoveLockedNode(std::string& name) {
  87. locked_nodes.remove(name);
  88. }
  89. protected:
  90. void CollectNewChildren(aiNode* nd, std::list<aiNode*>& nodes);
  91. void FindInstancedMeshes (aiNode* pNode);
  92. private:
  93. #ifdef AI_OG_USE_HASHING
  94. typedef std::set<unsigned int> LockedSetType;
  95. #else
  96. typedef std::set<std::string> LockedSetType;
  97. #endif
  98. //! Scene we're working with
  99. aiScene* mScene;
  100. //! List of locked names. Stored is the hash of the name
  101. LockedSetType locked;
  102. //! List of nodes to be locked in addition to those with animations, lights or cameras assigned.
  103. std::list<std::string> locked_nodes;
  104. //! Node counters for logging purposes
  105. unsigned int nodes_in,nodes_out, count_merged;
  106. //! Reference counters for meshes
  107. std::vector<unsigned int> meshes;
  108. };
  109. } // end of namespace Assimp
  110. #endif // AI_OPTIMIZEGRAPHPROCESS_H_INC