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 INodeDefManager *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;
96 TileSpec tile_liquid_top;
99 video::SColor color_liquid_top;
100 struct NeighborData {
104 bool top_is_same_liquid;
106 NeighborData liquid_neighbors[3][3];
107 f32 corner_levels[2][2];
109 void prepareLiquidNodeDrawing();
110 void getLiquidNeighborhood();
111 void calculateCornerLevels();
112 f32 getCornerLevel(int i, int k);
113 void drawLiquidSides();
114 void drawLiquidTop();
117 // name of the group that enables connecting to raillike nodes of different kind
118 static const std::string raillike_groupname;
120 bool isSameRail(v3s16 dir);
122 // plantlike-specific
123 PlantlikeStyle draw_style;
126 bool random_offset_Y;
130 void drawPlantlikeQuad(float rotation, float quad_offset = 0,
131 bool offset_top_only = false);
132 void drawPlantlike();
135 void drawFirelikeQuad(float rotation, float opening_angle,
136 float offset_h, float offset_v = 0.0);
139 void drawLiquidNode();
140 void drawGlasslikeNode();
141 void drawGlasslikeFramedNode();
142 void drawAllfacesNode();
143 void drawTorchlikeNode();
144 void drawSignlikeNode();
145 void drawPlantlikeNode();
146 void drawPlantlikeRootedNode();
147 void drawFirelikeNode();
148 void drawFencelikeNode();
149 void drawRaillikeNode();
150 void drawNodeboxNode();
154 void errorUnknownDrawtype();
158 MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output);
160 void renderSingle(content_t node);