2017-06-26 15:57:14 +10:00
|
|
|
# Example of a group that edits a single property
|
2018-07-14 23:55:20 +02:00
|
|
|
# using the predefined gizmo arrow.
|
2017-06-26 15:57:14 +10:00
|
|
|
#
|
2024-01-11 11:01:44 -05:00
|
|
|
# Usage: Select a light in the 3D view and drag the arrow at its rear
|
|
|
|
# to change its energy value.
|
2017-06-26 15:57:14 +10:00
|
|
|
#
|
|
|
|
import bpy
|
|
|
|
from bpy.types import (
|
2018-07-14 23:55:20 +02:00
|
|
|
GizmoGroup,
|
2017-06-26 15:57:14 +10:00
|
|
|
)
|
|
|
|
|
2018-06-26 22:56:39 +02:00
|
|
|
|
2018-07-14 23:55:20 +02:00
|
|
|
class MyLightWidgetGroup(GizmoGroup):
|
2018-07-15 14:24:10 +02:00
|
|
|
bl_idname = "OBJECT_GGT_light_test"
|
2018-06-27 14:41:53 +02:00
|
|
|
bl_label = "Test Light Widget"
|
2017-06-26 15:57:14 +10:00
|
|
|
bl_space_type = 'VIEW_3D'
|
|
|
|
bl_region_type = 'WINDOW'
|
|
|
|
bl_options = {'3D', 'PERSISTENT'}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
ob = context.object
|
2018-06-27 14:41:53 +02:00
|
|
|
return (ob and ob.type == 'LIGHT')
|
2017-06-26 15:57:14 +10:00
|
|
|
|
|
|
|
def setup(self, context):
|
2024-10-16 14:45:08 +11:00
|
|
|
# Arrow gizmo has one `offset` property we can assign to the light energy.
|
2017-06-26 15:57:14 +10:00
|
|
|
ob = context.object
|
2021-01-29 11:33:54 +11:00
|
|
|
gz = self.gizmos.new("GIZMO_GT_arrow_3d")
|
|
|
|
gz.target_set_prop("offset", ob.data, "energy")
|
|
|
|
gz.matrix_basis = ob.matrix_world.normalized()
|
|
|
|
gz.draw_style = 'BOX'
|
2017-06-26 15:57:14 +10:00
|
|
|
|
2021-01-29 11:33:54 +11:00
|
|
|
gz.color = 1.0, 0.5, 0.0
|
|
|
|
gz.alpha = 0.5
|
2017-07-17 15:06:18 +10:00
|
|
|
|
2021-01-29 11:33:54 +11:00
|
|
|
gz.color_highlight = 1.0, 0.5, 1.0
|
|
|
|
gz.alpha_highlight = 0.5
|
2017-06-26 15:57:14 +10:00
|
|
|
|
2021-01-29 11:33:54 +11:00
|
|
|
self.energy_gizmo = gz
|
2017-06-26 15:57:14 +10:00
|
|
|
|
|
|
|
def refresh(self, context):
|
|
|
|
ob = context.object
|
2021-01-29 11:33:54 +11:00
|
|
|
gz = self.energy_gizmo
|
|
|
|
gz.matrix_basis = ob.matrix_world.normalized()
|
2017-06-26 15:57:14 +10:00
|
|
|
|
2018-06-26 22:56:39 +02:00
|
|
|
|
2018-06-27 14:41:53 +02:00
|
|
|
bpy.utils.register_class(MyLightWidgetGroup)
|