-
Notifications
You must be signed in to change notification settings - Fork 6
/
__init__.py
158 lines (126 loc) · 5.02 KB
/
__init__.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
# Light Painter, Blender add-on that creates lights based on where the user paints.
# Copyright (C) 2024 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/>.
if "bpy" in locals():
import importlib
import os
import types
# double-check this add-on is imported, so it can be referenced and reloaded
import lightpainter
def reload_package(package):
assert (hasattr(package, '__package__'))
fn = package.__file__
fn_dir = os.path.dirname(fn) + os.sep
module_visit = {fn}
del fn
def reload_recursive_ex(module):
module_iter = (
module_child
for module_child in vars(module).values()
if isinstance(module_child, types.ModuleType)
)
for module_child in module_iter:
fn_child = getattr(module_child, '__file__', None)
if (fn_child is not None) and fn_child.startswith(fn_dir) and fn_child not in module_visit:
# print('Reloading:', fn_child, 'from', module)
module_visit.add(fn_child)
reload_recursive_ex(module_child)
importlib.reload(module)
return reload_recursive_ex(package)
reload_package(lightpainter)
import bpy
from . import axis, operators, panel
from . import translations
bl_info = {
'name': 'Light Painter',
'author': 'Spencer Magnusson',
'version': (1, 3, 3),
'blender': (3, 6, 0),
'description': 'Creates lights based on where the user paints',
'location': 'View 3D > Light Paint',
'support': 'COMMUNITY',
'category': '3D View',
'doc_url': 'https://semagnum.github.io/light-painter/',
'tracker_url': 'https://github.com/semagnum/light-painter/issues',
}
operators_to_register = (
operators.LIGHTPAINTER_OT_Lamp,
operators.LIGHTPAINTER_OT_Lamp_Adjust,
operators.LIGHTPAINTER_OT_Mesh,
operators.LIGHTPAINTER_OT_Tube_Light,
operators.LIGHTPAINTER_OT_Sky,
operators.LIGHTPAINTER_OT_Sun,
operators.LIGHTPAINTER_OT_Flag,
operators.LIGHTPAINTER_OT_Lamp_Texture,
operators.LIGHTPAINTER_OT_Lamp_Texture_Remove,
)
tools = (
panel.VIEW3D_T_light_paint,
panel.VIEW3D_T_sun_paint,
panel.VIEW3D_T_sky_paint,
panel.VIEW3D_T_mesh_light_paint,
panel.VIEW3D_T_tube_light_paint,
panel.VIEW3D_T_flag_paint,
panel.VIEW3D_T_light_paint_adjust,
)
REGISTERED_WITH_UI = False
def register():
"""Registers Light Painter operators and tools."""
for cls in operators_to_register:
bpy.utils.register_class(cls)
texture_type_items = [
('NOISE', 'Noise', ''),
('MAGIC', 'Magic', ''),
('MUSGRAVE', 'Musgrave', ''),
('VORONOI', 'Voronoi', ''),
('WAVE', 'Wave', ''),
]
# Musgrave node is merged into the Noise mode in Blender 4.1
if bpy.app.version >= (4, 1, 0):
texture_type_items.pop(2)
bpy.types.WindowManager.lightpainter_texture_type = bpy.props.EnumProperty(
name='Texture Type',
items=texture_type_items,
default='NOISE',
)
# In background mode (no GUI), we don't need to register the tools or panel.
# stored to prevent unregistering tools that were never registered
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
global REGISTERED_WITH_UI
REGISTERED_WITH_UI = True
bpy.utils.register_tool(panel.VIEW3D_T_light_paint, separator=True)
bpy.utils.register_tool(panel.VIEW3D_T_sky_paint, group=True)
bpy.utils.register_tool(panel.VIEW3D_T_sun_paint, after=panel.VIEW3D_T_sky_paint.bl_idname)
bpy.utils.register_tool(panel.VIEW3D_T_mesh_light_paint)
bpy.utils.register_tool(panel.VIEW3D_T_tube_light_paint)
bpy.utils.register_tool(panel.VIEW3D_T_flag_paint)
bpy.utils.register_tool(panel.VIEW3D_T_light_paint_adjust)
bpy.utils.register_class(panel.LIGHTPAINTER_PT_Texture)
translations.register()
def unregister():
"""Unregisters Light Painter operators and lamp_tool_group."""
global REGISTERED_WITH_UI
if REGISTERED_WITH_UI:
for tool in tools[::-1]:
bpy.utils.unregister_tool(tool)
bpy.utils.unregister_class(panel.LIGHTPAINTER_PT_Texture)
translations.unregister()
for cls in operators_to_register[::-1]:
bpy.utils.unregister_class(cls)
if __name__ == '__main__':
register()