/src/assimp/code/PostProcessing/OptimizeMeshes.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | Open Asset Import Library (assimp) |
3 | | ---------------------------------------------------------------------- |
4 | | |
5 | | Copyright (c) 2006-2025, 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 OptimizeMeshes.h |
43 | | * @brief Declares a post processing step to join meshes, if possible |
44 | | */ |
45 | | #ifndef AI_OPTIMIZEMESHESPROCESS_H_INC |
46 | | #define AI_OPTIMIZEMESHESPROCESS_H_INC |
47 | | |
48 | | #include "Common/BaseProcess.h" |
49 | | |
50 | | #include <assimp/types.h> |
51 | | |
52 | | #include <vector> |
53 | | |
54 | | struct aiMesh; |
55 | | struct aiNode; |
56 | | class OptimizeMeshesProcessTest; |
57 | | |
58 | | namespace Assimp { |
59 | | |
60 | | // --------------------------------------------------------------------------- |
61 | | /** @brief Postprocessing step to optimize mesh usage |
62 | | * |
63 | | * The implementation looks for meshes that could be joined and joins them. |
64 | | * Usually this will reduce the number of drawcalls. |
65 | | * |
66 | | * @note Instanced meshes are currently not processed. |
67 | | */ |
68 | | class OptimizeMeshesProcess : public BaseProcess { |
69 | | public: |
70 | | // ------------------------------------------------------------------- |
71 | | /// The default class constructor / destructor. |
72 | | OptimizeMeshesProcess(); |
73 | 1.77k | ~OptimizeMeshesProcess() override = default; |
74 | | |
75 | | /** @brief Internal utility to store additional mesh info |
76 | | */ |
77 | | struct MeshInfo { |
78 | | MeshInfo() AI_NO_EXCEPT |
79 | 0 | : instance_cnt(0) |
80 | 0 | , vertex_format(0) |
81 | 0 | , output_id(0xffffffff) { |
82 | | // empty |
83 | 0 | } |
84 | | |
85 | | //! Number of times this mesh is referenced |
86 | | unsigned int instance_cnt; |
87 | | |
88 | | //! Vertex format id |
89 | | unsigned int vertex_format; |
90 | | |
91 | | //! Output ID |
92 | | unsigned int output_id; |
93 | | }; |
94 | | |
95 | | // ------------------------------------------------------------------- |
96 | | bool IsActive( unsigned int pFlags) const override; |
97 | | |
98 | | // ------------------------------------------------------------------- |
99 | | void Execute( aiScene* pScene) override; |
100 | | |
101 | | // ------------------------------------------------------------------- |
102 | | void SetupProperties(const Importer* pImp) override; |
103 | | |
104 | | // ------------------------------------------------------------------- |
105 | | /** @brief Specify whether you want meshes with different |
106 | | * primitive types to be merged as well. |
107 | | * |
108 | | * IsActive() sets this property automatically to true if the |
109 | | * aiProcess_SortByPType flag is found. |
110 | | */ |
111 | 0 | void EnablePrimitiveTypeSorting(bool enable) { |
112 | 0 | pts = enable; |
113 | 0 | } |
114 | | |
115 | | // Getter |
116 | 0 | bool IsPrimitiveTypeSortingEnabled () const { |
117 | 0 | return pts; |
118 | 0 | } |
119 | | |
120 | | |
121 | | // ------------------------------------------------------------------- |
122 | | /** @brief Specify a maximum size of a single output mesh. |
123 | | * |
124 | | * If a single input mesh already exceeds this limit, it won't |
125 | | * be split. |
126 | | * @param verts Maximum number of vertices per mesh |
127 | | * @param faces Maximum number of faces per mesh |
128 | | */ |
129 | | void SetPreferredMeshSizeLimit (unsigned int verts, unsigned int faces) |
130 | 0 | { |
131 | 0 | max_verts = verts; |
132 | 0 | max_faces = faces; |
133 | 0 | } |
134 | | |
135 | | |
136 | | protected: |
137 | | |
138 | | // ------------------------------------------------------------------- |
139 | | /** @brief Do the actual optimization on all meshes of this node |
140 | | * @param pNode Node we're working with |
141 | | */ |
142 | | void ProcessNode( aiNode* pNode); |
143 | | |
144 | | // ------------------------------------------------------------------- |
145 | | /** @brief Returns true if b can be joined with a |
146 | | * |
147 | | * @param verts Number of output verts up to now |
148 | | * @param faces Number of output faces up to now |
149 | | */ |
150 | | bool CanJoin ( unsigned int a, unsigned int b, |
151 | | unsigned int verts, unsigned int faces ); |
152 | | |
153 | | // ------------------------------------------------------------------- |
154 | | /** @brief Find instanced meshes, for the moment we're excluding |
155 | | * them from all optimizations |
156 | | */ |
157 | | void FindInstancedMeshes (aiNode* pNode); |
158 | | |
159 | | private: |
160 | | |
161 | | //! Scene we're working with |
162 | | aiScene* mScene; |
163 | | |
164 | | //! Per mesh info |
165 | | std::vector<MeshInfo> meshes; |
166 | | |
167 | | //! Output meshes |
168 | | std::vector<aiMesh*> output; |
169 | | |
170 | | //! @see EnablePrimitiveTypeSorting |
171 | | mutable bool pts; |
172 | | |
173 | | //! @see SetPreferredMeshSizeLimit |
174 | | mutable unsigned int max_verts,max_faces; |
175 | | |
176 | | //! Temporary storage |
177 | | std::vector<aiMesh*> merge_list; |
178 | | }; |
179 | | |
180 | | } // end of namespace Assimp |
181 | | |
182 | | #endif // AI_CALCTANGENTSPROCESS_H_INC |