OptimizeMeshes.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2008, ASSIMP Development 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 Development 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 OptimizeMeshes.h
  34. * @brief Declares a post processing step to join meshes, if possible
  35. */
  36. #ifndef AI_OPTIMIZEMESHESPROCESS_H_INC
  37. #define AI_OPTIMIZEMESHESPROCESS_H_INC
  38. #include "BaseProcess.h"
  39. #include "../include/aiTypes.h"
  40. struct aiMesh;
  41. class OptimizeMeshesProcessTest;
  42. namespace Assimp {
  43. // ---------------------------------------------------------------------------
  44. /** @brief Postprocessing step to optimize mesh usage
  45. *
  46. * The implementation looks for meshes that could be joined and joins them.
  47. * Usually this will reduce the number of drawcalls.
  48. *
  49. * @note Instanced meshes are currently not processed.
  50. */
  51. class ASSIMP_API OptimizeMeshesProcess : public BaseProcess
  52. {
  53. friend class Importer;
  54. friend class ::OptimizeMeshesProcessTest;
  55. protected:
  56. /** Constructor to be privately used by Importer */
  57. OptimizeMeshesProcess();
  58. /** Destructor, private as well */
  59. ~OptimizeMeshesProcess();
  60. /** @brief Internal utility to store additional mesh info
  61. */
  62. struct MeshInfo
  63. {
  64. MeshInfo()
  65. : instance_cnt (0)
  66. , vertex_format (0)
  67. , output_id (0xffffffff)
  68. {}
  69. //! Number of times this mesh is referenced
  70. unsigned int instance_cnt;
  71. //! Vertex format id
  72. unsigned int vertex_format;
  73. //! Output ID
  74. unsigned int output_id;
  75. };
  76. public:
  77. // -------------------------------------------------------------------
  78. bool IsActive( unsigned int pFlags) const;
  79. // -------------------------------------------------------------------
  80. void Execute( aiScene* pScene);
  81. // -------------------------------------------------------------------
  82. void SetupProperties(const Importer* pImp);
  83. // -------------------------------------------------------------------
  84. /** @brief Specify whether you want meshes with different
  85. * primitive types to be merged as well.
  86. *
  87. * IsActive() sets this property automatically to true if the
  88. * aiProcess_SortByPType flag is found.
  89. */
  90. void EnablePrimitiveTypeSorting(bool enable) {
  91. pts = enable;
  92. }
  93. // Getter
  94. bool IsPrimitiveTypeSortingEnabled () const {
  95. return pts;
  96. }
  97. // -------------------------------------------------------------------
  98. /** @brief Specify a maximum size of a single output mesh.
  99. *
  100. * If a single input mesh already exceeds this limit, it won't
  101. * be splitted.
  102. * @param verts Maximum number of vertices per mesh
  103. * @param faces Maximum number of faces per mesh
  104. */
  105. void SetPreferredMeshSizeLimit (unsigned int verts, unsigned int faces)
  106. {
  107. max_verts = verts;
  108. max_faces = faces;
  109. }
  110. protected:
  111. // -------------------------------------------------------------------
  112. /** @brief Do the actual optimization on all meshes of this node
  113. * @param pNode Node we're working with
  114. */
  115. void ProcessNode( aiNode* pNode);
  116. // -------------------------------------------------------------------
  117. /** @brief Returns true if b can be joined with a
  118. *
  119. * @param verts Number of output verts up to now
  120. * @param faces Number of output faces up to now
  121. */
  122. bool CanJoin ( unsigned int a, unsigned int b,
  123. unsigned int verts, unsigned int faces );
  124. // -------------------------------------------------------------------
  125. /** @brief Find instanced meshes, for the moment we're excluding
  126. * them from all optimizations
  127. */
  128. void FindInstancedMeshes (aiNode* pNode);
  129. private:
  130. //! Scene we're working with
  131. aiScene* mScene;
  132. //! Per mesh info
  133. std::vector<MeshInfo> meshes;
  134. //! Next output mesh
  135. aiMesh* mesh;
  136. //! Output meshes
  137. std::vector<aiMesh*> output;
  138. //! @see EnablePrimitiveTypeSorting
  139. mutable bool pts;
  140. //! @see SetPreferredMeshSizeLimit
  141. mutable unsigned int max_verts,max_faces;
  142. //! Temporary storage
  143. std::vector<aiMesh*> merge_list;
  144. };
  145. } // end of namespace Assimp
  146. #endif // AI_CALCTANGENTSPROCESS_H_INC