mesh.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 3.0 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef MESH_HEADER
  17. #define MESH_HEADER
  18. #include "irrlichttypes_extrabloated.h"
  19. #include "nodedef.h"
  20. /*!
  21. * Applies shading to a color based on the surface's
  22. * normal vector.
  23. */
  24. void applyFacesShading(video::SColor &color, const v3f &normal);
  25. /*
  26. Create a new cube mesh.
  27. Vertices are at (+-scale.X/2, +-scale.Y/2, +-scale.Z/2).
  28. The resulting mesh has 6 materials (up, down, right, left, back, front)
  29. which must be defined by the caller.
  30. */
  31. scene::IAnimatedMesh* createCubeMesh(v3f scale);
  32. /*
  33. Multiplies each vertex coordinate by the specified scaling factors
  34. (componentwise vector multiplication).
  35. */
  36. void scaleMesh(scene::IMesh *mesh, v3f scale);
  37. /*
  38. Translate each vertex coordinate by the specified vector.
  39. */
  40. void translateMesh(scene::IMesh *mesh, v3f vec);
  41. /*!
  42. * Sets a constant color for all vertices in the mesh buffer.
  43. */
  44. void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color);
  45. /*
  46. Set a constant color for all vertices in the mesh
  47. */
  48. void setMeshColor(scene::IMesh *mesh, const video::SColor &color);
  49. /*!
  50. * Overwrites the color of a mesh buffer.
  51. * The color is darkened based on the normal vector of the vertices.
  52. */
  53. void colorizeMeshBuffer(scene::IMeshBuffer *buf, const video::SColor *buffercolor);
  54. /*
  55. Set the color of all vertices in the mesh.
  56. For each vertex, determine the largest absolute entry in
  57. the normal vector, and choose one of colorX, colorY or
  58. colorZ accordingly.
  59. */
  60. void setMeshColorByNormalXYZ(scene::IMesh *mesh,
  61. const video::SColor &colorX,
  62. const video::SColor &colorY,
  63. const video::SColor &colorZ);
  64. void setMeshColorByNormal(scene::IMesh *mesh, const v3f &normal,
  65. const video::SColor &color);
  66. /*
  67. Rotate the mesh by 6d facedir value.
  68. Method only for meshnodes, not suitable for entities.
  69. */
  70. void rotateMeshBy6dFacedir(scene::IMesh *mesh, int facedir);
  71. /*
  72. Rotate the mesh around the axis and given angle in degrees.
  73. */
  74. void rotateMeshXYby (scene::IMesh *mesh, f64 degrees);
  75. void rotateMeshXZby (scene::IMesh *mesh, f64 degrees);
  76. void rotateMeshYZby (scene::IMesh *mesh, f64 degrees);
  77. /*
  78. * Clone the mesh buffer.
  79. * The returned pointer should be dropped.
  80. */
  81. scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer);
  82. /*
  83. Clone the mesh.
  84. */
  85. scene::SMesh* cloneMesh(scene::IMesh *src_mesh);
  86. /*
  87. Convert nodeboxes to mesh. Each tile goes into a different buffer.
  88. boxes - set of nodeboxes to be converted into cuboids
  89. uv_coords[24] - table of texture uv coords for each cuboid face
  90. expand - factor by which cuboids will be resized
  91. */
  92. scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
  93. const f32 *uv_coords = NULL, float expand = 0);
  94. /*
  95. Update bounding box for a mesh.
  96. */
  97. void recalculateBoundingBox(scene::IMesh *src_mesh);
  98. /*
  99. Vertex cache optimization according to the Forsyth paper:
  100. http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html
  101. Ported from irrlicht 1.8
  102. */
  103. scene::IMesh* createForsythOptimizedMesh(const scene::IMesh *mesh);
  104. #endif