maps4fs 0.6.8__tar.gz → 0.7.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {maps4fs-0.6.8 → maps4fs-0.7.2}/PKG-INFO +31 -14
- {maps4fs-0.6.8 → maps4fs-0.7.2}/README.md +30 -12
- maps4fs-0.7.2/maps4fs/generator/component.py +99 -0
- {maps4fs-0.6.8 → maps4fs-0.7.2}/maps4fs/generator/config.py +17 -6
- {maps4fs-0.6.8 → maps4fs-0.7.2}/maps4fs/generator/dem.py +72 -39
- {maps4fs-0.6.8 → maps4fs-0.7.2}/maps4fs/generator/map.py +20 -22
- {maps4fs-0.6.8 → maps4fs-0.7.2}/maps4fs/generator/texture.py +11 -11
- {maps4fs-0.6.8 → maps4fs-0.7.2}/maps4fs.egg-info/PKG-INFO +31 -14
- {maps4fs-0.6.8 → maps4fs-0.7.2}/maps4fs.egg-info/requires.txt +0 -1
- {maps4fs-0.6.8 → maps4fs-0.7.2}/pyproject.toml +1 -2
- {maps4fs-0.6.8 → maps4fs-0.7.2}/tests/test_generator.py +21 -57
- maps4fs-0.6.8/maps4fs/generator/component.py +0 -55
- {maps4fs-0.6.8 → maps4fs-0.7.2}/LICENSE.md +0 -0
- {maps4fs-0.6.8 → maps4fs-0.7.2}/maps4fs/__init__.py +0 -0
- {maps4fs-0.6.8 → maps4fs-0.7.2}/maps4fs/generator/__init__.py +0 -0
- {maps4fs-0.6.8 → maps4fs-0.7.2}/maps4fs/generator/game.py +0 -0
- {maps4fs-0.6.8 → maps4fs-0.7.2}/maps4fs/logger.py +0 -0
- {maps4fs-0.6.8 → maps4fs-0.7.2}/maps4fs.egg-info/SOURCES.txt +0 -0
- {maps4fs-0.6.8 → maps4fs-0.7.2}/maps4fs.egg-info/dependency_links.txt +0 -0
- {maps4fs-0.6.8 → maps4fs-0.7.2}/maps4fs.egg-info/top_level.txt +0 -0
- {maps4fs-0.6.8 → maps4fs-0.7.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: maps4fs
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.7.2
|
4
4
|
Summary: Generate map templates for Farming Simulator from real places.
|
5
5
|
Author-email: iwatkot <iwatkot@gmail.com>
|
6
6
|
License: MIT License
|
@@ -16,7 +16,6 @@ License-File: LICENSE.md
|
|
16
16
|
Requires-Dist: opencv-python
|
17
17
|
Requires-Dist: osmnx<2.0.0
|
18
18
|
Requires-Dist: rasterio
|
19
|
-
Requires-Dist: python_dotenv
|
20
19
|
Requires-Dist: tqdm
|
21
20
|
|
22
21
|
<div align="center" markdown>
|
@@ -28,7 +27,7 @@ Requires-Dist: tqdm
|
|
28
27
|
<a href="#How-To-Run">How-To-Run</a> •
|
29
28
|
<a href="#Features">Features</a> •
|
30
29
|
<a href="#Supported-objects">Supported objects</a> •
|
31
|
-
<a href="Settings">Settings</a> •
|
30
|
+
<a href="#Advanced Settings">Advanced Settings</a> •
|
32
31
|
<a href="#Bugs-and-feature-requests">Bugs and feature requests</a>
|
33
32
|
</p>
|
34
33
|
|
@@ -80,6 +79,20 @@ So, if you're new to map making, here's a quick overview of the process:
|
|
80
79
|
3. Open the map template in the Giants Editor.
|
81
80
|
4. Now you can start creating your map (adding roads, fields, buildings, etc.).
|
82
81
|
|
82
|
+
### Previews
|
83
|
+
|
84
|
+
The generator also creates a multiple previews of the map. Here's the list of them:
|
85
|
+
1. General preview - merging all the layers into one image with different colors.
|
86
|
+
2. Grayscale DEM preview - a grayscale image of the height map (as it is).
|
87
|
+
3. Colored DEM preview - a colored image of the height map (from blue to red). The blue color represents the lowest point, and the red color represents the highest point.
|
88
|
+
|
89
|
+
<br>
|
90
|
+
*Preview of a 16 km map with a 500-meter mountain in the middle of it.*<br>
|
91
|
+
|
92
|
+
Parameters:
|
93
|
+
- coordinates: 45.15, 19.71
|
94
|
+
- size: 16 x 16 km
|
95
|
+
|
83
96
|
## How-To-Run
|
84
97
|
|
85
98
|
You'll find detailed instructions on how to run the project below. But if you prefer video tutorials, here's one for you:
|
@@ -143,10 +156,9 @@ import maps4fs as mfs
|
|
143
156
|
map = mfs.Map(
|
144
157
|
game,
|
145
158
|
(52.5200, 13.4050), # Latitude and longitude of the map center.
|
146
|
-
|
159
|
+
height=1024, # The height of the map in meters.
|
160
|
+
width=1024, # The width of the map in meters.
|
147
161
|
map_directory="path/to/your/map/directory", # The directory where the map will be saved.
|
148
|
-
blur_seed=5, # The seed for the blur algorithm. The default value is 5, which means 5 meters.
|
149
|
-
max_height=400 # The maximum height of the map.
|
150
162
|
)
|
151
163
|
```
|
152
164
|
|
@@ -157,11 +169,6 @@ map.generate()
|
|
157
169
|
|
158
170
|
The map will be saved in the `map_directory` directory.
|
159
171
|
|
160
|
-
## Settings
|
161
|
-
Advanced settings are available in the tool's UI under the **Advanced Settings** tab. Here's the list of them:
|
162
|
-
- `max_height` - the maximum height of the map. The default value is 400. Select smaller values for plain-like maps and bigger values for mountainous maps. You may need to experiment with this value to get the desired result.
|
163
|
-
- `blur_seed` - the seed for the blur algorithm. The default value is 5, which means 5 meters. The bigger the value, the smoother the map will be. The smaller the value, the more detailed the map will be. Keep in mind that for some regions, where terrain is bumpy, disabling the blur algorithm may lead to a very rough map. So, I recommend leaving this value as it is.
|
164
|
-
|
165
172
|
## Features
|
166
173
|
- Allows to enter a location by lat and lon (e.g. from Google Maps).
|
167
174
|
- Allows to select a size of the map (2x2, 4x4, 8x8 km, 16x16 km).
|
@@ -186,18 +193,28 @@ The list will be updated as the project develops.
|
|
186
193
|
The script will also generate the `generation_info.json` file in the `output` folder. It contains the following keys: <br>
|
187
194
|
`"coordinates"` - the coordinates of the map center which you entered,<br>
|
188
195
|
`"bbox"` - the bounding box of the map in lat and lon,<br>
|
189
|
-
`"
|
196
|
+
`"map_height"` - the height of the map in meters (this one is from the user input, e.g. 2048 and so on),<br>
|
197
|
+
`"map_width"` - the width of the map in meters (same as above),<br>
|
190
198
|
`"minimum_x"` - the minimum x coordinate of the map (UTM projection),<br>
|
191
199
|
`"minimum_y"` - the minimum y coordinate of the map (UTM projection),<br>
|
192
200
|
`"maximum_x"` - the maximum x coordinate of the map (UTM projection),<br>
|
193
201
|
`"maximum_y"` - the maximum y coordinate of the map (UTM projection),<br>
|
194
|
-
`"height"` - the height of the map in meters (it won't be equal to the
|
195
|
-
`"width"` - the width of the map in meters,<br>
|
202
|
+
`"height"` - the height of the map in meters (it won't be equal to the parameters above since the Earth is not flat, sorry flat-earthers),<br>
|
203
|
+
`"width"` - the width of the map in meters (same as above),<br>
|
196
204
|
`"height_coef"` - since we need a texture of exact size, the height of the map is multiplied by this coefficient,<br>
|
197
205
|
`"width_coef"` - same as above but for the width,<br>
|
198
206
|
`"tile_name"` - the name of the SRTM tile which was used to generate the height map, e.g. "N52E013"<br>
|
199
207
|
|
200
208
|
You can use this information to adjust some other sources of data to the map, e.g. textures, height maps, etc.
|
201
209
|
|
210
|
+
## Advanced Settings
|
211
|
+
You can also apply some advanced settings to the map generation process. Note that they're ADVANCED, so you don't need to use them if you're not sure what they do.<br>
|
212
|
+
|
213
|
+
Here's the list of the advanced settings:
|
214
|
+
|
215
|
+
- DEM multiplier: the height of the map is multiplied by this value. So the DEM map is just a 16-bit grayscale image, which means that the maximum avaiable value there is 65535, while the actual difference between the deepest and the highest point on Earth is about 20 km. So, by default this value is set to 3. Just note that this setting mostly does not matter, because you can always adjust it in the Giants Editor, learn more about the [heightScale](https://www.farming-simulator.org/19/terrain-heightscale.php) parameter on the [PMC Farming Simulator](https://www.farming-simulator.org/) website.
|
216
|
+
|
217
|
+
- DEM Blur radius: the radius of the Gaussian blur filter applied to the DEM map. By default, it's set to 21. This filter just makes the DEM map smoother, so the height transitions will be more natural. You can set it to 1 to disable the filter, but it will result as a Minecraft-like map.
|
218
|
+
|
202
219
|
## Bugs and feature requests
|
203
220
|
If you find a bug or have an idea for a new feature, please create an issue [here](https://github.com/iwatkot/maps4fs/issues) or contact me directly on [Telegram](https://t.me/iwatkot).<br>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<a href="#How-To-Run">How-To-Run</a> •
|
8
8
|
<a href="#Features">Features</a> •
|
9
9
|
<a href="#Supported-objects">Supported objects</a> •
|
10
|
-
<a href="Settings">Settings</a> •
|
10
|
+
<a href="#Advanced Settings">Advanced Settings</a> •
|
11
11
|
<a href="#Bugs-and-feature-requests">Bugs and feature requests</a>
|
12
12
|
</p>
|
13
13
|
|
@@ -59,6 +59,20 @@ So, if you're new to map making, here's a quick overview of the process:
|
|
59
59
|
3. Open the map template in the Giants Editor.
|
60
60
|
4. Now you can start creating your map (adding roads, fields, buildings, etc.).
|
61
61
|
|
62
|
+
### Previews
|
63
|
+
|
64
|
+
The generator also creates a multiple previews of the map. Here's the list of them:
|
65
|
+
1. General preview - merging all the layers into one image with different colors.
|
66
|
+
2. Grayscale DEM preview - a grayscale image of the height map (as it is).
|
67
|
+
3. Colored DEM preview - a colored image of the height map (from blue to red). The blue color represents the lowest point, and the red color represents the highest point.
|
68
|
+
|
69
|
+
<br>
|
70
|
+
*Preview of a 16 km map with a 500-meter mountain in the middle of it.*<br>
|
71
|
+
|
72
|
+
Parameters:
|
73
|
+
- coordinates: 45.15, 19.71
|
74
|
+
- size: 16 x 16 km
|
75
|
+
|
62
76
|
## How-To-Run
|
63
77
|
|
64
78
|
You'll find detailed instructions on how to run the project below. But if you prefer video tutorials, here's one for you:
|
@@ -122,10 +136,9 @@ import maps4fs as mfs
|
|
122
136
|
map = mfs.Map(
|
123
137
|
game,
|
124
138
|
(52.5200, 13.4050), # Latitude and longitude of the map center.
|
125
|
-
|
139
|
+
height=1024, # The height of the map in meters.
|
140
|
+
width=1024, # The width of the map in meters.
|
126
141
|
map_directory="path/to/your/map/directory", # The directory where the map will be saved.
|
127
|
-
blur_seed=5, # The seed for the blur algorithm. The default value is 5, which means 5 meters.
|
128
|
-
max_height=400 # The maximum height of the map.
|
129
142
|
)
|
130
143
|
```
|
131
144
|
|
@@ -136,11 +149,6 @@ map.generate()
|
|
136
149
|
|
137
150
|
The map will be saved in the `map_directory` directory.
|
138
151
|
|
139
|
-
## Settings
|
140
|
-
Advanced settings are available in the tool's UI under the **Advanced Settings** tab. Here's the list of them:
|
141
|
-
- `max_height` - the maximum height of the map. The default value is 400. Select smaller values for plain-like maps and bigger values for mountainous maps. You may need to experiment with this value to get the desired result.
|
142
|
-
- `blur_seed` - the seed for the blur algorithm. The default value is 5, which means 5 meters. The bigger the value, the smoother the map will be. The smaller the value, the more detailed the map will be. Keep in mind that for some regions, where terrain is bumpy, disabling the blur algorithm may lead to a very rough map. So, I recommend leaving this value as it is.
|
143
|
-
|
144
152
|
## Features
|
145
153
|
- Allows to enter a location by lat and lon (e.g. from Google Maps).
|
146
154
|
- Allows to select a size of the map (2x2, 4x4, 8x8 km, 16x16 km).
|
@@ -165,18 +173,28 @@ The list will be updated as the project develops.
|
|
165
173
|
The script will also generate the `generation_info.json` file in the `output` folder. It contains the following keys: <br>
|
166
174
|
`"coordinates"` - the coordinates of the map center which you entered,<br>
|
167
175
|
`"bbox"` - the bounding box of the map in lat and lon,<br>
|
168
|
-
`"
|
176
|
+
`"map_height"` - the height of the map in meters (this one is from the user input, e.g. 2048 and so on),<br>
|
177
|
+
`"map_width"` - the width of the map in meters (same as above),<br>
|
169
178
|
`"minimum_x"` - the minimum x coordinate of the map (UTM projection),<br>
|
170
179
|
`"minimum_y"` - the minimum y coordinate of the map (UTM projection),<br>
|
171
180
|
`"maximum_x"` - the maximum x coordinate of the map (UTM projection),<br>
|
172
181
|
`"maximum_y"` - the maximum y coordinate of the map (UTM projection),<br>
|
173
|
-
`"height"` - the height of the map in meters (it won't be equal to the
|
174
|
-
`"width"` - the width of the map in meters,<br>
|
182
|
+
`"height"` - the height of the map in meters (it won't be equal to the parameters above since the Earth is not flat, sorry flat-earthers),<br>
|
183
|
+
`"width"` - the width of the map in meters (same as above),<br>
|
175
184
|
`"height_coef"` - since we need a texture of exact size, the height of the map is multiplied by this coefficient,<br>
|
176
185
|
`"width_coef"` - same as above but for the width,<br>
|
177
186
|
`"tile_name"` - the name of the SRTM tile which was used to generate the height map, e.g. "N52E013"<br>
|
178
187
|
|
179
188
|
You can use this information to adjust some other sources of data to the map, e.g. textures, height maps, etc.
|
180
189
|
|
190
|
+
## Advanced Settings
|
191
|
+
You can also apply some advanced settings to the map generation process. Note that they're ADVANCED, so you don't need to use them if you're not sure what they do.<br>
|
192
|
+
|
193
|
+
Here's the list of the advanced settings:
|
194
|
+
|
195
|
+
- DEM multiplier: the height of the map is multiplied by this value. So the DEM map is just a 16-bit grayscale image, which means that the maximum avaiable value there is 65535, while the actual difference between the deepest and the highest point on Earth is about 20 km. So, by default this value is set to 3. Just note that this setting mostly does not matter, because you can always adjust it in the Giants Editor, learn more about the [heightScale](https://www.farming-simulator.org/19/terrain-heightscale.php) parameter on the [PMC Farming Simulator](https://www.farming-simulator.org/) website.
|
196
|
+
|
197
|
+
- DEM Blur radius: the radius of the Gaussian blur filter applied to the DEM map. By default, it's set to 21. This filter just makes the DEM map smoother, so the height transitions will be more natural. You can set it to 1 to disable the filter, but it will result as a Minecraft-like map.
|
198
|
+
|
181
199
|
## Bugs and feature requests
|
182
200
|
If you find a bug or have an idea for a new feature, please create an issue [here](https://github.com/iwatkot/maps4fs/issues) or contact me directly on [Telegram](https://t.me/iwatkot).<br>
|
@@ -0,0 +1,99 @@
|
|
1
|
+
"""This module contains the base class for all map generation components."""
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
from typing import TYPE_CHECKING, Any
|
6
|
+
|
7
|
+
import osmnx as ox # type: ignore
|
8
|
+
|
9
|
+
if TYPE_CHECKING:
|
10
|
+
from maps4fs.generator.game import Game
|
11
|
+
|
12
|
+
|
13
|
+
# pylint: disable=R0801, R0903, R0902
|
14
|
+
class Component:
|
15
|
+
"""Base class for all map generation components.
|
16
|
+
|
17
|
+
Args:
|
18
|
+
coordinates (tuple[float, float]): The latitude and longitude of the center of the map.
|
19
|
+
map_height (int): The height of the map in pixels.
|
20
|
+
map_width (int): The width of the map in pixels.
|
21
|
+
map_directory (str): The directory where the map files are stored.
|
22
|
+
logger (Any, optional): The logger to use. Must have at least three basic methods: debug,
|
23
|
+
info, warning. If not provided, default logging will be used.
|
24
|
+
"""
|
25
|
+
|
26
|
+
def __init__(
|
27
|
+
self,
|
28
|
+
game: Game,
|
29
|
+
coordinates: tuple[float, float],
|
30
|
+
map_height: int,
|
31
|
+
map_width: int,
|
32
|
+
map_directory: str,
|
33
|
+
logger: Any = None,
|
34
|
+
**kwargs, # pylint: disable=W0613, R0913, R0917
|
35
|
+
):
|
36
|
+
self.game = game
|
37
|
+
self.coordinates = coordinates
|
38
|
+
self.map_height = map_height
|
39
|
+
self.map_width = map_width
|
40
|
+
self.map_directory = map_directory
|
41
|
+
self.logger = logger
|
42
|
+
self.kwargs = kwargs
|
43
|
+
|
44
|
+
self.save_bbox()
|
45
|
+
self.preprocess()
|
46
|
+
|
47
|
+
def preprocess(self) -> None:
|
48
|
+
"""Prepares the component for processing. Must be implemented in the child class.
|
49
|
+
|
50
|
+
Raises:
|
51
|
+
NotImplementedError: If the method is not implemented in the child class.
|
52
|
+
"""
|
53
|
+
raise NotImplementedError
|
54
|
+
|
55
|
+
def process(self) -> None:
|
56
|
+
"""Launches the component processing. Must be implemented in the child class.
|
57
|
+
|
58
|
+
Raises:
|
59
|
+
NotImplementedError: If the method is not implemented in the child class.
|
60
|
+
"""
|
61
|
+
raise NotImplementedError
|
62
|
+
|
63
|
+
def previews(self) -> list[str]:
|
64
|
+
"""Returns a list of paths to the preview images. Must be implemented in the child class.
|
65
|
+
|
66
|
+
Raises:
|
67
|
+
NotImplementedError: If the method is not implemented in the child class.
|
68
|
+
"""
|
69
|
+
raise NotImplementedError
|
70
|
+
|
71
|
+
def get_bbox(self, project_utm: bool = False) -> tuple[int, int, int, int]:
|
72
|
+
"""Calculates the bounding box of the map from the coordinates and the height and
|
73
|
+
width of the map.
|
74
|
+
|
75
|
+
Args:
|
76
|
+
project_utm (bool, optional): Whether to project the bounding box to UTM.
|
77
|
+
|
78
|
+
Returns:
|
79
|
+
tuple[int, int, int, int]: The bounding box of the map.
|
80
|
+
"""
|
81
|
+
north, south, _, _ = ox.utils_geo.bbox_from_point(
|
82
|
+
self.coordinates, dist=self.map_height / 2, project_utm=project_utm
|
83
|
+
)
|
84
|
+
_, _, east, west = ox.utils_geo.bbox_from_point(
|
85
|
+
self.coordinates, dist=self.map_width / 2, project_utm=project_utm
|
86
|
+
)
|
87
|
+
bbox = north, south, east, west
|
88
|
+
self.logger.debug(
|
89
|
+
f"Calculated bounding box for component: {self.__class__.__name__}: {bbox}, "
|
90
|
+
f"project_utm: {project_utm}"
|
91
|
+
)
|
92
|
+
return bbox
|
93
|
+
|
94
|
+
def save_bbox(self) -> None:
|
95
|
+
"""Saves the bounding box of the map to the component instance from the coordinates and the
|
96
|
+
height and width of the map.
|
97
|
+
"""
|
98
|
+
self.bbox = self.get_bbox(project_utm=False)
|
99
|
+
self.logger.debug(f"Saved bounding box: {self.bbox}")
|
@@ -14,7 +14,8 @@ class Config(Component):
|
|
14
14
|
|
15
15
|
Args:
|
16
16
|
coordinates (tuple[float, float]): The latitude and longitude of the center of the map.
|
17
|
-
|
17
|
+
map_height (int): The height of the map in pixels.
|
18
|
+
map_width (int): The width of the map in pixels.
|
18
19
|
map_directory (str): The directory where the map files are stored.
|
19
20
|
logger (Any, optional): The logger to use. Must have at least three basic methods: debug,
|
20
21
|
info, warning. If not provided, default logging will be used.
|
@@ -22,7 +23,7 @@ class Config(Component):
|
|
22
23
|
|
23
24
|
def preprocess(self) -> None:
|
24
25
|
self._map_xml_path = self.game.map_xml_path(self.map_directory)
|
25
|
-
self.logger.debug(
|
26
|
+
self.logger.debug("Map XML path: %s.", self._map_xml_path)
|
26
27
|
|
27
28
|
def process(self):
|
28
29
|
self._set_map_size()
|
@@ -36,9 +37,19 @@ class Config(Component):
|
|
36
37
|
self.logger.debug("Map XML file loaded from: %s.", self._map_xml_path)
|
37
38
|
root = tree.getroot()
|
38
39
|
for map_elem in root.iter("map"):
|
39
|
-
width
|
40
|
-
map_elem.set("
|
41
|
-
|
42
|
-
|
40
|
+
map_elem.set("width", str(self.map_width))
|
41
|
+
map_elem.set("height", str(self.map_height))
|
42
|
+
self.logger.debug(
|
43
|
+
"Map size set to %sx%s in Map XML file.", self.map_width, self.map_height
|
44
|
+
)
|
43
45
|
tree.write(self._map_xml_path)
|
44
46
|
self.logger.debug("Map XML file saved to: %s.", self._map_xml_path)
|
47
|
+
|
48
|
+
def previews(self) -> list[str]:
|
49
|
+
"""Returns a list of paths to the preview images (empty list).
|
50
|
+
The component does not generate any preview images so it returns an empty list.
|
51
|
+
|
52
|
+
Returns:
|
53
|
+
list[str]: An empty list.
|
54
|
+
"""
|
55
|
+
return []
|
@@ -7,13 +7,14 @@ import shutil
|
|
7
7
|
|
8
8
|
import cv2
|
9
9
|
import numpy as np
|
10
|
-
import osmnx as ox # type: ignore
|
11
10
|
import rasterio # type: ignore
|
12
11
|
import requests
|
13
12
|
|
14
13
|
from maps4fs.generator.component import Component
|
15
14
|
|
16
15
|
SRTM = "https://elevation-tiles-prod.s3.amazonaws.com/skadi/{latitude_band}/{tile_name}.hgt.gz"
|
16
|
+
DEFAULT_MULTIPLIER = 3
|
17
|
+
DEFAULT_BLUR_RADIUS = 21
|
17
18
|
|
18
19
|
|
19
20
|
# pylint: disable=R0903
|
@@ -22,16 +23,14 @@ class DEM(Component):
|
|
22
23
|
|
23
24
|
Args:
|
24
25
|
coordinates (tuple[float, float]): The latitude and longitude of the center of the map.
|
25
|
-
|
26
|
+
map_height (int): The height of the map in pixels.
|
27
|
+
map_width (int): The width of the map in pixels.
|
26
28
|
map_directory (str): The directory where the map files are stored.
|
27
29
|
logger (Any, optional): The logger to use. Must have at least three basic methods: debug,
|
28
30
|
info, warning. If not provided, default logging will be used.
|
29
31
|
"""
|
30
32
|
|
31
33
|
def preprocess(self) -> None:
|
32
|
-
self._blur_seed: int = self.kwargs.get("blur_seed") or 5
|
33
|
-
self._max_height: int = self.kwargs.get("max_height") or 200
|
34
|
-
|
35
34
|
self._dem_path = self.game.dem_file_path(self.map_directory)
|
36
35
|
self.temp_dir = "temp"
|
37
36
|
self.hgt_dir = os.path.join(self.temp_dir, "hgt")
|
@@ -39,24 +38,27 @@ class DEM(Component):
|
|
39
38
|
os.makedirs(self.hgt_dir, exist_ok=True)
|
40
39
|
os.makedirs(self.gz_dir, exist_ok=True)
|
41
40
|
|
41
|
+
self.multiplier = self.kwargs.get("multiplier", DEFAULT_MULTIPLIER)
|
42
|
+
self.blur_radius = self.kwargs.get("blur_radius", DEFAULT_BLUR_RADIUS)
|
43
|
+
self.logger.debug(
|
44
|
+
"DEM multiplier is %s, blur radius is %s.", self.multiplier, self.blur_radius
|
45
|
+
)
|
46
|
+
|
42
47
|
# pylint: disable=no-member
|
43
48
|
def process(self) -> None:
|
44
49
|
"""Reads SRTM file, crops it to map size, normalizes and blurs it,
|
45
50
|
saves to map directory."""
|
46
|
-
north, south, east, west =
|
47
|
-
self.coordinates, dist=self.distance
|
48
|
-
)
|
49
|
-
self.logger.debug(
|
50
|
-
f"Processing DEM. North: {north}, south: {south}, east: {east}, west: {west}."
|
51
|
-
)
|
51
|
+
north, south, east, west = self.bbox
|
52
52
|
|
53
|
-
|
53
|
+
dem_height = self.map_height * self.game.dem_multipliyer + 1
|
54
|
+
dem_width = self.map_width * self.game.dem_multipliyer + 1
|
54
55
|
self.logger.debug(
|
55
|
-
"DEM multiplier is %s, DEM
|
56
|
+
"DEM multiplier is %s, DEM height is %s, DEM width is %s.",
|
56
57
|
self.game.dem_multipliyer,
|
57
|
-
|
58
|
+
dem_height,
|
59
|
+
dem_width,
|
58
60
|
)
|
59
|
-
dem_output_resolution = (
|
61
|
+
dem_output_resolution = (dem_width, dem_height)
|
60
62
|
self.logger.debug("DEM output resolution: %s.", dem_output_resolution)
|
61
63
|
|
62
64
|
tile_path = self._srtm_tile()
|
@@ -87,19 +89,34 @@ class DEM(Component):
|
|
87
89
|
f"Min: {data.min()}, max: {data.max()}."
|
88
90
|
)
|
89
91
|
|
90
|
-
normalized_data = self._normalize_dem(data)
|
91
|
-
|
92
92
|
resampled_data = cv2.resize(
|
93
|
-
|
93
|
+
data, dem_output_resolution, interpolation=cv2.INTER_LINEAR
|
94
|
+
).astype("uint16")
|
95
|
+
|
96
|
+
self.logger.debug(
|
97
|
+
f"Maximum value in resampled data: {resampled_data.max()}, "
|
98
|
+
f"minimum value: {resampled_data.min()}."
|
94
99
|
)
|
100
|
+
|
101
|
+
resampled_data = resampled_data * self.multiplier
|
102
|
+
self.logger.debug(
|
103
|
+
f"DEM data multiplied by {self.multiplier}. Shape: {resampled_data.shape}, "
|
104
|
+
f"dtype: {resampled_data.dtype}. "
|
105
|
+
f"Min: {resampled_data.min()}, max: {resampled_data.max()}."
|
106
|
+
)
|
107
|
+
|
95
108
|
self.logger.debug(
|
96
109
|
f"DEM data was resampled. Shape: {resampled_data.shape}, "
|
97
110
|
f"dtype: {resampled_data.dtype}. "
|
98
111
|
f"Min: {resampled_data.min()}, max: {resampled_data.max()}."
|
99
112
|
)
|
100
113
|
|
101
|
-
|
102
|
-
|
114
|
+
resampled_data = cv2.GaussianBlur(resampled_data, (self.blur_radius, self.blur_radius), 0)
|
115
|
+
self.logger.debug(
|
116
|
+
f"Gaussion blur applied to DEM data with kernel size {self.blur_radius}. "
|
117
|
+
)
|
118
|
+
|
119
|
+
cv2.imwrite(self._dem_path, resampled_data)
|
103
120
|
self.logger.debug("DEM data was saved to %s.", self._dem_path)
|
104
121
|
|
105
122
|
def _tile_info(self, lat: float, lon: float) -> tuple[str, str]:
|
@@ -182,26 +199,42 @@ class DEM(Component):
|
|
182
199
|
cv2.imwrite(self._dem_path, dem_data) # pylint: disable=no-member
|
183
200
|
self.logger.warning("DEM data filled with zeros and saved to %s.", self._dem_path)
|
184
201
|
|
185
|
-
def
|
186
|
-
"""
|
202
|
+
def grayscale_preview(self) -> str:
|
203
|
+
"""Converts DEM image to grayscale RGB image and saves it to the map directory.
|
204
|
+
Returns path to the preview image.
|
187
205
|
|
188
|
-
|
189
|
-
|
206
|
+
Returns:
|
207
|
+
str: Path to the preview image.
|
208
|
+
"""
|
209
|
+
rgb_dem_path = self._dem_path.replace(".png", "_grayscale.png")
|
210
|
+
dem_data = cv2.imread(self._dem_path, cv2.IMREAD_GRAYSCALE)
|
211
|
+
dem_data_rgb = cv2.cvtColor(dem_data, cv2.COLOR_GRAY2RGB)
|
212
|
+
cv2.imwrite(rgb_dem_path, dem_data_rgb)
|
213
|
+
return rgb_dem_path
|
214
|
+
|
215
|
+
def colored_preview(self) -> str:
|
216
|
+
"""Converts DEM image to colored RGB image and saves it to the map directory.
|
217
|
+
Returns path to the preview image.
|
190
218
|
|
191
219
|
Returns:
|
192
|
-
|
220
|
+
list[str]: List with a single path to the DEM file
|
193
221
|
"""
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
222
|
+
|
223
|
+
colored_dem_path = self._dem_path.replace(".png", "_colored.png")
|
224
|
+
dem_data = cv2.imread(self._dem_path, cv2.IMREAD_GRAYSCALE)
|
225
|
+
|
226
|
+
# Normalize the DEM data to the range [0, 255]
|
227
|
+
# dem_data_normalized = cv2.normalize(dem_data, None, 0, 255, cv2.NORM_MINMAX)
|
228
|
+
|
229
|
+
dem_data_colored = cv2.applyColorMap(dem_data, cv2.COLORMAP_JET)
|
230
|
+
|
231
|
+
cv2.imwrite(colored_dem_path, dem_data_colored)
|
232
|
+
return colored_dem_path
|
233
|
+
|
234
|
+
def previews(self) -> list[str]:
|
235
|
+
"""Get list of preview images.
|
236
|
+
|
237
|
+
Returns:
|
238
|
+
list[str]: List of preview images.
|
239
|
+
"""
|
240
|
+
return [self.grayscale_preview(), self.colored_preview()]
|
@@ -6,21 +6,21 @@ from typing import Any
|
|
6
6
|
|
7
7
|
from tqdm import tqdm
|
8
8
|
|
9
|
+
from maps4fs.generator.component import Component
|
9
10
|
from maps4fs.generator.game import Game
|
10
11
|
from maps4fs.logger import Logger
|
11
12
|
|
12
13
|
|
13
|
-
# pylint: disable=R0913
|
14
|
+
# pylint: disable=R0913, R0902
|
14
15
|
class Map:
|
15
16
|
"""Class used to generate map using all components.
|
16
17
|
|
17
18
|
Args:
|
18
19
|
game (Type[Game]): Game for which the map is generated.
|
19
20
|
coordinates (tuple[float, float]): Coordinates of the center of the map.
|
20
|
-
|
21
|
+
height (int): Height of the map in pixels.
|
22
|
+
width (int): Width of the map in pixels.
|
21
23
|
map_directory (str): Path to the directory where map files will be stored.
|
22
|
-
blur_seed (int): Seed used for blur effect.
|
23
|
-
max_height (int): Maximum height of the map.
|
24
24
|
logger (Any): Logger instance
|
25
25
|
"""
|
26
26
|
|
@@ -28,15 +28,17 @@ class Map:
|
|
28
28
|
self,
|
29
29
|
game: Game,
|
30
30
|
coordinates: tuple[float, float],
|
31
|
-
|
31
|
+
height: int,
|
32
|
+
width: int,
|
32
33
|
map_directory: str,
|
33
|
-
blur_seed: int,
|
34
|
-
max_height: int,
|
35
34
|
logger: Any = None,
|
35
|
+
**kwargs,
|
36
36
|
):
|
37
37
|
self.game = game
|
38
|
+
self.components: list[Component] = []
|
38
39
|
self.coordinates = coordinates
|
39
|
-
self.
|
40
|
+
self.height = height
|
41
|
+
self.width = width
|
40
42
|
self.map_directory = map_directory
|
41
43
|
|
42
44
|
if not logger:
|
@@ -44,6 +46,8 @@ class Map:
|
|
44
46
|
self.logger = logger
|
45
47
|
self.logger.debug("Game was set to %s", game.code)
|
46
48
|
|
49
|
+
self.kwargs = kwargs
|
50
|
+
|
47
51
|
os.makedirs(self.map_directory, exist_ok=True)
|
48
52
|
self.logger.debug("Map directory created: %s", self.map_directory)
|
49
53
|
|
@@ -53,15 +57,6 @@ class Map:
|
|
53
57
|
except Exception as e:
|
54
58
|
raise RuntimeError(f"Can not unpack map template due to error: {e}") from e
|
55
59
|
|
56
|
-
# Blur seed should be positive and odd.
|
57
|
-
if blur_seed <= 0:
|
58
|
-
raise ValueError("Blur seed should be positive.")
|
59
|
-
if blur_seed % 2 == 0:
|
60
|
-
blur_seed += 1
|
61
|
-
|
62
|
-
self.blur_seed = blur_seed
|
63
|
-
self.max_height = max_height
|
64
|
-
|
65
60
|
def generate(self) -> None:
|
66
61
|
"""Launch map generation using all components."""
|
67
62
|
with tqdm(total=len(self.game.components), desc="Generating map...") as pbar:
|
@@ -69,11 +64,11 @@ class Map:
|
|
69
64
|
component = game_component(
|
70
65
|
self.game,
|
71
66
|
self.coordinates,
|
72
|
-
self.
|
67
|
+
self.height,
|
68
|
+
self.width,
|
73
69
|
self.map_directory,
|
74
70
|
self.logger,
|
75
|
-
|
76
|
-
max_height=self.max_height,
|
71
|
+
**self.kwargs,
|
77
72
|
)
|
78
73
|
try:
|
79
74
|
component.process()
|
@@ -84,7 +79,7 @@ class Map:
|
|
84
79
|
e,
|
85
80
|
)
|
86
81
|
raise e
|
87
|
-
|
82
|
+
self.components.append(component)
|
88
83
|
|
89
84
|
pbar.update(1)
|
90
85
|
|
@@ -94,7 +89,10 @@ class Map:
|
|
94
89
|
Returns:
|
95
90
|
list[str]: List of preview images.
|
96
91
|
"""
|
97
|
-
|
92
|
+
previews = []
|
93
|
+
for component in self.components:
|
94
|
+
previews.extend(component.previews())
|
95
|
+
return previews
|
98
96
|
|
99
97
|
def pack(self, archive_name: str) -> str:
|
100
98
|
"""Pack map directory to zip archive.
|
@@ -116,7 +116,6 @@ class Texture(Component):
|
|
116
116
|
self.logger.info("Loaded %s layers.", len(self.layers))
|
117
117
|
|
118
118
|
self._weights_dir = os.path.join(self.map_directory, "maps", "map", "data")
|
119
|
-
self._bbox = ox.utils_geo.bbox_from_point(self.coordinates, dist=self.distance)
|
120
119
|
self.info_save_path = os.path.join(self.map_directory, "generation_info.json")
|
121
120
|
|
122
121
|
def process(self):
|
@@ -132,9 +131,8 @@ class Texture(Component):
|
|
132
131
|
- map dimensions in meters
|
133
132
|
- map coefficients (meters per pixel)
|
134
133
|
"""
|
135
|
-
north, south, east, west =
|
136
|
-
|
137
|
-
)
|
134
|
+
north, south, east, west = self.get_bbox(project_utm=True)
|
135
|
+
|
138
136
|
# Parameters of the map in UTM format (meters).
|
139
137
|
self.minimum_x = min(west, east)
|
140
138
|
self.minimum_y = min(south, north)
|
@@ -147,8 +145,8 @@ class Texture(Component):
|
|
147
145
|
self.width = abs(east - west)
|
148
146
|
self.logger.info("Map dimensions (HxW): %s x %s.", self.height, self.width)
|
149
147
|
|
150
|
-
self.height_coef = self.height /
|
151
|
-
self.width_coef = self.width /
|
148
|
+
self.height_coef = self.height / self.map_height
|
149
|
+
self.width_coef = self.width / self.map_width
|
152
150
|
self.logger.debug("Map coefficients (HxW): %s x %s.", self.height_coef, self.width_coef)
|
153
151
|
|
154
152
|
def info_sequence(self) -> None:
|
@@ -157,7 +155,8 @@ class Texture(Component):
|
|
157
155
|
Info sequence contains following attributes:
|
158
156
|
- coordinates
|
159
157
|
- bbox
|
160
|
-
-
|
158
|
+
- map_height
|
159
|
+
- map_width
|
161
160
|
- minimum_x
|
162
161
|
- minimum_y
|
163
162
|
- maximum_x
|
@@ -170,7 +169,8 @@ class Texture(Component):
|
|
170
169
|
useful_attributes = [
|
171
170
|
"coordinates",
|
172
171
|
"bbox",
|
173
|
-
"
|
172
|
+
"map_height",
|
173
|
+
"map_width",
|
174
174
|
"minimum_x",
|
175
175
|
"minimum_y",
|
176
176
|
"maximum_x",
|
@@ -201,7 +201,7 @@ class Texture(Component):
|
|
201
201
|
texture_name (str): Name of the texture.
|
202
202
|
layer_numbers (int): Number of layers in the texture.
|
203
203
|
"""
|
204
|
-
size = self.
|
204
|
+
size = (self.map_height, self.map_width)
|
205
205
|
postfix = "_weight.png"
|
206
206
|
if layer_numbers == 0:
|
207
207
|
filepaths = [os.path.join(self._weights_dir, texture_name + postfix)]
|
@@ -212,7 +212,7 @@ class Texture(Component):
|
|
212
212
|
]
|
213
213
|
|
214
214
|
for filepath in filepaths:
|
215
|
-
img = np.zeros(
|
215
|
+
img = np.zeros(size, dtype=np.uint8)
|
216
216
|
cv2.imwrite(filepath, img) # pylint: disable=no-member
|
217
217
|
|
218
218
|
@property
|
@@ -356,7 +356,7 @@ class Texture(Component):
|
|
356
356
|
try:
|
357
357
|
with warnings.catch_warnings():
|
358
358
|
warnings.simplefilter("ignore", DeprecationWarning)
|
359
|
-
objects = ox.features_from_bbox(bbox=self.
|
359
|
+
objects = ox.features_from_bbox(bbox=self.bbox, tags=tags)
|
360
360
|
except Exception as e: # pylint: disable=W0718
|
361
361
|
self.logger.warning("Error fetching objects for tags: %s.", tags)
|
362
362
|
self.logger.warning(e)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: maps4fs
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.7.2
|
4
4
|
Summary: Generate map templates for Farming Simulator from real places.
|
5
5
|
Author-email: iwatkot <iwatkot@gmail.com>
|
6
6
|
License: MIT License
|
@@ -16,7 +16,6 @@ License-File: LICENSE.md
|
|
16
16
|
Requires-Dist: opencv-python
|
17
17
|
Requires-Dist: osmnx<2.0.0
|
18
18
|
Requires-Dist: rasterio
|
19
|
-
Requires-Dist: python_dotenv
|
20
19
|
Requires-Dist: tqdm
|
21
20
|
|
22
21
|
<div align="center" markdown>
|
@@ -28,7 +27,7 @@ Requires-Dist: tqdm
|
|
28
27
|
<a href="#How-To-Run">How-To-Run</a> •
|
29
28
|
<a href="#Features">Features</a> •
|
30
29
|
<a href="#Supported-objects">Supported objects</a> •
|
31
|
-
<a href="Settings">Settings</a> •
|
30
|
+
<a href="#Advanced Settings">Advanced Settings</a> •
|
32
31
|
<a href="#Bugs-and-feature-requests">Bugs and feature requests</a>
|
33
32
|
</p>
|
34
33
|
|
@@ -80,6 +79,20 @@ So, if you're new to map making, here's a quick overview of the process:
|
|
80
79
|
3. Open the map template in the Giants Editor.
|
81
80
|
4. Now you can start creating your map (adding roads, fields, buildings, etc.).
|
82
81
|
|
82
|
+
### Previews
|
83
|
+
|
84
|
+
The generator also creates a multiple previews of the map. Here's the list of them:
|
85
|
+
1. General preview - merging all the layers into one image with different colors.
|
86
|
+
2. Grayscale DEM preview - a grayscale image of the height map (as it is).
|
87
|
+
3. Colored DEM preview - a colored image of the height map (from blue to red). The blue color represents the lowest point, and the red color represents the highest point.
|
88
|
+
|
89
|
+
<br>
|
90
|
+
*Preview of a 16 km map with a 500-meter mountain in the middle of it.*<br>
|
91
|
+
|
92
|
+
Parameters:
|
93
|
+
- coordinates: 45.15, 19.71
|
94
|
+
- size: 16 x 16 km
|
95
|
+
|
83
96
|
## How-To-Run
|
84
97
|
|
85
98
|
You'll find detailed instructions on how to run the project below. But if you prefer video tutorials, here's one for you:
|
@@ -143,10 +156,9 @@ import maps4fs as mfs
|
|
143
156
|
map = mfs.Map(
|
144
157
|
game,
|
145
158
|
(52.5200, 13.4050), # Latitude and longitude of the map center.
|
146
|
-
|
159
|
+
height=1024, # The height of the map in meters.
|
160
|
+
width=1024, # The width of the map in meters.
|
147
161
|
map_directory="path/to/your/map/directory", # The directory where the map will be saved.
|
148
|
-
blur_seed=5, # The seed for the blur algorithm. The default value is 5, which means 5 meters.
|
149
|
-
max_height=400 # The maximum height of the map.
|
150
162
|
)
|
151
163
|
```
|
152
164
|
|
@@ -157,11 +169,6 @@ map.generate()
|
|
157
169
|
|
158
170
|
The map will be saved in the `map_directory` directory.
|
159
171
|
|
160
|
-
## Settings
|
161
|
-
Advanced settings are available in the tool's UI under the **Advanced Settings** tab. Here's the list of them:
|
162
|
-
- `max_height` - the maximum height of the map. The default value is 400. Select smaller values for plain-like maps and bigger values for mountainous maps. You may need to experiment with this value to get the desired result.
|
163
|
-
- `blur_seed` - the seed for the blur algorithm. The default value is 5, which means 5 meters. The bigger the value, the smoother the map will be. The smaller the value, the more detailed the map will be. Keep in mind that for some regions, where terrain is bumpy, disabling the blur algorithm may lead to a very rough map. So, I recommend leaving this value as it is.
|
164
|
-
|
165
172
|
## Features
|
166
173
|
- Allows to enter a location by lat and lon (e.g. from Google Maps).
|
167
174
|
- Allows to select a size of the map (2x2, 4x4, 8x8 km, 16x16 km).
|
@@ -186,18 +193,28 @@ The list will be updated as the project develops.
|
|
186
193
|
The script will also generate the `generation_info.json` file in the `output` folder. It contains the following keys: <br>
|
187
194
|
`"coordinates"` - the coordinates of the map center which you entered,<br>
|
188
195
|
`"bbox"` - the bounding box of the map in lat and lon,<br>
|
189
|
-
`"
|
196
|
+
`"map_height"` - the height of the map in meters (this one is from the user input, e.g. 2048 and so on),<br>
|
197
|
+
`"map_width"` - the width of the map in meters (same as above),<br>
|
190
198
|
`"minimum_x"` - the minimum x coordinate of the map (UTM projection),<br>
|
191
199
|
`"minimum_y"` - the minimum y coordinate of the map (UTM projection),<br>
|
192
200
|
`"maximum_x"` - the maximum x coordinate of the map (UTM projection),<br>
|
193
201
|
`"maximum_y"` - the maximum y coordinate of the map (UTM projection),<br>
|
194
|
-
`"height"` - the height of the map in meters (it won't be equal to the
|
195
|
-
`"width"` - the width of the map in meters,<br>
|
202
|
+
`"height"` - the height of the map in meters (it won't be equal to the parameters above since the Earth is not flat, sorry flat-earthers),<br>
|
203
|
+
`"width"` - the width of the map in meters (same as above),<br>
|
196
204
|
`"height_coef"` - since we need a texture of exact size, the height of the map is multiplied by this coefficient,<br>
|
197
205
|
`"width_coef"` - same as above but for the width,<br>
|
198
206
|
`"tile_name"` - the name of the SRTM tile which was used to generate the height map, e.g. "N52E013"<br>
|
199
207
|
|
200
208
|
You can use this information to adjust some other sources of data to the map, e.g. textures, height maps, etc.
|
201
209
|
|
210
|
+
## Advanced Settings
|
211
|
+
You can also apply some advanced settings to the map generation process. Note that they're ADVANCED, so you don't need to use them if you're not sure what they do.<br>
|
212
|
+
|
213
|
+
Here's the list of the advanced settings:
|
214
|
+
|
215
|
+
- DEM multiplier: the height of the map is multiplied by this value. So the DEM map is just a 16-bit grayscale image, which means that the maximum avaiable value there is 65535, while the actual difference between the deepest and the highest point on Earth is about 20 km. So, by default this value is set to 3. Just note that this setting mostly does not matter, because you can always adjust it in the Giants Editor, learn more about the [heightScale](https://www.farming-simulator.org/19/terrain-heightscale.php) parameter on the [PMC Farming Simulator](https://www.farming-simulator.org/) website.
|
216
|
+
|
217
|
+
- DEM Blur radius: the radius of the Gaussian blur filter applied to the DEM map. By default, it's set to 21. This filter just makes the DEM map smoother, so the height transitions will be more natural. You can set it to 1 to disable the filter, but it will result as a Minecraft-like map.
|
218
|
+
|
202
219
|
## Bugs and feature requests
|
203
220
|
If you find a bug or have an idea for a new feature, please create an issue [here](https://github.com/iwatkot/maps4fs/issues) or contact me directly on [Telegram](https://t.me/iwatkot).<br>
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "maps4fs"
|
7
|
-
version = "0.
|
7
|
+
version = "0.7.2"
|
8
8
|
description = "Generate map templates for Farming Simulator from real places."
|
9
9
|
authors = [{name = "iwatkot", email = "iwatkot@gmail.com"}]
|
10
10
|
license = {text = "MIT License"}
|
@@ -20,7 +20,6 @@ dependencies = [
|
|
20
20
|
"opencv-python",
|
21
21
|
"osmnx<2.0.0",
|
22
22
|
"rasterio",
|
23
|
-
"python_dotenv",
|
24
23
|
"tqdm",
|
25
24
|
]
|
26
25
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import json
|
2
2
|
import os
|
3
3
|
import shutil
|
4
|
-
from random import choice
|
4
|
+
from random import choice
|
5
5
|
from time import time
|
6
6
|
|
7
7
|
import cv2
|
@@ -9,8 +9,6 @@ import cv2
|
|
9
9
|
from maps4fs import Map
|
10
10
|
from maps4fs.generator.game import Game
|
11
11
|
|
12
|
-
# from maps4fs.generator.texture import TEXTURES
|
13
|
-
|
14
12
|
working_directory = os.getcwd()
|
15
13
|
|
16
14
|
base_directory = os.path.join(working_directory, "tests/data")
|
@@ -30,32 +28,14 @@ coordinates_cases = [
|
|
30
28
|
game_code_cases = ["FS22"]
|
31
29
|
|
32
30
|
|
33
|
-
def
|
34
|
-
"""Return random
|
35
|
-
|
36
|
-
Returns:
|
37
|
-
int: Random distance.
|
38
|
-
"""
|
39
|
-
distances_cases = [1024, 2048, 4096, 8192]
|
40
|
-
return choice(distances_cases[:2]) # Larger maps are too slow for automated tests.
|
41
|
-
|
42
|
-
|
43
|
-
def random_blur_seed() -> int:
|
44
|
-
"""Return random blur seed.
|
45
|
-
|
46
|
-
Returns:
|
47
|
-
int: Random blur seed.
|
48
|
-
"""
|
49
|
-
return randint(1, 30)
|
50
|
-
|
51
|
-
|
52
|
-
def random_max_height() -> int:
|
53
|
-
"""Return random max height.
|
31
|
+
def get_random_size() -> tuple[int, int]:
|
32
|
+
"""Return random size.
|
54
33
|
|
55
34
|
Returns:
|
56
|
-
int: Random
|
35
|
+
tuple[int, int]: Random size.
|
57
36
|
"""
|
58
|
-
|
37
|
+
sizes_cases = [(1024, 1024), (2048, 2048), (4096, 4096), (8192, 8192)]
|
38
|
+
return choice(sizes_cases[:2]) # Larger maps are too slow for automated tests.
|
59
39
|
|
60
40
|
|
61
41
|
def map_directory() -> str:
|
@@ -88,18 +68,15 @@ def test_map():
|
|
88
68
|
for game_code in game_code_cases:
|
89
69
|
game = Game.from_code(game_code)
|
90
70
|
for coordinates in coordinates_cases:
|
91
|
-
|
92
|
-
blur_seed = random_blur_seed()
|
93
|
-
max_height = random_max_height()
|
71
|
+
height, width = get_random_size()
|
94
72
|
directory = map_directory()
|
95
73
|
|
96
74
|
map = Map(
|
97
75
|
game=game,
|
98
76
|
coordinates=coordinates,
|
99
|
-
|
77
|
+
height=height,
|
78
|
+
width=width,
|
100
79
|
map_directory=directory,
|
101
|
-
blur_seed=blur_seed,
|
102
|
-
max_height=max_height,
|
103
80
|
)
|
104
81
|
|
105
82
|
map.generate()
|
@@ -121,41 +98,36 @@ def test_map():
|
|
121
98
|
img = cv2.imread(texture_path)
|
122
99
|
assert img is not None, f"Texture could not be read: {texture_path}"
|
123
100
|
assert img.shape == (
|
124
|
-
|
125
|
-
|
101
|
+
height,
|
102
|
+
width,
|
126
103
|
3,
|
127
|
-
), f"Texture shape mismatch: {img.shape} != {(
|
104
|
+
), f"Texture shape mismatch: {img.shape} != {(height, width, 3)}"
|
128
105
|
assert img.dtype == "uint8", f"Texture dtype mismatch: {img.dtype} != uint8"
|
129
106
|
|
130
107
|
dem_file = os.path.join(textures_directory, "map_dem.png")
|
131
108
|
assert os.path.isfile(dem_file), f"DEM file not found: {dem_file}"
|
132
109
|
img = cv2.imread(dem_file, cv2.IMREAD_UNCHANGED)
|
133
110
|
assert img is not None, f"DEM could not be read: {dem_file}"
|
134
|
-
|
135
|
-
distance + 1,
|
136
|
-
distance + 1,
|
137
|
-
), f"DEM shape mismatch: {img.shape} != {(distance + 1, distance + 1)}"
|
111
|
+
|
138
112
|
assert img.dtype == "uint16", f"DEM dtype mismatch: {img.dtype} != uint16"
|
139
113
|
|
140
114
|
|
141
115
|
def test_map_preview():
|
142
116
|
"""Test Map preview generation."""
|
143
117
|
case = choice(coordinates_cases)
|
144
|
-
distance = random_distance()
|
145
|
-
blur_seed = random_blur_seed()
|
146
|
-
max_height = random_max_height()
|
147
118
|
|
148
119
|
game_code = choice(game_code_cases)
|
149
120
|
game = Game.from_code(game_code)
|
150
121
|
|
122
|
+
height, width = get_random_size()
|
123
|
+
|
151
124
|
directory = map_directory()
|
152
125
|
map = Map(
|
153
126
|
game=game,
|
154
127
|
coordinates=case,
|
155
|
-
|
128
|
+
height=height,
|
129
|
+
width=width,
|
156
130
|
map_directory=directory,
|
157
|
-
blur_seed=blur_seed,
|
158
|
-
max_height=max_height,
|
159
131
|
)
|
160
132
|
map.generate()
|
161
133
|
previews_paths = map.previews()
|
@@ -163,32 +135,24 @@ def test_map_preview():
|
|
163
135
|
assert os.path.isfile(preview_path), f"Preview not found: {preview_path}"
|
164
136
|
img = cv2.imread(preview_path)
|
165
137
|
assert img is not None, f"Preview could not be read: {preview_path}"
|
166
|
-
assert img.shape == (
|
167
|
-
2048,
|
168
|
-
2048,
|
169
|
-
3,
|
170
|
-
), f"Preview shape mismatch: {img.shape} != (2048, 2048, 3)"
|
171
|
-
assert img.dtype == "uint8", f"Preview dtype mismatch: {img.dtype} != uint8"
|
172
138
|
|
173
139
|
|
174
140
|
def test_map_pack():
|
175
141
|
"""Test Map packing into zip archive."""
|
176
142
|
case = choice(coordinates_cases)
|
177
|
-
distance = random_distance()
|
178
|
-
blur_seed = random_blur_seed()
|
179
|
-
max_height = random_max_height()
|
180
143
|
|
181
144
|
game_code = choice(game_code_cases)
|
182
145
|
game = Game.from_code(game_code)
|
183
146
|
|
147
|
+
height, width = get_random_size()
|
148
|
+
|
184
149
|
directory = map_directory()
|
185
150
|
map = Map(
|
186
151
|
game=game,
|
187
152
|
coordinates=case,
|
188
|
-
|
153
|
+
height=height,
|
154
|
+
width=width,
|
189
155
|
map_directory=directory,
|
190
|
-
blur_seed=blur_seed,
|
191
|
-
max_height=max_height,
|
192
156
|
)
|
193
157
|
map.generate()
|
194
158
|
archive_name = os.path.join(base_directory, "archive")
|
@@ -1,55 +0,0 @@
|
|
1
|
-
"""This module contains the base class for all map generation components."""
|
2
|
-
|
3
|
-
from __future__ import annotations
|
4
|
-
|
5
|
-
from typing import TYPE_CHECKING, Any
|
6
|
-
|
7
|
-
if TYPE_CHECKING:
|
8
|
-
from maps4fs.generator.game import Game
|
9
|
-
|
10
|
-
|
11
|
-
# pylint: disable=R0801, R0903
|
12
|
-
class Component:
|
13
|
-
"""Base class for all map generation components.
|
14
|
-
|
15
|
-
Args:
|
16
|
-
coordinates (tuple[float, float]): The latitude and longitude of the center of the map.
|
17
|
-
distance (int): The distance from the center to the edge of the map.
|
18
|
-
map_directory (str): The directory where the map files are stored.
|
19
|
-
logger (Any, optional): The logger to use. Must have at least three basic methods: debug,
|
20
|
-
info, warning. If not provided, default logging will be used.
|
21
|
-
"""
|
22
|
-
|
23
|
-
def __init__(
|
24
|
-
self,
|
25
|
-
game: Game,
|
26
|
-
coordinates: tuple[float, float],
|
27
|
-
distance: int,
|
28
|
-
map_directory: str,
|
29
|
-
logger: Any = None,
|
30
|
-
**kwargs, # pylint: disable=W0613, R0913, R0917
|
31
|
-
):
|
32
|
-
self.game = game
|
33
|
-
self.coordinates = coordinates
|
34
|
-
self.distance = distance
|
35
|
-
self.map_directory = map_directory
|
36
|
-
self.logger = logger
|
37
|
-
self.kwargs = kwargs
|
38
|
-
|
39
|
-
self.preprocess()
|
40
|
-
|
41
|
-
def preprocess(self) -> None:
|
42
|
-
"""Prepares the component for processing. Must be implemented in the child class.
|
43
|
-
|
44
|
-
Raises:
|
45
|
-
NotImplementedError: If the method is not implemented in the child class.
|
46
|
-
"""
|
47
|
-
raise NotImplementedError
|
48
|
-
|
49
|
-
def process(self) -> None:
|
50
|
-
"""Launches the component processing. Must be implemented in the child class.
|
51
|
-
|
52
|
-
Raises:
|
53
|
-
NotImplementedError: If the method is not implemented in the child class.
|
54
|
-
"""
|
55
|
-
raise NotImplementedError
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|