Cleanup: pep8
[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_EEVEE', 'BLENDER_WORKBENCH'}
216
217     def draw_header(self, context):
218         cam = context.camera
219         dof = cam.dof
220         self.layout.prop(dof, "use_dof", text="")
221
222     def draw(self, context):
223         layout = self.layout
224         layout.use_property_split = True
225
226         cam = context.camera
227         dof = cam.dof
228         layout.active = dof.use_dof
229
230         col = layout.column()
231         col.prop(dof, "focus_object", text="Focus on Object")
232         sub = col.column()
233         sub.active = (dof.focus_object is None)
234         sub.prop(dof, "focus_distance", text="Focus Distance")
235
236
237 class DATA_PT_camera_dof_aperture(CameraButtonsPanel, Panel):
238     bl_label = "Aperture"
239     bl_parent_id = "DATA_PT_camera_dof"
240     COMPAT_ENGINES = {'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
241
242     def draw(self, context):
243         layout = self.layout
244         layout.use_property_split = True
245
246         cam = context.camera
247         dof = cam.dof
248         layout.active = dof.use_dof
249
250         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
251
252         col = flow.column()
253         col.prop(dof, "aperture_fstop")
254
255         col = flow.column()
256         col.prop(dof, "aperture_blades")
257         col.prop(dof, "aperture_rotation")
258         col.prop(dof, "aperture_ratio")
259
260
261 class DATA_PT_camera_background_image(CameraButtonsPanel, Panel):
262     bl_label = "Background Images"
263     bl_options = {'DEFAULT_CLOSED'}
264     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
265
266     def draw_header(self, context):
267         cam = context.camera
268
269         self.layout.prop(cam, "show_background_images", text="")
270
271     def draw(self, context):
272         layout = self.layout
273         layout.use_property_split = True
274         layout.use_property_decorate = False
275
276         cam = context.camera
277         use_multiview = context.scene.render.use_multiview
278
279         col = layout.column()
280         col.operator("view3d.background_image_add", text="Add Image")
281
282         for i, bg in enumerate(cam.background_images):
283             layout.active = cam.show_background_images
284             box = layout.box()
285             row = box.row(align=True)
286             row.prop(bg, "show_expanded", text="", emboss=False)
287             if bg.source == 'IMAGE' and bg.image:
288                 row.prop(bg.image, "name", text="", emboss=False)
289             elif bg.source == 'MOVIE_CLIP' and bg.clip:
290                 row.prop(bg.clip, "name", text="", emboss=False)
291             elif bg.source and bg.use_camera_clip:
292                 row.label(text="Camera Clip")
293             else:
294                 row.label(text="Not Set")
295
296             row.prop(
297                 bg,
298                 "show_background_image",
299                 text="",
300                 emboss=False,
301                 icon='RESTRICT_VIEW_OFF' if bg.show_background_image else 'RESTRICT_VIEW_ON',
302             )
303
304             row.operator("view3d.background_image_remove", text="", emboss=False, icon='X').index = i
305
306             if bg.show_expanded:
307                 row = box.row()
308                 row.prop(bg, "source", expand=True)
309
310                 has_bg = False
311                 if bg.source == 'IMAGE':
312                     row = box.row()
313                     row.template_ID(bg, "image", open="image.open")
314                     if bg.image is not None:
315                         box.template_image(bg, "image", bg.image_user, compact=True)
316                         has_bg = True
317
318                         if use_multiview:
319                             box.prop(bg.image, "use_multiview")
320
321                             column = box.column()
322                             column.active = bg.image.use_multiview
323
324                             column.label(text="Views Format:")
325                             column.row().prop(bg.image, "views_format", expand=True)
326
327                             sub = column.box()
328                             sub.active = bg.image.views_format == 'STEREO_3D'
329                             sub.template_image_stereo_3d(bg.image.stereo_3d_format)
330
331                 elif bg.source == 'MOVIE_CLIP':
332                     box.prop(bg, "use_camera_clip")
333
334                     column = box.column()
335                     column.active = not bg.use_camera_clip
336                     column.template_ID(bg, "clip", open="clip.open")
337
338                     if bg.clip:
339                         column.template_movieclip(bg, "clip", compact=True)
340
341                     if bg.use_camera_clip or bg.clip:
342                         has_bg = True
343
344                     column = box.column()
345                     column.active = has_bg
346                     column.prop(bg.clip_user, "use_render_undistorted")
347                     column.prop(bg.clip_user, "proxy_render_size")
348
349                 if has_bg:
350                     col = box.column()
351                     col.prop(bg, "alpha", slider=True)
352                     col.row().prop(bg, "display_depth", expand=True)
353
354                     col.row().prop(bg, "frame_method", expand=True)
355
356                     row = box.row()
357                     row.prop(bg, "offset")
358
359                     col = box.column()
360                     col.prop(bg, "rotation")
361                     col.prop(bg, "scale")
362
363                     col.prop(bg, "use_flip_x")
364                     col.prop(bg, "use_flip_y")
365
366
367 class DATA_PT_camera_display(CameraButtonsPanel, Panel):
368     bl_label = "Viewport Display"
369     bl_options = {'DEFAULT_CLOSED'}
370     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
371
372     def draw(self, context):
373         layout = self.layout
374         layout.use_property_split = True
375
376         cam = context.camera
377
378         col = layout.column(align=True)
379
380         col.separator()
381
382         col.prop(cam, "display_size", text="Size")
383
384         col.separator()
385
386         flow = layout.grid_flow(row_major=False, columns=0, even_columns=False, even_rows=False, align=False)
387
388         col = flow.column()
389         col.prop(cam, "show_limits", text="Limits")
390         col = flow.column()
391         col.prop(cam, "show_mist", text="Mist")
392         col = flow.column()
393         col.prop(cam, "show_sensor", text="Sensor")
394         col = flow.column()
395         col.prop(cam, "show_name", text="Name")
396
397
398 class DATA_PT_camera_display_composition_guides(CameraButtonsPanel, Panel):
399     bl_label = "Composition Guides"
400     bl_parent_id = "DATA_PT_camera_display"
401     bl_options = {'DEFAULT_CLOSED'}
402     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
403
404     def draw(self, context):
405         layout = self.layout
406         layout.use_property_split = True
407
408         cam = context.camera
409
410         flow = layout.grid_flow(row_major=False, columns=0, even_columns=False, even_rows=False, align=False)
411
412         col = flow.column()
413         col.prop(cam, "show_composition_center")
414         col = flow.column()
415         col.prop(cam, "show_composition_center_diagonal")
416         col = flow.column()
417         col.prop(cam, "show_composition_thirds")
418         col = flow.column()
419         col.prop(cam, "show_composition_golden")
420         col = flow.column()
421         col.prop(cam, "show_composition_golden_tria_a")
422         col = flow.column()
423         col.prop(cam, "show_composition_golden_tria_b")
424         col = flow.column()
425         col.prop(cam, "show_composition_harmony_tri_a")
426         col = flow.column()
427         col.prop(cam, "show_composition_harmony_tri_b")
428
429
430 class DATA_PT_camera_display_passepartout(CameraButtonsPanel, Panel):
431     bl_label = "Passepartout"
432     bl_parent_id = "DATA_PT_camera_display"
433     bl_options = {'DEFAULT_CLOSED'}
434     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
435
436     def draw_header(self, context):
437         cam = context.camera
438
439         self.layout.prop(cam, "show_passepartout", text="")
440
441     def draw(self, context):
442         layout = self.layout
443         layout.use_property_split = True
444
445         cam = context.camera
446
447         layout.active = cam.show_passepartout
448         layout.prop(cam, "passepartout_alpha", text="Opacity", slider=True)
449
450
451 class DATA_PT_camera_safe_areas(CameraButtonsPanel, Panel):
452     bl_label = "Safe Areas"
453     bl_options = {'DEFAULT_CLOSED'}
454     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
455
456     def draw_header(self, context):
457         cam = context.camera
458
459         self.layout.prop(cam, "show_safe_areas", text="")
460
461     def draw_header_preset(self, _context):
462         SAFE_AREAS_PT_presets.draw_panel_header(self.layout)
463
464     def draw(self, context):
465         layout = self.layout
466         safe_data = context.scene.safe_areas
467         camera = context.camera
468
469         layout.use_property_split = True
470
471         layout.active = camera.show_safe_areas
472
473         col = layout.column()
474
475         sub = col.column()
476         sub.prop(safe_data, "title", slider=True)
477         sub.prop(safe_data, "action", slider=True)
478
479
480 class DATA_PT_camera_safe_areas_center_cut(CameraButtonsPanel, Panel):
481     bl_label = "Center-Cut Safe Areas"
482     bl_parent_id = "DATA_PT_camera_safe_areas"
483     bl_options = {'DEFAULT_CLOSED'}
484     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
485
486     def draw_header(self, context):
487         cam = context.camera
488
489         layout = self.layout
490         layout.active = cam.show_safe_areas
491         layout.prop(cam, "show_safe_center", text="")
492
493     def draw(self, context):
494         layout = self.layout
495         safe_data = context.scene.safe_areas
496         camera = context.camera
497
498         layout.use_property_split = True
499
500         layout.active = camera.show_safe_areas and camera.show_safe_center
501
502         col = layout.column()
503         col.prop(safe_data, "title_center", slider=True)
504
505
506 class DATA_PT_custom_props_camera(CameraButtonsPanel, PropertyPanel, Panel):
507     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
508     _context_path = "object.data"
509     _property_type = bpy.types.Camera
510
511
512 def draw_display_safe_settings(layout, safe_data, settings):
513     show_safe_areas = settings.show_safe_areas
514     show_safe_center = settings.show_safe_center
515
516     layout.use_property_split = True
517
518     col = layout.column()
519     col.active = show_safe_areas
520
521     sub = col.column()
522     sub.prop(safe_data, "title", slider=True)
523     sub.prop(safe_data, "action", slider=True)
524
525     col.separator()
526
527     col.prop(settings, "show_safe_center", text="Center-Cut Safe Areas")
528
529     sub = col.column()
530     sub.active = show_safe_areas and show_safe_center
531     sub.prop(safe_data, "title_center", slider=True)
532     sub.prop(safe_data, "action_center", slider=True)
533
534
535 classes = (
536     CAMERA_PT_presets,
537     SAFE_AREAS_PT_presets,
538     DATA_PT_context_camera,
539     DATA_PT_lens,
540     DATA_PT_camera_dof,
541     DATA_PT_camera_dof_aperture,
542     DATA_PT_camera,
543     DATA_PT_camera_stereoscopy,
544     DATA_PT_camera_safe_areas,
545     DATA_PT_camera_safe_areas_center_cut,
546     DATA_PT_camera_background_image,
547     DATA_PT_camera_display,
548     DATA_PT_camera_display_composition_guides,
549     DATA_PT_camera_display_passepartout,
550     DATA_PT_custom_props_camera,
551 )
552
553 if __name__ == "__main__":  # only for live edit.
554     from bpy.utils import register_class
555     for cls in classes:
556         register_class(cls)