vrshoot

view libs/assimp/OptimizeMeshes.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
21 * Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ----------------------------------------------------------------------
39 */
41 /** @file OptimizeMeshes.h
42 * @brief Declares a post processing step to join meshes, if possible
43 */
44 #ifndef AI_OPTIMIZEMESHESPROCESS_H_INC
45 #define AI_OPTIMIZEMESHESPROCESS_H_INC
47 #include "BaseProcess.h"
48 #include "assimp/types.h"
50 struct aiMesh;
51 class OptimizeMeshesProcessTest;
52 namespace Assimp {
54 // ---------------------------------------------------------------------------
55 /** @brief Postprocessing step to optimize mesh usage
56 *
57 * The implementation looks for meshes that could be joined and joins them.
58 * Usually this will reduce the number of drawcalls.
59 *
60 * @note Instanced meshes are currently not processed.
61 */
62 class OptimizeMeshesProcess : public BaseProcess
63 {
64 public:
66 OptimizeMeshesProcess();
67 ~OptimizeMeshesProcess();
70 /** @brief Internal utility to store additional mesh info
71 */
72 struct MeshInfo
73 {
74 MeshInfo()
75 : instance_cnt (0)
76 , vertex_format (0)
77 , output_id (0xffffffff)
78 {}
80 //! Number of times this mesh is referenced
81 unsigned int instance_cnt;
83 //! Vertex format id
84 unsigned int vertex_format;
86 //! Output ID
87 unsigned int output_id;
88 };
90 public:
91 // -------------------------------------------------------------------
92 bool IsActive( unsigned int pFlags) const;
94 // -------------------------------------------------------------------
95 void Execute( aiScene* pScene);
97 // -------------------------------------------------------------------
98 void SetupProperties(const Importer* pImp);
101 // -------------------------------------------------------------------
102 /** @brief Specify whether you want meshes with different
103 * primitive types to be merged as well.
104 *
105 * IsActive() sets this property automatically to true if the
106 * aiProcess_SortByPType flag is found.
107 */
108 void EnablePrimitiveTypeSorting(bool enable) {
109 pts = enable;
110 }
112 // Getter
113 bool IsPrimitiveTypeSortingEnabled () const {
114 return pts;
115 }
118 // -------------------------------------------------------------------
119 /** @brief Specify a maximum size of a single output mesh.
120 *
121 * If a single input mesh already exceeds this limit, it won't
122 * be split.
123 * @param verts Maximum number of vertices per mesh
124 * @param faces Maximum number of faces per mesh
125 */
126 void SetPreferredMeshSizeLimit (unsigned int verts, unsigned int faces)
127 {
128 max_verts = verts;
129 max_faces = faces;
130 }
133 protected:
135 // -------------------------------------------------------------------
136 /** @brief Do the actual optimization on all meshes of this node
137 * @param pNode Node we're working with
138 */
139 void ProcessNode( aiNode* pNode);
141 // -------------------------------------------------------------------
142 /** @brief Returns true if b can be joined with a
143 *
144 * @param verts Number of output verts up to now
145 * @param faces Number of output faces up to now
146 */
147 bool CanJoin ( unsigned int a, unsigned int b,
148 unsigned int verts, unsigned int faces );
150 // -------------------------------------------------------------------
151 /** @brief Find instanced meshes, for the moment we're excluding
152 * them from all optimizations
153 */
154 void FindInstancedMeshes (aiNode* pNode);
156 private:
158 //! Scene we're working with
159 aiScene* mScene;
161 //! Per mesh info
162 std::vector<MeshInfo> meshes;
164 //! Next output mesh
165 aiMesh* mesh;
167 //! Output meshes
168 std::vector<aiMesh*> output;
170 //! @see EnablePrimitiveTypeSorting
171 mutable bool pts;
173 //! @see SetPreferredMeshSizeLimit
174 mutable unsigned int max_verts,max_faces;
176 //! Temporary storage
177 std::vector<aiMesh*> merge_list;
178 };
180 } // end of namespace Assimp
182 #endif // AI_CALCTANGENTSPROCESS_H_INC