gizmo_operator_target.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Example of a gizmo that activates an operator
  2. # using the predefined dial gizmo to change the camera roll.
  3. #
  4. # Usage: Run this script and select a camera in the 3D view.
  5. #
  6. import bpy
  7. from bpy.types import (
  8. GizmoGroup,
  9. )
  10. class MyCameraWidgetGroup(GizmoGroup):
  11. bl_idname = "OBJECT_GGT_test_camera"
  12. bl_label = "Object Camera Test Widget"
  13. bl_space_type = 'VIEW_3D'
  14. bl_region_type = 'WINDOW'
  15. bl_options = {'3D', 'PERSISTENT'}
  16. @classmethod
  17. def poll(cls, context):
  18. ob = context.object
  19. return (ob and ob.type == 'CAMERA')
  20. def setup(self, context):
  21. # Run an operator using the dial gizmo
  22. ob = context.object
  23. mpr = self.gizmos.new("GIZMO_GT_dial_3d")
  24. props = mpr.target_set_operator("transform.rotate")
  25. props.constraint_axis = False, False, True
  26. props.orient_type = 'LOCAL'
  27. props.release_confirm = True
  28. mpr.matrix_basis = ob.matrix_world.normalized()
  29. mpr.line_width = 3
  30. mpr.color = 0.8, 0.8, 0.8
  31. mpr.alpha = 0.5
  32. mpr.color_highlight = 1.0, 1.0, 1.0
  33. mpr.alpha_highlight = 1.0
  34. self.roll_widget = mpr
  35. def refresh(self, context):
  36. ob = context.object
  37. mpr = self.roll_widget
  38. mpr.matrix_basis = ob.matrix_world.normalized()
  39. bpy.utils.register_class(MyCameraWidgetGroup)