2017-06-26 05:57:14 +00:00
|
|
|
# Example of a group that edits a single property
|
2018-07-14 21:55:20 +00:00
|
|
|
# using the predefined gizmo arrow.
|
2017-06-26 05:57:14 +00:00
|
|
|
#
|
2018-06-27 12:41:53 +00:00
|
|
|
# Usage: Select a light in the 3D view and drag the arrow at it's rear
|
2017-06-26 05:57:14 +00:00
|
|
|
# to change it's energy value.
|
|
|
|
#
|
|
|
|
import bpy
|
|
|
|
from bpy.types import (
|
2018-07-14 21:55:20 +00:00
|
|
|
GizmoGroup,
|
2017-06-26 05:57:14 +00:00
|
|
|
)
|
|
|
|
|
2018-06-26 20:56:39 +00:00
|
|
|
|
2018-07-14 21:55:20 +00:00
|
|
|
class MyLightWidgetGroup(GizmoGroup):
|
2018-07-15 12:24:10 +00:00
|
|
|
bl_idname = "OBJECT_GGT_light_test"
|
2018-06-27 12:41:53 +00:00
|
|
|
bl_label = "Test Light Widget"
|
2017-06-26 05:57:14 +00: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 12:41:53 +00:00
|
|
|
return (ob and ob.type == 'LIGHT')
|
2017-06-26 05:57:14 +00:00
|
|
|
|
|
|
|
def setup(self, context):
|
2018-07-14 21:55:20 +00:00
|
|
|
# Arrow gizmo has one 'offset' property we can assign to the light energy.
|
2017-06-26 05:57:14 +00:00
|
|
|
ob = context.object
|
2018-07-15 12:24:10 +00:00
|
|
|
mpr = self.gizmos.new("GIZMO_GGT_arrow_3d")
|
2017-06-26 05:57:14 +00:00
|
|
|
mpr.target_set_prop("offset", ob.data, "energy")
|
|
|
|
mpr.matrix_basis = ob.matrix_world.normalized()
|
|
|
|
mpr.draw_style = 'BOX'
|
|
|
|
|
2017-07-17 05:06:18 +00:00
|
|
|
mpr.color = 1.0, 0.5, 0.0
|
|
|
|
mpr.alpha = 0.5
|
|
|
|
|
|
|
|
mpr.color_highlight = 1.0, 0.5, 1.0
|
|
|
|
mpr.alpha_highlight = 0.5
|
2017-06-26 05:57:14 +00:00
|
|
|
|
|
|
|
self.energy_widget = mpr
|
|
|
|
|
|
|
|
def refresh(self, context):
|
|
|
|
ob = context.object
|
|
|
|
mpr = self.energy_widget
|
|
|
|
mpr.matrix_basis = ob.matrix_world.normalized()
|
|
|
|
|
2018-06-26 20:56:39 +00:00
|
|
|
|
2018-06-27 12:41:53 +00:00
|
|
|
bpy.utils.register_class(MyLightWidgetGroup)
|