content_mapblock.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 "nodedef.h"
  18. #include <IMeshManipulator.h>
  19. struct MeshMakeData;
  20. struct MeshCollector;
  21. struct LightPair {
  22. u8 lightDay;
  23. u8 lightNight;
  24. LightPair() = default;
  25. explicit LightPair(u16 value) : lightDay(value & 0xff), lightNight(value >> 8) {}
  26. LightPair(u8 valueA, u8 valueB) : lightDay(valueA), lightNight(valueB) {}
  27. LightPair(float valueA, float valueB) :
  28. lightDay(core::clamp(core::round32(valueA), 0, 255)),
  29. lightNight(core::clamp(core::round32(valueB), 0, 255)) {}
  30. operator u16() const { return lightDay | lightNight << 8; }
  31. };
  32. struct LightInfo {
  33. float light_day;
  34. float light_night;
  35. float light_boosted;
  36. LightPair getPair(float sunlight_boost = 0.0) const
  37. {
  38. return LightPair(
  39. (1 - sunlight_boost) * light_day
  40. + sunlight_boost * light_boosted,
  41. light_night);
  42. }
  43. };
  44. struct LightFrame {
  45. f32 lightsDay[8];
  46. f32 lightsNight[8];
  47. bool sunlight[8];
  48. };
  49. class MapblockMeshGenerator
  50. {
  51. public:
  52. MeshMakeData *data;
  53. MeshCollector *collector;
  54. const NodeDefManager *nodedef;
  55. scene::IMeshManipulator *meshmanip;
  56. // options
  57. bool enable_mesh_cache;
  58. // current node
  59. v3s16 blockpos_nodes;
  60. v3s16 p;
  61. v3f origin;
  62. MapNode n;
  63. const ContentFeatures *f;
  64. LightPair light;
  65. LightFrame frame;
  66. video::SColor color;
  67. TileSpec tile;
  68. float scale;
  69. // lighting
  70. void getSmoothLightFrame();
  71. LightInfo blendLight(const v3f &vertex_pos);
  72. video::SColor blendLightColor(const v3f &vertex_pos);
  73. video::SColor blendLightColor(const v3f &vertex_pos, const v3f &vertex_normal);
  74. void useTile(int index = 0, u8 set_flags = MATERIAL_FLAG_CRACK_OVERLAY,
  75. u8 reset_flags = 0, bool special = false);
  76. void getTile(int index, TileSpec *tile);
  77. void getTile(v3s16 direction, TileSpec *tile);
  78. void getSpecialTile(int index, TileSpec *tile, bool apply_crack = false);
  79. // face drawing
  80. void drawQuad(v3f *vertices, const v3s16 &normal = v3s16(0, 0, 0),
  81. float vertical_tiling = 1.0);
  82. // cuboid drawing!
  83. void drawCuboid(const aabb3f &box, TileSpec *tiles, int tilecount,
  84. const LightInfo *lights , const f32 *txc, u8 mask = 0);
  85. void generateCuboidTextureCoords(aabb3f const &box, f32 *coords);
  86. void drawAutoLightedCuboid(aabb3f box, const f32 *txc = NULL,
  87. TileSpec *tiles = NULL, int tile_count = 0, u8 mask = 0);
  88. u8 getNodeBoxMask(aabb3f box, u8 solid_neighbors, u8 sametype_neighbors) const;
  89. // liquid-specific
  90. bool top_is_same_liquid;
  91. bool draw_liquid_bottom;
  92. TileSpec tile_liquid;
  93. TileSpec tile_liquid_top;
  94. content_t c_flowing;
  95. content_t c_source;
  96. video::SColor color_liquid_top;
  97. struct NeighborData {
  98. f32 level;
  99. content_t content;
  100. bool is_same_liquid;
  101. bool top_is_same_liquid;
  102. };
  103. NeighborData liquid_neighbors[3][3];
  104. f32 corner_levels[2][2];
  105. void prepareLiquidNodeDrawing();
  106. void getLiquidNeighborhood();
  107. void calculateCornerLevels();
  108. f32 getCornerLevel(int i, int k);
  109. void drawLiquidSides();
  110. void drawLiquidTop();
  111. void drawLiquidBottom();
  112. // raillike-specific
  113. // name of the group that enables connecting to raillike nodes of different kind
  114. static const std::string raillike_groupname;
  115. int raillike_group;
  116. bool isSameRail(v3s16 dir);
  117. // plantlike-specific
  118. PlantlikeStyle draw_style;
  119. v3f offset;
  120. float rotate_degree;
  121. bool random_offset_Y;
  122. int face_num;
  123. float plant_height;
  124. void drawPlantlikeQuad(float rotation, float quad_offset = 0,
  125. bool offset_top_only = false);
  126. void drawPlantlike(bool is_rooted = false);
  127. // firelike-specific
  128. void drawFirelikeQuad(float rotation, float opening_angle,
  129. float offset_h, float offset_v = 0.0);
  130. // drawtypes
  131. void drawLiquidNode();
  132. void drawGlasslikeNode();
  133. void drawGlasslikeFramedNode();
  134. void drawAllfacesNode();
  135. void drawTorchlikeNode();
  136. void drawSignlikeNode();
  137. void drawPlantlikeNode();
  138. void drawPlantlikeRootedNode();
  139. void drawFirelikeNode();
  140. void drawFencelikeNode();
  141. void drawRaillikeNode();
  142. void drawNodeboxNode();
  143. void drawMeshNode();
  144. // common
  145. void errorUnknownDrawtype();
  146. void drawNode();
  147. public:
  148. MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output,
  149. scene::IMeshManipulator *mm);
  150. void generate();
  151. void renderSingle(content_t node, u8 param2 = 0x00);
  152. };