IGeometryCreator.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #ifndef IRR_I_GEOMETRY_CREATOR_H_INCLUDED
  5. #define IRR_I_GEOMETRY_CREATOR_H_INCLUDED
  6. #include "IReferenceCounted.h"
  7. #include "IMesh.h"
  8. #include "IImage.h"
  9. namespace irr
  10. {
  11. namespace video
  12. {
  13. class IVideoDriver;
  14. class SMaterial;
  15. }
  16. namespace scene
  17. {
  18. enum ECUBE_MESH_TYPE
  19. {
  20. //! Single buffer with 12 different vertices, normals are average of adjacent planes
  21. //! Order for outgoing (front-face) normals of planes would be: NEG_Z, POS_X, POS_Z, NEG_X, POS_Y, NEG_Y
  22. //! This was the only available type before Irrlicht 1.9, so it's still the default in some functions.
  23. //! It has the least vertices, but is pretty much unusable if you have dynamic light
  24. ECMT_1BUF_12VTX_NA,
  25. //! One buffer per side, each with 4 vertices, normals are perpendicular to sides
  26. //! You can use this one if you need different texture on each cube side
  27. ECMT_6BUF_4VTX_NP,
  28. //! Single buffer with 24 different vertices, normals are perpendicular to sides
  29. ECMT_1BUF_24VTX_NP,
  30. //! not used, counts the number of enumerated types
  31. ECMT_COUNT
  32. };
  33. //! Names for ECUBE_MESH_TYPE
  34. const c8* const CubeMeshTypeNames[ECMT_COUNT+1] =
  35. {
  36. "1BUF_12VTX_NA",
  37. "ECMT_6BUF_4VTX_NP",
  38. "1BUF_24VTX_NP",
  39. 0
  40. };
  41. //! Helper class for creating geometry on the fly.
  42. /** You can get an instance of this class through ISceneManager::getGeometryCreator() */
  43. class IGeometryCreator : public IReferenceCounted
  44. {
  45. public:
  46. //! Creates a simple cube mesh.
  47. /**
  48. \param size Dimensions of the cube.
  49. \param type One of ECUBE_MESH_TYPE. So you can chose between cubes with single material or independent materials per side.
  50. \return Generated mesh.
  51. Note: UV's go always from 0 to 1. Which can produce wrong colors at edges with texture filtering.
  52. Fixing UV's depends on texture-size (have to be moved half a pixel towards the inside, so 0.5f/texure_size as then the pixel center is exactly on the border)
  53. Easier solution is usually to set TextureWrapU and TextureWrapV to ETC_CLAMP_TO_EDGE in the Material.
  54. */
  55. virtual IMesh* createCubeMesh(const core::vector3df& size=core::vector3df(5.f,5.f,5.f), ECUBE_MESH_TYPE type = ECMT_1BUF_12VTX_NA) const =0;
  56. //! Create a pseudo-random mesh representing a hilly terrain.
  57. /**
  58. \param tileSize The size of each tile.
  59. \param tileCount The number of tiles in each dimension.
  60. \param material The material to apply to the mesh.
  61. \param hillHeight The maximum height of the hills.
  62. \param countHills The number of hills along each dimension.
  63. \param textureRepeatCount The number of times to repeat the material texture along each dimension.
  64. \return Generated mesh.
  65. */
  66. virtual IMesh* createHillPlaneMesh(
  67. const core::dimension2d<f32>& tileSize,
  68. const core::dimension2d<u32>& tileCount,
  69. video::SMaterial* material, f32 hillHeight,
  70. const core::dimension2d<f32>& countHills,
  71. const core::dimension2d<f32>& textureRepeatCount) const =0;
  72. //! Create a simple rectangular textured plane mesh.
  73. /**
  74. \param tileSize The size of each tile.
  75. \param tileCount The number of tiles in each dimension.
  76. \param material The material to apply to the mesh.
  77. \param textureRepeatCount The number of times to repeat the material texture along each dimension.
  78. \return Generated mesh.
  79. */
  80. IMesh* createPlaneMesh(
  81. const core::dimension2d<f32>& tileSize,
  82. const core::dimension2d<u32>& tileCount=core::dimension2du(1,1),
  83. video::SMaterial* material=0,
  84. const core::dimension2df& textureRepeatCount=core::dimension2df(1.f,1.f)) const
  85. {
  86. return createHillPlaneMesh(tileSize, tileCount, material, 0.f, core::dimension2df(), textureRepeatCount);
  87. }
  88. //! Create a geoplane.
  89. /**
  90. \param radius Radius of the plane
  91. \param rows How many rows to place
  92. \param columns How many columns to place
  93. \return Generated mesh.
  94. */
  95. virtual IMesh* createGeoplaneMesh(f32 radius = 5.f,
  96. u32 rows = 16, u32 columns = 16) const =0;
  97. //! Create a terrain mesh from an image representing a heightfield.
  98. /**
  99. \param texture The texture to apply to the terrain.
  100. \param heightmap An image that will be interpreted as a heightmap. The
  101. brightness (average color) of each pixel is interpreted as a height,
  102. with a 255 brightness pixel producing the maximum height.
  103. \param stretchSize The size that each pixel will produce, i.e. a
  104. 512x512 heightmap
  105. and a stretchSize of (10.f, 20.f) will produce a mesh of size
  106. 5120.f x 10240.f
  107. \param maxHeight The maximum height of the terrain.
  108. \param driver The current video driver.
  109. \param defaultVertexBlockSize (to be documented)
  110. \param debugBorders (to be documented)
  111. \return Generated mesh.
  112. */
  113. virtual IMesh* createTerrainMesh(video::IImage* texture,
  114. video::IImage* heightmap,
  115. const core::dimension2d<f32>& stretchSize,
  116. f32 maxHeight, video::IVideoDriver* driver,
  117. const core::dimension2d<u32>& defaultVertexBlockSize,
  118. bool debugBorders=false) const =0;
  119. //! Create an arrow mesh, composed of a cylinder and a cone.
  120. /**
  121. \param tessellationCylinder Number of quads composing the cylinder.
  122. \param tessellationCone Number of triangles composing the cone's roof.
  123. \param height Total height of the arrow
  124. \param cylinderHeight Total height of the cylinder, should be lesser
  125. than total height
  126. \param widthCylinder Diameter of the cylinder
  127. \param widthCone Diameter of the cone's base, should be not smaller
  128. than the cylinder's diameter
  129. \param colorCylinder color of the cylinder
  130. \param colorCone color of the cone
  131. \return Generated mesh.
  132. */
  133. virtual IMesh* createArrowMesh(const u32 tessellationCylinder = 16,
  134. const u32 tessellationCone = 16, const f32 height = 1.f,
  135. const f32 cylinderHeight = 0.6f, const f32 widthCylinder = 0.05f,
  136. const f32 widthCone = 0.3f, const video::SColor colorCylinder = 0xFFFFFFFF,
  137. const video::SColor colorCone = 0xFFFFFFFF) const =0;
  138. //! Create a sphere mesh.
  139. /**
  140. \param radius Radius of the sphere
  141. \param polyCountX Number of quads used for the horizontal tiling
  142. \param polyCountY Number of quads used for the vertical tiling
  143. \return Generated mesh.
  144. */
  145. virtual IMesh* createSphereMesh(f32 radius = 5.f,
  146. u32 polyCountX = 16, u32 polyCountY = 16) const =0;
  147. //! Create a cylinder mesh.
  148. /**
  149. \param radius Radius of the cylinder.
  150. \param length Length of the cylinder.
  151. \param tessellation Number of quads around the circumference of the cylinder.
  152. \param color The color of the cylinder.
  153. \param closeTop If true, close the ends of the cylinder, otherwise leave them open.
  154. \param oblique X-offset (shear) of top compared to bottom.
  155. \param normalType When 0 side normals are radial from origin. Note that origin is at the bottom.
  156. When 1 side normals are flat along top/bottom polygons.
  157. NOTE: To get normals which are perpendicular to the side of an oblique
  158. cylinder, don't use the oblique parameter. Instead set normalType to 1
  159. and create a cylinder with oblique set to 0. Then use
  160. IMeshManipulator::transform with a shear matrix on the returned mesh.
  161. You get a shear matrix for an identical effect of this oblique parameter when you
  162. set the 4th element of an identity matrix to (oblique/length).
  163. \return Generated mesh.
  164. */
  165. virtual IMesh* createCylinderMesh(f32 radius, f32 length,
  166. u32 tessellation,
  167. const video::SColor& color=video::SColor(0xffffffff),
  168. bool closeTop=true, f32 oblique=0.f, u32 normalType=0) const =0;
  169. //! Create a cone mesh.
  170. /**
  171. \param radius Radius of the cone.
  172. \param length Length of the cone.
  173. \param tessellation Number of triangles around the circumference of the cone.
  174. \param colorTop The color of the top of the cone.
  175. \param colorBottom The color of the bottom of the cone.
  176. \param oblique (to be documented)
  177. \return Generated mesh.
  178. */
  179. virtual IMesh* createConeMesh(f32 radius, f32 length, u32 tessellation,
  180. const video::SColor& colorTop=video::SColor(0xffffffff),
  181. const video::SColor& colorBottom=video::SColor(0xffffffff),
  182. f32 oblique=0.f) const =0;
  183. //! Create a torus mesh
  184. /** Note: Segments might get reduced to ensure it fits into 16-bit meshbuffer.
  185. With 255 segments for minor and major circle you'll hit the maximum.
  186. When using caps 2 more vertices are added.
  187. Note: UV's for caps are probably not useful
  188. \param majorRadius Starting from mesh center
  189. \param minorRadius Starting from a circle at majorRadius distance around center
  190. \param majorSegments Segments for major circle. Will use at least 3 segments.
  191. \param minorSegments Segments for minor circle. Will use at least 3 segments.
  192. \param angleStart Start major circle between 0 and 360° and < angleEnd
  193. \param angleEnd End major circle between 0 and 360° and > angleStart
  194. \param capEnds When you don't create a full major circle you might want caps
  195. 0 = no caps (default)
  196. Bit 1: add cap at angleStart
  197. Bit 2: add cap at angleEnd
  198. */
  199. virtual IMesh* createTorusMesh(f32 majorRadius, f32 minorRadius,
  200. u32 majorSegments = 32, u32 minorSegments = 16,
  201. f32 angleStart=0.f, f32 angleEnd=360.f, int capEnds=0) const = 0;
  202. //! Create a volume light mesh.
  203. /**
  204. \param subdivideU Horizontal patch count.
  205. \param subdivideV Vertical patch count.
  206. \param footColor Color at the bottom of the light.
  207. \param tailColor Color at the mid of the light.
  208. \param lpDistance Virtual distance of the light point for normals.
  209. \param lightDim Dimensions of the light.
  210. \return Generated mesh.
  211. */
  212. virtual IMesh* createVolumeLightMesh(
  213. const u32 subdivideU=32, const u32 subdivideV=32,
  214. const video::SColor footColor = 0xffffffff,
  215. const video::SColor tailColor = 0xffffffff,
  216. const f32 lpDistance = 8.f,
  217. const core::vector3df& lightDim = core::vector3df(1.f,1.2f,1.f)) const =0;
  218. };
  219. } // end namespace scene
  220. } // end namespace irr
  221. #endif // IRR_I_GEOMETRY_CREATOR_H_INCLUDED