mesh.h 4.2 KB

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