StandardShapes.h 6.4 KB

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