IGeometryCreator.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 __I_GEOMETRY_CREATOR_H_INCLUDED__
  5. #define __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. ECMT_1BUF_12VTX_NA,
  23. //! One buffer per side, each with 4 vertices, normals are perpendicular to sides
  24. //! Note: You probably will have to scale down your texture uv's to avoid white lines at borders
  25. // as this mesh sets them to 0,1 values. We can't do that when creating the mesh as it
  26. // depends on texture resolution which we don't know at that point.
  27. ECMT_6BUF_4VTX_NP
  28. };
  29. //! Helper class for creating geometry on the fly.
  30. /** You can get an instance of this class through ISceneManager::getGeometryCreator() */
  31. class IGeometryCreator : public IReferenceCounted
  32. {
  33. public:
  34. //! Creates a simple cube mesh.
  35. /**
  36. \param size Dimensions of the cube.
  37. \param type One of ECUBE_MESH_TYPE. So you can chose between cubes with single material or independent materials per side.
  38. \return Generated mesh.
  39. */
  40. 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;
  41. //! Create a pseudo-random mesh representing a hilly terrain.
  42. /**
  43. \param tileSize The size of each tile.
  44. \param tileCount The number of tiles in each dimension.
  45. \param material The material to apply to the mesh.
  46. \param hillHeight The maximum height of the hills.
  47. \param countHills The number of hills along each dimension.
  48. \param textureRepeatCount The number of times to repeat the material texture along each dimension.
  49. \return Generated mesh.
  50. */
  51. virtual IMesh* createHillPlaneMesh(
  52. const core::dimension2d<f32>& tileSize,
  53. const core::dimension2d<u32>& tileCount,
  54. video::SMaterial* material, f32 hillHeight,
  55. const core::dimension2d<f32>& countHills,
  56. const core::dimension2d<f32>& textureRepeatCount) const =0;
  57. //! Create a simple rectangular textured plane mesh.
  58. /**
  59. \param tileSize The size of each tile.
  60. \param tileCount The number of tiles in each dimension.
  61. \param material The material to apply to the mesh.
  62. \param textureRepeatCount The number of times to repeat the material texture along each dimension.
  63. \return Generated mesh.
  64. */
  65. IMesh* createPlaneMesh(
  66. const core::dimension2d<f32>& tileSize,
  67. const core::dimension2d<u32>& tileCount=core::dimension2du(1,1),
  68. video::SMaterial* material=0,
  69. const core::dimension2df& textureRepeatCount=core::dimension2df(1.f,1.f)) const
  70. {
  71. return createHillPlaneMesh(tileSize, tileCount, material, 0.f, core::dimension2df(), textureRepeatCount);
  72. }
  73. //! Create a geoplane.
  74. /**
  75. \param radius Radius of the plane
  76. \param rows How many rows to place
  77. \param columns How many columns to place
  78. \return Generated mesh.
  79. */
  80. virtual IMesh* createGeoplaneMesh(f32 radius = 5.f,
  81. u32 rows = 16, u32 columns = 16) const =0;
  82. //! Create a terrain mesh from an image representing a heightfield.
  83. /**
  84. \param texture The texture to apply to the terrain.
  85. \param heightmap An image that will be interpreted as a heightmap. The
  86. brightness (average color) of each pixel is interpreted as a height,
  87. with a 255 brightness pixel producing the maximum height.
  88. \param stretchSize The size that each pixel will produce, i.e. a
  89. 512x512 heightmap
  90. and a stretchSize of (10.f, 20.f) will produce a mesh of size
  91. 5120.f x 10240.f
  92. \param maxHeight The maximum height of the terrain.
  93. \param driver The current video driver.
  94. \param defaultVertexBlockSize (to be documented)
  95. \param debugBorders (to be documented)
  96. \return Generated mesh.
  97. */
  98. virtual IMesh* createTerrainMesh(video::IImage* texture,
  99. video::IImage* heightmap,
  100. const core::dimension2d<f32>& stretchSize,
  101. f32 maxHeight, video::IVideoDriver* driver,
  102. const core::dimension2d<u32>& defaultVertexBlockSize,
  103. bool debugBorders=false) const =0;
  104. //! Create an arrow mesh, composed of a cylinder and a cone.
  105. /**
  106. \param tesselationCylinder Number of quads composing the cylinder.
  107. \param tesselationCone Number of triangles composing the cone's roof.
  108. \param height Total height of the arrow
  109. \param cylinderHeight Total height of the cylinder, should be lesser
  110. than total height
  111. \param widthCylinder Diameter of the cylinder
  112. \param widthCone Diameter of the cone's base, should be not smaller
  113. than the cylinder's diameter
  114. \param colorCylinder color of the cylinder
  115. \param colorCone color of the cone
  116. \return Generated mesh.
  117. */
  118. virtual IMesh* createArrowMesh(const u32 tesselationCylinder = 4,
  119. const u32 tesselationCone = 8, const f32 height = 1.f,
  120. const f32 cylinderHeight = 0.6f, const f32 widthCylinder = 0.05f,
  121. const f32 widthCone = 0.3f, const video::SColor colorCylinder = 0xFFFFFFFF,
  122. const video::SColor colorCone = 0xFFFFFFFF) const =0;
  123. //! Create a sphere mesh.
  124. /**
  125. \param radius Radius of the sphere
  126. \param polyCountX Number of quads used for the horizontal tiling
  127. \param polyCountY Number of quads used for the vertical tiling
  128. \return Generated mesh.
  129. */
  130. virtual IMesh* createSphereMesh(f32 radius = 5.f,
  131. u32 polyCountX = 16, u32 polyCountY = 16) const =0;
  132. //! Create a cylinder mesh.
  133. /**
  134. \param radius Radius of the cylinder.
  135. \param length Length of the cylinder.
  136. \param tesselation Number of quads around the circumference of the cylinder.
  137. \param color The color of the cylinder.
  138. \param closeTop If true, close the ends of the cylinder, otherwise leave them open.
  139. \param oblique X-offset (shear) of top compared to bottom.
  140. \param normalType When 0 side normals are radial from origin. Note that origin is at the bottom.
  141. When 1 side normals are flat along top/bottom polygons.
  142. NOTE: To get normals which are perpendicular to the side of an oblique
  143. cylinder, don't use the oblique parameter. Instead set normalType to 1
  144. and create a cylinder with oblique set to 0. Then use
  145. IMeshManipulator::transform with a shear matrix on the returned mesh.
  146. You get a shear matrix for an identical effect of this oblique parameter when you
  147. set the 4th element of an identity matrix to (oblique/length).
  148. \return Generated mesh.
  149. */
  150. virtual IMesh* createCylinderMesh(f32 radius, f32 length,
  151. u32 tesselation,
  152. const video::SColor& color=video::SColor(0xffffffff),
  153. bool closeTop=true, f32 oblique=0.f, u32 normalType=0) const =0;
  154. //! Create a cone mesh.
  155. /**
  156. \param radius Radius of the cone.
  157. \param length Length of the cone.
  158. \param tesselation Number of quads around the circumference of the cone.
  159. \param colorTop The color of the top of the cone.
  160. \param colorBottom The color of the bottom of the cone.
  161. \param oblique (to be documented)
  162. \return Generated mesh.
  163. */
  164. virtual IMesh* createConeMesh(f32 radius, f32 length, u32 tesselation,
  165. const video::SColor& colorTop=video::SColor(0xffffffff),
  166. const video::SColor& colorBottom=video::SColor(0xffffffff),
  167. f32 oblique=0.f) const =0;
  168. //! Create a volume light mesh.
  169. /**
  170. \param subdivideU Horizontal patch count.
  171. \param subdivideV Vertical patch count.
  172. \param footColor Color at the bottom of the light.
  173. \param tailColor Color at the mid of the light.
  174. \param lpDistance Virtual distance of the light point for normals.
  175. \param lightDim Dimensions of the light.
  176. \return Generated mesh.
  177. */
  178. virtual IMesh* createVolumeLightMesh(
  179. const u32 subdivideU=32, const u32 subdivideV=32,
  180. const video::SColor footColor = 0xffffffff,
  181. const video::SColor tailColor = 0xffffffff,
  182. const f32 lpDistance = 8.f,
  183. const core::vector3df& lightDim = core::vector3df(1.f,1.2f,1.f)) const =0;
  184. };
  185. } // end namespace scene
  186. } // end namespace irr
  187. #endif // __I_GEOMETRY_CREATOR_H_INCLUDED__