tester.gd 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. extends WorldEnvironment
  2. const ROT_SPEED = 0.003
  3. const ZOOM_SPEED = 0.125
  4. const MAIN_BUTTONS = MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT | MOUSE_BUTTON_MASK_MIDDLE
  5. var tester_index = 0
  6. var rot_x = deg_to_rad(-22.5) # This must be kept in sync with RotationX.
  7. var rot_y = deg_to_rad(90) # This must be kept in sync with CameraHolder.
  8. var zoom = 2.5
  9. var base_height = ProjectSettings.get_setting("display/window/size/viewport_height")
  10. @onready var testers = $Testers
  11. @onready var camera_holder = $CameraHolder # Has a position and rotates on Y.
  12. @onready var rotation_x = $CameraHolder/RotationX
  13. @onready var camera = $CameraHolder/RotationX/Camera3D
  14. func _ready():
  15. camera_holder.transform.basis = Basis.from_euler(Vector3(0, rot_y, 0))
  16. rotation_x.transform.basis = Basis.from_euler(Vector3(rot_x, 0, 0))
  17. update_gui()
  18. func _unhandled_input(event):
  19. if event.is_action_pressed("ui_left"):
  20. _on_previous_pressed()
  21. if event.is_action_pressed("ui_right"):
  22. _on_next_pressed()
  23. if event is InputEventMouseButton:
  24. if event.button_index == MOUSE_BUTTON_WHEEL_UP:
  25. zoom -= ZOOM_SPEED
  26. if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
  27. zoom += ZOOM_SPEED
  28. zoom = clamp(zoom, 1.5, 4)
  29. if event is InputEventMouseMotion and event.button_mask & MAIN_BUTTONS:
  30. # Compensate motion speed to be resolution-independent (based on the window height).
  31. var relative_motion = event.relative * DisplayServer.window_get_size().y / base_height
  32. rot_y -= relative_motion.x * ROT_SPEED
  33. rot_x -= relative_motion.y * ROT_SPEED
  34. rot_x = clamp(rot_x, deg_to_rad(-90), 0)
  35. camera_holder.transform.basis = Basis.from_euler(Vector3(0, rot_y, 0))
  36. rotation_x.transform.basis = Basis.from_euler(Vector3(rot_x, 0, 0))
  37. func _process(delta):
  38. var current_tester = testers.get_child(tester_index)
  39. # This code assumes CameraHolder's X and Y coordinates are already correct.
  40. var current_position = camera_holder.global_transform.origin.z
  41. var target_position = current_tester.global_transform.origin.z
  42. camera_holder.global_transform.origin.z = lerpf(current_position, target_position, 3 * delta)
  43. camera.position.z = lerpf(camera.position.z, zoom, 10 * delta)
  44. func _on_previous_pressed():
  45. tester_index = max(0, tester_index - 1)
  46. update_gui()
  47. func _on_next_pressed():
  48. tester_index = min(tester_index + 1, testers.get_child_count() - 1)
  49. update_gui()
  50. func update_gui():
  51. $TestName.text = str(testers.get_child(tester_index).name).capitalize()
  52. $Previous.disabled = tester_index == 0
  53. $Next.disabled = tester_index == testers.get_child_count() - 1
  54. func _on_enable_sun_toggled(button_pressed):
  55. $DirectionalLight3D.visible = button_pressed
  56. func _on_animate_lights_toggled(button_pressed):
  57. for animatable_node in get_tree().get_nodes_in_group("animatable"):
  58. animatable_node.set_process(button_pressed)
  59. func _on_shadow_resolution_item_selected(index):
  60. var size = 4096
  61. match index:
  62. 0:
  63. size = 1024
  64. 1:
  65. size = 2048
  66. 2:
  67. size = 4096
  68. 3:
  69. size = 8192
  70. 4:
  71. size = 16384
  72. RenderingServer.directional_shadow_atlas_set_size(size, true)
  73. get_viewport().positional_shadow_atlas_size = size
  74. func _on_shadow_filter_quality_item_selected(index):
  75. # Values are numbered in the OptionButton to match the RenderingServer.ShadowQuality enum.
  76. RenderingServer.directional_soft_shadow_filter_set_quality(index)
  77. RenderingServer.positional_soft_shadow_filter_set_quality(index)
  78. func _on_projector_filter_mode_item_selected(index):
  79. # Values are numbered in the OptionButton to match the RenderingServer.LightProjectorFilter enum.
  80. RenderingServer.light_projectors_set_filter(index)