diff --git a/prop_mesher.cpp b/prop_mesher.cpp index 15112cc..37f7183 100644 --- a/prop_mesher.cpp +++ b/prop_mesher.cpp @@ -476,6 +476,8 @@ void PropMesher::add_tiled_wall_simple(const int width, const int height, const return; } + float flavour_chance = tiled_wall_data->get_flavour_chance(); + //collect rects Vector normal_rects; Vector flavour_rects; @@ -508,39 +510,101 @@ void PropMesher::add_tiled_wall_simple(const int width, const int height, const if (tiling_type == TiledWallData::TILED_WALL_TILING_TYPE_NONE) { Rect2 r = normal_rects[0]; - for (int x = 0; x < width; ++x) { - for (int y = 0; y < height; ++y) { - add_tiled_wall_mesh_rect_simple(x, y, transform, r); + if (flavour_rects.size() == 0) { + //no flavours + for (int x = 0; x < width; ++x) { + for (int y = 0; y < height; ++y) { + add_tiled_wall_mesh_rect_simple(x, y, transform, r); + } + } + } else { + //has flavours + for (int x = 0; x < width; ++x) { + for (int y = 0; y < height; ++y) { + if (Math::randf() > flavour_chance) { + add_tiled_wall_mesh_rect_simple(x, y, transform, r); + } else { + add_tiled_wall_mesh_rect_simple(x, y, transform, flavour_rects[Math::rand() % flavour_rects.size()]); + } + } } } } else if (tiling_type == TiledWallData::TILED_WALL_TILING_TYPE_HORIZONTAL) { Rect2 r; - for (int x = 0; x < width; ++x) { - r = normal_rects[x % normal_rects.size()]; + if (flavour_rects.size() == 0) { + //no flavours + for (int x = 0; x < width; ++x) { + r = normal_rects[x % normal_rects.size()]; - for (int y = 0; y < height; ++y) { - add_tiled_wall_mesh_rect_simple(x, y, transform, r); + for (int y = 0; y < height; ++y) { + add_tiled_wall_mesh_rect_simple(x, y, transform, r); + } + } + } else { + //has flavours + for (int x = 0; x < width; ++x) { + r = normal_rects[x % normal_rects.size()]; + + for (int y = 0; y < height; ++y) { + if (Math::randf() > flavour_chance) { + add_tiled_wall_mesh_rect_simple(x, y, transform, r); + } else { + add_tiled_wall_mesh_rect_simple(x, y, transform, flavour_rects[Math::rand() % flavour_rects.size()]); + } + } } } } else if (tiling_type == TiledWallData::TILED_WALL_TILING_TYPE_VERTICAL) { Rect2 r; - for (int x = 0; x < width; ++x) { - for (int y = 0; y < height; ++y) { - r = normal_rects[y % normal_rects.size()]; + if (flavour_rects.size() == 0) { + //no flavours + for (int x = 0; x < width; ++x) { + for (int y = 0; y < height; ++y) { + r = normal_rects[y % normal_rects.size()]; - add_tiled_wall_mesh_rect_simple(x, y, transform, r); + add_tiled_wall_mesh_rect_simple(x, y, transform, r); + } + } + } else { + //has flavours + for (int x = 0; x < width; ++x) { + for (int y = 0; y < height; ++y) { + r = normal_rects[y % normal_rects.size()]; + + if (Math::randf() > flavour_chance) { + add_tiled_wall_mesh_rect_simple(x, y, transform, r); + } else { + add_tiled_wall_mesh_rect_simple(x, y, transform, flavour_rects[Math::rand() % flavour_rects.size()]); + } + } } } } else if (tiling_type == TiledWallData::TILED_WALL_TILING_TYPE_BOTH) { Rect2 r; - for (int x = 0; x < width; ++x) { - for (int y = 0; y < height; ++y) { - r = normal_rects[(x + y) % normal_rects.size()]; + if (flavour_rects.size() == 0) { + //no flavours + for (int x = 0; x < width; ++x) { + for (int y = 0; y < height; ++y) { + r = normal_rects[(x + y) % normal_rects.size()]; - add_tiled_wall_mesh_rect_simple(x, y, transform, r); + add_tiled_wall_mesh_rect_simple(x, y, transform, r); + } + } + } else { + //has flavours + for (int x = 0; x < width; ++x) { + for (int y = 0; y < height; ++y) { + r = normal_rects[(x + y) % normal_rects.size()]; + + if (Math::randf() > flavour_chance) { + add_tiled_wall_mesh_rect_simple(x, y, transform, r); + } else { + add_tiled_wall_mesh_rect_simple(x, y, transform, flavour_rects[Math::rand() % flavour_rects.size()]); + } + } } } } diff --git a/tiled_wall/tiled_wall_data.cpp b/tiled_wall/tiled_wall_data.cpp index 6b6fa3a..c54bd20 100644 --- a/tiled_wall/tiled_wall_data.cpp +++ b/tiled_wall/tiled_wall_data.cpp @@ -167,6 +167,13 @@ void TiledWallData::set_flavour_textures(const Vector &textures) { emit_changed(); } +float TiledWallData::get_flavour_chance() const { + return _flavour_chance; +} +void TiledWallData::set_flavour_chance(const float value) { + _flavour_chance = value; +} + //materials void TiledWallData::material_add(const Ref &value) { ERR_FAIL_COND(!value.is_valid()); @@ -291,6 +298,7 @@ void TiledWallData::copy_from(const Ref &tiled_wall_data) { TiledWallData::TiledWallData() { _tiling_type = TILED_WALL_TILING_TYPE_NONE; + _flavour_chance = 0.15; } TiledWallData::~TiledWallData() { _textures.clear(); @@ -327,6 +335,10 @@ void TiledWallData::_bind_methods() { ClassDB::bind_method(D_METHOD("set_flavour_textures", "textures"), &TiledWallData::set_flavour_textures); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "flavour_textures", PROPERTY_HINT_NONE, "17/17:Texture", PROPERTY_USAGE_DEFAULT, "Texture"), "set_flavour_textures", "get_flavour_textures"); + ClassDB::bind_method(D_METHOD("get_flavour_chance"), &TiledWallData::get_flavour_chance); + ClassDB::bind_method(D_METHOD("set_flavour_chance", "texture"), &TiledWallData::set_flavour_chance); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "flavour_chance"), "set_flavour_chance", "get_flavour_chance"); + //materials ClassDB::bind_method(D_METHOD("material_add", "value"), &TiledWallData::material_add); ClassDB::bind_method(D_METHOD("material_set", "index", "value"), &TiledWallData::material_set); diff --git a/tiled_wall/tiled_wall_data.h b/tiled_wall/tiled_wall_data.h index 7c4733f..002a603 100644 --- a/tiled_wall/tiled_wall_data.h +++ b/tiled_wall/tiled_wall_data.h @@ -89,6 +89,9 @@ public: Vector get_flavour_textures(); void set_flavour_textures(const Vector &textures); + float get_flavour_chance() const; + void set_flavour_chance(const float value); + //materials void material_add(const Ref &value); void material_set(const int index, const Ref &value); @@ -121,6 +124,8 @@ private: Vector> _textures; Vector> _flavour_textures; + float _flavour_chance; + Vector> _materials; };