mirror of
https://github.com/Relintai/props.git
synced 2024-11-12 10:15:25 +01:00
Implemented flavours.
This commit is contained in:
parent
9c970bbed5
commit
9d26fd35f2
@ -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<Rect2> normal_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) {
|
||||
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()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -167,6 +167,13 @@ void TiledWallData::set_flavour_textures(const Vector<Variant> &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<Material> &value) {
|
||||
ERR_FAIL_COND(!value.is_valid());
|
||||
@ -291,6 +298,7 @@ void TiledWallData::copy_from(const Ref<TiledWallData> &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);
|
||||
|
@ -89,6 +89,9 @@ public:
|
||||
Vector<Variant> get_flavour_textures();
|
||||
void set_flavour_textures(const Vector<Variant> &textures);
|
||||
|
||||
float get_flavour_chance() const;
|
||||
void set_flavour_chance(const float value);
|
||||
|
||||
//materials
|
||||
void material_add(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>> _flavour_textures;
|
||||
float _flavour_chance;
|
||||
|
||||
Vector<Ref<Material>> _materials;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user