3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <IMeshManipulator.h>
32 LightPair() = default;
33 explicit LightPair(u16 value) : lightA(value & 0xff), lightB(value >> 8) {}
34 LightPair(u8 valueA, u8 valueB) : lightA(valueA), lightB(valueB) {}
35 LightPair(float valueA, float valueB) :
36 lightA(core::clamp(core::round32(valueA), 0, 255)),
37 lightB(core::clamp(core::round32(valueB), 0, 255)) {}
38 operator u16() const { return lightA | lightB << 8; }
46 class MapblockMeshGenerator
50 MeshCollector *collector;
52 const NodeDefManager *nodedef;
53 scene::IMeshManipulator *meshmanip;
56 bool enable_mesh_cache;
63 const ContentFeatures *f;
71 void getSmoothLightFrame();
72 LightPair blendLight(const v3f &vertex_pos);
73 video::SColor blendLightColor(const v3f &vertex_pos);
74 video::SColor blendLightColor(const v3f &vertex_pos, const v3f &vertex_normal);
76 void useTile(int index = 0, u8 set_flags = MATERIAL_FLAG_CRACK_OVERLAY,
77 u8 reset_flags = 0, bool special = false);
78 void getTile(int index, TileSpec *tile);
79 void getTile(v3s16 direction, TileSpec *tile);
80 void getSpecialTile(int index, TileSpec *tile, bool apply_crack = false);
83 void drawQuad(v3f *vertices, const v3s16 &normal = v3s16(0, 0, 0),
84 float vertical_tiling = 1.0);
87 void drawCuboid(const aabb3f &box, TileSpec *tiles, int tilecount,
88 const LightPair *lights , const f32 *txc);
89 void generateCuboidTextureCoords(aabb3f const &box, f32 *coords);
90 void drawAutoLightedCuboid(aabb3f box, const f32 *txc = NULL,
91 TileSpec *tiles = NULL, int tile_count = 0);
94 bool top_is_same_liquid;
95 bool draw_liquid_bottom;
97 TileSpec tile_liquid_top;
100 video::SColor color_liquid_top;
101 struct NeighborData {
105 bool top_is_same_liquid;
107 NeighborData liquid_neighbors[3][3];
108 f32 corner_levels[2][2];
110 void prepareLiquidNodeDrawing();
111 void getLiquidNeighborhood();
112 void calculateCornerLevels();
113 f32 getCornerLevel(int i, int k);
114 void drawLiquidSides();
115 void drawLiquidTop();
116 void drawLiquidBottom();
119 // name of the group that enables connecting to raillike nodes of different kind
120 static const std::string raillike_groupname;
122 bool isSameRail(v3s16 dir);
124 // plantlike-specific
125 PlantlikeStyle draw_style;
128 bool random_offset_Y;
132 void drawPlantlikeQuad(float rotation, float quad_offset = 0,
133 bool offset_top_only = false);
134 void drawPlantlike();
137 void drawFirelikeQuad(float rotation, float opening_angle,
138 float offset_h, float offset_v = 0.0);
141 void drawLiquidNode();
142 void drawGlasslikeNode();
143 void drawGlasslikeFramedNode();
144 void drawAllfacesNode();
145 void drawTorchlikeNode();
146 void drawSignlikeNode();
147 void drawPlantlikeNode();
148 void drawPlantlikeRootedNode();
149 void drawFirelikeNode();
150 void drawFencelikeNode();
151 void drawRaillikeNode();
152 void drawNodeboxNode();
156 void errorUnknownDrawtype();
160 MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output);
162 void renderSingle(content_t node);