mesh.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 2.1 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. #pragma once
  17. #include "irrlichttypes_extrabloated.h"
  18. #include "nodedef.h"
  19. /*!
  20. * Applies shading to a color based on the surface's
  21. * normal vector.
  22. */
  23. void applyFacesShading(video::SColor &color, const v3f &normal);
  24. /*
  25. Create a new cube mesh.
  26. Vertices are at (+-scale.X/2, +-scale.Y/2, +-scale.Z/2).
  27. The resulting mesh has 6 materials (up, down, right, left, back, front)
  28. which must be defined by the caller.
  29. */
  30. scene::IAnimatedMesh* createCubeMesh(v3f scale);
  31. /*
  32. Multiplies each vertex coordinate by the specified scaling factors
  33. (componentwise vector multiplication).
  34. */
  35. void scaleMesh(scene::IMesh *mesh, v3f scale);
  36. /*
  37. Translate each vertex coordinate by the specified vector.
  38. */
  39. void translateMesh(scene::IMesh *mesh, v3f vec);
  40. /*!
  41. * Sets a constant color for all vertices in the mesh buffer.
  42. */
  43. void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color);
  44. /*
  45. Set a constant color for all vertices in the mesh
  46. */
  47. void setMeshColor(scene::IMesh *mesh, const video::SColor &color);
  48. /*!
  49. * Overwrites the color of a mesh buffer.
  50. * The color is darkened based on the normal vector of the vertices.
  51. */
  52. void colorizeMeshBuffer(scene::IMeshBuffer *buf, const video::SColor *buffercolor);
  53. /*
  54. Set the color of all vertices in the mesh.
  55. For each vertex, determine the largest absolute entry in
  56. the normal vector, and choose one of colorX, colorY or
  57. colorZ accordingly.
  58. */
  59. void setMeshColorByNormalXYZ(scene::IMesh *mesh,
  60. const video::SColor &colorX,
  61. const video::SColor &colorY,
  62. const video::SColor &colorZ);
  63. void setMeshColorByNormal(scene::IMesh *mesh, const v3f &normal,
  64. const video::SColor &color);
  65. /*
  66. Rotate the mesh by 6d facedir value.
  67. Method only for meshnodes, not suitable for entities.
  68. */
  69. void rotateMeshBy6dFacedir(scene::IMesh *mesh, int facedir);
  70. /*
  71. Rotate the mesh around the axis and given angle in degrees.
  72. */
  73. void rotateMeshXYby (scene::IMesh *mesh, f64 degrees);
  74. void rotateMeshXZby (scene::IMesh *mesh, f64 degrees);
  75. void rotateMeshYZby (scene::IMesh *mesh, f64 degrees);
  76. /*
  77. * Clone the mesh buffer.
  78. * The returned pointer should be dropped.
  79. */
  80. scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer);
  81. /*
  82. Clone the mesh.
  83. */
  84. scene::SMesh* cloneMesh(scene::IMesh *src_mesh);
  85. /*
  86. Convert nodeboxes to mesh. Each tile goes into a different buffer.
  87. boxes - set of nodeboxes to be converted into cuboids
  88. uv_coords[24] - table of texture uv coords for each cuboid face
  89. expand - factor by which cuboids will be resized
  90. */
  91. scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
  92. const f32 *uv_coords = NULL, float expand = 0);
  93. /*
  94. Update bounding box for a mesh.
  95. */
  96. void recalculateBoundingBox(scene::IMesh *src_mesh);
  97. /*
  98. Vertex cache optimization according to the Forsyth paper:
  99. http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html
  100. Ported from irrlicht 1.8
  101. */
  102. scene::IMesh* createForsythOptimizedMesh(const scene::IMesh *mesh);