130264bb91db4bac625086d6a6f3aef67a588c10
[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, Menu
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_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
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_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
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_OPENGL'}
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_OPENGL'}
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="Latitute Min")
110                     sub.prop(ccam, "latitude_max", text="Max")
111                     sub = col.column(align=True)
112                     sub.prop(ccam, "longitude_min", text="Longiture Min")
113                     sub.prop(ccam, "longitude_max", text="Max")
114             elif engine in {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}:
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_OPENGL'}
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     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
185
186     def draw_header_preset(self, context):
187         CAMERA_PT_presets.draw_panel_header(self.layout)
188
189     def draw(self, context):
190         layout = self.layout
191
192         cam = context.camera
193
194         layout.use_property_split = True
195
196         col = layout.column()
197         col.prop(cam, "sensor_fit")
198
199         if cam.sensor_fit == 'AUTO':
200             col.prop(cam, "sensor_width")
201         else:
202             sub = col.column(align=True)
203             sub.active = cam.sensor_fit == 'HORIZONTAL'
204             sub.prop(cam, "sensor_width", text="Width")
205
206             sub = col.column(align=True)
207             sub.active = cam.sensor_fit == 'VERTICAL'
208             sub.prop(cam, "sensor_height", text="Height")
209
210
211 class DATA_PT_camera_dof(CameraButtonsPanel, Panel):
212     bl_label = "Depth of Field"
213     bl_options = {'DEFAULT_CLOSED'}
214     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}
215
216     def draw(self, context):
217         layout = self.layout
218         layout.use_property_split = True
219
220         cam = context.camera
221         dof_options = cam.gpu_dof
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_RENDER', 'BLENDER_EEVEE'}
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         if context.engine == 'BLENDER_EEVEE':
245             col = flow.column()
246             col.prop(dof_options, "fstop")
247             col.prop(dof_options, "blades")
248
249             col = flow.column()
250             col.prop(dof_options, "rotation")
251             col.prop(dof_options, "ratio")
252         else:
253             col = flow.column()
254             col.label(text="Viewport")
255             col.prop(dof_options, "fstop")
256             col.prop(dof_options, "blades")
257
258
259 class DATA_PT_camera_background_image(CameraButtonsPanel, Panel):
260     bl_label = "Background Images"
261     bl_options = {'DEFAULT_CLOSED'}
262     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
263
264     def draw_header(self, context):
265         cam = context.camera
266
267         self.layout.prop(cam, "show_background_images", text="")
268
269     def draw(self, context):
270         layout = self.layout
271
272         cam = context.camera
273         use_multiview = context.scene.render.use_multiview
274
275         col = layout.column()
276         col.operator("view3d.background_image_add", text="Add Image")
277
278         for i, bg in enumerate(cam.background_images):
279             layout.active = cam.show_background_images
280             box = layout.box()
281             row = box.row(align=True)
282             row.prop(bg, "show_expanded", text="", emboss=False)
283             if bg.source == 'IMAGE' and bg.image:
284                 row.prop(bg.image, "name", text="", emboss=False)
285             elif bg.source == 'MOVIE_CLIP' and bg.clip:
286                 row.prop(bg.clip, "name", text="", emboss=False)
287             elif bg.source and bg.use_camera_clip:
288                 row.label(text="Camera Clip")
289             else:
290                 row.label(text="Not Set")
291
292             if bg.show_background_image:
293                 row.prop(bg, "show_background_image", text="", emboss=False, icon='RESTRICT_VIEW_OFF')
294             else:
295                 row.prop(bg, "show_background_image", text="", emboss=False, icon='RESTRICT_VIEW_ON')
296
297             row.operator("view3d.background_image_remove", text="", emboss=False, icon='X').index = i
298
299             if bg.show_expanded:
300                 row = box.row()
301                 row.prop(bg, "source", expand=True)
302
303                 has_bg = False
304                 if bg.source == 'IMAGE':
305                     row = box.row()
306                     row.template_ID(bg, "image", open="image.open")
307                     if bg.image is not None:
308                         box.template_image(bg, "image", bg.image_user, compact=True)
309                         has_bg = True
310
311                         if use_multiview and bg.view_axis in {'CAMERA', 'ALL'}:
312                             box.prop(bg.image, "use_multiview")
313
314                             column = box.column()
315                             column.active = bg.image.use_multiview
316
317                             column.label(text="Views Format:")
318                             column.row().prop(bg.image, "views_format", expand=True)
319
320                             sub = column.box()
321                             sub.active = bg.image.views_format == 'STEREO_3D'
322                             sub.template_image_stereo_3d(bg.image.stereo_3d_format)
323
324                 elif bg.source == 'MOVIE_CLIP':
325                     box.prop(bg, "use_camera_clip")
326
327                     column = box.column()
328                     column.active = not bg.use_camera_clip
329                     column.template_ID(bg, "clip", open="clip.open")
330
331                     if bg.clip:
332                         column.template_movieclip(bg, "clip", compact=True)
333
334                     if bg.use_camera_clip or bg.clip:
335                         has_bg = True
336
337                     column = box.column()
338                     column.active = has_bg
339                     column.prop(bg.clip_user, "proxy_render_size", text="")
340                     column.prop(bg.clip_user, "use_render_undistorted")
341
342                 if has_bg:
343                     col = box.column()
344                     col.prop(bg, "alpha", slider=True)
345                     col.row().prop(bg, "draw_depth", expand=True)
346
347                     col.row().prop(bg, "frame_method", expand=True)
348
349                     box = col.box()
350                     row = box.row()
351                     row.prop(bg, "offset")
352
353                     row = box.row()
354                     row.prop(bg, "use_flip_x")
355                     row.prop(bg, "use_flip_y")
356
357                     row = box.row()
358                     row.prop(bg, "rotation")
359                     row.prop(bg, "scale")
360
361
362 class DATA_PT_camera_display(CameraButtonsPanel, Panel):
363     bl_label = "Viewport Display"
364     bl_options = {'DEFAULT_CLOSED'}
365     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
366
367     def draw(self, context):
368         layout = self.layout
369         layout.use_property_split = True
370
371         cam = context.camera
372
373         split = layout.split()
374         split.label()
375         split.prop_menu_enum(cam, "show_guide")
376
377         col = layout.column(align=True)
378
379         col.separator()
380         col.prop(cam, "draw_size", text="Size")
381         col.separator()
382         col.prop(cam, "show_passepartout", text="Passepartout")
383         sub = col.column()
384         sub.active = cam.show_passepartout
385         sub.prop(cam, "passepartout_alpha", text="Alpha", slider=True)
386
387         col.separator()
388
389         col.prop(cam, "show_limits", text="Limits")
390         col.prop(cam, "show_mist", text="Mist")
391         col.prop(cam, "show_sensor", text="Sensor")
392         col.prop(cam, "show_name", text="Name")
393
394
395 class DATA_PT_camera_safe_areas(CameraButtonsPanel, Panel):
396     bl_label = "Safe Areas"
397     bl_options = {'DEFAULT_CLOSED'}
398     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
399
400     def draw_header(self, context):
401         cam = context.camera
402
403         self.layout.prop(cam, "show_safe_areas", text="")
404
405     def draw_header_preset(self, context):
406         SAFE_AREAS_PT_presets.draw_panel_header(self.layout)
407
408     def draw(self, context):
409         layout = self.layout
410         safe_data = context.scene.safe_areas
411         camera = context.camera
412
413         draw_display_safe_settings(layout, safe_data, camera)
414
415
416 class DATA_PT_custom_props_camera(CameraButtonsPanel, PropertyPanel, Panel):
417     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
418     _context_path = "object.data"
419     _property_type = bpy.types.Camera
420
421
422 def draw_display_safe_settings(layout, safe_data, settings):
423     show_safe_areas = settings.show_safe_areas
424     show_safe_center = settings.show_safe_center
425
426     layout.use_property_split = True
427
428     col = layout.column()
429     col.active = show_safe_areas
430
431     sub = col.column()
432     sub.prop(safe_data, "title", slider=True)
433     sub.prop(safe_data, "action", slider=True)
434
435     col.separator()
436
437     col.prop(settings, "show_safe_center", text="Center-Cut Safe Areas")
438
439     sub = col.column()
440     sub.active = show_safe_areas and show_safe_center
441     sub.prop(safe_data, "title_center", slider=True)
442     sub.prop(safe_data, "action_center", slider=True)
443
444
445 classes = (
446     CAMERA_PT_presets,
447     SAFE_AREAS_PT_presets,
448     DATA_PT_context_camera,
449     DATA_PT_lens,
450     DATA_PT_camera,
451     DATA_PT_camera_stereoscopy,
452     DATA_PT_camera_dof,
453     DATA_PT_camera_dof_aperture,
454     DATA_PT_camera_display,
455     DATA_PT_camera_safe_areas,
456     DATA_PT_camera_background_image,
457     DATA_PT_custom_props_camera,
458 )
459
460 if __name__ == "__main__":  # only for live edit.
461     from bpy.utils import register_class
462     for cls in classes:
463         register_class(cls)