/src/assimp/code/PostProcessing/OptimizeGraph.h
Line | Count | Source |
1 | | /* |
2 | | Open Asset Import Library (assimp) |
3 | | ---------------------------------------------------------------------- |
4 | | |
5 | | Copyright (c) 2006-2026, assimp team |
6 | | |
7 | | All rights reserved. |
8 | | |
9 | | Redistribution and use of this software in source and binary forms, |
10 | | with or without modification, are permitted provided that the |
11 | | following conditions are met: |
12 | | |
13 | | * Redistributions of source code must retain the above |
14 | | copyright notice, this list of conditions and the |
15 | | following disclaimer. |
16 | | |
17 | | * Redistributions in binary form must reproduce the above |
18 | | copyright notice, this list of conditions and the |
19 | | following disclaimer in the documentation and/or other |
20 | | materials provided with the distribution. |
21 | | |
22 | | * Neither the name of the assimp team, nor the names of its |
23 | | contributors may be used to endorse or promote products |
24 | | derived from this software without specific prior |
25 | | written permission of the assimp team. |
26 | | |
27 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
30 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
31 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
32 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
33 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
34 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
35 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
36 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
37 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | | |
39 | | ---------------------------------------------------------------------- |
40 | | */ |
41 | | |
42 | | /** @file OptimizeGraph.h |
43 | | * @brief Declares a post processing step to optimize the scenegraph |
44 | | */ |
45 | | #ifndef AI_OPTIMIZEGRAPHPROCESS_H_INC |
46 | | #define AI_OPTIMIZEGRAPHPROCESS_H_INC |
47 | | |
48 | | #include "Common/BaseProcess.h" |
49 | | #include "PostProcessing/ProcessHelper.h" |
50 | | |
51 | | #include <assimp/types.h> |
52 | | |
53 | | #include <set> |
54 | | |
55 | | // Forward declarations |
56 | | struct aiMesh; |
57 | | |
58 | | class OptimizeGraphProcessTest; |
59 | | |
60 | | namespace Assimp { |
61 | | |
62 | | // ----------------------------------------------------------------------------- |
63 | | /** @brief Postprocessing step to optimize the scenegraph |
64 | | * |
65 | | * The implementation tries to merge nodes, even if they use different |
66 | | * transformations. Animations are preserved. |
67 | | * |
68 | | * @see aiProcess_OptimizeGraph for a detailed description of the |
69 | | * algorithm being applied. |
70 | | */ |
71 | | class OptimizeGraphProcess : public BaseProcess { |
72 | | public: |
73 | | // ------------------------------------------------------------------- |
74 | | /// The default class constructor / destructor. |
75 | | OptimizeGraphProcess(); |
76 | 12.0k | ~OptimizeGraphProcess() override = default; |
77 | | |
78 | | // ------------------------------------------------------------------- |
79 | | bool IsActive( unsigned int pFlags) const override; |
80 | | |
81 | | // ------------------------------------------------------------------- |
82 | | void Execute( aiScene* pScene) override; |
83 | | |
84 | | // ------------------------------------------------------------------- |
85 | | void SetupProperties(const Importer* pImp) override; |
86 | | |
87 | | // ------------------------------------------------------------------- |
88 | | /** @brief Add a list of node names to be locked and not modified. |
89 | | * @param in List of nodes. See #AI_CONFIG_PP_OG_EXCLUDE_LIST for |
90 | | * format explanations. |
91 | | */ |
92 | 0 | inline void AddLockedNodeList(std::string& in) { |
93 | 0 | ConvertListToStrings (in,locked_nodes); |
94 | 0 | } |
95 | | |
96 | | // ------------------------------------------------------------------- |
97 | | /** @brief Add another node to be locked and not modified. |
98 | | * @param name Name to be locked |
99 | | */ |
100 | 0 | inline void AddLockedNode(std::string& name) { |
101 | 0 | locked_nodes.push_back(name); |
102 | 0 | } |
103 | | |
104 | | // ------------------------------------------------------------------- |
105 | | /** @brief Remove a node from the list of locked nodes. |
106 | | * @param name Name to be unlocked |
107 | | */ |
108 | 0 | inline void RemoveLockedNode(std::string& name) { |
109 | 0 | locked_nodes.remove(name); |
110 | 0 | } |
111 | | |
112 | | protected: |
113 | | void CollectNewChildren(aiNode* nd, std::list<aiNode*>& nodes); |
114 | | void FindInstancedMeshes (aiNode* pNode); |
115 | | |
116 | | private: |
117 | | #ifdef AI_OG_USE_HASHING |
118 | | typedef std::set<unsigned int> LockedSetType; |
119 | | #else |
120 | | typedef std::set<std::string> LockedSetType; |
121 | | #endif |
122 | | |
123 | | //! Scene we're working with |
124 | | aiScene* mScene; |
125 | | |
126 | | //! List of locked names. Stored is the hash of the name |
127 | | LockedSetType locked; |
128 | | |
129 | | //! List of nodes to be locked in addition to those with animations, lights or cameras assigned. |
130 | | std::list<std::string> locked_nodes; |
131 | | |
132 | | //! Node counters for logging purposes |
133 | | unsigned int nodes_in,nodes_out, count_merged; |
134 | | |
135 | | //! Reference counters for meshes |
136 | | std::vector<unsigned int> meshes; |
137 | | }; |
138 | | |
139 | | } // end of namespace Assimp |
140 | | |
141 | | #endif // AI_OPTIMIZEGRAPHPROCESS_H_INC |