From a39bb94b370411ab6c1c60a5d0993dd510d794fc Mon Sep 17 00:00:00 2001 From: Stan Soldatov <118521851+iwatkot@users.noreply.github.com> Date: Sun, 29 Dec 2024 13:50:34 +0100 Subject: [PATCH] Background resize factor update * RF update. * Save custom schemas, docs update. * Linter updates. * README update. --- README.md | 5 +++-- docs/custom_osm.md | 12 ++++++++++-- maps4fs/generator/background.py | 2 +- maps4fs/generator/map.py | 19 ++++++++++++++++--- webui/generator.py | 7 ++----- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index fe130436..42426b39 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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). \ No newline at end of file +- [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. diff --git a/docs/custom_osm.md b/docs/custom_osm.md index 4faadbfa..c9c9e7b6 100644 --- a/docs/custom_osm.md +++ b/docs/custom_osm.md @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/maps4fs/generator/background.py b/maps4fs/generator/background.py index 8b593b98..9a4bb35a 100644 --- a/maps4fs/generator/background.py +++ b/maps4fs/generator/background.py @@ -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 ) diff --git a/maps4fs/generator/map.py b/maps4fs/generator/map.py index 9ce3be8d..f502017a 100644 --- a/maps4fs/generator/map.py +++ b/maps4fs/generator/map.py @@ -2,6 +2,7 @@ from __future__ import annotations +import json import os import shutil from typing import Any, Generator @@ -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): @@ -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], @@ -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) diff --git a/webui/generator.py b/webui/generator.py index 7507adbb..989b3618 100644 --- a/webui/generator.py +++ b/webui/generator.py @@ -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) @@ -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"]