maps4fs 2.1.3__tar.gz → 2.1.5__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-2.1.3 → maps4fs-2.1.5}/PKG-INFO +1 -1
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/background.py +29 -6
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/base/component.py +1 -1
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/base/component_image.py +6 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/dem.py +1 -1
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/settings.py +3 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs.egg-info/PKG-INFO +1 -1
- {maps4fs-2.1.3 → maps4fs-2.1.5}/pyproject.toml +1 -1
- {maps4fs-2.1.3 → maps4fs-2.1.5}/LICENSE.md +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/README.md +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/__init__.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/__init__.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/__init__.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/base/__init__.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/base/component_mesh.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/base/component_xml.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/config.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/grle.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/i3d.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/layer.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/satellite.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/component/texture.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/game.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/map.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/qgis.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/generator/statistics.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs/logger.py +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs.egg-info/SOURCES.txt +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs.egg-info/dependency_links.txt +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs.egg-info/requires.txt +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/maps4fs.egg-info/top_level.txt +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/setup.cfg +0 -0
- {maps4fs-2.1.3 → maps4fs-2.1.5}/tests/test_generator.py +0 -0
@@ -69,6 +69,8 @@ class Background(MeshComponent, ImageComponent):
|
|
69
69
|
)
|
70
70
|
self.not_resized_path: str = os.path.join(self.background_directory, "not_resized.png")
|
71
71
|
|
72
|
+
self.flatten_water_to: int | None = None
|
73
|
+
|
72
74
|
self.dem = DEM(
|
73
75
|
self.game,
|
74
76
|
self.map,
|
@@ -520,11 +522,26 @@ class Background(MeshComponent, ImageComponent):
|
|
520
522
|
if self.map.shared_settings.mesh_z_scaling_factor is not None
|
521
523
|
else 257
|
522
524
|
)
|
525
|
+
flatten_to = None
|
526
|
+
subtract_by = int(self.map.dem_settings.water_depth * z_scaling_factor)
|
527
|
+
|
528
|
+
if self.map.background_settings.flatten_water:
|
529
|
+
try:
|
530
|
+
mask = water_resources_image == 255
|
531
|
+
flatten_to = int(np.mean(dem_image[mask]) - subtract_by) # type: ignore
|
532
|
+
self.flatten_water_to = flatten_to # type: ignore
|
533
|
+
except Exception as e:
|
534
|
+
self.logger.warning("Error occurred while flattening water: %s", e)
|
523
535
|
|
524
536
|
dem_image = self.subtract_by_mask(
|
525
537
|
dem_image, # type: ignore
|
526
538
|
water_resources_image, # type: ignore
|
527
|
-
|
539
|
+
subtract_by=subtract_by,
|
540
|
+
flatten_to=flatten_to,
|
541
|
+
)
|
542
|
+
|
543
|
+
dem_image = self.blur_edges_by_mask(
|
544
|
+
dem_image, water_resources_image, smaller_kernel=3, iterations=5, bigger_kernel=5 # type: ignore
|
528
545
|
)
|
529
546
|
|
530
547
|
# Save the modified dem_image back to the output path
|
@@ -594,7 +611,7 @@ class Background(MeshComponent, ImageComponent):
|
|
594
611
|
return
|
595
612
|
|
596
613
|
# Create a mesh from the 3D polygons
|
597
|
-
mesh = self.mesh_from_3d_polygons(fitted_polygons)
|
614
|
+
mesh = self.mesh_from_3d_polygons(fitted_polygons, single_z_value=self.flatten_water_to)
|
598
615
|
if mesh is None:
|
599
616
|
self.logger.warning("No mesh could be created from the water polygons.")
|
600
617
|
return
|
@@ -607,13 +624,16 @@ class Background(MeshComponent, ImageComponent):
|
|
607
624
|
mesh.export(line_based_save_path)
|
608
625
|
self.logger.debug("Line-based water mesh saved to %s", line_based_save_path)
|
609
626
|
|
610
|
-
def mesh_from_3d_polygons(
|
627
|
+
def mesh_from_3d_polygons(
|
628
|
+
self, polygons: list[shapely.Polygon], single_z_value: int | None = None
|
629
|
+
) -> Trimesh | None:
|
611
630
|
"""Create a simple mesh from a list of 3D shapely Polygons.
|
612
631
|
Each polygon must be flat (all Z the same or nearly the same for each polygon).
|
613
632
|
Returns a single Trimesh mesh.
|
614
633
|
|
615
634
|
Arguments:
|
616
635
|
polygons (list[shapely.Polygon]): List of 3D shapely Polygons to create the mesh from.
|
636
|
+
single_z_value (int | None): The Z value to use for all vertices in the mesh.
|
617
637
|
|
618
638
|
Returns:
|
619
639
|
Trimesh: A single Trimesh object containing the mesh created from the polygons.
|
@@ -645,9 +665,12 @@ class Background(MeshComponent, ImageComponent):
|
|
645
665
|
dists = np.linalg.norm(exterior_2d - v[:2], axis=1)
|
646
666
|
idx = np.argmin(dists)
|
647
667
|
# z = exterior_coords[idx, 2]
|
648
|
-
|
649
|
-
|
650
|
-
|
668
|
+
if not single_z_value:
|
669
|
+
z = self.get_z_coordinate_from_dem(
|
670
|
+
not_resized_dem, exterior_coords[idx, 0], exterior_coords[idx, 1] # type: ignore
|
671
|
+
)
|
672
|
+
else:
|
673
|
+
z = single_z_value
|
651
674
|
vertices_3d.append([v[0], v[1], z])
|
652
675
|
vertices_3d = np.array(vertices_3d) # type: ignore
|
653
676
|
|
@@ -417,7 +417,7 @@ class Component:
|
|
417
417
|
fitted_osm_object = osm_object.intersection(bounds)
|
418
418
|
self.logger.debug("Fitted the osm_object into the bounds: %s", bounds)
|
419
419
|
except Exception as e:
|
420
|
-
raise ValueError(f"Could not fit the osm_object into the bounds: {e}")
|
420
|
+
raise ValueError(f"Could not fit the osm_object into the bounds: {e}") from e
|
421
421
|
|
422
422
|
if not isinstance(fitted_osm_object, object_type):
|
423
423
|
raise ValueError("The fitted osm_object is not valid (probably splitted into parts).")
|
@@ -67,6 +67,7 @@ class ImageComponent(Component):
|
|
67
67
|
mask_by: int = 255,
|
68
68
|
erode_kernel: int | None = 3,
|
69
69
|
erode_iter: int | None = 1,
|
70
|
+
flatten_to: int | None = None,
|
70
71
|
) -> np.ndarray:
|
71
72
|
"""Subtracts a value from the image where the mask is equal to the mask by value.
|
72
73
|
|
@@ -77,6 +78,7 @@ class ImageComponent(Component):
|
|
77
78
|
mask_by (int, optional): The value to mask by. Defaults to 255.
|
78
79
|
erode_kernel (int, optional): The kernel size for the erosion. Defaults to 3.
|
79
80
|
erode_iter (int, optional): The number of iterations for the erosion. Defaults to 1.
|
81
|
+
flatten_to_mean (bool, optional): Whether to flatten the image to the mean value.
|
80
82
|
|
81
83
|
Returns:
|
82
84
|
np.ndarray: The image with the subtracted value.
|
@@ -90,6 +92,10 @@ class ImageComponent(Component):
|
|
90
92
|
).astype(bool)
|
91
93
|
|
92
94
|
image[mask] = image[mask] - subtract_by
|
95
|
+
|
96
|
+
if flatten_to:
|
97
|
+
image[mask] = flatten_to
|
98
|
+
|
93
99
|
return image
|
94
100
|
|
95
101
|
@staticmethod
|
@@ -132,7 +132,7 @@ class DEM(ImageComponent):
|
|
132
132
|
raise ValueError(
|
133
133
|
f"Failed to get DEM data from DTM provider: {e}. "
|
134
134
|
"Try using different DTM provider."
|
135
|
-
)
|
135
|
+
) from e
|
136
136
|
|
137
137
|
if len(data.shape) != 2:
|
138
138
|
self.logger.error("DTM provider returned incorrect data: more than 1 channel.")
|
@@ -164,6 +164,8 @@ class BackgroundSettings(SettingsModel):
|
|
164
164
|
remove_center (bool): remove the center of the background terrain.
|
165
165
|
It will be used to remove the center of the map where the player starts.
|
166
166
|
flatten_roads (bool): if True, roads will be flattened in the DEM data.
|
167
|
+
flatten_water (bool): if True, the bottom of the water resources will be flattened
|
168
|
+
to the average height of the water resources.
|
167
169
|
"""
|
168
170
|
|
169
171
|
generate_background: bool = False
|
@@ -171,6 +173,7 @@ class BackgroundSettings(SettingsModel):
|
|
171
173
|
water_blurriness: int = 20
|
172
174
|
remove_center: bool = True
|
173
175
|
flatten_roads: bool = False
|
176
|
+
flatten_water: bool = False
|
174
177
|
|
175
178
|
|
176
179
|
class GRLESettings(SettingsModel):
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "maps4fs"
|
7
|
-
version = "2.1.
|
7
|
+
version = "2.1.5"
|
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 = "Apache License 2.0"}
|
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
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|