Newer
Older
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
# ##### BEGIN GPL LICENSE BLOCK #####
#
# 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 2
# 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
"""User interface imports and preferences for the addon."""
# import addon_utils
# from time import sleep
import bpy
from bpy.app.handlers import persistent
# from bpy.utils import register_class, unregister_class
# from bpy.types import (
# Operator,
# Menu,
# UIList,
# Panel,
# Brush,
# Material,
# Light,
# World,
# ParticleSettings,
# FreestyleLineStyle,
# )
# from bl_operators.presets import AddPresetBase
from . import (
render_gui,
scenography_gui,
object_gui,
shading_gui,
texturing_gui,
shading_nodes, # for POV specific nodes
scripting_gui,
# ------------ POV-Centric WORKSPACE ------------ #
def pov_centric_moray_like_workspace(dummy):
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
"""Set up a POV centric Workspace if addon was activated and saved as default renderer.
This would bring a ’_RestrictData’ error because UI needs to be fully loaded before
workspace changes so registering this function in bpy.app.handlers is needed.
By default handlers are freed when loading new files, but here we want the handler
to stay running across multiple files as part of this add-on. That is why the
bpy.app.handlers.persistent decorator is used (@persistent) above.
"""
# Scripting workspace may have been altered from factory though, so should
# we put all within a Try... Except AttributeErrors ? Any better solution ?
# Should it simply not run when opening existing file? be a preferences operator to create
# Moray like workspace
if 'Scripting' in bpy.data.workspaces:
wsp = bpy.data.workspaces.get('Scripting')
context = bpy.context
if context.scene.render.engine == 'POVRAY_RENDER' and wsp is not None:
bpy.ops.workspace.duplicate({'workspace': wsp})
bpy.data.workspaces['Scripting.001'].name = 'POV'
# Already done it would seem, but explicitly make this workspace the active one
context.window.workspace = bpy.data.workspaces['POV']
pov_screen = bpy.data.workspaces['POV'].screens[0]
pov_workspace = pov_screen.areas
pov_window = context.window
try:
# Already outliners but invert both types
pov_workspace[1].spaces[0].display_mode = 'LIBRARIES'
pov_workspace[3].spaces[0].display_mode = 'VIEW_LAYER'
except AttributeError:
# But not necessarily outliners in existing blend files
pass
override = bpy.context.copy()
for area in pov_workspace:
if area.type == 'VIEW_3D':
for region in [r for r in area.regions if r.type == 'WINDOW']:
for space in area.spaces:
if space.type == 'VIEW_3D':
# override['screen'] = pov_screen
override['area'] = area
override['region'] = region
# bpy.data.workspaces['POV'].screens[0].areas[6].spaces[0].width = 333 # Read only,
# how do we set ?
# This has a glitch:
# bpy.ops.screen.area_move(override, x=(area.x + area.width), y=(area.y + 5), delta=100)
# bpy.ops.screen.area_move(override, x=(area.x + 5), y=area.y, delta=-100)
bpy.ops.screen.space_type_set_or_cycle(
override, space_type='TEXT_EDITOR'
)
space.show_region_ui = True
# bpy.ops.screen.region_scale(override)
# bpy.ops.screen.region_scale()
break
elif area.type == 'CONSOLE':
for region in [r for r in area.regions if r.type == 'WINDOW']:
for space in area.spaces:
if space.type == 'CONSOLE':
override['screen'] = pov_screen
override['window'] = pov_window
override['area'] = area
override['region'] = region
# area_x = area.x + (area.width / 2)
# area_y = area.y + area.height
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
215
216
217
218
219
220
221
222
bpy.ops.screen.space_type_set_or_cycle(override, space_type='INFO')
try:
if area == pov_workspace[6] and bpy.ops.screen.area_move.poll(
override
):
# bpy.ops.screen.area_move(override, x = area_x, y = area_y, delta = -300)
pass
# pov_window.cursor_warp(area_x, area_y-300) # Is manual move emulation necessary
# despite the delta?
except IndexError:
# Not necessarily so many areas in existing blend files
pass
break
elif area.type == 'INFO':
for region in [r for r in area.regions if r.type == 'WINDOW']:
for space in area.spaces:
if space.type == 'INFO':
# override['screen'] = pov_screen
override['area'] = area
override['region'] = region
bpy.ops.screen.space_type_set_or_cycle(
override, space_type='CONSOLE'
)
break
elif area.type == 'TEXT_EDITOR':
for region in [r for r in area.regions if r.type == 'WINDOW']:
for space in area.spaces:
if space.type == 'TEXT_EDITOR':
# override['screen'] = pov_screen
override['area'] = area
override['region'] = region
# bpy.ops.screen.space_type_set_or_cycle(space_type='VIEW_3D')
# space.type = 'VIEW_3D'
bpy.ops.screen.space_type_set_or_cycle(
override, space_type='VIEW_3D'
)
# bpy.ops.screen.area_join(override, cursor=(area.x, area.y + area.height))
break
if area.type == 'VIEW_3D':
for region in [r for r in area.regions if r.type == 'WINDOW']:
for space in area.spaces:
if space.type == 'VIEW_3D':
# override['screen'] = pov_screen
override['area'] = area
override['region'] = region
bpy.ops.screen.region_quadview(override)
space.region_3d.view_perspective = 'CAMERA'
# bpy.ops.screen.space_type_set_or_cycle(override, space_type = 'TEXT_EDITOR')
# bpy.ops.screen.region_quadview(override)
elif area.type == 'OUTLINER':
for region in [
r for r in area.regions if r.type == 'HEADER' and (r.y - area.y)
]:
for space in area.spaces:
if space.display_mode == 'LIBRARIES':
override['area'] = area
override['region'] = region
override['window'] = pov_window
bpy.ops.screen.region_flip(override)
bpy.data.workspaces.update()
'''
for window in bpy.context.window_manager.windows:
for area in [a for a in window.screen.areas if a.type == 'VIEW_3D']:
for region in [r for r in area.regions if r.type == 'WINDOW']:
context_override = {
'window': window,
'screen': window.screen,
'area': area,
'region': region,
'space_data': area.spaces.active,
'scene': bpy.context.scene
}
bpy.ops.view3d.camera_to_view(context_override)
'''
else:
print(
"\nPOV centric workspace available if you set render option\n"
"and save it in default file with CTRL+U"
)
else:
print(
"\nThe factory 'Scripting' workspace is needed before POV centric "
"\nworkspace may activate when POV is set as your default renderer"
)
# -----------------------------------UTF-8---------------------------------- #
# Check and fix all strings in current .blend file to be valid UTF-8 Unicode
# sometimes needed for old, 2.4x / 2.6x area files
bpy.ops.wm.blend_strings_utf8_validate()
def check_material(mat):
"""Allow use of material properties buttons rather than nodes."""
if mat is not None:
if mat.use_nodes:
if not mat.node_tree: # FORMERLY : #mat.active_node_material is not None:
return True
return False
return True
return False
def simple_material(mat):
"""Test if a material is nodeless."""
return (mat is not None) and (not mat.use_nodes)
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
def pov_context_tex_datablock(context):
"""Recreate texture context type as deprecated in blender 2.8."""
idblock = context.brush
if idblock and context.scene.texture_context == 'OTHER':
return idblock
# idblock = bpy.context.active_object.active_material
idblock = context.view_layer.objects.active.active_material
if idblock and context.scene.texture_context == 'MATERIAL':
return idblock
idblock = context.scene.world
if idblock and context.scene.texture_context == 'WORLD':
return idblock
idblock = context.light
if idblock and context.scene.texture_context == 'LIGHT':
return idblock
if context.particle_system and context.scene.texture_context == 'PARTICLES':
idblock = context.particle_system.settings
return idblock
idblock = context.line_style
if idblock and context.scene.texture_context == 'LINESTYLE':
return idblock
# class TextureTypePanel(TextureButtonsPanel):
# @classmethod
# def poll(cls, context):
# tex = context.texture
# engine = context.scene.render.engine
# return tex and ((tex.type == cls.tex_type and not tex.use_nodes) and (engine in cls.COMPAT_ENGINES))
def register():
render_gui.register()
scenography_gui.register()
object_gui.register()
shading_gui.register()
texturing_gui.register()
shading_nodes.register()
scripting_gui.register()
if pov_centric_moray_like_workspace not in bpy.app.handlers.load_post:
bpy.app.handlers.load_post.append(pov_centric_moray_like_workspace)
if pov_centric_moray_like_workspace in bpy.app.handlers.load_post:
bpy.app.handlers.load_post.remove(pov_centric_moray_like_workspace)
scripting_gui.unregister()
shading_nodes.unregister()
texturing_gui.unregister()
shading_gui.unregister()
object_gui.unregister()
scenography_gui.unregister()
render_gui.unregister()