aboutsummaryrefslogtreecommitdiff
path: root/game/addons/zylann.hterrain/tools/generate_mesh_dialog.gd
blob: f567e0244cf51a6c868f6db0567f72284c94b838 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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()