mesh.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. Sets texture coords for vertices in the mesh buffer.
  50. `uv[]` must have `count` elements
  51. */
  52. void setMeshBufferTextureCoords(scene::IMeshBuffer *buf, const v2f *uv, u32 count);
  53. /*
  54. Set a constant color for an animated mesh
  55. */
  56. void setAnimatedMeshColor(scene::IAnimatedMeshSceneNode *node, const video::SColor &color);
  57. /*!
  58. * Overwrites the color of a mesh buffer.
  59. * The color is darkened based on the normal vector of the vertices.
  60. */
  61. void colorizeMeshBuffer(scene::IMeshBuffer *buf, const video::SColor *buffercolor);
  62. /*
  63. Set the color of all vertices in the mesh.
  64. For each vertex, determine the largest absolute entry in
  65. the normal vector, and choose one of colorX, colorY or
  66. colorZ accordingly.
  67. */
  68. void setMeshColorByNormalXYZ(scene::IMesh *mesh,
  69. const video::SColor &colorX,
  70. const video::SColor &colorY,
  71. const video::SColor &colorZ);
  72. void setMeshColorByNormal(scene::IMesh *mesh, const v3f &normal,
  73. const video::SColor &color);
  74. /*
  75. Rotate the mesh by 6d facedir value.
  76. Method only for meshnodes, not suitable for entities.
  77. */
  78. void rotateMeshBy6dFacedir(scene::IMesh *mesh, int facedir);
  79. /*
  80. Rotate the mesh around the axis and given angle in degrees.
  81. */
  82. void rotateMeshXYby (scene::IMesh *mesh, f64 degrees);
  83. void rotateMeshXZby (scene::IMesh *mesh, f64 degrees);
  84. void rotateMeshYZby (scene::IMesh *mesh, f64 degrees);
  85. /*
  86. * Clone the mesh buffer.
  87. * The returned pointer should be dropped.
  88. */
  89. scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer);
  90. /*
  91. Clone the mesh.
  92. */
  93. scene::SMesh* cloneMesh(scene::IMesh *src_mesh);
  94. /*
  95. Convert nodeboxes to mesh. Each tile goes into a different buffer.
  96. boxes - set of nodeboxes to be converted into cuboids
  97. uv_coords[24] - table of texture uv coords for each cuboid face
  98. expand - factor by which cuboids will be resized
  99. */
  100. scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
  101. const f32 *uv_coords = NULL, float expand = 0);
  102. /*
  103. Update bounding box for a mesh.
  104. */
  105. void recalculateBoundingBox(scene::IMesh *src_mesh);
  106. /*
  107. Check if mesh has valid normals and return true if it does.
  108. We assume normal to be valid when it's 0 < length < Inf. and not NaN
  109. */
  110. bool checkMeshNormals(scene::IMesh *mesh);