Implemented flavours.

This commit is contained in:
Relintai 2021-08-18 17:10:45 +02:00
parent 9c970bbed5
commit 9d26fd35f2
3 changed files with 96 additions and 15 deletions

View File

@ -476,6 +476,8 @@ void PropMesher::add_tiled_wall_simple(const int width, const int height, const
return; return;
} }
float flavour_chance = tiled_wall_data->get_flavour_chance();
//collect rects //collect rects
Vector<Rect2> normal_rects; Vector<Rect2> normal_rects;
Vector<Rect2> flavour_rects; Vector<Rect2> 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) { if (tiling_type == TiledWallData::TILED_WALL_TILING_TYPE_NONE) {
Rect2 r = normal_rects[0]; Rect2 r = normal_rects[0];
for (int x = 0; x < width; ++x) { if (flavour_rects.size() == 0) {
for (int y = 0; y < height; ++y) { //no flavours
add_tiled_wall_mesh_rect_simple(x, y, transform, r); 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) { } else if (tiling_type == TiledWallData::TILED_WALL_TILING_TYPE_HORIZONTAL) {
Rect2 r; Rect2 r;
for (int x = 0; x < width; ++x) { if (flavour_rects.size() == 0) {
r = normal_rects[x % normal_rects.size()]; //no flavours
for (int x = 0; x < width; ++x) {
r = normal_rects[x % normal_rects.size()];
for (int y = 0; y < height; ++y) { for (int y = 0; y < height; ++y) {
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) {
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) { } else if (tiling_type == TiledWallData::TILED_WALL_TILING_TYPE_VERTICAL) {
Rect2 r; Rect2 r;
for (int x = 0; x < width; ++x) { if (flavour_rects.size() == 0) {
for (int y = 0; y < height; ++y) { //no flavours
r = normal_rects[y % normal_rects.size()]; 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) { } else if (tiling_type == TiledWallData::TILED_WALL_TILING_TYPE_BOTH) {
Rect2 r; Rect2 r;
for (int x = 0; x < width; ++x) { if (flavour_rects.size() == 0) {
for (int y = 0; y < height; ++y) { //no flavours
r = normal_rects[(x + y) % normal_rects.size()]; 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()]);
}
}
} }
} }
} }

View File

@ -167,6 +167,13 @@ void TiledWallData::set_flavour_textures(const Vector<Variant> &textures) {
emit_changed(); emit_changed();
} }
float TiledWallData::get_flavour_chance() const {
return _flavour_chance;
}
void TiledWallData::set_flavour_chance(const float value) {
_flavour_chance = value;
}
//materials //materials
void TiledWallData::material_add(const Ref<Material> &value) { void TiledWallData::material_add(const Ref<Material> &value) {
ERR_FAIL_COND(!value.is_valid()); ERR_FAIL_COND(!value.is_valid());
@ -291,6 +298,7 @@ void TiledWallData::copy_from(const Ref<TiledWallData> &tiled_wall_data) {
TiledWallData::TiledWallData() { TiledWallData::TiledWallData() {
_tiling_type = TILED_WALL_TILING_TYPE_NONE; _tiling_type = TILED_WALL_TILING_TYPE_NONE;
_flavour_chance = 0.15;
} }
TiledWallData::~TiledWallData() { TiledWallData::~TiledWallData() {
_textures.clear(); _textures.clear();
@ -327,6 +335,10 @@ void TiledWallData::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_flavour_textures", "textures"), &TiledWallData::set_flavour_textures); 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"); 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 //materials
ClassDB::bind_method(D_METHOD("material_add", "value"), &TiledWallData::material_add); ClassDB::bind_method(D_METHOD("material_add", "value"), &TiledWallData::material_add);
ClassDB::bind_method(D_METHOD("material_set", "index", "value"), &TiledWallData::material_set); ClassDB::bind_method(D_METHOD("material_set", "index", "value"), &TiledWallData::material_set);

View File

@ -89,6 +89,9 @@ public:
Vector<Variant> get_flavour_textures(); Vector<Variant> get_flavour_textures();
void set_flavour_textures(const Vector<Variant> &textures); void set_flavour_textures(const Vector<Variant> &textures);
float get_flavour_chance() const;
void set_flavour_chance(const float value);
//materials //materials
void material_add(const Ref<Material> &value); void material_add(const Ref<Material> &value);
void material_set(const int index, const Ref<Material> &value); void material_set(const int index, const Ref<Material> &value);
@ -121,6 +124,8 @@ private:
Vector<Ref<Texture>> _textures; Vector<Ref<Texture>> _textures;
Vector<Ref<Texture>> _flavour_textures; Vector<Ref<Texture>> _flavour_textures;
float _flavour_chance;
Vector<Ref<Material>> _materials; Vector<Ref<Material>> _materials;
}; };