StandardShapes.h 6.6 KB

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