maps4fs 2.1.4__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.
Files changed (33) hide show
  1. {maps4fs-2.1.4 → maps4fs-2.1.5}/PKG-INFO +1 -1
  2. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/background.py +25 -6
  3. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/base/component_image.py +6 -0
  4. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/settings.py +3 -0
  5. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs.egg-info/PKG-INFO +1 -1
  6. {maps4fs-2.1.4 → maps4fs-2.1.5}/pyproject.toml +1 -1
  7. {maps4fs-2.1.4 → maps4fs-2.1.5}/LICENSE.md +0 -0
  8. {maps4fs-2.1.4 → maps4fs-2.1.5}/README.md +0 -0
  9. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/__init__.py +0 -0
  10. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/__init__.py +0 -0
  11. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/__init__.py +0 -0
  12. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/base/__init__.py +0 -0
  13. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/base/component.py +0 -0
  14. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/base/component_mesh.py +0 -0
  15. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/base/component_xml.py +0 -0
  16. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/config.py +0 -0
  17. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/dem.py +0 -0
  18. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/grle.py +0 -0
  19. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/i3d.py +0 -0
  20. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/layer.py +0 -0
  21. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/satellite.py +0 -0
  22. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/component/texture.py +0 -0
  23. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/game.py +0 -0
  24. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/map.py +0 -0
  25. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/qgis.py +0 -0
  26. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/generator/statistics.py +0 -0
  27. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs/logger.py +0 -0
  28. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs.egg-info/SOURCES.txt +0 -0
  29. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs.egg-info/dependency_links.txt +0 -0
  30. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs.egg-info/requires.txt +0 -0
  31. {maps4fs-2.1.4 → maps4fs-2.1.5}/maps4fs.egg-info/top_level.txt +0 -0
  32. {maps4fs-2.1.4 → maps4fs-2.1.5}/setup.cfg +0 -0
  33. {maps4fs-2.1.4 → maps4fs-2.1.5}/tests/test_generator.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maps4fs
3
- Version: 2.1.4
3
+ Version: 2.1.5
4
4
  Summary: Generate map templates for Farming Simulator from real places.
5
5
  Author-email: iwatkot <iwatkot@gmail.com>
6
6
  License: Apache License 2.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,22 @@ 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
- int(self.map.dem_settings.water_depth * z_scaling_factor),
539
+ subtract_by=subtract_by,
540
+ flatten_to=flatten_to,
528
541
  )
529
542
 
530
543
  dem_image = self.blur_edges_by_mask(
@@ -598,7 +611,7 @@ class Background(MeshComponent, ImageComponent):
598
611
  return
599
612
 
600
613
  # Create a mesh from the 3D polygons
601
- mesh = self.mesh_from_3d_polygons(fitted_polygons)
614
+ mesh = self.mesh_from_3d_polygons(fitted_polygons, single_z_value=self.flatten_water_to)
602
615
  if mesh is None:
603
616
  self.logger.warning("No mesh could be created from the water polygons.")
604
617
  return
@@ -611,13 +624,16 @@ class Background(MeshComponent, ImageComponent):
611
624
  mesh.export(line_based_save_path)
612
625
  self.logger.debug("Line-based water mesh saved to %s", line_based_save_path)
613
626
 
614
- def mesh_from_3d_polygons(self, polygons: list[shapely.Polygon]) -> Trimesh | None:
627
+ def mesh_from_3d_polygons(
628
+ self, polygons: list[shapely.Polygon], single_z_value: int | None = None
629
+ ) -> Trimesh | None:
615
630
  """Create a simple mesh from a list of 3D shapely Polygons.
616
631
  Each polygon must be flat (all Z the same or nearly the same for each polygon).
617
632
  Returns a single Trimesh mesh.
618
633
 
619
634
  Arguments:
620
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.
621
637
 
622
638
  Returns:
623
639
  Trimesh: A single Trimesh object containing the mesh created from the polygons.
@@ -649,9 +665,12 @@ class Background(MeshComponent, ImageComponent):
649
665
  dists = np.linalg.norm(exterior_2d - v[:2], axis=1)
650
666
  idx = np.argmin(dists)
651
667
  # z = exterior_coords[idx, 2]
652
- z = self.get_z_coordinate_from_dem(
653
- not_resized_dem, exterior_coords[idx, 0], exterior_coords[idx, 1] # type: ignore
654
- )
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
655
674
  vertices_3d.append([v[0], v[1], z])
656
675
  vertices_3d = np.array(vertices_3d) # type: ignore
657
676
 
@@ -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
@@ -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):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maps4fs
3
- Version: 2.1.4
3
+ Version: 2.1.5
4
4
  Summary: Generate map templates for Farming Simulator from real places.
5
5
  Author-email: iwatkot <iwatkot@gmail.com>
6
6
  License: Apache License 2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "maps4fs"
7
- version = "2.1.4"
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