PretransformVertices.h 5.9 KB

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