Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating grass fix, use random plants option #81

Merged
merged 4 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<a href="#Background-terrain">Background terrain</a> •
<a href="#Overview-image">Overview image</a><br>
<a href="#DDS-conversion">DDS conversion</a> •
<a href="#For-advanced-users">For advanced users</a> •
<a href="#Advanced-settings">Advanced settings</a> •
<a href="#Resources">Resources</a> •
<a href="#Bugs-and-feature-requests">Bugs and feature requests</a><br>
<a href="#Special-thanks">Special thanks</a>
Expand Down Expand Up @@ -434,7 +434,7 @@ List of the important DDS files:
- `preview.dds` - 2048x2048 pixels, the preview image of the map on the loading screen,
- `mapsUS/overview.dds` - 4096x4096 pixels, the overview image of the map (in-game map)

## For advanced users
## Advanced settings
The tool supports the custom size of the map. To use this feature select `Custom` in the `Map size` dropdown and enter the desired size. The tool will generate a map with the size you entered.<br>

⛔️ Do not use this feature, if you don't know what you're doing. In most cases, the Giants Editor will just crash on opening the file, because you need to enter specific values for the map size.<br><br>
Expand All @@ -459,6 +459,12 @@ 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.

### 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.

- Random plants - when adding decorative foliage, enabling this option will add different species of plants to the map. If unchecked only basic grass (smallDenseMix) will be added. Defaults to True.

## Resources
In this section, you'll find a list of the resources that you need to create a map for the Farming Simulator.<br>
To create a basic map, you only need the Giants Editor. But if you want to create a background terrain - the world around the map, so it won't look like it's floating in the void - you also need Blender and the Blender Exporter Plugins. To create realistic textures for the background terrain, the QGIS is required to obtain high-resolution satellite images.<br>
Expand Down
2 changes: 1 addition & 1 deletion data/fs25-texture-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
{
"name": "grassDirtPatchy",
"count": 2,
"tags": { "natural": ["wood", "tree_row", "forest"] },
"tags": { "natural": ["wood", "tree_row"], "landuse": "forest" },
"width": 2,
"color": [0, 252, 124],
"usage": "forest"
Expand Down
10 changes: 9 additions & 1 deletion maps4fs/generator/grle.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def preprocess(self) -> None:
attribute. If the game does not support I3D files, the attribute is set to None."""

self.farmland_margin = self.kwargs.get("farmland_margin", 0)
self.randomize_plants = self.kwargs.get("randomize_plants", True)

try:
grle_schema_path = self.game.grle_schema
Expand Down Expand Up @@ -357,7 +358,8 @@ def get_rounded_polygon(
# Add islands of plants to the base image.
island_count = self.map_size
self.logger.info("Adding %s islands of plants to the base image.", island_count)
grass_image_copy = create_island_of_plants(grass_image_copy, island_count)
if self.randomize_plants:
grass_image_copy = create_island_of_plants(grass_image_copy, island_count)
self.logger.debug("Islands of plants added to the base image.")

# Sligtly reduce the size of the grass_image, that we'll use as mask.
Expand All @@ -368,6 +370,12 @@ def get_rounded_polygon(
grass_image_copy[grass_image == 0] = 0
self.logger.debug("Removed the values where the base image has zeros.")

# Set zeros on all sides of the image
grass_image_copy[0, :] = 0 # Top side
grass_image_copy[-1, :] = 0 # Bottom side
grass_image_copy[:, 0] = 0 # Left side
grass_image_copy[:, -1] = 0 # Right side

# Value of 33 represents the base grass plant.
# After painting it with base grass, we'll create multiple islands of different plants.
# On the final step, we'll remove all the values which in pixels
Expand Down
9 changes: 9 additions & 0 deletions webui/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def add_left_widgets(self) -> None:
self.fields_padding = 0
self.farmland_margin = 3
self.forest_density = 10
self.randomize_plants = True

if not self.auto_process:
self.logger.info("Auto preset is disabled.")
Expand Down Expand Up @@ -347,6 +348,13 @@ def add_left_widgets(self) -> None:
label_visibility="collapsed",
)

st.write("Random plants:")
st.write(Messages.RANDOMIZE_PLANTS_INFO)

self.randomize_plants = st.checkbox(
"Random plants", value=True, key="randomize_plants"
)

# Add an empty container for status messages.
self.status_container = st.empty()

Expand Down Expand Up @@ -455,6 +463,7 @@ def generate_map(self) -> None:
fields_padding=self.fields_padding,
farmland_margin=self.farmland_margin,
forest_density=self.forest_density,
randomize_plants=self.randomize_plants,
)

if self.community:
Expand Down
4 changes: 4 additions & 0 deletions webui/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ class Messages:
"and the map size, it may generate dozens of thousands of trees, which can cause "
"performance issues."
)
RANDOMIZE_PLANTS_INFO = (
"If checked, random species of plants will be generated. "
"If unchecked, only basic smallDenseMix will be applied."
)
Loading