-
Notifications
You must be signed in to change notification settings - Fork 8
/
panel.py
214 lines (176 loc) · 7.6 KB
/
panel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Light Painter, Blender add-on that creates lights based on where the user paints.
# Copyright (C) 2023 Spencer Magnusson
# semagnum@gmail.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import bpy
from pathlib import Path
from .operators import (
LIGHTPAINTER_OT_Lamp,
LIGHTPAINTER_OT_Lamp_Adjust,
LIGHTPAINTER_OT_Mesh,
LIGHTPAINTER_OT_Tube_Light,
LIGHTPAINTER_OT_Sky,
LIGHTPAINTER_OT_Sun,
LIGHTPAINTER_OT_Flag,
LIGHTPAINTER_OT_Lamp_Texture,
LIGHTPAINTER_OT_Lamp_Texture_Remove,
)
def icon_path(name: str):
return (Path(__file__).parent / ('light_painter.' + name)).as_posix()
class VIEW3D_T_light_paint(bpy.types.WorkSpaceTool):
bl_idname = 'view3d.lightpaint_lamp'
bl_space_type = 'VIEW_3D'
bl_context_mode = 'OBJECT'
bl_label = 'Light Paint'
bl_operator = LIGHTPAINTER_OT_Lamp.bl_idname
bl_icon = icon_path('light_paint')
bl_keymap = (
(LIGHTPAINTER_OT_Lamp.bl_idname, {'type': 'LEFTMOUSE', 'value': 'PRESS'}, None),
)
def draw_settings(context, layout, tool):
props = tool.operator_properties(LIGHTPAINTER_OT_Lamp.bl_idname)
layout.prop(props, 'lamp_type')
layout.prop(props, 'light_color')
class VIEW3D_T_light_paint_adjust(bpy.types.WorkSpaceTool):
bl_idname = 'view3d.lightpaint_lamp_adjust'
bl_space_type = 'VIEW_3D'
bl_context_mode = 'OBJECT'
bl_label = 'Adjust Light'
bl_operator = LIGHTPAINTER_OT_Lamp_Adjust.bl_idname
bl_icon = icon_path('light_paint_adjust')
bl_keymap = (
(LIGHTPAINTER_OT_Lamp_Adjust.bl_idname, {'type': 'LEFTMOUSE', 'value': 'PRESS'}, None),
)
class VIEW3D_T_mesh_light_paint(bpy.types.WorkSpaceTool):
bl_idname = 'view3d.lightpaint_mesh'
bl_space_type = 'VIEW_3D'
bl_context_mode = 'OBJECT'
bl_label = 'Mesh Light Paint'
bl_operator = LIGHTPAINTER_OT_Mesh.bl_idname
bl_icon = icon_path('mesh_light_paint')
bl_keymap = (
(LIGHTPAINTER_OT_Mesh.bl_idname, {'type': 'LEFTMOUSE', 'value': 'PRESS'}, None),
)
def draw_settings(context, layout, tool):
props = tool.operator_properties(LIGHTPAINTER_OT_Mesh.bl_idname)
layout.prop(props, 'light_color')
layout.prop(props, 'flatten')
class VIEW3D_T_tube_light_paint(bpy.types.WorkSpaceTool):
bl_idname = 'view3d.lightpaint_tube_light'
bl_space_type = 'VIEW_3D'
bl_context_mode = 'OBJECT'
bl_label = 'Tube Light Paint'
bl_operator = LIGHTPAINTER_OT_Tube_Light.bl_idname
bl_icon = icon_path('tube_light_paint')
bl_keymap = (
(LIGHTPAINTER_OT_Tube_Light.bl_idname, {'type': 'LEFTMOUSE', 'value': 'PRESS'}, None),
)
def draw_settings(context, layout, tool, extra=False):
props = tool.operator_properties(LIGHTPAINTER_OT_Tube_Light.bl_idname)
if not extra:
layout.prop(props, 'light_color')
layout.prop(props, 'merge_distance')
layout.prop(props, 'skin_radius')
layout.prop(props, 'is_smooth')
if context.region.type == 'TOOL_HEADER':
layout.popover('TOPBAR_PT_tool_settings_extra', text='...')
if extra or context.region.type != 'TOOL_HEADER':
layout.label(text='Subdivision')
col = layout.column()
col.prop(props, 'pre_subdiv', text='Path')
col.prop(props, 'post_subdiv', text='Surface')
class VIEW3D_T_sky_paint(bpy.types.WorkSpaceTool):
bl_idname = 'view3d.lightpaint_sky'
bl_space_type = 'VIEW_3D'
bl_context_mode = 'OBJECT'
bl_label = 'Sky Paint'
bl_operator = LIGHTPAINTER_OT_Sky.bl_idname
bl_icon = icon_path('sky_paint')
bl_keymap = (
(LIGHTPAINTER_OT_Sky.bl_idname, {'type': 'LEFTMOUSE', 'value': 'PRESS'}, None),
)
def draw_settings(context, layout, tool, extra=False):
props = tool.operator_properties(LIGHTPAINTER_OT_Sky.bl_idname)
if not extra:
layout.prop(props, 'texture_type')
layout.prop(props, 'power')
layout.prop(props, 'size')
if context.region.type == 'TOOL_HEADER':
layout.popover('TOPBAR_PT_tool_settings_extra', text='...')
if extra or context.region.type != 'TOOL_HEADER':
layout.label(text='Method:')
row = layout.row()
row.prop(props, 'normal_method', expand=True)
col = layout.column()
col.active = props.normal_method == 'OCCLUSION'
col.prop(props, 'longitude_samples')
col.prop(props, 'latitude_samples')
col.prop(props, 'elevation_clamp', slider=True)
class VIEW3D_T_sun_paint(bpy.types.WorkSpaceTool):
bl_idname = 'view3d.lightpaint_sun'
bl_space_type = 'VIEW_3D'
bl_context_mode = 'OBJECT'
bl_label = 'Sun Paint'
bl_operator = LIGHTPAINTER_OT_Sun.bl_idname
bl_icon = icon_path('light_paint')
bl_keymap = (
(LIGHTPAINTER_OT_Sun.bl_idname, {'type': 'LEFTMOUSE', 'value': 'PRESS'}, None),
)
def draw_settings(context, layout, tool, extra=False):
props = tool.operator_properties(LIGHTPAINTER_OT_Sun.bl_idname)
if not extra and context.region.type == 'TOOL_HEADER':
layout.prop(props, 'light_color')
layout.popover('TOPBAR_PT_tool_settings_extra', text='...')
else:
layout.label(text='Method:')
row = layout.row()
row.prop(props, 'normal_method', expand=True)
col = layout.column()
col.active = props.normal_method == 'OCCLUSION'
col.prop(props, 'longitude_samples')
col.prop(props, 'latitude_samples')
col.prop(props, 'elevation_clamp', slider=True)
class VIEW3D_T_flag_paint(bpy.types.WorkSpaceTool):
bl_idname = 'view3d.lightpaint_flag'
bl_space_type = 'VIEW_3D'
bl_context_mode = 'OBJECT'
bl_label = 'Shadow Paint'
bl_operator = LIGHTPAINTER_OT_Flag.bl_idname
bl_icon = icon_path('shadow_paint')
bl_keymap = (
(LIGHTPAINTER_OT_Flag.bl_idname, {'type': 'LEFTMOUSE', 'value': 'PRESS'}, None),
)
def draw_settings(context, layout, tool):
props = tool.operator_properties(LIGHTPAINTER_OT_Flag.bl_idname)
layout.prop(props, 'shadow_color')
layout.prop(props, 'factor')
layout.prop(props, 'offset')
class LIGHTPAINTER_PT_Texture(bpy.types.Panel):
bl_label = 'Light Painter Gobos'
bl_idname = 'LIGHTPAINTER_PT_Texture'
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = 'data'
@classmethod
def poll(cls, context):
active_obj = context.active_object
return active_obj is not None and active_obj.type == 'LIGHT' and context.engine == 'CYCLES'
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False # No animation
layout.prop(context.window_manager, 'lightpainter_texture_type')
layout.operator(LIGHTPAINTER_OT_Lamp_Texture.bl_idname, icon='MATERIAL')
layout.operator(LIGHTPAINTER_OT_Lamp_Texture_Remove.bl_idname, icon='MATERIAL')