1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2017, assimp team
6
7All rights reserved.
8
9Redistribution and use of this software in source and binary forms,
10with or without modification, are permitted provided that the
11following 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
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37OF 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 "BaseProcess.h"
49#include "ProcessHelper.h"
50#include <assimp/types.h>
51#include <set>
52
53struct aiMesh;
54class OptimizeGraphProcessTest;
55namespace Assimp {
56
57// -----------------------------------------------------------------------------
58/** @brief Postprocessing step to optimize the scenegraph
59 *
60 * The implementation tries to merge nodes, even if they use different
61 * transformations. Animations are preserved.
62 *
63 * @see aiProcess_OptimizeGraph for a detailed description of the
64 * algorithm being applied.
65 */
66class OptimizeGraphProcess : public BaseProcess
67{
68public:
69
70 OptimizeGraphProcess();
71 ~OptimizeGraphProcess();
72
73public:
74 // -------------------------------------------------------------------
75 bool IsActive( unsigned int pFlags) const;
76
77 // -------------------------------------------------------------------
78 void Execute( aiScene* pScene);
79
80 // -------------------------------------------------------------------
81 void SetupProperties(const Importer* pImp);
82
83
84 // -------------------------------------------------------------------
85 /** @brief Add a list of node names to be locked and not modified.
86 * @param in List of nodes. See #AI_CONFIG_PP_OG_EXCLUDE_LIST for
87 * format explanations.
88 */
89 inline void AddLockedNodeList(std::string& in)
90 {
91 ConvertListToStrings (in,locked_nodes);
92 }
93
94 // -------------------------------------------------------------------
95 /** @brief Add another node to be locked and not modified.
96 * @param name Name to be locked
97 */
98 inline void AddLockedNode(std::string& name)
99 {
100 locked_nodes.push_back(name);
101 }
102
103 // -------------------------------------------------------------------
104 /** @brief Rmeove a node from the list of locked nodes.
105 * @param name Name to be unlocked
106 */
107 inline void RemoveLockedNode(std::string& name)
108 {
109 locked_nodes.remove(name);
110 }
111
112protected:
113
114 void CollectNewChildren(aiNode* nd, std::list<aiNode*>& nodes);
115 void FindInstancedMeshes (aiNode* pNode);
116
117private:
118
119#ifdef AI_OG_USE_HASHING
120 typedef std::set<unsigned int> LockedSetType;
121#else
122 typedef std::set<std::string> LockedSetType;
123#endif
124
125
126 //! Scene we're working with
127 aiScene* mScene;
128
129 //! List of locked names. Stored is the hash of the name
130 LockedSetType locked;
131
132 //! List of nodes to be locked in addition to those with animations, lights or cameras assigned.
133 std::list<std::string> locked_nodes;
134
135 //! Node counters for logging purposes
136 unsigned int nodes_in,nodes_out, count_merged;
137
138 //! Reference counters for meshes
139 std::vector<unsigned int> meshes;
140};
141
142} // end of namespace Assimp
143
144#endif // AI_OPTIMIZEGRAPHPROCESS_H_INC
145