PretransformVertices.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2020, assimp 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 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 PretransformVertices.h
  34. * @brief Defines a post processing step to pretransform all
  35. * vertices in the scenegraph
  36. */
  37. #ifndef AI_PRETRANSFORMVERTICES_H_INC
  38. #define AI_PRETRANSFORMVERTICES_H_INC
  39. #include "Common/BaseProcess.h"
  40. #include <assimp/mesh.h>
  41. #include <list>
  42. #include <vector>
  43. // Forward declarations
  44. struct aiNode;
  45. class PretransformVerticesTest;
  46. namespace Assimp {
  47. // ---------------------------------------------------------------------------
  48. /** The PretransformVertices pre-transforms all vertices in the node tree
  49. * and removes the whole graph. The output is a list of meshes, one for
  50. * each material.
  51. */
  52. class ASSIMP_API PretransformVertices : public BaseProcess {
  53. public:
  54. PretransformVertices();
  55. ~PretransformVertices();
  56. // -------------------------------------------------------------------
  57. // Check whether step is active
  58. bool IsActive(unsigned int pFlags) const override;
  59. // -------------------------------------------------------------------
  60. // Execute step on a given scene
  61. void Execute(aiScene *pScene) override;
  62. // -------------------------------------------------------------------
  63. // Setup import settings
  64. void SetupProperties(const Importer *pImp) override;
  65. // -------------------------------------------------------------------
  66. /** @brief Toggle the 'keep hierarchy' option
  67. * @param keep true for keep configuration.
  68. */
  69. void KeepHierarchy(bool keep) {
  70. configKeepHierarchy = keep;
  71. }
  72. // -------------------------------------------------------------------
  73. /** @brief Check whether 'keep hierarchy' is currently enabled.
  74. * @return ...
  75. */
  76. bool IsHierarchyKept() const {
  77. return configKeepHierarchy;
  78. }
  79. private:
  80. // -------------------------------------------------------------------
  81. // Count the number of nodes
  82. unsigned int CountNodes(const aiNode *pcNode) const;
  83. // -------------------------------------------------------------------
  84. // Get a bitwise combination identifying the vertex format of a mesh
  85. unsigned int GetMeshVFormat(aiMesh *pcMesh) const;
  86. // -------------------------------------------------------------------
  87. // Count the number of vertices in the whole scene and a given
  88. // material index
  89. void CountVerticesAndFaces(const aiScene *pcScene, const aiNode *pcNode,
  90. unsigned int iMat,
  91. unsigned int iVFormat,
  92. unsigned int *piFaces,
  93. unsigned int *piVertices) const;
  94. // -------------------------------------------------------------------
  95. // Collect vertex/face data
  96. void CollectData(const aiScene *pcScene, const aiNode *pcNode,
  97. unsigned int iMat,
  98. unsigned int iVFormat,
  99. aiMesh *pcMeshOut,
  100. unsigned int aiCurrent[2],
  101. unsigned int *num_refs) const;
  102. // -------------------------------------------------------------------
  103. // Get a list of all vertex formats that occur for a given material
  104. // The output list contains duplicate elements
  105. void GetVFormatList(const aiScene *pcScene, unsigned int iMat,
  106. std::list<unsigned int> &aiOut) const;
  107. // -------------------------------------------------------------------
  108. // Compute the absolute transformation matrices of each node
  109. void ComputeAbsoluteTransform(aiNode *pcNode);
  110. // -------------------------------------------------------------------
  111. // Simple routine to build meshes in worldspace, no further optimization
  112. void BuildWCSMeshes(std::vector<aiMesh *> &out, aiMesh **in,
  113. unsigned int numIn, aiNode *node) const;
  114. // -------------------------------------------------------------------
  115. // Apply the node transformation to a mesh
  116. void ApplyTransform(aiMesh *mesh, const aiMatrix4x4 &mat) const;
  117. // -------------------------------------------------------------------
  118. // Reset transformation matrices to identity
  119. void MakeIdentityTransform(aiNode *nd) const;
  120. // -------------------------------------------------------------------
  121. // Build reference counters for all meshes
  122. void BuildMeshRefCountArray(const aiNode *nd, unsigned int *refs) const;
  123. //! Configuration option: keep scene hierarchy as long as possible
  124. bool configKeepHierarchy;
  125. bool configNormalize;
  126. bool configTransform;
  127. aiMatrix4x4 configTransformation;
  128. bool mConfigPointCloud;
  129. };
  130. } // end of namespace Assimp
  131. #endif // !!AI_GENFACENORMALPROCESS_H_INC