-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpie_menu.py
More file actions
560 lines (468 loc) · 20.1 KB
/
Copy pathpie_menu.py
File metadata and controls
560 lines (468 loc) · 20.1 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
import bpy
from bpy.types import Menu
from .camera_presets import CAM_MANAGER_MT_camera_presets
RESOLUTION_PRESET_ITEMS = [
('1080x1080', "Square (HD) 1080x1080", "1080x1080 (1:1)"),
('1280x720', "HD (720p) 1280x720", "1280x720 (16:9)"),
('1920x1080', "Full HD (1080p) 1920x1080", "1920x1080 (16:9)"),
('2560x1440', "QHD (1440p) 2560x1440", "2560x1440 (16:9)"),
('3840x2160', "4K UHD 3840x2160", "3840x2160 (16:9)"),
('7680x4320', "8K UHD 7680x4320", "7680x4320 (16:9)"),
('2560x1080', "Ultra-Wide HD 2560x1080", "2560x1080 (21:9)"),
('3440x1440', "Ultra-Wide QHD 3440x1440", "3440x1440 (21:9)"),
('5120x2160', "Ultra-Wide 4K 5120x2160", "5120x2160 (21:9)"),
('512x512', "Square 512x512", "512x512 (1:1)"),
('1024x1024', "Square 1024x1024", "1024x1024 (1:1)"),
('2048x2048', "Square 2048x2048", "2048x2048 (1:1)"),
('4096x4096', "Square 4096x4096", "4096x4096 (1:1)"),
('1080x1080_insta', "Instagram Square 1080x1080", "1080x1080 (1:1)"),
('1080x1350_insta', "Instagram Portrait 1080x1350", "1080x1350 (4:5)"),
('1080x608_insta', "Instagram Landscape 1080x608", "1080x608 (1.91:1)"),
('820x312_fb', "Facebook Cover 820x312", "820x312 (2.63:1)"),
('1280x720_yt', "YouTube Thumbnail 1280x720", "1280x720 (16:9)"),
('1500x500_tw', "Twitter Header 1500x500", "1500x500 (3:1)"),
('1584x396_linkedin', "LinkedIn Banner 1584x396", "1584x396 (4:1)"),
('720x480', "SD (Standard Definition) 720x480", "720x480 (4:3)"),
('2048x1080', "2K (DCI) 2048x1080", "2048x1080 (17:9)"),
('4096x2160', "4K DCI 4096x2160", "4096x2160 (17:9)"),
]
FOCAL_LENGTH_PRESET_ITEMS = [
('14', "Ultra Wide 14mm", "14mm — Ultra Wide"),
('18', "Wide 18mm", "18mm — Wide"),
('24', "Wide 24mm", "24mm — Wide"),
('28', "Wide 28mm", "28mm — Wide"),
('35', "Standard Wide 35mm", "35mm — Standard Wide"),
('40', "Standard Wide 40mm", "40mm — Standard Wide"),
('50', "Normal 50mm", "50mm — Normal"),
('85', "Portrait 85mm", "85mm — Portrait"),
('100', "Macro / Portrait 100mm", "100mm — Macro / Portrait"),
('105', "Portrait / Macro 105mm", "105mm — Portrait / Macro"),
('120', "Medium Telephoto 120mm", "120mm — Medium Telephoto"),
('135', "Short Telephoto 135mm", "135mm — Short Telephoto"),
('200', "Telephoto 200mm", "200mm — Telephoto"),
]
RESOLUTION_PRESET_MAP = {
'512x512': (512, 512),
'1024x1024': (1024, 1024),
'2048x2048': (2048, 2048),
'4096x4096': (4096, 4096),
'1080x1080': (1080, 1080),
'1280x720': (1280, 720),
'1920x1080': (1920, 1080),
'2560x1440': (2560, 1440),
'3840x2160': (3840, 2160),
'7680x4320': (7680, 4320),
'2560x1080': (2560, 1080),
'3440x1440': (3440, 1440),
'5120x2160': (5120, 2160),
'1080x1080_insta': (1080, 1080),
'1080x1350_insta': (1080, 1350),
'1080x608_insta': (1080, 608),
'820x312_fb': (820, 312),
'1280x720_yt': (1280, 720),
'1500x500_tw': (1500, 500),
'1584x396_linkedin': (1584, 396),
'720x480': (720, 480),
'2048x1080': (2048, 1080),
'4096x2160': (4096, 2160),
}
class CAM_MANAGER_OT_apply_resolution_preset(bpy.types.Operator):
"""Apply a common resolution preset to the active camera"""
bl_idname = "cam_manager.apply_resolution_preset"
bl_label = "Resolution Preset"
bl_description = "Apply a common resolution preset to the camera and enable resolution overwrite"
bl_options = {'REGISTER', 'UNDO'}
preset: bpy.props.EnumProperty(
name="Preset",
items=RESOLUTION_PRESET_ITEMS,
)
def execute(self, context):
cam_obj = context.scene.camera
if cam_obj is None:
return {'CANCELLED'}
cam = cam_obj.data
w, h = RESOLUTION_PRESET_MAP[self.preset]
cam.resolution = (w, h)
cam.resolution_overwrite = True
return {'FINISHED'}
class CAM_MANAGER_OT_apply_focal_length_preset(bpy.types.Operator):
"""Apply a common focal length preset to the active camera"""
bl_idname = "cam_manager.apply_focal_length_preset"
bl_label = "Focal Length Preset"
bl_description = "Apply a common focal length preset to the camera"
bl_options = {'REGISTER', 'UNDO'}
preset: bpy.props.EnumProperty(
name="Preset",
items=FOCAL_LENGTH_PRESET_ITEMS,
)
def execute(self, context):
cam_obj = context.scene.camera
if cam_obj is None:
return {'CANCELLED'}
cam_obj.data.lens = float(self.preset)
return {'FINISHED'}
BUILTIN_CAMERA_PRESETS = {
# Sensor sizes match Blender's own bundled camera presets
# (scripts/presets/camera/*.py) so these agree with the "Sensor Format"
# dropdown next to this one, rather than introducing a second,
# possibly-inconsistent set of numbers for the same real-world formats.
'Full Frame 50mm f/1.8': {
'lens': 50.0,
'sensor_width': 36.0,
'sensor_height': 24.0,
'sensor_fit': 'HORIZONTAL',
'clip_start': 0.1,
'clip_end': 100.0,
'dof': {'use_dof': True, 'aperture_fstop': 1.8, 'focus_distance': 1.5},
},
'Full Frame 85mm Portrait f/1.4': {
'lens': 85.0,
'sensor_width': 36.0,
'sensor_height': 24.0,
'sensor_fit': 'HORIZONTAL',
'clip_start': 0.3,
'clip_end': 100.0,
'dof': {'use_dof': True, 'aperture_fstop': 1.4, 'focus_distance': 1.2},
},
'APS-C 90mm Macro f/2.8': {
'lens': 90.0,
'sensor_width': 22.3,
'sensor_height': 14.9,
'sensor_fit': 'HORIZONTAL',
'clip_start': 0.01,
'clip_end': 10.0,
'dof': {'use_dof': True, 'aperture_fstop': 2.8, 'focus_distance': 0.3},
},
'MFT 25mm Establishing f/5.6': {
'lens': 25.0,
'sensor_width': 17.3,
'sensor_height': 13.0,
'sensor_fit': 'HORIZONTAL',
'clip_start': 0.1,
'clip_end': 1000.0,
'dof': {'use_dof': False},
},
'Medium Format 80mm Studio f/4': {
'lens': 80.0,
'sensor_width': 44.0,
'sensor_height': 33.0,
'sensor_fit': 'HORIZONTAL',
'clip_start': 0.3,
'clip_end': 100.0,
'dof': {'use_dof': True, 'aperture_fstop': 4.0, 'focus_distance': 1.5},
},
'Studio Orthographic': {
'type': 'ORTHO',
'ortho_scale': 5.0,
'dof': {'use_dof': False},
},
}
BUILTIN_CAMERA_PRESET_ITEMS = [(name, name, "") for name in BUILTIN_CAMERA_PRESETS]
class CAM_MANAGER_OT_apply_builtin_camera_preset(bpy.types.Operator):
"""Apply one of Simple Camera Manager's built-in camera presets"""
bl_idname = "cam_manager.apply_builtin_camera_preset"
bl_label = "Built-in Camera Preset"
bl_description = "Apply one of Simple Camera Manager's built-in camera presets"
bl_options = {'REGISTER', 'UNDO'}
preset: bpy.props.EnumProperty(
name="Preset",
items=BUILTIN_CAMERA_PRESET_ITEMS,
)
def execute(self, context):
cam_obj = context.scene.camera
if cam_obj is None:
self.report({'WARNING'}, "No active scene camera")
return {'CANCELLED'}
cam = cam_obj.data
for key, value in BUILTIN_CAMERA_PRESETS[self.preset].items():
if key == 'dof':
for dof_key, dof_value in value.items():
setattr(cam.dof, dof_key, dof_value)
else:
setattr(cam, key, value)
return {'FINISHED'}
# spawn an edit mode selection pie (run while object is in edit mode to get a valid output)
def draw_camera_settings(context, layout, cam_obj, use_subpanel=False):
"""Draw resolution, lens, clipping, focus, lighting, and background image settings for a camera."""
if cam_obj is None:
return
cam = cam_obj.data
# Presets
row = layout.row(align=True)
row.menu("CAM_MANAGER_MT_camera_presets", text=CAM_MANAGER_MT_camera_presets.bl_label)
row.operator("cam_manager.camera_preset_add", text="", icon='ADD')
op = row.operator("cam_manager.camera_preset_add", text="", icon='REMOVE')
op.remove_active = True
row = layout.row(align=True)
row.operator_menu_enum("cam_manager.apply_builtin_camera_preset", "preset", text="Built-in Presets")
# Blender's own native sensor-format presets (Full Frame, APS-C, MFT,
# Hasselblad, Arri, RED, phone sensors, ~30 in total) - reused as-is
# rather than duplicating that database, sets sensor_width/height/fit only.
row.menu("CAMERA_MT_presets", text="Sensor Format")
# Resolution
row = layout.row(align=True)
col = layout.column(align=True)
row.prop(cam, "resolution_overwrite")
row = col.row(align=True)
row.enabled = cam.resolution_overwrite
row.prop(cam, "resolution", text="Resolution")
row.operator_menu_enum("cam_manager.apply_resolution_preset", "preset", text="", icon='DOWNARROW_HLT')
# Lens / Orthographic Scale
col = layout.column(align=True)
if cam.type == 'ORTHO':
col.prop(cam, "ortho_scale")
else:
row = col.row(align=True)
row.prop(cam, "lens")
row.operator_menu_enum("cam_manager.apply_focal_length_preset", "preset", text="", icon='DOWNARROW_HLT')
row = col.row(align=True)
row.prop(cam, 'angle')
col = layout.column(align=True)
row = col.row(align=True)
row.prop(cam, "clip_start")
row = col.row(align=True)
row.prop(cam, "clip_end")
row = layout.row(align=True)
row.prop(cam, "show_rotation_gizmo", text="Show Rotation Gizmo")
def draw_focus_settings(layout):
dof = cam.dof
layout.label(text="Focus:")
layout.prop(dof, 'use_dof')
col = layout.column()
col.prop(dof, "focus_object", text="Focus on Object")
if dof.focus_object and dof.focus_object.type == 'ARMATURE':
col.prop_search(dof, "focus_subtarget", dof.focus_object.data, "bones", text="Focus Bone")
sub = col.row()
sub.active = dof.focus_object is None
sub.prop(dof, "focus_distance", text="Focus Distance")
sub.operator(
"ui.eyedropper_depth",
icon='EYEDROPPER',
text=""
).prop_data_path = "scene.camera.data.dof.focus_distance"
col.prop(cam, "dolly_zoom_link_focus", text="Link to Dolly Zoom Target")
ob = context.object
gizmo_cam = ob.data if (ob and ob.type == 'CAMERA') else cam
col.prop(gizmo_cam, "show_dolly_gizmo", text="Show Gizmo")
def draw_lighting_settings(layout):
layout.label(text="Camera Lighting:")
col = layout.column(align=False)
row = col.row(align=True)
row.prop(cam, 'exposure', text='Exposure')
row = col.row(align=True)
row.prop(cam, 'world', text='World')
def draw_background_image_settings(layout):
layout.label(text="Background Image:")
col = layout.column(align=True)
if not cam_obj.visible_get():
row = layout.row(align=True)
row.label(text="Camera is hidden", icon='ERROR')
if len(cam.background_images) > 0:
for img in cam.background_images:
row = col.row(align=True)
row.prop(img, "show_background_image")
row = col.row(align=True)
op = row.operator("cam_manager.camera_resolutio_from_image", icon='IMAGE_BACKGROUND')
op.camera_name = cam.name
row = col.row(align=True)
row.prop(img, "alpha")
row = col.row(align=True)
row.prop(img, "display_depth")
else:
row = col.row(align=True)
row.label(text="Camera has no Background Images", icon='INFO')
# Conditionally use subpanels or direct layout
if use_subpanel:
header, body = layout.panel(idname="FOCUS_PANEL", default_closed=True)
header.label(text="Focus:")
if body:
draw_focus_settings(body)
header, body = layout.panel(idname="LIGHT_PANEL", default_closed=True)
header.label(text="Camera Lighting:")
if body:
draw_lighting_settings(body)
header, body = layout.panel(idname="BACKGROUND_IMG", default_closed=True)
header.label(text="Background Image:")
if body:
draw_background_image_settings(body)
else:
draw_focus_settings(layout)
draw_lighting_settings(layout)
class CAMERA_MT_pie_menu(Menu):
# label is displayed at the center of the pie menu.
bl_label = "Active Camera Pie"
bl_idname = "CAMERA_MT_pie_menu"
def draw(self, context):
layout = self.layout
view = bpy.context.space_data
scene = context.scene
region_3d = view.region_3d
in_camera_view = bool(region_3d) and region_3d.view_perspective == 'CAMERA'
pie = layout.menu_pie()
# operator_enum will just spread all available options
# for the type enum of the operator on the pie
cam_obj = scene.camera
# West
pie.operator("cam_manager.cycle_cameras_next", text="previous", icon='TRIA_LEFT')
# East
pie.operator("cam_manager.cycle_cameras_backward", text="next", icon='TRIA_RIGHT')
# South lock camrea to view
pie.prop(view, "lock_camera")
# North — everything below lives inside a single top-level column
# (not a box, to avoid an enclosing backdrop rectangle), so this is
# one pie item as far as hit-testing is concerned. North West/East
# directly border it and used to hold their own pie items, which
# competed with this column for clicks; they're left empty now
# (below) and their actions moved into this column's header instead.
col = pie.column()
header = col.row(align=True)
if in_camera_view:
header.operator("view3d.view_camera", text="Exit Camera View", icon='VIEW_CAMERA')
header.operator("camera.align_camera_to_view", text="Align Camera to View", icon='CAMERA_DATA')
else:
header.operator("view3d.view_camera", text="View Camera", icon='VIEW_CAMERA')
header.operator("camera.create_camera_from_view", text="Camera from View", icon='OUTLINER_OB_CAMERA')
col.separator()
if cam_obj:
split = col.split()
column_order = (
(self.draw_display_column, self.draw_camera_column, self.draw_render_column)
if in_camera_view else
(self.draw_render_column, self.draw_camera_column, self.draw_display_column)
)
for draw_fn in column_order:
b = split.box()
draw_fn(context, b.column(), cam_obj)
else:
col.label(text="Please specify a scene camera", icon='ERROR')
# North West — left empty, see North box header above.
pie.separator()
# North East — left empty, see North box header above.
pie.separator()
# South West
if cam_obj:
if cam_obj.get('lock'):
op = pie.operator("cam_manager.lock_unlock_camera", icon='UNLOCKED', text='')
op.camera_name = cam_obj.name
op.cam_lock = False
else:
op = pie.operator("cam_manager.lock_unlock_camera", icon='LOCKED', text='')
op.camera_name = cam_obj.name
op.cam_lock = True
else:
pie.separator()
# South East
pie.operator('cameras.select_active_cam')
def draw_render_column(self, context, col, cam_obj):
row = col.row()
row.scale_y = 1.5
cam = cam_obj.data
scene = context.scene
row = col.row(align=True)
row.label(text='Render settings')
row = col.row(align=True)
row.prop(cam, "slot")
op = row.operator('cameras.custom_render', text='Render', icon='RENDER_STILL')
op.camera_name = cam_obj.name
row = col.row(align=True)
row.label(text='Cameras Collection')
row = col.row(align=True)
# hide visibility settings for collection if it doesn't yet exist
if scene.cam_collection.collection:
row.prop(scene.cam_collection.collection, 'hide_viewport', text='')
row.prop(context.view_layer.layer_collection.children[scene.cam_collection.collection.name],
'hide_viewport', text='')
row.prop_search(scene.cam_collection, "collection", bpy.data, "collections", text='')
op = row.operator("cameras.add_collection", icon='OUTLINER_COLLECTION', text='')
op.object_name = cam_obj.name
row = col.row(align=True)
row.label(text='Background Images')
if not cam_obj.visible_get():
row = col.row(align=True)
row.label(text="Camera is hidden", icon='ERROR')
if len(cam.background_images) > 0:
for img in cam.background_images:
row = col.row(align=True)
row.prop(img, "show_background_image")
row = col.row(align=True)
op = row.operator("cam_manager.camera_resolutio_from_image", icon='IMAGE_BACKGROUND')
op.camera_name = cam.name
row = col.row(align=True)
row.prop(img, "alpha")
row = col.row(align=True)
row.prop(img, "display_depth")
else:
row = col.row(align=True)
row.label(text="Camera has no Background Images", icon='INFO')
def draw_camera_column(self, context, layout, cam_obj):
row = layout.row(align=True)
row.label(text='Camera Settings')
draw_camera_settings(context, layout, cam_obj, use_subpanel=False)
def draw_display_column(self, context, col, cam_obj):
# col.scale_x = 2
row = col.row()
# row.scale_y = 1.5
cam = cam_obj.data
view = context.space_data
overlay = view.overlay
shading = view.shading
col.use_property_decorate = False
row = col.row(align=True)
row.prop(overlay, "show_overlays", icon='OVERLAY', text="")
row.label(text='Viewport Display')
row = col.row(align=True)
row.separator()
row = col.row(align=True)
row.label(text='Passepartout')
row = col.row(align=True)
row.prop(cam, "show_passepartout", text="")
row.active = cam.show_passepartout
row.prop(cam, "passepartout_alpha", text="")
row.prop_decorator(cam, "passepartout_alpha")
row = col.row(align=True)
row.prop(cam, 'show_name')
row = col.row()
row.prop(cam, "show_composition_thirds")
row = col.row()
row.prop(cam, "show_composition_center")
row = col.row()
row.prop(cam, "show_composition_center_diagonal")
row = col.row()
row.prop(cam, "show_composition_golden")
row = col.row()
row.prop(cam, "show_composition_golden_tria_a", text="Golden Triangle A")
row = col.row()
row.prop(cam, "show_composition_golden_tria_b", text="Golden Triangle B")
row = col.row()
row.prop(cam, "show_composition_harmony_tri_a", text="Harmony Triangle A")
row = col.row()
row.prop(cam, "show_composition_harmony_tri_b", text="Harmony Triangle B")
col.separator()
row = col.row()
row.prop(cam, "show_safe_areas")
row = col.row()
row.active = cam.show_safe_areas
row.prop(cam, "show_safe_center", text="Center-Cut")
if cam.show_safe_areas:
safe_data = context.scene.safe_areas
sub = col.column(align=True)
sub.prop(safe_data, "title", slider=True)
sub.prop(safe_data, "action", slider=True)
if cam.show_safe_center:
sub.prop(safe_data, "title_center", slider=True)
sub.prop(safe_data, "action_center", slider=True)
classes = (
CAM_MANAGER_OT_apply_resolution_preset,
CAM_MANAGER_OT_apply_focal_length_preset,
CAM_MANAGER_OT_apply_builtin_camera_preset,
CAMERA_MT_pie_menu,
)
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
if hasattr(cls, 'bl_rna'):
unregister_class(cls)