aboutsummaryrefslogtreecommitdiff
path: root/game/addons/zylann.hterrain/tools/generate_mesh_dialog.gd
diff options
context:
space:
mode:
author Gone2Daly <71726742+Gone2Daly@users.noreply.github.com>2023-07-22 21:05:42 +0200
committer Gone2Daly <71726742+Gone2Daly@users.noreply.github.com>2023-07-22 21:05:42 +0200
commit71b3cd829f80de4c2cd3972d8bfd5ee470a5d180 (patch)
treeb4280fde6eef2ae6987648bc7bf8e00e9011bb7f /game/addons/zylann.hterrain/tools/generate_mesh_dialog.gd
parentce9022d0df74d6c33db3686622be2050d873ab0b (diff)
init_testtest3d
Diffstat (limited to 'game/addons/zylann.hterrain/tools/generate_mesh_dialog.gd')
-rw-r--r--game/addons/zylann.hterrain/tools/generate_mesh_dialog.gd54
1 files changed, 54 insertions, 0 deletions
diff --git a/game/addons/zylann.hterrain/tools/generate_mesh_dialog.gd b/game/addons/zylann.hterrain/tools/generate_mesh_dialog.gd
new file mode 100644
index 0000000..f567e02
--- /dev/null
+++ b/game/addons/zylann.hterrain/tools/generate_mesh_dialog.gd
@@ -0,0 +1,54 @@
+@tool
+extends AcceptDialog
+
+signal generate_selected(lod)
+
+const HTerrain = preload("../hterrain.gd")
+const HTerrainMesher = preload("../hterrain_mesher.gd")
+const HT_Util = preload("../util/util.gd")
+
+@onready var _preview_label : Label = $VBoxContainer/PreviewLabel
+@onready var _lod_spinbox : SpinBox = $VBoxContainer/HBoxContainer/LODSpinBox
+
+var _terrain : HTerrain = null
+
+
+func _init():
+ get_ok_button().hide()
+
+
+func set_terrain(terrain: HTerrain):
+ _terrain = terrain
+
+
+func _notification(what: int):
+ if what == NOTIFICATION_VISIBILITY_CHANGED:
+ if visible and _terrain != null:
+ _update_preview()
+
+
+func _on_LODSpinBox_value_changed(value):
+ _update_preview()
+
+
+func _update_preview():
+ assert(_terrain != null)
+ assert(_terrain.get_data() != null)
+ var resolution := _terrain.get_data().get_resolution()
+ var stride := int(_lod_spinbox.value)
+ resolution /= stride
+ var s := HTerrainMesher.get_mesh_size(resolution, resolution)
+ _preview_label.text = str( \
+ HT_Util.format_integer(s.vertices), " vertices, ", \
+ HT_Util.format_integer(s.triangles), " triangles")
+
+
+func _on_Generate_pressed():
+ var stride := int(_lod_spinbox.value)
+ generate_selected.emit(stride)
+ hide()
+
+
+func _on_Cancel_pressed():
+ hide()
+