Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import bpy
- import bgl
- import blf
- def draw_callback_px(self, context):
- bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
- blf.position(0, 15, context.region.height - 60, 0)
- blf.size(0, 20, 72)
- blf.draw(0, '{0:06.2f} fps'.format(1.0 / self.timer.time_delta))
- bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
- class ModalDrawOperator(bpy.types.Operator):
- bl_idname = 'view3d.fps'
- bl_label = 'fps'
- def modal(self, context, event):
- #print(event.type, self.timer.time_delta, self.timer.time_duration, self.timer.time_step)
- if self._handle is None:
- for sa in context.screen.areas:
- if sa.type == 'VIEW_3D':
- for ar in sa.regions:
- if ar.type == 'WINDOW':
- self._handle = ar.callback_add(draw_callback_px, (self, context), 'POST_PIXEL')
- self._region = ar
- break
- if event.type == 'IINBETWEEN_MOUSEMOVE':
- return {'PASS_THROUGH'}
- elif event.type == 'ESC':
- if self._handle is not None:
- self._region.callback_remove(self._handle)
- context.window_manager.event_timer_remove(self.timer)
- for sa in context.screen.areas:
- if sa.type == 'VIEW_3D':
- sa.tag_redraw()
- if event.type == 'ESC':
- return {'CANCELLED'}
- return {'PASS_THROUGH'}
- def invoke(self, context, event):
- self.timer = context.window_manager.event_timer_add(0.01, context.window)
- context.window_manager.modal_handler_add(self)
- if context.area.type == 'VIEW_3D':
- self._handle = context.region.callback_add(draw_callback_px, (self, context), 'POST_PIXEL')
- self._region = context.region
- else:
- self._handle = None
- return {'RUNNING_MODAL'}
- def register():
- bpy.utils.register_class(ModalDrawOperator)
- def unregister():
- bpy.utils.unregister_class(ModalDrawOperator)
- if __name__ == '__main__':
- register()
- bpy.ops.view3d.fps('INVOKE_DEFAULT')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement