maps4fs 0.8.2__py3-none-any.whl → 0.8.3__py3-none-any.whl
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/generator/background.py +292 -0
- maps4fs/generator/component.py +65 -0
- maps4fs/generator/dem.py +67 -24
- maps4fs/generator/game.py +2 -1
- maps4fs/generator/map.py +42 -27
- maps4fs/generator/path_steps.py +72 -0
- maps4fs/generator/texture.py +5 -25
- maps4fs/generator/tile.py +55 -0
- {maps4fs-0.8.2.dist-info → maps4fs-0.8.3.dist-info}/METADATA +171 -25
- maps4fs-0.8.3.dist-info/RECORD +18 -0
- maps4fs-0.8.2.dist-info/RECORD +0 -15
- {maps4fs-0.8.2.dist-info → maps4fs-0.8.3.dist-info}/LICENSE.md +0 -0
- {maps4fs-0.8.2.dist-info → maps4fs-0.8.3.dist-info}/WHEEL +0 -0
- {maps4fs-0.8.2.dist-info → maps4fs-0.8.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,292 @@
|
|
1
|
+
"""This module contains the Background component, which generates 3D obj files based on DEM data
|
2
|
+
around the map."""
|
3
|
+
|
4
|
+
from __future__ import annotations
|
5
|
+
|
6
|
+
import os
|
7
|
+
|
8
|
+
import cv2
|
9
|
+
import numpy as np
|
10
|
+
import trimesh # type: ignore
|
11
|
+
from pyproj import Transformer
|
12
|
+
|
13
|
+
from maps4fs.generator.component import Component
|
14
|
+
from maps4fs.generator.path_steps import DEFAULT_DISTANCE, get_steps
|
15
|
+
from maps4fs.generator.tile import Tile
|
16
|
+
|
17
|
+
RESIZE_FACTOR = 1 / 4
|
18
|
+
|
19
|
+
|
20
|
+
class Background(Component):
|
21
|
+
"""Component for creating 3D obj files based on DEM data around the map.
|
22
|
+
|
23
|
+
Args:
|
24
|
+
coordinates (tuple[float, float]): The latitude and longitude of the center of the map.
|
25
|
+
map_height (int): The height of the map in pixels.
|
26
|
+
map_width (int): The width of the map in pixels.
|
27
|
+
map_directory (str): The directory where the map files are stored.
|
28
|
+
logger (Any, optional): The logger to use. Must have at least three basic methods: debug,
|
29
|
+
info, warning. If not provided, default logging will be used.
|
30
|
+
"""
|
31
|
+
|
32
|
+
def preprocess(self) -> None:
|
33
|
+
"""Prepares the component for processing. Registers the tiles around the map by moving
|
34
|
+
clockwise from North, then clockwise."""
|
35
|
+
self.tiles: list[Tile] = []
|
36
|
+
origin = self.coordinates
|
37
|
+
|
38
|
+
# Getting a list of 8 tiles around the map starting from the N(North) tile.
|
39
|
+
for path_step in get_steps(self.map_height, self.map_width):
|
40
|
+
# Getting the destination coordinates for the current tile.
|
41
|
+
tile_coordinates = path_step.get_destination(origin)
|
42
|
+
|
43
|
+
# Create a Tile component, which is needed to save the DEM image.
|
44
|
+
tile = Tile(
|
45
|
+
game=self.game,
|
46
|
+
coordinates=tile_coordinates,
|
47
|
+
map_height=path_step.size[1],
|
48
|
+
map_width=path_step.size[0],
|
49
|
+
map_directory=self.map_directory,
|
50
|
+
logger=self.logger,
|
51
|
+
tile_code=path_step.code,
|
52
|
+
auto_process=False,
|
53
|
+
blur_radius=self.kwargs.get("blur_radius"),
|
54
|
+
multiplier=1,
|
55
|
+
)
|
56
|
+
|
57
|
+
# Update the origin for the next tile.
|
58
|
+
origin = tile_coordinates
|
59
|
+
self.tiles.append(tile)
|
60
|
+
self.logger.debug(
|
61
|
+
"Registered tile: %s, coordinates: %s, size: %s",
|
62
|
+
tile.code,
|
63
|
+
tile_coordinates,
|
64
|
+
path_step.size,
|
65
|
+
)
|
66
|
+
|
67
|
+
def process(self) -> None:
|
68
|
+
"""Launches the component processing. Iterates over all tiles and processes them
|
69
|
+
as a result the DEM files will be saved, then based on them the obj files will be
|
70
|
+
generated."""
|
71
|
+
for tile in self.tiles:
|
72
|
+
tile.process()
|
73
|
+
|
74
|
+
self.generate_obj_files()
|
75
|
+
|
76
|
+
def info_sequence(self) -> dict[str, dict[str, str | float | int]]:
|
77
|
+
"""Returns a dictionary with information about the tiles around the map.
|
78
|
+
Adds the EPSG:3857 string to the data for convenient usage in QGIS.
|
79
|
+
|
80
|
+
Returns:
|
81
|
+
dict[str, dict[str, float | int]] -- A dictionary with information about the tiles.
|
82
|
+
"""
|
83
|
+
data = {}
|
84
|
+
for tile in self.tiles:
|
85
|
+
north, south, east, west = tile.bbox
|
86
|
+
|
87
|
+
# The default CMS in library is EPSG:4326.
|
88
|
+
# It needed to be converted to EPSG:3857 for convinient usage in QGIS.
|
89
|
+
|
90
|
+
transformer = Transformer.from_crs("epsg:4326", "epsg:3857")
|
91
|
+
epsg3857_north, epsg3857_west = transformer.transform(north, west)
|
92
|
+
epsg3857_south, epsg3857_east = transformer.transform(south, east)
|
93
|
+
|
94
|
+
epsg3857_string = (
|
95
|
+
f"{epsg3857_north},{epsg3857_south},{epsg3857_east},{epsg3857_west} [EPSG:3857]"
|
96
|
+
)
|
97
|
+
|
98
|
+
tile_entry = {
|
99
|
+
"center_latitude": tile.coordinates[0],
|
100
|
+
"center_longitude": tile.coordinates[1],
|
101
|
+
"epsg3857_string": epsg3857_string,
|
102
|
+
"height": tile.map_height,
|
103
|
+
"width": tile.map_width,
|
104
|
+
"north": north,
|
105
|
+
"south": south,
|
106
|
+
"east": east,
|
107
|
+
"west": west,
|
108
|
+
}
|
109
|
+
if tile.code is not None:
|
110
|
+
data[tile.code] = tile_entry
|
111
|
+
|
112
|
+
return data # type: ignore
|
113
|
+
|
114
|
+
def generate_obj_files(self) -> None:
|
115
|
+
"""Iterates over all tiles and generates 3D obj files based on DEM data.
|
116
|
+
If at least one DEM file is missing, the generation will be stopped at all.
|
117
|
+
"""
|
118
|
+
for tile in self.tiles:
|
119
|
+
# Read DEM data from the tile.
|
120
|
+
dem_path = tile.dem_path
|
121
|
+
if not os.path.isfile(dem_path):
|
122
|
+
self.logger.warning("DEM file not found, generation will be stopped: %s", dem_path)
|
123
|
+
return
|
124
|
+
|
125
|
+
self.logger.info("DEM file for tile %s found: %s", tile.code, dem_path)
|
126
|
+
|
127
|
+
base_directory = os.path.dirname(dem_path)
|
128
|
+
save_path = os.path.join(base_directory, f"{tile.code}.obj")
|
129
|
+
self.logger.debug("Generating obj file for tile %s in path: %s", tile.code, save_path)
|
130
|
+
|
131
|
+
dem_data = cv2.imread(tile.dem_path, cv2.IMREAD_UNCHANGED) # pylint: disable=no-member
|
132
|
+
self.plane_from_np(dem_data, save_path)
|
133
|
+
|
134
|
+
# pylint: disable=too-many-locals
|
135
|
+
def plane_from_np(self, dem_data: np.ndarray, save_path: str) -> None:
|
136
|
+
"""Generates a 3D obj file based on DEM data.
|
137
|
+
|
138
|
+
Arguments:
|
139
|
+
dem_data (np.ndarray) -- The DEM data as a numpy array.
|
140
|
+
save_path (str) -- The path where the obj file will be saved.
|
141
|
+
"""
|
142
|
+
dem_data = cv2.resize( # pylint: disable=no-member
|
143
|
+
dem_data, (0, 0), fx=RESIZE_FACTOR, fy=RESIZE_FACTOR
|
144
|
+
)
|
145
|
+
self.logger.debug(
|
146
|
+
"DEM data resized to shape: %s with factor: %s", dem_data.shape, RESIZE_FACTOR
|
147
|
+
)
|
148
|
+
|
149
|
+
rows, cols = dem_data.shape
|
150
|
+
x = np.linspace(0, cols - 1, cols)
|
151
|
+
y = np.linspace(0, rows - 1, rows)
|
152
|
+
x, y = np.meshgrid(x, y)
|
153
|
+
z = dem_data
|
154
|
+
|
155
|
+
vertices = np.column_stack([x.ravel(), y.ravel(), z.ravel()])
|
156
|
+
faces = []
|
157
|
+
|
158
|
+
for i in range(rows - 1):
|
159
|
+
for j in range(cols - 1):
|
160
|
+
top_left = i * cols + j
|
161
|
+
top_right = top_left + 1
|
162
|
+
bottom_left = top_left + cols
|
163
|
+
bottom_right = bottom_left + 1
|
164
|
+
|
165
|
+
# Invert the order of vertices to flip the normals
|
166
|
+
faces.append([top_left, bottom_right, bottom_left])
|
167
|
+
faces.append([top_left, top_right, bottom_right])
|
168
|
+
|
169
|
+
faces = np.array(faces) # type: ignore
|
170
|
+
mesh = trimesh.Trimesh(vertices=vertices, faces=faces)
|
171
|
+
|
172
|
+
# Simplify the mesh to reduce the number of faces.
|
173
|
+
mesh = mesh.simplify_quadric_decimation(face_count=len(faces) // 10)
|
174
|
+
self.logger.debug("Mesh simplified to %s faces", len(mesh.faces))
|
175
|
+
|
176
|
+
mesh.export(save_path)
|
177
|
+
self.logger.info("Obj file saved: %s", save_path)
|
178
|
+
|
179
|
+
def previews(self) -> list[str]:
|
180
|
+
"""Generates a preview by combining all tiles into one image.
|
181
|
+
NOTE: The map itself is not included in the preview, so it will be empty.
|
182
|
+
|
183
|
+
Returns:
|
184
|
+
list[str] -- A list of paths to the preview images."""
|
185
|
+
|
186
|
+
self.logger.info("Generating a preview image for the background DEM")
|
187
|
+
|
188
|
+
image_height = self.map_height + DEFAULT_DISTANCE * 2
|
189
|
+
image_width = self.map_width + DEFAULT_DISTANCE * 2
|
190
|
+
self.logger.debug("Full size of the preview image: %s x %s", image_width, image_height)
|
191
|
+
|
192
|
+
image = np.zeros((image_height, image_width), np.uint16) # pylint: disable=no-member
|
193
|
+
self.logger.debug("Empty image created: %s", image.shape)
|
194
|
+
|
195
|
+
for tile in self.tiles:
|
196
|
+
# pylint: disable=no-member
|
197
|
+
tile_image = cv2.imread(tile.dem_path, cv2.IMREAD_UNCHANGED)
|
198
|
+
|
199
|
+
self.logger.debug(
|
200
|
+
"Tile %s image shape: %s, dtype: %s, max: %s, min: %s",
|
201
|
+
tile.code,
|
202
|
+
tile_image.shape,
|
203
|
+
tile_image.dtype,
|
204
|
+
tile_image.max(),
|
205
|
+
tile_image.min(),
|
206
|
+
)
|
207
|
+
|
208
|
+
tile_height, tile_width = tile_image.shape
|
209
|
+
self.logger.debug("Tile %s size: %s x %s", tile.code, tile_width, tile_height)
|
210
|
+
|
211
|
+
# Calculate the position based on the tile code
|
212
|
+
if tile.code == "N":
|
213
|
+
x = DEFAULT_DISTANCE
|
214
|
+
y = 0
|
215
|
+
elif tile.code == "NE":
|
216
|
+
x = self.map_width + DEFAULT_DISTANCE
|
217
|
+
y = 0
|
218
|
+
elif tile.code == "E":
|
219
|
+
x = self.map_width + DEFAULT_DISTANCE
|
220
|
+
y = DEFAULT_DISTANCE
|
221
|
+
elif tile.code == "SE":
|
222
|
+
x = self.map_width + DEFAULT_DISTANCE
|
223
|
+
y = self.map_height + DEFAULT_DISTANCE
|
224
|
+
elif tile.code == "S":
|
225
|
+
x = DEFAULT_DISTANCE
|
226
|
+
y = self.map_height + DEFAULT_DISTANCE
|
227
|
+
elif tile.code == "SW":
|
228
|
+
x = 0
|
229
|
+
y = self.map_height + DEFAULT_DISTANCE
|
230
|
+
elif tile.code == "W":
|
231
|
+
x = 0
|
232
|
+
y = DEFAULT_DISTANCE
|
233
|
+
elif tile.code == "NW":
|
234
|
+
x = 0
|
235
|
+
y = 0
|
236
|
+
|
237
|
+
# pylint: disable=possibly-used-before-assignment
|
238
|
+
x2 = x + tile_width
|
239
|
+
y2 = y + tile_height
|
240
|
+
|
241
|
+
self.logger.debug(
|
242
|
+
"Tile %s position. X from %s to %s, Y from %s to %s", tile.code, x, x2, y, y2
|
243
|
+
)
|
244
|
+
|
245
|
+
# pylint: disable=possibly-used-before-assignment
|
246
|
+
image[y:y2, x:x2] = tile_image
|
247
|
+
|
248
|
+
# Save image to the map directory.
|
249
|
+
preview_path = os.path.join(self.previews_directory, "background_dem.png")
|
250
|
+
|
251
|
+
# pylint: disable=no-member
|
252
|
+
image = cv2.normalize(image, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U) # type: ignore
|
253
|
+
image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR) # type: ignore
|
254
|
+
cv2.imwrite(preview_path, image)
|
255
|
+
|
256
|
+
return [preview_path]
|
257
|
+
|
258
|
+
|
259
|
+
# Creates tiles around the map.
|
260
|
+
# The one on corners 2048x2048, on sides and in the middle map_size x 2048.
|
261
|
+
# So 2048 is a distance FROM the edge of the map, but the other size depends on the map size.
|
262
|
+
# But for corner tiles it's always 2048.
|
263
|
+
|
264
|
+
# In the beginning we have coordinates of the central point of the map and it's size.
|
265
|
+
# We need to calculate the coordinates of central points all 8 tiles around the map.
|
266
|
+
|
267
|
+
# Latitude is a vertical line, Longitude is a horizontal line.
|
268
|
+
|
269
|
+
# 2048
|
270
|
+
# | |
|
271
|
+
# ____________________|_________|___
|
272
|
+
# | | | |
|
273
|
+
# | NW | N | NE | 2048
|
274
|
+
# |_________|_________|_________|___
|
275
|
+
# | | | |
|
276
|
+
# | W | C | E |
|
277
|
+
# |_________|_________|_________|
|
278
|
+
# | | | |
|
279
|
+
# | SW | S | SE |
|
280
|
+
# |_________|_________|_________|
|
281
|
+
#
|
282
|
+
# N = C map_height / 2 + 1024; N_width = map_width; N_height = 2048
|
283
|
+
# NW = N - map_width / 2 - 1024; NW_width = 2048; NW_height = 2048
|
284
|
+
# and so on...
|
285
|
+
|
286
|
+
# lat, lon = 45.28565000315636, 20.237121355049904
|
287
|
+
# dst = 1024
|
288
|
+
|
289
|
+
# # N
|
290
|
+
# destination = distance(meters=dst).destination((lat, lon), 0)
|
291
|
+
# lat, lon = destination.latitude, destination.longitude
|
292
|
+
# print(lat, lon)
|
maps4fs/generator/component.py
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
from __future__ import annotations
|
4
4
|
|
5
|
+
import json
|
6
|
+
import os
|
7
|
+
from copy import deepcopy
|
5
8
|
from typing import TYPE_CHECKING, Any
|
6
9
|
|
7
10
|
import osmnx as ox # type: ignore
|
@@ -42,6 +45,8 @@ class Component:
|
|
42
45
|
self.logger = logger
|
43
46
|
self.kwargs = kwargs
|
44
47
|
|
48
|
+
os.makedirs(self.previews_directory, exist_ok=True)
|
49
|
+
|
45
50
|
self.save_bbox()
|
46
51
|
self.preprocess()
|
47
52
|
|
@@ -69,6 +74,66 @@ class Component:
|
|
69
74
|
"""
|
70
75
|
raise NotImplementedError
|
71
76
|
|
77
|
+
@property
|
78
|
+
def previews_directory(self) -> str:
|
79
|
+
"""The directory where the preview images are stored.
|
80
|
+
|
81
|
+
Returns:
|
82
|
+
str: The directory where the preview images are stored.
|
83
|
+
"""
|
84
|
+
return os.path.join(self.map_directory, "previews")
|
85
|
+
|
86
|
+
@property
|
87
|
+
def generation_info_path(self) -> str:
|
88
|
+
"""The path to the generation info JSON file.
|
89
|
+
|
90
|
+
Returns:
|
91
|
+
str: The path to the generation info JSON file.
|
92
|
+
"""
|
93
|
+
return os.path.join(self.map_directory, "generation_info.json")
|
94
|
+
|
95
|
+
def info_sequence(self) -> dict[Any, Any]:
|
96
|
+
"""Returns the information sequence for the component. Must be implemented in the child
|
97
|
+
class. If the component does not have an information sequence, an empty dictionary must be
|
98
|
+
returned.
|
99
|
+
|
100
|
+
Returns:
|
101
|
+
dict[Any, Any]: The information sequence for the component.
|
102
|
+
"""
|
103
|
+
return {}
|
104
|
+
|
105
|
+
def commit_generation_info(self) -> None:
|
106
|
+
"""Commits the generation info to the generation info JSON file."""
|
107
|
+
self.update_generation_info(self.info_sequence())
|
108
|
+
|
109
|
+
def update_generation_info(self, data: dict[Any, Any]) -> None:
|
110
|
+
"""Updates the generation info with the provided data.
|
111
|
+
If the generation info file does not exist, it will be created.
|
112
|
+
|
113
|
+
Args:
|
114
|
+
data (dict[Any, Any]): The data to update the generation info with.
|
115
|
+
"""
|
116
|
+
if os.path.isfile(self.generation_info_path):
|
117
|
+
with open(self.generation_info_path, "r", encoding="utf-8") as file:
|
118
|
+
generation_info = json.load(file)
|
119
|
+
self.logger.debug("Loaded generation info from %s", self.generation_info_path)
|
120
|
+
else:
|
121
|
+
self.logger.debug(
|
122
|
+
"Generation info file does not exist, creating a new one in %s",
|
123
|
+
self.generation_info_path,
|
124
|
+
)
|
125
|
+
generation_info = {}
|
126
|
+
|
127
|
+
updated_generation_info = deepcopy(generation_info)
|
128
|
+
updated_generation_info[self.__class__.__name__] = data
|
129
|
+
|
130
|
+
self.logger.debug("Updated generation info, now contains %s fields", len(data))
|
131
|
+
|
132
|
+
with open(self.generation_info_path, "w", encoding="utf-8") as file:
|
133
|
+
json.dump(updated_generation_info, file, indent=4)
|
134
|
+
|
135
|
+
self.logger.debug("Saved updated generation info to %s", self.generation_info_path)
|
136
|
+
|
72
137
|
def get_bbox(self, project_utm: bool = False) -> tuple[int, int, int, int]:
|
73
138
|
"""Calculates the bounding box of the map from the coordinates and the height and
|
74
139
|
width of the map.
|
maps4fs/generator/dem.py
CHANGED
@@ -19,7 +19,7 @@ DEFAULT_BLUR_RADIUS = 35
|
|
19
19
|
|
20
20
|
# pylint: disable=R0903
|
21
21
|
class DEM(Component):
|
22
|
-
"""Component for
|
22
|
+
"""Component for processing Digital Elevation Model data.
|
23
23
|
|
24
24
|
Args:
|
25
25
|
coordinates (tuple[float, float]): The latitude and longitude of the center of the map.
|
@@ -40,7 +40,10 @@ class DEM(Component):
|
|
40
40
|
|
41
41
|
self.multiplier = self.kwargs.get("multiplier", DEFAULT_MULTIPLIER)
|
42
42
|
blur_radius = self.kwargs.get("blur_radius", DEFAULT_BLUR_RADIUS)
|
43
|
-
if blur_radius
|
43
|
+
if blur_radius is None or blur_radius <= 0:
|
44
|
+
# We'll disable blur if the radius is 0 or negative.
|
45
|
+
blur_radius = 0
|
46
|
+
elif blur_radius % 2 == 0:
|
44
47
|
blur_radius += 1
|
45
48
|
self.blur_radius = blur_radius
|
46
49
|
self.logger.debug(
|
@@ -49,12 +52,21 @@ class DEM(Component):
|
|
49
52
|
|
50
53
|
self.auto_process = self.kwargs.get("auto_process", False)
|
51
54
|
|
52
|
-
|
53
|
-
def
|
54
|
-
"""
|
55
|
-
|
56
|
-
|
55
|
+
@property
|
56
|
+
def dem_path(self) -> str:
|
57
|
+
"""Returns path to the DEM file.
|
58
|
+
|
59
|
+
Returns:
|
60
|
+
str: Path to the DEM file.
|
61
|
+
"""
|
62
|
+
return self._dem_path
|
63
|
+
|
64
|
+
def get_output_resolution(self) -> tuple[int, int]:
|
65
|
+
"""Get output resolution for DEM data.
|
57
66
|
|
67
|
+
Returns:
|
68
|
+
tuple[int, int]: Output resolution for DEM data.
|
69
|
+
"""
|
58
70
|
dem_height = int((self.map_height / 2) * self.game.dem_multipliyer + 1)
|
59
71
|
dem_width = int((self.map_width / 2) * self.game.dem_multipliyer + 1)
|
60
72
|
self.logger.debug(
|
@@ -63,7 +75,15 @@ class DEM(Component):
|
|
63
75
|
dem_height,
|
64
76
|
dem_width,
|
65
77
|
)
|
66
|
-
|
78
|
+
return dem_width, dem_height
|
79
|
+
|
80
|
+
# pylint: disable=no-member
|
81
|
+
def process(self) -> None:
|
82
|
+
"""Reads SRTM file, crops it to map size, normalizes and blurs it,
|
83
|
+
saves to map directory."""
|
84
|
+
north, south, east, west = self.bbox
|
85
|
+
|
86
|
+
dem_output_resolution = self.get_output_resolution()
|
67
87
|
self.logger.debug("DEM output resolution: %s.", dem_output_resolution)
|
68
88
|
|
69
89
|
tile_path = self._srtm_tile()
|
@@ -122,13 +142,15 @@ class DEM(Component):
|
|
122
142
|
resampled_data.max(),
|
123
143
|
)
|
124
144
|
|
125
|
-
|
126
|
-
resampled_data
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
145
|
+
if self.blur_radius > 0:
|
146
|
+
resampled_data = cv2.GaussianBlur(
|
147
|
+
resampled_data, (self.blur_radius, self.blur_radius), sigmaX=40, sigmaY=40
|
148
|
+
)
|
149
|
+
self.logger.debug(
|
150
|
+
"Gaussion blur applied to DEM data with kernel size %s.",
|
151
|
+
self.blur_radius,
|
152
|
+
)
|
153
|
+
|
132
154
|
self.logger.debug(
|
133
155
|
"DEM data was blurred. Shape: %s, dtype: %s. Min: %s, max: %s.",
|
134
156
|
resampled_data.shape,
|
@@ -141,10 +163,20 @@ class DEM(Component):
|
|
141
163
|
self.logger.debug("DEM data was saved to %s.", self._dem_path)
|
142
164
|
|
143
165
|
if self.game.additional_dem_name is not None:
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
166
|
+
self.make_copy(self.game.additional_dem_name)
|
167
|
+
|
168
|
+
def make_copy(self, dem_name: str) -> None:
|
169
|
+
"""Copies DEM data to additional DEM file.
|
170
|
+
|
171
|
+
Args:
|
172
|
+
dem_name (str): Name of the additional DEM file.
|
173
|
+
"""
|
174
|
+
dem_directory = os.path.dirname(self._dem_path)
|
175
|
+
|
176
|
+
additional_dem_path = os.path.join(dem_directory, dem_name)
|
177
|
+
|
178
|
+
shutil.copyfile(self._dem_path, additional_dem_path)
|
179
|
+
self.logger.debug("Additional DEM data was copied to %s.", additional_dem_path)
|
148
180
|
|
149
181
|
def _tile_info(self, lat: float, lon: float) -> tuple[str, str]:
|
150
182
|
"""Returns latitude band and tile name for SRTM tile from coordinates.
|
@@ -234,14 +266,15 @@ class DEM(Component):
|
|
234
266
|
Returns:
|
235
267
|
str: Path to the preview image.
|
236
268
|
"""
|
237
|
-
rgb_dem_path = self._dem_path.replace(".png", "_grayscale.png")
|
269
|
+
# rgb_dem_path = self._dem_path.replace(".png", "_grayscale.png")
|
270
|
+
grayscale_dem_path = os.path.join(self.previews_directory, "dem_grayscale.png")
|
238
271
|
|
239
|
-
self.logger.debug("Creating grayscale preview of DEM data in %s.",
|
272
|
+
self.logger.debug("Creating grayscale preview of DEM data in %s.", grayscale_dem_path)
|
240
273
|
|
241
274
|
dem_data = cv2.imread(self._dem_path, cv2.IMREAD_GRAYSCALE)
|
242
275
|
dem_data_rgb = cv2.cvtColor(dem_data, cv2.COLOR_GRAY2RGB)
|
243
|
-
cv2.imwrite(
|
244
|
-
return
|
276
|
+
cv2.imwrite(grayscale_dem_path, dem_data_rgb)
|
277
|
+
return grayscale_dem_path
|
245
278
|
|
246
279
|
def colored_preview(self) -> str:
|
247
280
|
"""Converts DEM image to colored RGB image and saves it to the map directory.
|
@@ -251,7 +284,8 @@ class DEM(Component):
|
|
251
284
|
list[str]: List with a single path to the DEM file
|
252
285
|
"""
|
253
286
|
|
254
|
-
colored_dem_path = self._dem_path.replace(".png", "_colored.png")
|
287
|
+
# colored_dem_path = self._dem_path.replace(".png", "_colored.png")
|
288
|
+
colored_dem_path = os.path.join(self.previews_directory, "dem_colored.png")
|
255
289
|
|
256
290
|
self.logger.debug("Creating colored preview of DEM data in %s.", colored_dem_path)
|
257
291
|
|
@@ -292,6 +326,15 @@ class DEM(Component):
|
|
292
326
|
return [self.grayscale_preview(), self.colored_preview()]
|
293
327
|
|
294
328
|
def _get_scaling_factor(self, maximum_deviation: int) -> float:
|
329
|
+
"""Calculate scaling factor for DEM data normalization.
|
330
|
+
NOTE: Needs reconsideration for the implementation.
|
331
|
+
|
332
|
+
Args:
|
333
|
+
maximum_deviation (int): Maximum deviation in DEM data.
|
334
|
+
|
335
|
+
Returns:
|
336
|
+
float: Scaling factor for DEM data normalization.
|
337
|
+
"""
|
295
338
|
ESTIMATED_MAXIMUM_DEVIATION = 1000 # pylint: disable=C0103
|
296
339
|
scaling_factor = maximum_deviation / ESTIMATED_MAXIMUM_DEVIATION
|
297
340
|
return scaling_factor if scaling_factor < 1 else 1
|
maps4fs/generator/game.py
CHANGED
@@ -6,6 +6,7 @@ from __future__ import annotations
|
|
6
6
|
|
7
7
|
import os
|
8
8
|
|
9
|
+
from maps4fs.generator.background import Background
|
9
10
|
from maps4fs.generator.config import Config
|
10
11
|
from maps4fs.generator.dem import DEM
|
11
12
|
from maps4fs.generator.i3d import I3d
|
@@ -35,7 +36,7 @@ class Game:
|
|
35
36
|
_map_template_path: str | None = None
|
36
37
|
_texture_schema: str | None = None
|
37
38
|
|
38
|
-
components = [Config, Texture, DEM, I3d]
|
39
|
+
components = [Config, Texture, DEM, I3d, Background]
|
39
40
|
|
40
41
|
def __init__(self, map_template_path: str | None = None):
|
41
42
|
if map_template_path:
|
maps4fs/generator/map.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
"""This module contains Map class, which is used to generate map using all components."""
|
2
2
|
|
3
|
+
from __future__ import annotations
|
4
|
+
|
3
5
|
import os
|
4
6
|
import shutil
|
5
|
-
from typing import Any
|
6
|
-
|
7
|
-
from tqdm import tqdm
|
7
|
+
from typing import Any, Generator
|
8
8
|
|
9
|
+
# from maps4fs.generator.background import Background
|
9
10
|
from maps4fs.generator.component import Component
|
10
11
|
from maps4fs.generator.game import Game
|
11
12
|
from maps4fs.logger import Logger
|
@@ -58,31 +59,45 @@ class Map:
|
|
58
59
|
except Exception as e:
|
59
60
|
raise RuntimeError(f"Can not unpack map template due to error: {e}") from e
|
60
61
|
|
61
|
-
def generate(self) -> None:
|
62
|
-
"""Launch map generation using all components.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
62
|
+
def generate(self) -> Generator[str, None, None]:
|
63
|
+
"""Launch map generation using all components. Yield component names during the process.
|
64
|
+
|
65
|
+
Yields:
|
66
|
+
Generator[str, None, None]: Component names.
|
67
|
+
"""
|
68
|
+
for game_component in self.game.components:
|
69
|
+
component = game_component(
|
70
|
+
self.game,
|
71
|
+
self.coordinates,
|
72
|
+
self.height,
|
73
|
+
self.width,
|
74
|
+
self.map_directory,
|
75
|
+
self.logger,
|
76
|
+
**self.kwargs,
|
77
|
+
)
|
78
|
+
|
79
|
+
yield component.__class__.__name__
|
80
|
+
|
81
|
+
try:
|
82
|
+
component.process()
|
83
|
+
except Exception as e: # pylint: disable=W0718
|
84
|
+
self.logger.error(
|
85
|
+
"Error processing component %s: %s",
|
86
|
+
component.__class__.__name__,
|
87
|
+
e,
|
88
|
+
)
|
89
|
+
raise e
|
90
|
+
|
91
|
+
try:
|
92
|
+
component.commit_generation_info()
|
93
|
+
except Exception as e: # pylint: disable=W0718
|
94
|
+
self.logger.error(
|
95
|
+
"Error committing generation info for component %s: %s",
|
96
|
+
component.__class__.__name__,
|
97
|
+
e,
|
73
98
|
)
|
74
|
-
|
75
|
-
|
76
|
-
except Exception as e: # pylint: disable=W0718
|
77
|
-
self.logger.error(
|
78
|
-
"Error processing component %s: %s",
|
79
|
-
component.__class__.__name__,
|
80
|
-
e,
|
81
|
-
)
|
82
|
-
raise e
|
83
|
-
self.components.append(component)
|
84
|
-
|
85
|
-
pbar.update(1)
|
99
|
+
raise e
|
100
|
+
self.components.append(component)
|
86
101
|
|
87
102
|
def previews(self) -> list[str]:
|
88
103
|
"""Get list of preview images.
|
@@ -0,0 +1,72 @@
|
|
1
|
+
"""This module contains functions and clas for generating path steps."""
|
2
|
+
|
3
|
+
from typing import NamedTuple
|
4
|
+
|
5
|
+
from geopy.distance import distance # type: ignore
|
6
|
+
|
7
|
+
DEFAULT_DISTANCE = 2048
|
8
|
+
|
9
|
+
|
10
|
+
class PathStep(NamedTuple):
|
11
|
+
"""Represents parameters of one step in the path.
|
12
|
+
|
13
|
+
Attributes:
|
14
|
+
code {str} -- Tile code (N, NE, E, SE, S, SW, W, NW).
|
15
|
+
angle {int} -- Angle in degrees (for example 0 for North, 90 for East).
|
16
|
+
distance {int} -- Distance in meters from previous step.
|
17
|
+
size {tuple[int, int]} -- Size of the tile in pixels (width, height).
|
18
|
+
"""
|
19
|
+
|
20
|
+
code: str
|
21
|
+
angle: int
|
22
|
+
distance: int
|
23
|
+
size: tuple[int, int]
|
24
|
+
|
25
|
+
def get_destination(self, origin: tuple[float, float]) -> tuple[float, float]:
|
26
|
+
"""Calculate destination coordinates based on origin and step parameters.
|
27
|
+
|
28
|
+
Arguments:
|
29
|
+
origin {tuple[float, float]} -- Origin coordinates (latitude, longitude)
|
30
|
+
|
31
|
+
Returns:
|
32
|
+
tuple[float, float] -- Destination coordinates (latitude, longitude)
|
33
|
+
"""
|
34
|
+
destination = distance(meters=self.distance).destination(origin, self.angle)
|
35
|
+
return destination.latitude, destination.longitude
|
36
|
+
|
37
|
+
|
38
|
+
def get_steps(map_height: int, map_width: int) -> list[PathStep]:
|
39
|
+
"""Return a list of PathStep objects for each tile, which represent a step in the path.
|
40
|
+
Moving from the center of the map to North, then clockwise.
|
41
|
+
|
42
|
+
Arguments:
|
43
|
+
map_height {int} -- Height of the map in pixels
|
44
|
+
map_width {int} -- Width of the map in pixels
|
45
|
+
|
46
|
+
Returns:
|
47
|
+
list[PathStep] -- List of PathStep objects
|
48
|
+
"""
|
49
|
+
# Move clockwise from N and calculate coordinates and sizes for each tile.
|
50
|
+
half_width = int(map_width / 2)
|
51
|
+
half_height = int(map_height / 2)
|
52
|
+
|
53
|
+
half_default_distance = int(DEFAULT_DISTANCE / 2)
|
54
|
+
|
55
|
+
return [
|
56
|
+
PathStep("N", 0, half_height + half_default_distance, (map_width, DEFAULT_DISTANCE)),
|
57
|
+
PathStep(
|
58
|
+
"NE", 90, half_width + half_default_distance, (DEFAULT_DISTANCE, DEFAULT_DISTANCE)
|
59
|
+
),
|
60
|
+
PathStep("E", 180, half_height + half_default_distance, (DEFAULT_DISTANCE, map_height)),
|
61
|
+
PathStep(
|
62
|
+
"SE", 180, half_height + half_default_distance, (DEFAULT_DISTANCE, DEFAULT_DISTANCE)
|
63
|
+
),
|
64
|
+
PathStep("S", 270, half_width + half_default_distance, (map_width, DEFAULT_DISTANCE)),
|
65
|
+
PathStep(
|
66
|
+
"SW", 270, half_width + half_default_distance, (DEFAULT_DISTANCE, DEFAULT_DISTANCE)
|
67
|
+
),
|
68
|
+
PathStep("W", 0, half_height + half_default_distance, (DEFAULT_DISTANCE, map_height)),
|
69
|
+
PathStep(
|
70
|
+
"NW", 0, half_height + half_default_distance, (DEFAULT_DISTANCE, DEFAULT_DISTANCE)
|
71
|
+
),
|
72
|
+
]
|
maps4fs/generator/texture.py
CHANGED
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
5
5
|
import json
|
6
6
|
import os
|
7
7
|
import warnings
|
8
|
-
from typing import Callable, Generator, Optional
|
8
|
+
from typing import Any, Callable, Generator, Optional
|
9
9
|
|
10
10
|
import cv2
|
11
11
|
import numpy as np
|
@@ -149,7 +149,6 @@ class Texture(Component):
|
|
149
149
|
self._prepare_weights()
|
150
150
|
self._read_parameters()
|
151
151
|
self.draw()
|
152
|
-
self.info_sequence()
|
153
152
|
|
154
153
|
# pylint: disable=W0201
|
155
154
|
def _read_parameters(self) -> None:
|
@@ -176,23 +175,8 @@ class Texture(Component):
|
|
176
175
|
self.width_coef = self.width / self.map_width
|
177
176
|
self.logger.debug("Map coefficients (HxW): %s x %s.", self.height_coef, self.width_coef)
|
178
177
|
|
179
|
-
def info_sequence(self) ->
|
180
|
-
"""
|
181
|
-
|
182
|
-
Info sequence contains following attributes:
|
183
|
-
- coordinates
|
184
|
-
- bbox
|
185
|
-
- map_height
|
186
|
-
- map_width
|
187
|
-
- minimum_x
|
188
|
-
- minimum_y
|
189
|
-
- maximum_x
|
190
|
-
- maximum_y
|
191
|
-
- height
|
192
|
-
- width
|
193
|
-
- height_coef
|
194
|
-
- width_coef
|
195
|
-
"""
|
178
|
+
def info_sequence(self) -> dict[str, Any]:
|
179
|
+
"""Returns the JSON representation of the generation info for textures."""
|
196
180
|
useful_attributes = [
|
197
181
|
"coordinates",
|
198
182
|
"bbox",
|
@@ -207,11 +191,7 @@ class Texture(Component):
|
|
207
191
|
"height_coef",
|
208
192
|
"width_coef",
|
209
193
|
]
|
210
|
-
|
211
|
-
|
212
|
-
with open(self.info_save_path, "w") as f: # pylint: disable=W1514
|
213
|
-
json.dump(info_sequence, f, indent=4)
|
214
|
-
self.logger.info("Generation info saved to %s.", self.info_save_path)
|
194
|
+
return {attr: getattr(self, attr, None) for attr in useful_attributes}
|
215
195
|
|
216
196
|
def _prepare_weights(self):
|
217
197
|
self.logger.debug("Starting preparing weights from %s layers.", len(self.layers))
|
@@ -505,7 +485,7 @@ class Texture(Component):
|
|
505
485
|
merged.shape,
|
506
486
|
merged.dtype,
|
507
487
|
)
|
508
|
-
preview_path = os.path.join(self.
|
488
|
+
preview_path = os.path.join(self.previews_directory, "textures_osm.png")
|
509
489
|
cv2.imwrite(preview_path, merged) # pylint: disable=no-member
|
510
490
|
self.logger.info("Preview saved to %s.", preview_path)
|
511
491
|
return preview_path
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"""This module contains the Tile component, which is used to generate a tile of DEM data around
|
2
|
+
the map."""
|
3
|
+
|
4
|
+
import os
|
5
|
+
|
6
|
+
from maps4fs.generator.dem import DEM
|
7
|
+
|
8
|
+
|
9
|
+
class Tile(DEM):
|
10
|
+
"""Component for creating a tile of DEM data around the map.
|
11
|
+
|
12
|
+
Arguments:
|
13
|
+
coordinates (tuple[float, float]): The latitude and longitude of the center of the map.
|
14
|
+
map_height (int): The height of the map in pixels.
|
15
|
+
map_width (int): The width of the map in pixels.
|
16
|
+
map_directory (str): The directory where the map files are stored.
|
17
|
+
logger (Any, optional): The logger to use. Must have at least three basic methods: debug,
|
18
|
+
info, warning. If not provided, default logging will be used.
|
19
|
+
|
20
|
+
Keyword Arguments:
|
21
|
+
tile_code (str): The code of the tile (N, NE, E, SE, S, SW, W, NW).
|
22
|
+
|
23
|
+
Public Methods:
|
24
|
+
get_output_resolution: Return the resolution of the output image.
|
25
|
+
process: Launch the component processing.
|
26
|
+
make_copy: Override the method to prevent copying the tile.
|
27
|
+
"""
|
28
|
+
|
29
|
+
def preprocess(self) -> None:
|
30
|
+
"""Prepares the component for processing. Reads the tile code from the kwargs and sets the
|
31
|
+
DEM path for the tile."""
|
32
|
+
super().preprocess()
|
33
|
+
self.code = self.kwargs.get("tile_code")
|
34
|
+
if not self.code:
|
35
|
+
raise ValueError("Tile code was not provided")
|
36
|
+
|
37
|
+
self.logger.debug(f"Generating tile {self.code}")
|
38
|
+
|
39
|
+
tiles_directory = os.path.join(self.map_directory, "objects", "tiles")
|
40
|
+
os.makedirs(tiles_directory, exist_ok=True)
|
41
|
+
|
42
|
+
self._dem_path = os.path.join(tiles_directory, f"{self.code}.png")
|
43
|
+
self.logger.debug(f"DEM path for tile {self.code} is {self._dem_path}")
|
44
|
+
|
45
|
+
def get_output_resolution(self) -> tuple[int, int]:
|
46
|
+
"""Return the resolution of the output image.
|
47
|
+
|
48
|
+
Returns:
|
49
|
+
tuple[int, int]: The width and height of the output image.
|
50
|
+
"""
|
51
|
+
return self.map_width, self.map_height
|
52
|
+
|
53
|
+
def make_copy(self, *args, **kwargs) -> None:
|
54
|
+
"""Override the method to prevent copying the tile."""
|
55
|
+
pass # pylint: disable=unnecessary-pass
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: maps4fs
|
3
|
-
Version: 0.8.
|
3
|
+
Version: 0.8.3
|
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,8 +16,9 @@ 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: tqdm
|
20
19
|
Requires-Dist: folium
|
20
|
+
Requires-Dist: geopy
|
21
|
+
Requires-Dist: trimesh
|
21
22
|
|
22
23
|
<div align="center" markdown>
|
23
24
|
<img src="https://github.com/iwatkot/maps4fs/assets/118521851/ffd7f0a3-e317-4c3f-911f-2c2fb736fbfa">
|
@@ -25,9 +26,13 @@ Requires-Dist: folium
|
|
25
26
|
<p align="center">
|
26
27
|
<a href="#Quick-Start">Quick Start</a> •
|
27
28
|
<a href="#Overview">Overview</a> •
|
28
|
-
<a href="#How-To-Run">How-To-Run</a>
|
29
|
-
<a href="#Supported-objects">Supported objects</a> •
|
30
|
-
<a href="#
|
29
|
+
<a href="#How-To-Run">How-To-Run</a><br>
|
30
|
+
<a href="#Supported-objects">Supported objects</a> •
|
31
|
+
<a href="#Generation-info">Generation info</a> •
|
32
|
+
<a href="#Texture-schema">Texture schema</a> •
|
33
|
+
<a href="Background-terrain">Background terrain</a><br>
|
34
|
+
<a href="#For-advanced-users">For advanced users</a> •
|
35
|
+
<a jref="#Resources">Resources</a> •
|
31
36
|
<a href="#Bugs-and-feature-requests">Bugs and feature requests</a>
|
32
37
|
</p>
|
33
38
|
|
@@ -37,6 +42,7 @@ Requires-Dist: folium
|
|
37
42
|
[](https://hub.docker.com/repository/docker/iwatkot/maps4fs/general)
|
38
43
|
[](https://github.com/iwatkot/maps4fs/issues)
|
39
44
|
[](https://codeclimate.com/github/iwatkot/maps4fs/maintainability)<br>
|
45
|
+
[](https://pypi.org/project/maps4fs)
|
40
46
|
[](https://mypy-lang.org/)
|
41
47
|
[](https://github.com/iwatkot/maps4fs/actions)
|
42
48
|
[](https://codeclimate.com/github/iwatkot/maps4fs/test_coverage)
|
@@ -49,6 +55,8 @@ Requires-Dist: folium
|
|
49
55
|
🏞️ Generates height using SRTM dataset<br>
|
50
56
|
📦 Provides a ready-to-use map template for the Giants Editor<br>
|
51
57
|
🚜 Supports Farming Simulator 22 and 25<br>
|
58
|
+
🔷 Generates *.obj files for background terrain based on the real-world height map 🆕<br>
|
59
|
+
📄 Generates commands to obtain high-resolution satellite images from [QGIS](https://qgis.org/download/) 🆕<br>
|
52
60
|
|
53
61
|
## Quick Start
|
54
62
|
There are several ways to use the tool. You obviously need the **first one**, but you can choose any of the others depending on your needs.<br>
|
@@ -120,7 +128,7 @@ docker run -d -p 8501:8501 iwatkot/maps4fs
|
|
120
128
|
4. Fill in the required fields and click on the `Generate` button.
|
121
129
|
5. When the map is generated click on the `Download` button to get the map.
|
122
130
|
|
123
|
-

|
124
132
|
|
125
133
|
### Option 3: Python package
|
126
134
|
🔴 Recommended for developers.<br>
|
@@ -161,8 +169,10 @@ map = mfs.Map(
|
|
161
169
|
```
|
162
170
|
|
163
171
|
4. Generate the map:
|
172
|
+
The `generate` method returns a generator, which yields the active component of the map. You can use it to track the progress of the generation process.
|
164
173
|
```python
|
165
|
-
map.generate()
|
174
|
+
for active_component in map.generate():
|
175
|
+
print(active_component)
|
166
176
|
```
|
167
177
|
|
168
178
|
The map will be saved in the `map_directory` directory.
|
@@ -182,30 +192,157 @@ The project is based on the [OpenStreetMap](https://www.openstreetmap.org/) data
|
|
182
192
|
|
183
193
|
The list will be updated as the project develops.
|
184
194
|
|
185
|
-
##
|
186
|
-
The script will
|
187
|
-
|
188
|
-
|
189
|
-
`
|
190
|
-
`
|
191
|
-
`
|
192
|
-
`
|
193
|
-
`
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
195
|
+
## Generation info
|
196
|
+
The script will generate the `generation_info.json` file in the `output` folder. It splitted to the different sections, which represents the components of the map generator. You may need this information to use some other tools and services to obtain additional data for your map.<br>
|
197
|
+
|
198
|
+
List of components:
|
199
|
+
- `Config` - this component handles the `map.xml` file, where the basic description of the map is stored.
|
200
|
+
- `Texture` - this component describes the textures, that were used to generate the map.
|
201
|
+
- `DEM` - this component describes the Digital Elevation Model (the one which creates terrain on your map), which was used to generate the height map and related to the `dem.png` file.
|
202
|
+
- `I3d` - this component describes the i3d file, where some specific attributes properties and path to the files are stored.
|
203
|
+
- `Background` - this component describes the 8 tiles, that surround the map.
|
204
|
+
|
205
|
+
Below you'll find descriptions of the components and the fields that they contain.<br>
|
206
|
+
ℹ️ If there's no information about the component, it means that at the moment it does not store any data in the `generation_info.json` file.
|
207
|
+
|
208
|
+
### Texture
|
209
|
+
|
210
|
+
Example of the `Texture` component:
|
211
|
+
```json
|
212
|
+
"Texture": {
|
213
|
+
"coordinates": [
|
214
|
+
45.28571409289627,
|
215
|
+
20.237433441210115
|
216
|
+
],
|
217
|
+
"bbox": [
|
218
|
+
45.29492313313172,
|
219
|
+
45.27650505266082,
|
220
|
+
20.250522423471406,
|
221
|
+
20.224344458948824
|
222
|
+
],
|
223
|
+
"map_height": 2048,
|
224
|
+
"map_width": 2048,
|
225
|
+
"minimum_x": 439161.2439774908,
|
226
|
+
"minimum_y": 5013940.540089059,
|
227
|
+
"maximum_x": 441233.5397821935,
|
228
|
+
"maximum_y": 5016006.074349126,
|
229
|
+
"height": 2065.5342600671574,
|
230
|
+
"width": 2072.295804702677,
|
231
|
+
"height_coef": 1.0085616504234167,
|
232
|
+
"width_coef": 1.011863185889979
|
233
|
+
},
|
234
|
+
```
|
235
|
+
|
236
|
+
And here's the list of the fields:
|
237
|
+
|
238
|
+
- `"coordinates"` - the coordinates of the map center which you entered,<br>
|
239
|
+
- `"bbox"` - the bounding box of the map in lat and lon,<br>
|
240
|
+
- `"map_height"` - the height of the map in meters (this one is from the user input, e.g. 2048 and so on),<br>
|
241
|
+
- `"map_width"` - the width of the map in meters (same as above),<br>
|
242
|
+
- `"minimum_x"` - the minimum x coordinate of the map (UTM projection),<br>
|
243
|
+
- `"minimum_y"` - the minimum y coordinate of the map (UTM projection),<br>
|
244
|
+
- `"maximum_x"` - the maximum x coordinate of the map (UTM projection),<br>
|
245
|
+
- `"maximum_y"` - the maximum y coordinate of the map (UTM projection),<br>
|
246
|
+
- `"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>
|
247
|
+
- `"width"` - the width of the map in meters (same as above),<br>
|
248
|
+
- `"height_coef"` - since we need a texture of exact size, the height of the map is multiplied by this coefficient,<br>
|
249
|
+
- `"width_coef"` - same as above but for the width,<br>
|
250
|
+
- `"tile_name"` - the name of the SRTM tile which was used to generate the height map, e.g. "N52E013"<br>
|
251
|
+
|
252
|
+
### Background
|
253
|
+
|
254
|
+
The background component consist of the 8 tiles, each one represents the tile, that surrounds the map. The tiles are named as the cardinal points, e.g. "N", "NE", "E" and so on.<br>
|
255
|
+
Example of the `Background` component:
|
256
|
+
|
257
|
+
```json
|
258
|
+
"Background": {
|
259
|
+
"N": {
|
260
|
+
"center_latitude": 45.30414170952092,
|
261
|
+
"center_longitude": 20.237433441210115,
|
262
|
+
"epsg3857_string": "2251363.25324853,2254278.318028022,5668072.719985372,5670987.784803056 [EPSG:3857]",
|
263
|
+
"height": 2048,
|
264
|
+
"width": 2048,
|
265
|
+
"north": 45.31335074975637,
|
266
|
+
"south": 45.29493266928547,
|
267
|
+
"east": 20.250526677438195,
|
268
|
+
"west": 20.224340204982035
|
269
|
+
},
|
270
|
+
}
|
271
|
+
```
|
272
|
+
|
273
|
+
And here's the list of the fields:
|
274
|
+
- `"center_latitude"` - the latitude of the center of the tile,<br>
|
275
|
+
- `"center_longitude"` - the longitude of the center of the tile,<br>
|
276
|
+
- `"epsg3857_string"` - the string representation of the bounding box in the EPSG:3857 projection, it's required to obtain the satellite images in the QGIS,<br>
|
277
|
+
- `"height"` - the height of the tile in meters,<br>
|
278
|
+
- `"width"` - the width of the tile in meters,<br>
|
279
|
+
- `"north"` - the northern border of the tile,<br>
|
280
|
+
- `"south"` - the southern border of the tile,<br>
|
281
|
+
- `"east"` - the eastern border of the tile,<br>
|
282
|
+
- `"west"` - the western border of the tile,<br>
|
283
|
+
|
284
|
+
## Texture schema
|
285
|
+
maps4fs uses a simple JSON file to define the texture schema. For each of supported games this file has unique entries, but the structure is the same. Here's an example of the schema for Farming Simulator 25:
|
286
|
+
|
287
|
+
```json
|
288
|
+
[
|
289
|
+
{
|
290
|
+
"name": "forestRockRoots",
|
291
|
+
"count": 2,
|
292
|
+
"exclude_weight": true
|
293
|
+
},
|
294
|
+
{
|
295
|
+
"name": "grass",
|
296
|
+
"count": 2,
|
297
|
+
"tags": { "natural": "grassland" },
|
298
|
+
"color": [34, 255, 34],
|
299
|
+
"priority": 0
|
300
|
+
},
|
301
|
+
{
|
302
|
+
"name": "grassClovers",
|
303
|
+
"count": 2
|
304
|
+
},
|
305
|
+
{
|
306
|
+
"name": "grassCut",
|
307
|
+
"count": 2
|
308
|
+
},
|
309
|
+
{
|
310
|
+
"name": "grassDirtPatchy",
|
311
|
+
"count": 2,
|
312
|
+
"tags": { "natural": ["wood", "tree_row"] },
|
313
|
+
"width": 2,
|
314
|
+
"color": [0, 252, 124]
|
315
|
+
}
|
316
|
+
]
|
317
|
+
```
|
318
|
+
Let's have a closer look at the fields:
|
319
|
+
- `name` - the name of the texture. Just the way the file will be named.
|
320
|
+
- `count` - the number of textures of this type. For example, for the **dirtMedium** texture there will be two textures: **dirtMedium01_weight.png** and **dirtMedium02_weight.png**.
|
321
|
+
ℹ️ There's one texture that have count `0`, it's the waterPuddle texture from FS22, which not present in FS25.
|
322
|
+
- `tags` - the tags from the OpenStreetMap data. Refer to the section [Supported objects](#supported-objects) to see the list of supported tags. If there are no tags, the texture file will be generated empty and no objects will be placed on it.
|
323
|
+
- `width` - the width of the texture in meters. Some of the objects from OSM (roads, for example) are lines, not areas. So, to draw them correctly, the tool needs to know the width of the line.
|
324
|
+
- `color` - the color of the texture. It's used only in the preview images and have no effect on the map itself. But remember that previews are crucial for the map making process, so it's better to set the color to something that represents the texture.
|
325
|
+
- `priority` - the priority of the texture for overlapping. Textures with higher priorities will be drawn over the textures with lower priorities.
|
326
|
+
ℹ️ The texture with 0 priority considers the base layer, which means that all empty areas will be filled with this texture.
|
327
|
+
- `exclude_weight` - this only used for the forestRockRoots texture from FS25. It's just means that this texture has no `weight` postfix, that's all.
|
328
|
+
|
329
|
+
## Background terrain
|
330
|
+
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 which can (and should) be texture to look fine.<br>
|
331
|
+
So, the tool generates the background terrain in the form of the 8 tiles, which surround the map. The tiles are named as the cardinal points, e.g. "N", "NE", "E" and so on. All those tiles will be saved in the `objects/tiles` directory with corresponding names: `N.obj`, `NE.obj`, `E.obj` and so on.<br>
|
332
|
+
If you're willing to create a background terrain, you will need: Blender, the Blender Exporter Plugins and the QGIS. You'll find the download links in the [Resources](#resources) section.<br>
|
333
|
+
|
334
|
+
If you're afraid of this task, please don't be. It's really simple and I've prepaired detailed step-by-step instructions for you, you'll find them in the separate README files. Here are the steps you need to follow:
|
335
|
+
|
336
|
+
1. [Download high-resolution satellite images](README_satellite_images.md).
|
337
|
+
2. [Prepare the i3d files](README_i3d.md).
|
338
|
+
3. [Import the i3d files to Giants Editor](README_giants_editor.md).
|
202
339
|
|
203
340
|
## For advanced users
|
204
341
|
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>
|
205
342
|
|
206
343
|
⛔️ 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 a specific values for the map size.<br><br>
|
207
344
|
|
208
|
-

|
209
346
|
|
210
347
|
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>
|
211
348
|
|
@@ -215,5 +352,14 @@ Here's the list of the advanced settings:
|
|
215
352
|
|
216
353
|
- 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.
|
217
354
|
|
355
|
+
## Resources
|
356
|
+
In this section you'll find a list of the resources that you need to create a map for the Farming Simulator.<br>
|
357
|
+
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>
|
358
|
+
|
359
|
+
1. [Giants Editor](https://gdn.giants-software.com/downloads.php) - the official tool for creating maps for the Farming Simulator.
|
360
|
+
2. [Blender](https://www.blender.org/download/) - the open-source 3D modeling software that you can use to create models for the Farming Simulator.
|
361
|
+
3. [Blender Exporter Plugins](https://gdn.giants-software.com/downloads.php) - the official plugins for exporting models from Blender to i3d format (the format used in the Farming Simulator).
|
362
|
+
4. [QGIS](https://qgis.org/download/) - the open-source GIS software that you can use to obtain high-resolution satellite images for your map.
|
363
|
+
|
218
364
|
## Bugs and feature requests
|
219
365
|
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,18 @@
|
|
1
|
+
maps4fs/__init__.py,sha256=da4jmND2Ths9AffnkAKgzLHNkvKFOc_l21gJisPXqWY,155
|
2
|
+
maps4fs/logger.py,sha256=CneeHxQywjNUJXqQrUUSeiDxu95FfrfyK_Si1v0gMZ8,1477
|
3
|
+
maps4fs/generator/__init__.py,sha256=zZMLEkGzb4z0xql650gOtGSvcgX58DnJ2yN3vC2daRk,43
|
4
|
+
maps4fs/generator/background.py,sha256=KsErhYERWXzMedGLg1H7wO94OXyaqw_XQYnotKNTStE,11267
|
5
|
+
maps4fs/generator/component.py,sha256=w5hUttO8m5bXcujLxB0pZjf25hxMnMPP4yPikQyoOkQ,6010
|
6
|
+
maps4fs/generator/config.py,sha256=ln_XGUdiPnc4zzhMVEueZRf-FGljeHtCHUnJ6FRlE4w,2264
|
7
|
+
maps4fs/generator/dem.py,sha256=FsYcaf0IQSYykKdbkHxAN5-Rc_PZZEBJfdZA2Z-b8AU,14514
|
8
|
+
maps4fs/generator/game.py,sha256=yry1tJYQi-tNLHlEY85Vz71KN_o2PVjxrAc4HDNB_Sg,6837
|
9
|
+
maps4fs/generator/i3d.py,sha256=UuQiQRusPQ2f6PvGKxJ_UZeXsx3uG15efmy8Ysnm3F8,3597
|
10
|
+
maps4fs/generator/map.py,sha256=2MXOIQxj7mDxhp76uh7EXqLP-v3T4TbiKQdx6my7GFc,4290
|
11
|
+
maps4fs/generator/path_steps.py,sha256=rKslIiG9mriCVL9_0i8Oet2p0DITrpBWi0pECpvuyUM,2707
|
12
|
+
maps4fs/generator/texture.py,sha256=0gkohGmamZbmqc9VpPqt8pli_x9w9SnUh2JjYGaiI3I,18170
|
13
|
+
maps4fs/generator/tile.py,sha256=3vmfjQiPiiUZKPuIo5tg2rOKkgcP1NRVkMGK-Vo10-A,2138
|
14
|
+
maps4fs-0.8.3.dist-info/LICENSE.md,sha256=-JY0v7p3dwXze61EbYiK7YEJ2aKrjaFZ8y2xYEOrmRY,1068
|
15
|
+
maps4fs-0.8.3.dist-info/METADATA,sha256=UbKREWFL9CnOpTHk1I76Q-4S5DEGOGbWoNro-qREB9c,20081
|
16
|
+
maps4fs-0.8.3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
17
|
+
maps4fs-0.8.3.dist-info/top_level.txt,sha256=Ue9DSRlejRQRCaJueB0uLcKrWwsEq9zezfv5dI5mV1M,8
|
18
|
+
maps4fs-0.8.3.dist-info/RECORD,,
|
maps4fs-0.8.2.dist-info/RECORD
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
maps4fs/__init__.py,sha256=da4jmND2Ths9AffnkAKgzLHNkvKFOc_l21gJisPXqWY,155
|
2
|
-
maps4fs/logger.py,sha256=CneeHxQywjNUJXqQrUUSeiDxu95FfrfyK_Si1v0gMZ8,1477
|
3
|
-
maps4fs/generator/__init__.py,sha256=zZMLEkGzb4z0xql650gOtGSvcgX58DnJ2yN3vC2daRk,43
|
4
|
-
maps4fs/generator/component.py,sha256=CL3DNuvKAd44pynLfir_JLnBC0c9Kr233_BbSHQng6Q,3534
|
5
|
-
maps4fs/generator/config.py,sha256=ln_XGUdiPnc4zzhMVEueZRf-FGljeHtCHUnJ6FRlE4w,2264
|
6
|
-
maps4fs/generator/dem.py,sha256=L91hOxoXnn2LtpaH7fVA6Ke2i7JNfFk_KGMsVWHVNps,13169
|
7
|
-
maps4fs/generator/game.py,sha256=mN9VeN4nk-e43oFujIC5GOGAQOYATKrmeIb1kLHuwtI,6773
|
8
|
-
maps4fs/generator/i3d.py,sha256=UuQiQRusPQ2f6PvGKxJ_UZeXsx3uG15efmy8Ysnm3F8,3597
|
9
|
-
maps4fs/generator/map.py,sha256=xYbSyGrcEB9CRJhVf8iTRCKLK6BvnewtlKO_Ut--Oik,3858
|
10
|
-
maps4fs/generator/texture.py,sha256=uH09vnYSTklv2VxV6ys0DM_f8KXHmxQr9l6flwVguLU,18726
|
11
|
-
maps4fs-0.8.2.dist-info/LICENSE.md,sha256=-JY0v7p3dwXze61EbYiK7YEJ2aKrjaFZ8y2xYEOrmRY,1068
|
12
|
-
maps4fs-0.8.2.dist-info/METADATA,sha256=Ombva3jSyqSsTuzspfzp24DESv1G8lqRWLTuTN0L81w,11866
|
13
|
-
maps4fs-0.8.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
14
|
-
maps4fs-0.8.2.dist-info/top_level.txt,sha256=Ue9DSRlejRQRCaJueB0uLcKrWwsEq9zezfv5dI5mV1M,8
|
15
|
-
maps4fs-0.8.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|