Skip to content

Commit

Permalink
Background resize factor update
Browse files Browse the repository at this point in the history
* RF update.

* Save custom schemas, docs update.

* Linter updates.

* README update.
  • Loading branch information
iwatkot authored Dec 29, 2024
1 parent 88926cd commit a39bb94
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ You can also apply some advanced settings to the map generation process. Note th

- Generate water - if enabled, the water planes obj files will be generated. You can turn it off if you already have those files or don't need them. By default, it's set to True.

- Resize factor - the factor by which the background terrain will be resized. In UI it sets as an integer number (default 8), will be converted to 1/8 (0.125). In expert mode use the float number. The higher the value, the smaller the background terrain will be. Warning: higher terrain will result long processing time and enormous file size.
- Resize factor - the factor by which the background terrain will be resized. It will be used as 1 / resize_factor while generating the models. Which means that the larger the value the more the terrain will be resized. The lowest value is 1, in this case background terrain will not be resized. Note, than low values will lead to long processing and enormous size of the obj files.

## Splines Advanced settings

Expand Down Expand Up @@ -513,4 +513,5 @@ But also, I want to thank the people who helped me with the project in some way,
- [BFernaesds](https://github.com/BFernaesds) - for the manual tests of the app.
- [gamerdesigns](https://github.com/gamerdesigns) - for the manual tests of the app.
- [Tox3](https://github.com/Tox3) - for the manual tests of the app.
- [Lucandia](https://github.com/Lucandia) - for the awesome StreamLit [widget to preview STL files](https://github.com/Lucandia/streamlit_stl).
- [Lucandia](https://github.com/Lucandia) - for the awesome StreamLit [widget to preview STL files](https://github.com/Lucandia/streamlit_stl).
- [H4rdB4se](https://github.com/H4rdB4se) - for investigating the issue with custom OSM files and finding a proper way to work with the files in JOSM.
12 changes: 10 additions & 2 deletions docs/custom_osm.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ If you see the error message "Download area too large", download it in parts.

9. You can start editing your map. You can add new objects, remove existing ones, change their properties, etc. And there will be no one to tell you that you're doing something wrong or reverse your changes.

10. Save the file: **File** -> **Save as** (Ctrl + Shift + S).
10. Pay attention to the fact that if you simply delete the object it will result a broken OSM file. Instead of simply removing something, you need to **Purge** it. To see this option, you need to enable the **Expert mode** in the settings.

![Enable expert mode](https://github.com/user-attachments/assets/eaee73df-76bb-48db-be6b-d4ddb7c5ea7c)

11. After it, you will see the **Purge** option in the **Edit** menu. Use it to remove the object properly.

![Purge object](https://github.com/user-attachments/assets/75c90888-cf6d-437b-906f-89b029350044)

12. Save the file: **File** -> **Save as** (Ctrl + Shift + S).
Now, you can use this file in the generator.
Friendly reminder: save your file in some safe place, so you won't lose your changes.
Friendly reminder: save your file in some safe place, so you won't lose your changes. It's also recommended to use version control systems like Git to track your changes, so you can easily revert them if something goes wrong.
2 changes: 1 addition & 1 deletion maps4fs/generator/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def plane_from_np(
is_preview (bool, optional) -- If True, the preview mesh will be generated.
include_zeros (bool, optional) -- If True, the mesh will include the zero height values.
"""
resize_factor = self.map.background_settings.resize_factor
resize_factor = 1 / self.map.background_settings.resize_factor
dem_data = cv2.resize( # pylint: disable=no-member
dem_data, (0, 0), fx=resize_factor, fy=resize_factor
)
Expand Down
19 changes: 16 additions & 3 deletions maps4fs/generator/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import json
import os
import shutil
from typing import Any, Generator
Expand Down Expand Up @@ -73,12 +74,13 @@ class BackgroundSettings(SettingsModel):
Attributes:
generate_background (bool): generate obj files for the background terrain.
generate_water (bool): generate obj files for the water.
resize_factor (float): resize factor for the background and water.
resize_factor (int): resize factor for the background terrain and water.
It will be used as 1 / resize_factor of the original size.
"""

generate_background: bool = True
generate_water: bool = True
resize_factor: float = 1 / 8
resize_factor: int = 8


class GRLESettings(SettingsModel):
Expand Down Expand Up @@ -140,7 +142,7 @@ class Map:
logger (Any): Logger instance
"""

def __init__( # pylint: disable=R0917
def __init__( # pylint: disable=R0917, R0915
self,
game: Game,
coordinates: tuple[float, float],
Expand Down Expand Up @@ -204,7 +206,18 @@ def __init__( # pylint: disable=R0917
self.logger.debug("Map directory created: %s", self.map_directory)

self.texture_custom_schema = kwargs.get("texture_custom_schema", None)
if self.texture_custom_schema:
save_path = os.path.join(self.map_directory, "texture_custom_schema.json")
with open(save_path, "w", encoding="utf-8") as file:
json.dump(self.texture_custom_schema, file, indent=4)
self.logger.debug("Texture custom schema saved to %s", save_path)

self.tree_custom_schema = kwargs.get("tree_custom_schema", None)
if self.tree_custom_schema:
save_path = os.path.join(self.map_directory, "tree_custom_schema.json")
with open(save_path, "w", encoding="utf-8") as file:
json.dump(self.tree_custom_schema, file, indent=4)
self.logger.debug("Tree custom schema saved to %s", save_path)

try:
shutil.unpack_archive(game.template_path, self.map_directory)
Expand Down
7 changes: 2 additions & 5 deletions webui/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,10 @@ def generate_map(self) -> None:
)
self.logger.debug("DEM settings: %s", dem_settings)

background_resize_factor = 1 / self.background_resize_factor

background_settings = mfs.BackgroundSettings(
generate_background=self.generate_background,
generate_water=self.generate_water,
resize_factor=background_resize_factor,
resize_factor=self.background_resize_factor,
)
self.logger.debug("Background settings: %s", background_settings)

Expand Down Expand Up @@ -642,11 +640,10 @@ def generate_map(self) -> None:

if self.public:
# Override the background resize factor for the public server.
# resize_factor = 0.125 for the public server.
background_settings = mfs.BackgroundSettings(
generate_background=background_settings.generate_background,
generate_water=background_settings.generate_water,
resize_factor=0.125,
resize_factor=8,
)

grle_settings = all_settings["GRLESettings"]
Expand Down

0 comments on commit a39bb94

Please sign in to comment.