Cleanup: style
[blender.git] / release / scripts / startup / bl_ui / properties_data_camera.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Panel
22 from rna_prop_ui import PropertyPanel
23 from bl_ui.utils import PresetPanel
24
25
26 class CameraButtonsPanel:
27     bl_space_type = 'PROPERTIES'
28     bl_region_type = 'WINDOW'
29     bl_context = "data"
30
31     @classmethod
32     def poll(cls, context):
33         engine = context.engine
34         return context.camera and (engine in cls.COMPAT_ENGINES)
35
36
37 class CAMERA_PT_presets(PresetPanel, Panel):
38     bl_label = "Camera Presets"
39     preset_subdir = "camera"
40     preset_operator = "script.execute_preset"
41     preset_add_operator = "camera.preset_add"
42     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
43
44
45 class SAFE_AREAS_PT_presets(PresetPanel, Panel):
46     bl_label = "Camera Presets"
47     preset_subdir = "safe_areas"
48     preset_operator = "script.execute_preset"
49     preset_add_operator = "safe_areas.preset_add"
50     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
51
52
53 class DATA_PT_context_camera(CameraButtonsPanel, Panel):
54     bl_label = ""
55     bl_options = {'HIDE_HEADER'}
56     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
57
58     def draw(self, context):
59         layout = self.layout
60
61         ob = context.object
62         cam = context.camera
63         space = context.space_data
64
65         if ob:
66             layout.template_ID(ob, "data")
67         elif cam:
68             layout.template_ID(space, "pin_id")
69
70
71 class DATA_PT_lens(CameraButtonsPanel, Panel):
72     bl_label = "Lens"
73     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
74
75     def draw(self, context):
76         layout = self.layout
77         layout.use_property_split = True
78
79         cam = context.camera
80
81         layout.prop(cam, "type")
82
83         col = layout.column()
84         col.separator()
85
86         if cam.type == 'PERSP':
87             col = layout.column()
88             if cam.lens_unit == 'MILLIMETERS':
89                 col.prop(cam, "lens")
90             elif cam.lens_unit == 'FOV':
91                 col.prop(cam, "angle")
92             col.prop(cam, "lens_unit")
93
94         elif cam.type == 'ORTHO':
95             col.prop(cam, "ortho_scale")
96
97         elif cam.type == 'PANO':
98             engine = context.engine
99             if engine == 'CYCLES':
100                 ccam = cam.cycles
101                 col.prop(ccam, "panorama_type")
102                 if ccam.panorama_type == 'FISHEYE_EQUIDISTANT':
103                     col.prop(ccam, "fisheye_fov")
104                 elif ccam.panorama_type == 'FISHEYE_EQUISOLID':
105                     col.prop(ccam, "fisheye_lens", text="Lens")
106                     col.prop(ccam, "fisheye_fov")
107                 elif ccam.panorama_type == 'EQUIRECTANGULAR':
108                     sub = col.column(align=True)
109                     sub.prop(ccam, "latitude_min", text="Latitude Min")
110                     sub.prop(ccam, "latitude_max", text="Max")
111                     sub = col.column(align=True)
112                     sub.prop(ccam, "longitude_min", text="Longitude Min")
113                     sub.prop(ccam, "longitude_max", text="Max")
114             elif engine in {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}:
115                 if cam.lens_unit == 'MILLIMETERS':
116                     col.prop(cam, "lens")
117                 elif cam.lens_unit == 'FOV':
118                     col.prop(cam, "angle")
119                 col.prop(cam, "lens_unit")
120
121         col = layout.column()
122         col.separator()
123
124         sub = col.column(align=True)
125         sub.prop(cam, "shift_x", text="Shift X")
126         sub.prop(cam, "shift_y", text="Y")
127
128         col.separator()
129         sub = col.column(align=True)
130         sub.prop(cam, "clip_start", text="Clip Start")
131         sub.prop(cam, "clip_end", text="End")
132
133
134 class DATA_PT_camera_stereoscopy(CameraButtonsPanel, Panel):
135     bl_label = "Stereoscopy"
136     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
137
138     @classmethod
139     def poll(cls, context):
140         render = context.scene.render
141         return (super().poll(context) and render.use_multiview and
142                 render.views_format == 'STEREO_3D')
143
144     def draw(self, context):
145         layout = self.layout
146         layout.use_property_split = True
147
148         render = context.scene.render
149         st = context.camera.stereo
150         cam = context.camera
151
152         is_spherical_stereo = cam.type != 'ORTHO' and render.use_spherical_stereo
153         use_spherical_stereo = is_spherical_stereo and st.use_spherical_stereo
154
155         layout.prop(st, "convergence_mode")
156
157         col = layout.column()
158         sub = col.column()
159         sub.active = st.convergence_mode != 'PARALLEL'
160         sub.prop(st, "convergence_distance")
161
162         col.prop(st, "interocular_distance")
163
164         if is_spherical_stereo:
165             col.separator()
166             col.prop(st, "use_spherical_stereo")
167             sub = col.column()
168             sub.active = st.use_spherical_stereo
169             sub.prop(st, "use_pole_merge")
170
171             sub = col.column(align=True)
172             sub.active = st.use_pole_merge
173             sub.prop(st, "pole_merge_angle_from", text="Pole Merge Angle Start")
174             sub.prop(st, "pole_merge_angle_to", text="End")
175
176         col = layout.column()
177         col.active = not use_spherical_stereo
178         col.separator()
179         col.prop(st, "pivot")
180
181
182 class DATA_PT_camera(CameraButtonsPanel, Panel):
183     bl_label = "Camera"
184     bl_options = {'DEFAULT_CLOSED'}
185     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
186
187     def draw_header_preset(self, context):
188         CAMERA_PT_presets.draw_panel_header(self.layout)
189
190     def draw(self, context):
191         layout = self.layout
192
193         cam = context.camera
194
195         layout.use_property_split = True
196
197         col = layout.column()
198         col.prop(cam, "sensor_fit")
199
200         if cam.sensor_fit == 'AUTO':
201             col.prop(cam, "sensor_width", text="Size")
202         else:
203             sub = col.column(align=True)
204             sub.active = cam.sensor_fit == 'HORIZONTAL'
205             sub.prop(cam, "sensor_width", text="Width")
206
207             sub = col.column(align=True)
208             sub.active = cam.sensor_fit == 'VERTICAL'
209             sub.prop(cam, "sensor_height", text="Height")
210
211
212 class DATA_PT_camera_dof(CameraButtonsPanel, Panel):
213     bl_label = "Depth of Field"
214     bl_options = {'DEFAULT_CLOSED'}
215     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
216
217     def draw(self, context):
218         layout = self.layout
219         layout.use_property_split = True
220
221         cam = context.camera
222
223         col = layout.column()
224         col.prop(cam, "dof_object", text="Focus on Object")
225         sub = col.column()
226         sub.active = (cam.dof_object is None)
227         sub.prop(cam, "dof_distance", text="Focus Distance")
228
229
230 class DATA_PT_camera_dof_aperture(CameraButtonsPanel, Panel):
231     bl_label = "Aperture"
232     bl_parent_id = "DATA_PT_camera_dof"
233     COMPAT_ENGINES = {'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
234
235     def draw(self, context):
236         layout = self.layout
237         layout.use_property_split = True
238
239         cam = context.camera
240         dof_options = cam.gpu_dof
241
242         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
243
244         col = flow.column()
245         col.prop(dof_options, "fstop")
246         col.prop(dof_options, "blades")
247
248         col = flow.column()
249         col.prop(dof_options, "rotation")
250         col.prop(dof_options, "ratio")
251
252
253 class DATA_PT_camera_background_image(CameraButtonsPanel, Panel):
254     bl_label = "Background Images"
255     bl_options = {'DEFAULT_CLOSED'}
256     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
257
258     def draw_header(self, context):
259         cam = context.camera
260
261         self.layout.prop(cam, "show_background_images", text="")
262
263     def draw(self, context):
264         layout = self.layout
265         layout.use_property_split = True
266         layout.use_property_decorate = False
267
268         cam = context.camera
269         use_multiview = context.scene.render.use_multiview
270
271         col = layout.column()
272         col.operator("view3d.background_image_add", text="Add Image")
273
274         for i, bg in enumerate(cam.background_images):
275             layout.active = cam.show_background_images
276             box = layout.box()
277             row = box.row(align=True)
278             row.prop(bg, "show_expanded", text="", emboss=False)
279             if bg.source == 'IMAGE' and bg.image:
280                 row.prop(bg.image, "name", text="", emboss=False)
281             elif bg.source == 'MOVIE_CLIP' and bg.clip:
282                 row.prop(bg.clip, "name", text="", emboss=False)
283             elif bg.source and bg.use_camera_clip:
284                 row.label(text="Camera Clip")
285             else:
286                 row.label(text="Not Set")
287
288             row.prop(
289                 bg,
290                 "show_background_image",
291                 text="",
292                 emboss=False,
293                 icon='RESTRICT_VIEW_OFF' if bg.show_background_image else 'RESTRICT_VIEW_ON',
294             )
295
296             row.operator("view3d.background_image_remove", text="", emboss=False, icon='X').index = i
297
298             if bg.show_expanded:
299                 row = box.row()
300                 row.prop(bg, "source", expand=True)
301
302                 has_bg = False
303                 if bg.source == 'IMAGE':
304                     row = box.row()
305                     row.template_ID(bg, "image", open="image.open")
306                     if bg.image is not None:
307                         box.template_image(bg, "image", bg.image_user, compact=True)
308                         has_bg = True
309
310                         if use_multiview:
311                             box.prop(bg.image, "use_multiview")
312
313                             column = box.column()
314                             column.active = bg.image.use_multiview
315
316                             column.label(text="Views Format:")
317                             column.row().prop(bg.image, "views_format", expand=True)
318
319                             sub = column.box()
320                             sub.active = bg.image.views_format == 'STEREO_3D'
321                             sub.template_image_stereo_3d(bg.image.stereo_3d_format)
322
323                 elif bg.source == 'MOVIE_CLIP':
324                     box.prop(bg, "use_camera_clip")
325
326                     column = box.column()
327                     column.active = not bg.use_camera_clip
328                     column.template_ID(bg, "clip", open="clip.open")
329
330                     if bg.clip:
331                         column.template_movieclip(bg, "clip", compact=True)
332
333                     if bg.use_camera_clip or bg.clip:
334                         has_bg = True
335
336                     column = box.column()
337                     column.active = has_bg
338                     column.prop(bg.clip_user, "use_render_undistorted")
339                     column.prop(bg.clip_user, "proxy_render_size")
340
341                 if has_bg:
342                     col = box.column()
343                     col.prop(bg, "alpha", slider=True)
344                     col.row().prop(bg, "display_depth", expand=True)
345
346                     col.row().prop(bg, "frame_method", expand=True)
347
348                     row = box.row()
349                     row.prop(bg, "offset")
350
351                     col = box.column()
352                     col.prop(bg, "rotation")
353                     col.prop(bg, "scale")
354
355                     col.prop(bg, "use_flip_x")
356                     col.prop(bg, "use_flip_y")
357
358
359 class DATA_PT_camera_display(CameraButtonsPanel, Panel):
360     bl_label = "Viewport Display"
361     bl_options = {'DEFAULT_CLOSED'}
362     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
363
364     def draw(self, context):
365         layout = self.layout
366         layout.use_property_split = True
367
368         cam = context.camera
369
370         col = layout.column(align=True)
371
372         col.separator()
373
374         col.prop(cam, "display_size", text="Size")
375
376         col.separator()
377
378         flow = layout.grid_flow(row_major=False, columns=0, even_columns=False, even_rows=False, align=False)
379
380         col = flow.column()
381         col.prop(cam, "show_limits", text="Limits")
382         col = flow.column()
383         col.prop(cam, "show_mist", text="Mist")
384         col = flow.column()
385         col.prop(cam, "show_sensor", text="Sensor")
386         col = flow.column()
387         col.prop(cam, "show_name", text="Name")
388
389
390 class DATA_PT_camera_display_composition_guides(CameraButtonsPanel, Panel):
391     bl_label = "Composition Guides"
392     bl_parent_id = "DATA_PT_camera_display"
393     bl_options = {'DEFAULT_CLOSED'}
394     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
395
396     def draw(self, context):
397         layout = self.layout
398         layout.use_property_split = True
399
400         cam = context.camera
401
402         flow = layout.grid_flow(row_major=False, columns=0, even_columns=False, even_rows=False, align=False)
403
404         col = flow.column()
405         col.prop(cam, "show_composition_center")
406         col = flow.column()
407         col.prop(cam, "show_composition_center_diagonal")
408         col = flow.column()
409         col.prop(cam, "show_composition_thirds")
410         col = flow.column()
411         col.prop(cam, "show_composition_golden")
412         col = flow.column()
413         col.prop(cam, "show_composition_golden_tria_a")
414         col = flow.column()
415         col.prop(cam, "show_composition_golden_tria_b")
416         col = flow.column()
417         col.prop(cam, "show_composition_harmony_tri_a")
418         col = flow.column()
419         col.prop(cam, "show_composition_harmony_tri_b")
420
421
422 class DATA_PT_camera_display_passepartout(CameraButtonsPanel, Panel):
423     bl_label = "Passepartout"
424     bl_parent_id = "DATA_PT_camera_display"
425     bl_options = {'DEFAULT_CLOSED'}
426     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
427
428     def draw_header(self, context):
429         cam = context.camera
430
431         self.layout.prop(cam, "show_passepartout", text="")
432
433     def draw(self, context):
434         layout = self.layout
435         layout.use_property_split = True
436
437         cam = context.camera
438
439         layout.active = cam.show_passepartout
440         layout.prop(cam, "passepartout_alpha", text="Opacity", slider=True)
441
442
443 class DATA_PT_camera_safe_areas(CameraButtonsPanel, Panel):
444     bl_label = "Safe Areas"
445     bl_options = {'DEFAULT_CLOSED'}
446     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
447
448     def draw_header(self, context):
449         cam = context.camera
450
451         self.layout.prop(cam, "show_safe_areas", text="")
452
453     def draw_header_preset(self, context):
454         SAFE_AREAS_PT_presets.draw_panel_header(self.layout)
455
456     def draw(self, context):
457         layout = self.layout
458         safe_data = context.scene.safe_areas
459         camera = context.camera
460
461         layout.use_property_split = True
462
463         layout.active = camera.show_safe_areas
464
465         col = layout.column()
466
467         sub = col.column()
468         sub.prop(safe_data, "title", slider=True)
469         sub.prop(safe_data, "action", slider=True)
470
471
472 class DATA_PT_camera_safe_areas_center_cut(CameraButtonsPanel, Panel):
473     bl_label = "Center-Cut Safe Areas"
474     bl_parent_id = "DATA_PT_camera_safe_areas"
475     bl_options = {'DEFAULT_CLOSED'}
476     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
477
478     def draw_header(self, context):
479         cam = context.camera
480
481         layout = self.layout
482         layout.active = cam.show_safe_areas
483         layout.prop(cam, "show_safe_center", text="")
484
485     def draw(self, context):
486         layout = self.layout
487         safe_data = context.scene.safe_areas
488         camera = context.camera
489
490         layout.use_property_split = True
491
492         layout.active = camera.show_safe_areas and camera.show_safe_center
493
494         col = layout.column()
495         col.prop(safe_data, "title_center", slider=True)
496
497
498 class DATA_PT_custom_props_camera(CameraButtonsPanel, PropertyPanel, Panel):
499     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
500     _context_path = "object.data"
501     _property_type = bpy.types.Camera
502
503
504 def draw_display_safe_settings(layout, safe_data, settings):
505     show_safe_areas = settings.show_safe_areas
506     show_safe_center = settings.show_safe_center
507
508     layout.use_property_split = True
509
510     col = layout.column()
511     col.active = show_safe_areas
512
513     sub = col.column()
514     sub.prop(safe_data, "title", slider=True)
515     sub.prop(safe_data, "action", slider=True)
516
517     col.separator()
518
519     col.prop(settings, "show_safe_center", text="Center-Cut Safe Areas")
520
521     sub = col.column()
522     sub.active = show_safe_areas and show_safe_center
523     sub.prop(safe_data, "title_center", slider=True)
524     sub.prop(safe_data, "action_center", slider=True)
525
526
527 classes = (
528     CAMERA_PT_presets,
529     SAFE_AREAS_PT_presets,
530     DATA_PT_context_camera,
531     DATA_PT_lens,
532     DATA_PT_camera_dof,
533     DATA_PT_camera_dof_aperture,
534     DATA_PT_camera,
535     DATA_PT_camera_stereoscopy,
536     DATA_PT_camera_safe_areas,
537     DATA_PT_camera_safe_areas_center_cut,
538     DATA_PT_camera_background_image,
539     DATA_PT_camera_display,
540     DATA_PT_camera_display_composition_guides,
541     DATA_PT_camera_display_passepartout,
542     DATA_PT_custom_props_camera,
543 )
544
545 if __name__ == "__main__":  # only for live edit.
546     from bpy.utils import register_class
547     for cls in classes:
548         register_class(cls)