5df988e9e7baa093c537e78d8759780c7385a267
[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_operators.presets import PresetMenu
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(PresetMenu):
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_EEVEE', 'BLENDER_WORKBENCH'}
43
44
45 class SAFE_AREAS_PT_presets(PresetMenu):
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_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_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_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_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_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_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")
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(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_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_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         split = layout.split()
371         split.label()
372         split.prop_menu_enum(cam, "show_guide")
373
374         col = layout.column(align=True)
375
376         col.separator()
377         col.prop(cam, "display_size", text="Size")
378         col.separator()
379         col.prop(cam, "show_passepartout", text="Passepartout")
380         sub = col.column()
381         sub.active = cam.show_passepartout
382         sub.prop(cam, "passepartout_alpha", text="Alpha", slider=True)
383
384         col.separator()
385
386         col.prop(cam, "show_limits", text="Limits")
387         col.prop(cam, "show_mist", text="Mist")
388         col.prop(cam, "show_sensor", text="Sensor")
389         col.prop(cam, "show_name", text="Name")
390
391
392 class DATA_PT_camera_safe_areas(CameraButtonsPanel, Panel):
393     bl_label = "Safe Areas"
394     bl_options = {'DEFAULT_CLOSED'}
395     COMPAT_ENGINES = {'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
396
397     def draw_header(self, context):
398         cam = context.camera
399
400         self.layout.prop(cam, "show_safe_areas", text="")
401
402     def draw_header_preset(self, context):
403         SAFE_AREAS_PT_presets.draw_panel_header(self.layout)
404
405     def draw(self, context):
406         layout = self.layout
407         safe_data = context.scene.safe_areas
408         camera = context.camera
409
410         draw_display_safe_settings(layout, safe_data, camera)
411
412
413 class DATA_PT_custom_props_camera(CameraButtonsPanel, PropertyPanel, Panel):
414     COMPAT_ENGINES = {'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
415     _context_path = "object.data"
416     _property_type = bpy.types.Camera
417
418
419 def draw_display_safe_settings(layout, safe_data, settings):
420     show_safe_areas = settings.show_safe_areas
421     show_safe_center = settings.show_safe_center
422
423     layout.use_property_split = True
424
425     col = layout.column()
426     col.active = show_safe_areas
427
428     sub = col.column()
429     sub.prop(safe_data, "title", slider=True)
430     sub.prop(safe_data, "action", slider=True)
431
432     col.separator()
433
434     col.prop(settings, "show_safe_center", text="Center-Cut Safe Areas")
435
436     sub = col.column()
437     sub.active = show_safe_areas and show_safe_center
438     sub.prop(safe_data, "title_center", slider=True)
439     sub.prop(safe_data, "action_center", slider=True)
440
441
442 classes = (
443     CAMERA_PT_presets,
444     SAFE_AREAS_PT_presets,
445     DATA_PT_context_camera,
446     DATA_PT_lens,
447     DATA_PT_camera_dof,
448     DATA_PT_camera_dof_aperture,
449     DATA_PT_camera,
450     DATA_PT_camera_stereoscopy,
451     DATA_PT_camera_safe_areas,
452     DATA_PT_camera_background_image,
453     DATA_PT_camera_display,
454     DATA_PT_custom_props_camera,
455 )
456
457 if __name__ == "__main__":  # only for live edit.
458     from bpy.utils import register_class
459     for cls in classes:
460         register_class(cls)