node_3d.gd 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. extends Node3D
  2. func _input(event: InputEvent) -> void:
  3. if event.is_action_pressed("toggle_occlusion_culling"):
  4. get_viewport().use_occlusion_culling = not get_viewport().use_occlusion_culling
  5. update_labels()
  6. if event.is_action_pressed("toggle_mesh_lod"):
  7. get_viewport().mesh_lod_threshold = 1.0 if is_zero_approx(get_viewport().mesh_lod_threshold) else 0.0
  8. update_labels()
  9. if event.is_action_pressed("cycle_draw_mode"):
  10. get_viewport().debug_draw = wrapi(get_viewport().debug_draw + 1, 0, 5) as Viewport.DebugDraw
  11. update_labels()
  12. if event.is_action_pressed("toggle_vsync"):
  13. if DisplayServer.window_get_vsync_mode() == DisplayServer.VSYNC_DISABLED:
  14. DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED)
  15. else:
  16. DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_DISABLED)
  17. func _process(_delta: float) -> void:
  18. $Performance.text = """%d FPS (%.2f mspf)
  19. Currently rendering:
  20. %d objects
  21. %dK primitive indices
  22. %d draw calls
  23. """ % [
  24. Engine.get_frames_per_second(),
  25. 1000.0 / Engine.get_frames_per_second(),
  26. RenderingServer.get_rendering_info(RenderingServer.RENDERING_INFO_TOTAL_OBJECTS_IN_FRAME),
  27. roundi(RenderingServer.get_rendering_info(RenderingServer.RENDERING_INFO_TOTAL_PRIMITIVES_IN_FRAME) * 0.001),
  28. RenderingServer.get_rendering_info(RenderingServer.RENDERING_INFO_TOTAL_DRAW_CALLS_IN_FRAME),
  29. ]
  30. func update_labels() -> void:
  31. $OcclusionCulling.text = "Occlusion culling: %s" % ("Enabled" if get_viewport().use_occlusion_culling else "Disabled")
  32. $MeshLOD.text = "Mesh LOD: %s" % ("Enabled" if not is_zero_approx(get_viewport().mesh_lod_threshold) else "Disabled")
  33. $DrawMode.text = "Draw mode: %s" % get_draw_mode_string(get_viewport().debug_draw)
  34. func get_draw_mode_string(draw_mode: int) -> String:
  35. match draw_mode:
  36. 0:
  37. return "Normal"
  38. 1:
  39. return "Unshaded"
  40. 2:
  41. return "Lighting"
  42. 3:
  43. return "Overdraw"
  44. 4:
  45. return "Wireframe"
  46. _:
  47. return "(unknown)"