Advertisement
Guest User

fps

a guest
May 3rd, 2012
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. import time
  2.  
  3. import bpy
  4. import bgl
  5. import blf
  6.  
  7.  
  8. def draw_callback_px(self, context):
  9. bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
  10. blf.position(0, 15, context.region.height - 60, 0)
  11. blf.size(0, 20, 72)
  12. blf.draw(0, '{0:06.2f} fps'.format(1.0 / self.timer.time_delta))
  13. bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
  14.  
  15.  
  16. class ModalDrawOperator(bpy.types.Operator):
  17. bl_idname = 'view3d.fps'
  18. bl_label = 'fps'
  19.  
  20. def modal(self, context, event):
  21. #print(event.type, self.timer.time_delta, self.timer.time_duration, self.timer.time_step)
  22. if self._handle is None:
  23. for sa in context.screen.areas:
  24. if sa.type == 'VIEW_3D':
  25. for ar in sa.regions:
  26. if ar.type == 'WINDOW':
  27. self._handle = ar.callback_add(draw_callback_px, (self, context), 'POST_PIXEL')
  28. self._region = ar
  29. break
  30. if event.type == 'IINBETWEEN_MOUSEMOVE':
  31. return {'PASS_THROUGH'}
  32. elif event.type == 'ESC':
  33. if self._handle is not None:
  34. self._region.callback_remove(self._handle)
  35. context.window_manager.event_timer_remove(self.timer)
  36. for sa in context.screen.areas:
  37. if sa.type == 'VIEW_3D':
  38. sa.tag_redraw()
  39. if event.type == 'ESC':
  40. return {'CANCELLED'}
  41. return {'PASS_THROUGH'}
  42.  
  43.  
  44. def invoke(self, context, event):
  45. self.timer = context.window_manager.event_timer_add(0.01, context.window)
  46. context.window_manager.modal_handler_add(self)
  47.  
  48. if context.area.type == 'VIEW_3D':
  49. self._handle = context.region.callback_add(draw_callback_px, (self, context), 'POST_PIXEL')
  50. self._region = context.region
  51. else:
  52. self._handle = None
  53.  
  54. return {'RUNNING_MODAL'}
  55.  
  56.  
  57. def register():
  58. bpy.utils.register_class(ModalDrawOperator)
  59.  
  60.  
  61. def unregister():
  62. bpy.utils.unregister_class(ModalDrawOperator)
  63.  
  64.  
  65. if __name__ == '__main__':
  66. register()
  67. bpy.ops.view3d.fps('INVOKE_DEFAULT')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement