Skip to content

Commit 6ea7ba7

Browse files
Fixes for color palette matching (#1)
1 parent 41f334a commit 6ea7ba7

File tree

6 files changed

+61
-16
lines changed

6 files changed

+61
-16
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,28 @@ git clone https://github.com/OpenGolfSim/meshery-tool.git
7777
cd meshery-tool
7878
```
7979

80-
Setup a python virtual environment:
80+
We use pyenv to manage local builds.
8181

8282
```bash
83-
python3 -m venv venv
83+
pyenv virtualenv 3.13.9 mesh_venv
84+
```
85+
86+
Set the virtual env (do this each time you open a new shell window)
87+
88+
```bash
89+
pyenv shell mesh_venv
8490
```
8591

8692
Then install the required dependencies:
8793

8894
```bash
89-
./venv/bin/pip install -r requirements.txt
95+
pip install -r requirements.txt
96+
```
97+
98+
Then you can run with:
99+
100+
```bash
101+
python src/meshery.py
90102
```
91103

92104
#### Building Distributable Apps
@@ -99,6 +111,7 @@ To build:
99111
pyinstaller meshery.spec
100112
```
101113

114+
102115
#### App Icons
103116

104117
Here's how I created the app icons. First add all the files you need to the iconset folder:

src/lib/process.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def run(self):
4949

5050
layer_index = 0
5151
for layer in self.svg_info['layers']:
52+
if self._running == False:
53+
raise Exception("Canceled")
5254
num_points = max(int(layer['path'].length()) * 20, 100)
5355
num_points = min(num_points, 10000)
5456
poly = path_to_polygon(layer['path'], num_points)
@@ -59,7 +61,7 @@ def run(self):
5961
self.debug_log.emit(f"Unable to determine surface type based on assigned fill color! ({layer["attr"]})")
6062
return None
6163

62-
self.debug_log.emit(f"Processing surface: {surface}, {num_points} points")
64+
self.debug_log.emit(f"Processing surface: {surface}, {num_points} points")
6365

6466
layers.append({
6567
"index": layer_index,
@@ -69,8 +71,8 @@ def run(self):
6971
"surface": surface,
7072
"color": color
7173
})
72-
7374
layer_index += 1
75+
7476
# self.progress.emit(layer_index)
7577
# time.sleep(1) # blocking work simulated
7678

@@ -92,6 +94,8 @@ def run(self):
9294
layers_completed = 0
9395

9496
for layer in layers:
97+
if self._running == False:
98+
raise Exception("Canceled")
9599
if layer['polygon'].is_empty:
96100
self.debug_log.emit(f" Skipping empty polygon for {layer['surface']}")
97101
continue
@@ -107,18 +111,26 @@ def run(self):
107111
interior_spacing = 0.5
108112
if layer['surface'] == "river":
109113
interior_spacing = 0.2
114+
# if layer['surface'] == "rough":
115+
# interior_spacing = 1.0
116+
# boundary_spacing = 0.75
110117

111118
self.debug_log.emit(f"Generating {layer['label']} polygons with spacing {interior_spacing}")
112119
vertices, faces = triangulate_polygon(layer['polygon'], boundary_spacing, interior_spacing)
113-
120+
if self._running == False:
121+
raise Exception("Canceled")
114122
if vertices.shape[0] == 0 or faces.shape[0] == 0:
115123
self.debug_log.emit(f" Skipping empty shape for {layer['surface']}")
116124
continue
117125

118126
# conform meshes to heightmap
119127
self.debug_log.emit(f"Conforming {layer['label']} polygon to heightmap")
128+
129+
# keep lake surfaces flat
130+
# if layer['surface'] != "water":
120131
vertices = map_mesh_to_heightmap(vertices, terrain_data["data"], self.svg_info["width"], self.svg_info["height"], max_world_height)
121-
132+
if self._running == False:
133+
raise Exception("Canceled")
122134
face_colors = np.tile(hex_to_rgba(layer["color"]), (faces.shape[0], 1))
123135
mesh = trimesh.Trimesh(vertices=vertices, faces=faces, face_colors=face_colors)
124136

@@ -138,9 +150,9 @@ def run(self):
138150
# # self.debug_log.emit(f"Exporting OBJ files to output folder: {self.output_path}")
139151
# # lib.export.export_individual_obj_files(allMeshes, layers, self.output_path)
140152

141-
self.finished.emit(result)
153+
self.finished.emit(0)
142154
except Exception as e:
143-
self.finished.emit(None)
155+
self.finished.emit(1)
144156
self.error.emit(str(e))
145157

146158
def stop(self):
@@ -151,6 +163,7 @@ def stop(self):
151163

152164

153165

166+
154167
def generate_meshes(args, layers, terrain_data, width, height, debug_log):
155168
allMeshes = []
156169

@@ -223,6 +236,7 @@ def parse_layers(svg_file):
223236
if (surface == None or color == None):
224237
debug_log(f"Unable to determine surface type based on assigned fill color! ({attr})", True)
225238
return None
239+
226240
print(f"Processing surface: {surface}, {num_points} points")
227241

228242
layers.append({

src/lib/surfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
def match_surface(attr, surfaceColorMap):
44
styleAttr = attr.get('style', None)
5-
colorPattern = r"fill:#([0-9a-f]+);"
5+
colorPattern = r"fill:#([0-9a-f]+)"
66
match_obj = re.search(colorPattern, styleAttr, re.IGNORECASE)
77
surface = None
88
matchedColor = None

src/lib/svg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def subtract_higher_layers(layers):
1212
union_above = None
1313
for layer in sorted_layers:
1414
poly = layer['polygon']
15+
# if layer['surface'] == 'lake_surface':
16+
# continue
1517
if union_above:
1618
poly = poly.difference(union_above)
1719
if poly.is_empty:

src/ui/progress.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from PySide6.QtGui import QPixmap
2121

2222
class UIProgress(QVBoxLayout):
23+
canceled = Signal()
24+
2325
def __init__(self, parent=None):
2426
super(UIProgress, self).__init__(parent)
2527

@@ -61,9 +63,7 @@ def __init__(self, parent=None):
6163
self.addWidget(self.cancel_button)
6264

6365
def cancel_work(self):
64-
if self.worker:
65-
self.worker.stop()
66-
self.switch_layout(0)
66+
self.canceled.emit()
6767

6868
def setup_progress(self, steps = 0):
6969
self.progress_bar.setMaximum(steps)
@@ -75,9 +75,12 @@ def update_progress(self, step = 0):
7575

7676
def on_finished(self, result):
7777
# handle result (None if cancelled)
78-
self.debug_log("Export completed successfully!")
79-
self.progress_bar.setValue(0)
80-
print("Finished!, result:", result)
78+
if result == 0:
79+
self.debug_log("Export completed successfully!")
80+
self.progress_bar.setValue(0)
81+
print("Finished!, result:", result)
82+
else:
83+
self.debug_log("Export failed")
8184

8285
def debug_log(self, message):
8386
print(message)

src/ui/window.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def __init__(self, parent=None):
4343

4444
self.progress_screen = UIProgress()
4545

46+
self.progress_screen.canceled.connect(self.on_canceled)
47+
4648
job_widget = QWidget()
4749
job_widget.setLayout(self.progress_screen)
4850
self.stacked_layout.addWidget(job_widget)
@@ -56,6 +58,17 @@ def __init__(self, parent=None):
5658
self.stacked_layout.setCurrentIndex(0)
5759
self.setLayout(main_layout)
5860

61+
def on_canceled(self):
62+
if self.worker:
63+
print("stop worker")
64+
self.worker.stop()
65+
66+
# if self.thread:
67+
# # print("stop thread")
68+
# self.thread.terminate()
69+
# self.thread.wait()
70+
71+
# self.stacked_layout.setCurrentIndex(0)
5972

6073
def on_restart_form(self):
6174
print("on_restart_form")

0 commit comments

Comments
 (0)