gizmo_simple.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Example of a group that edits a single property
  2. # using the predefined gizmo arrow.
  3. #
  4. # Usage: Select a light in the 3D view and drag the arrow at it's rear
  5. # to change it's energy value.
  6. #
  7. import bpy
  8. from bpy.types import (
  9. GizmoGroup,
  10. )
  11. class MyLightWidgetGroup(GizmoGroup):
  12. bl_idname = "OBJECT_GGT_light_test"
  13. bl_label = "Test Light Widget"
  14. bl_space_type = 'VIEW_3D'
  15. bl_region_type = 'WINDOW'
  16. bl_options = {'3D', 'PERSISTENT'}
  17. @classmethod
  18. def poll(cls, context):
  19. ob = context.object
  20. return (ob and ob.type == 'LIGHT')
  21. def setup(self, context):
  22. # Arrow gizmo has one 'offset' property we can assign to the light energy.
  23. ob = context.object
  24. mpr = self.gizmos.new("GIZMO_GT_arrow_3d")
  25. mpr.target_set_prop("offset", ob.data, "energy")
  26. mpr.matrix_basis = ob.matrix_world.normalized()
  27. mpr.draw_style = 'BOX'
  28. mpr.color = 1.0, 0.5, 0.0
  29. mpr.alpha = 0.5
  30. mpr.color_highlight = 1.0, 0.5, 1.0
  31. mpr.alpha_highlight = 0.5
  32. self.energy_widget = mpr
  33. def refresh(self, context):
  34. ob = context.object
  35. mpr = self.energy_widget
  36. mpr.matrix_basis = ob.matrix_world.normalized()
  37. bpy.utils.register_class(MyLightWidgetGroup)