StandardShapes.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2025, 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 Declares a helper class, "StandardShapes" which generates
  34. * vertices for standard shapes, such as cylinders, cones, spheres ..
  35. */
  36. #pragma once
  37. #ifndef AI_STANDARD_SHAPES_H_INC
  38. #define AI_STANDARD_SHAPES_H_INC
  39. #ifdef __GNUC__
  40. # pragma GCC system_header
  41. #endif
  42. #include <assimp/vector3.h>
  43. #include <stddef.h>
  44. #include <vector>
  45. struct aiMesh;
  46. namespace Assimp {
  47. // ---------------------------------------------------------------------------
  48. /** \brief Helper class to generate vertex buffers for standard geometric
  49. * shapes, such as cylinders, cones, boxes, spheres, elipsoids ... .
  50. */
  51. class ASSIMP_API StandardShapes
  52. {
  53. // class cannot be instanced
  54. StandardShapes() {}
  55. public:
  56. // ----------------------------------------------------------------
  57. /** Generates a mesh from an array of vertex positions.
  58. *
  59. * @param positions List of vertex positions
  60. * @param numIndices Number of indices per primitive
  61. * @return Output mesh
  62. */
  63. static aiMesh* MakeMesh(const std::vector<aiVector3D>& positions,
  64. unsigned int numIndices);
  65. static aiMesh* MakeMesh ( unsigned int (*GenerateFunc)
  66. (std::vector<aiVector3D>&));
  67. static aiMesh* MakeMesh ( unsigned int (*GenerateFunc)
  68. (std::vector<aiVector3D>&, bool));
  69. static aiMesh* MakeMesh ( unsigned int n, void (*GenerateFunc)
  70. (unsigned int,std::vector<aiVector3D>&));
  71. // ----------------------------------------------------------------
  72. /** @brief Generates a hexahedron (cube)
  73. *
  74. * Hexahedrons can be scaled on all axes.
  75. * @param positions Receives output triangles.
  76. * @param polygons If you pass true here quads will be returned
  77. * @return Number of vertices per face
  78. */
  79. static unsigned int MakeHexahedron(
  80. std::vector<aiVector3D>& positions,
  81. bool polygons = false);
  82. // ----------------------------------------------------------------
  83. /** @brief Generates an icosahedron
  84. *
  85. * @param positions Receives output triangles.
  86. * @return Number of vertices per face
  87. */
  88. static unsigned int MakeIcosahedron(
  89. std::vector<aiVector3D>& positions);
  90. // ----------------------------------------------------------------
  91. /** @brief Generates a dodecahedron
  92. *
  93. * @param positions Receives output triangles
  94. * @param polygons If you pass true here pentagons will be returned
  95. * @return Number of vertices per face
  96. */
  97. static unsigned int MakeDodecahedron(
  98. std::vector<aiVector3D>& positions,
  99. bool polygons = false);
  100. // ----------------------------------------------------------------
  101. /** @brief Generates an octahedron
  102. *
  103. * @param positions Receives output triangles.
  104. * @return Number of vertices per face
  105. */
  106. static unsigned int MakeOctahedron(
  107. std::vector<aiVector3D>& positions);
  108. // ----------------------------------------------------------------
  109. /** @brief Generates a tetrahedron
  110. *
  111. * @param positions Receives output triangles.
  112. * @return Number of vertices per face
  113. */
  114. static unsigned int MakeTetrahedron(
  115. std::vector<aiVector3D>& positions);
  116. // ----------------------------------------------------------------
  117. /** @brief Generates a sphere
  118. *
  119. * @param tess Number of subdivions - 0 generates a octahedron
  120. * @param positions Receives output triangles.
  121. */
  122. static void MakeSphere(unsigned int tess,
  123. std::vector<aiVector3D>& positions);
  124. // ----------------------------------------------------------------
  125. /** @brief Generates a cone or a cylinder, either open or closed.
  126. *
  127. * @code
  128. *
  129. * |-----| <- radius 1
  130. *
  131. * __x__ <- ] ^
  132. * / \ | height |
  133. * / \ | Y
  134. * / \ |
  135. * / \ |
  136. * /______x______\ <- ] <- end cap
  137. *
  138. * |-------------| <- radius 2
  139. *
  140. * @endcode
  141. *
  142. * @param height Height of the cone
  143. * @param radius1 First radius
  144. * @param radius2 Second radius
  145. * @param tess Number of triangles.
  146. * @param bOpened true for an open cone/cylinder. An open shape has
  147. * no 'end caps'
  148. * @param positions Receives output triangles
  149. */
  150. static void MakeCone(ai_real height,ai_real radius1,
  151. ai_real radius2,unsigned int tess,
  152. std::vector<aiVector3D>& positions,bool bOpen= false);
  153. // ----------------------------------------------------------------
  154. /** @brief Generates a flat circle
  155. *
  156. * The circle is constructed in the planned formed by the x,z
  157. * axes of the cartesian coordinate system.
  158. *
  159. * @param radius Radius of the circle
  160. * @param tess Number of segments.
  161. * @param positions Receives output triangles.
  162. */
  163. static void MakeCircle(ai_real radius, unsigned int tess,
  164. std::vector<aiVector3D>& positions);
  165. };
  166. } // ! Assimp
  167. #endif // !! AI_STANDARD_SHAPES_H_INC