node_3d.gd 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. extends Node3D
  2. func _input(event):
  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)
  11. update_labels()
  12. func _process(delta):
  13. $Performance.text = """%d FPS (%.2f mspf)
  14. Currently rendering:
  15. %d objects
  16. %dK primitive indices
  17. %d draw calls
  18. """ % [
  19. Engine.get_frames_per_second(),
  20. 1000.0 / Engine.get_frames_per_second(),
  21. RenderingServer.get_rendering_info(RenderingServer.RENDERING_INFO_TOTAL_OBJECTS_IN_FRAME),
  22. RenderingServer.get_rendering_info(RenderingServer.RENDERING_INFO_TOTAL_PRIMITIVES_IN_FRAME) * 0.001,
  23. RenderingServer.get_rendering_info(RenderingServer.RENDERING_INFO_TOTAL_DRAW_CALLS_IN_FRAME),
  24. ]
  25. func update_labels():
  26. $OcclusionCulling.text = "Occlusion culling: %s" % ("Enabled" if get_viewport().use_occlusion_culling else "Disabled")
  27. $MeshLOD.text = "Mesh LOD: %s" % ("Enabled" if not is_zero_approx(get_viewport().mesh_lod_threshold) else "Disabled")
  28. $DrawMode.text = "Draw mode: %s" % get_draw_mode_string(get_viewport().debug_draw)
  29. func get_draw_mode_string(draw_mode):
  30. match draw_mode:
  31. 0:
  32. return "Normal"
  33. 1:
  34. return "Unshaded"
  35. 2:
  36. return "Lighting"
  37. 3:
  38. return "Overdraw"
  39. 4:
  40. return "Wireframe"