Skip to content

Commit

Permalink
Add farmyards to farmlands
Browse files Browse the repository at this point in the history
* Farmyards.

* README update.
  • Loading branch information
iwatkot authored Dec 31, 2024
1 parent 464d79b commit be36198
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ Let's have a closer look at the fields:
- `priority` - the priority of the texture for overlapping. Textures with higher priorities will be drawn over the textures with lower priorities.
ℹ️ The texture with 0 priority considers the base layer, which means that all empty areas will be filled with this texture.
- `exclude_weight` - this is only used for the forestRockRoots texture from FS25. It just means that this texture has no `weight` postfix, that's all.
- `usage` - the usage of the texture. Mainly used to group different textures by the purpose. For example, the `grass`, `forest`, `drain`.
- `background` - set it to True for the textures, which should have impact on the Background Terrain, by default it's used to subtract the water depth from the DEM and background terrain.
- `info_layer` - if the layer is saving some data in JSON format, this section will describe it's name in the JSON file. Used to find the needed JSON data, for example for fields it will be `fields` and as a value - list of polygon coordinates.
- `invisible` - set it to True for the textures, which should not be drawn in the files, but only to save the data in the JSON file (related to the previous field).

## Background terrain
The tool now supports the generation of the background terrain. If you don't know what it is, here's a brief explanation. The background terrain is the world around the map. It's important to create it because if you don't, the map will look like it's floating in the void. The background terrain is a simple plane that can (and should) be textured to look fine.<br>
Expand Down Expand Up @@ -468,6 +472,8 @@ You can also apply some advanced settings to the map generation process. Note th

- Farmlands margin - this value (in meters) will be applied to each farmland, making it bigger. You can use the value to adjust how much the farmland should be bigger than the actual field. By default, it's set to 3.

- Add Farmyards - if enabled, the tool will create farmlands from the regions that are marked as farmyards in the OSM data. Those farmlands will not have fields and also will not be drawn on textures. By default, it's turned off.

### Vegetation Advanced settings

- Forest density - the density of the forest in meters. The lower the value, the lower the distance between the trees, which makes the forest denser. Note, that low values will lead to enormous number of trees, which may cause the Giants Editor to crash or lead to performance issues. By default, it's set to 10.
Expand Down
6 changes: 5 additions & 1 deletion data/fs25-texture-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@
},
{
"name": "grassFreshMiddle",
"count": 2
"count": 2,
"tags": { "landuse": "farmyard" },
"info_layer": "farmyards",
"color": [34, 255, 34],
"invisible": true
},
{
"name": "grassFreshShort",
Expand Down
5 changes: 5 additions & 0 deletions maps4fs/generator/grle.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ def _add_farmlands(self) -> None:

self.logger.info("Found %s fields in textures info layer.", len(fields))

farmyards: list[list[tuple[int, int]]] | None = textures_info_layer.get("farmyards")
if farmyards and self.map.grle_settings.add_farmyards:
fields.extend(farmyards)
self.logger.info("Found %s farmyards in textures info layer.", len(farmyards))

info_layer_farmlands_path = os.path.join(
self.game.weights_dir_path(self.map_directory), "infoLayer_farmlands.png"
)
Expand Down
3 changes: 3 additions & 0 deletions maps4fs/generator/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ class GRLESettings(SettingsModel):
Attributes:
farmland_margin (int): margin around the farmland.
random_plants (bool): generate random plants on the map or use the default one.
add_farmyards (bool): If True, regions of frarmyards will be added to the map
without corresponding fields.
"""

farmland_margin: int = 0
random_plants: bool = True
add_farmyards: bool = False


class I3DSettings(SettingsModel):
Expand Down
9 changes: 8 additions & 1 deletion maps4fs/generator/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class Layer:
exclude_weight (bool): Flag to exclude weight from the texture.
priority (int | None): Priority of the layer.
info_layer (str | None): Name of the corresnponding info layer.
usage (str | None): Usage of the layer.
background (bool): Flag to determine if the layer is a background.
invisible (bool): Flag to determine if the layer is invisible.
Attributes:
name (str): Name of the layer.
Expand All @@ -65,6 +68,7 @@ def __init__( # pylint: disable=R0917
info_layer: str | None = None,
usage: str | None = None,
background: bool = False,
invisible: bool = False,
):
self.name = name
self.count = count
Expand All @@ -76,6 +80,7 @@ def __init__( # pylint: disable=R0917
self.info_layer = info_layer
self.usage = usage
self.background = background
self.invisible = invisible

def to_json(self) -> dict[str, str | list[str] | bool]: # type: ignore
"""Returns dictionary with layer data.
Expand All @@ -93,6 +98,7 @@ def to_json(self) -> dict[str, str | list[str] | bool]: # type: ignore
"info_layer": self.info_layer,
"usage": self.usage,
"background": self.background,
"invisible": self.invisible,
}

data = {k: v for k, v in data.items() if v is not None}
Expand Down Expand Up @@ -417,7 +423,8 @@ def draw(self) -> None:
info_layer_data[layer.info_layer].append(
self.np_to_polygon_points(polygon) # type: ignore
)
cv2.fillPoly(layer_image, [polygon], color=255) # type: ignore
if not layer.invisible:
cv2.fillPoly(layer_image, [polygon], color=255) # type: ignore

if layer.info_layer == "roads":
for linestring in self.objects_generator(
Expand Down
10 changes: 10 additions & 0 deletions webui/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def add_left_widgets(self) -> None:
self.background_resize_factor = 8
self.expert_mode = False
self.raw_config = None
self.add_farmyards = False

if not self.auto_process:
self.logger.info("Auto preset is disabled.")
Expand Down Expand Up @@ -385,6 +386,14 @@ def add_left_widgets(self) -> None:
key="farmland_margin",
)

st.write(Messages.ADD_FARMYARDS_INFO)

self.add_farmyards = st.checkbox(
"Add farmyards",
value=False,
key="add_farmyards",
)

with st.expander("Vegetation Advanced Settings", icon="🌲"):
st.info(
"ℹ️ Settings related to the vegetation of the map, which represent the trees, "
Expand Down Expand Up @@ -614,6 +623,7 @@ def generate_map(self) -> None:
grle_settings = mfs.GRLESettings(
farmland_margin=self.farmland_margin,
random_plants=self.randomize_plants,
add_farmyards=self.add_farmyards,
)
self.logger.debug("GRLE settings: %s", grle_settings)

Expand Down
6 changes: 6 additions & 0 deletions webui/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,9 @@ class Messages:
"will not be resized. Low values will result with a very long processing and "
"meshes of enormous size. Do not change it unless you know what you are doing."
)
ADD_FARMYARDS_INFO = (
"If add farmyards is enabled and info_layer: farmyards is present in the texture schema, "
"the regions with correspoding tas will be added as a farmland even without the "
"corresponding field. It can be useful if you want to add some farmland in the "
"regions without fields."
)

0 comments on commit be36198

Please sign in to comment.