177012dec3209b4fe709180eab40dff132668878
[blender-staging.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
24
25 class CameraButtonsPanel:
26     bl_space_type = 'PROPERTIES'
27     bl_region_type = 'WINDOW'
28     bl_context = "data"
29
30     @classmethod
31     def poll(cls, context):
32         engine = context.scene.render.engine
33         return context.camera and (engine in cls.COMPAT_ENGINES)
34
35
36 class CAMERA_MT_presets(Menu):
37     bl_label = "Camera Presets"
38     preset_subdir = "camera"
39     preset_operator = "script.execute_preset"
40     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
41     draw = Menu.draw_preset
42
43
44 class SAFE_AREAS_MT_presets(Menu):
45     bl_label = "Camera Presets"
46     preset_subdir = "safe_areas"
47     preset_operator = "script.execute_preset"
48     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
49     draw = Menu.draw_preset
50
51
52 class DATA_PT_context_camera(CameraButtonsPanel, Panel):
53     bl_label = ""
54     bl_options = {'HIDE_HEADER'}
55     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
56
57     def draw(self, context):
58         layout = self.layout
59
60         ob = context.object
61         cam = context.camera
62         space = context.space_data
63
64         split = layout.split(percentage=0.65)
65         if ob:
66             split.template_ID(ob, "data")
67             split.separator()
68         elif cam:
69             split.template_ID(space, "pin_id")
70             split.separator()
71
72
73 class DATA_PT_lens(CameraButtonsPanel, Panel):
74     bl_label = "Lens"
75     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
76
77     def draw(self, context):
78         layout = self.layout
79
80         cam = context.camera
81
82         layout.prop(cam, "type", expand=True)
83
84         split = layout.split()
85
86         col = split.column()
87         if cam.type == 'PERSP':
88             row = col.row()
89             if cam.lens_unit == 'MILLIMETERS':
90                 row.prop(cam, "lens")
91             elif cam.lens_unit == 'FOV':
92                 row.prop(cam, "angle")
93             row.prop(cam, "lens_unit", text="")
94
95         elif cam.type == 'ORTHO':
96             col.prop(cam, "ortho_scale")
97
98         elif cam.type == 'PANO':
99             engine = context.scene.render.engine
100             if engine == 'CYCLES':
101                 ccam = cam.cycles
102                 col.prop(ccam, "panorama_type", text="Type")
103                 if ccam.panorama_type == 'FISHEYE_EQUIDISTANT':
104                     col.prop(ccam, "fisheye_fov")
105                 elif ccam.panorama_type == 'FISHEYE_EQUISOLID':
106                     row = layout.row()
107                     row.prop(ccam, "fisheye_lens", text="Lens")
108                     row.prop(ccam, "fisheye_fov")
109                 elif ccam.panorama_type == 'EQUIRECTANGULAR':
110                     row = layout.row()
111                     sub = row.column(align=True)
112                     sub.prop(ccam, "latitude_min")
113                     sub.prop(ccam, "latitude_max")
114                     sub = row.column(align=True)
115                     sub.prop(ccam, "longitude_min")
116                     sub.prop(ccam, "longitude_max")
117             elif engine == 'BLENDER_RENDER':
118                 row = col.row()
119                 if cam.lens_unit == 'MILLIMETERS':
120                     row.prop(cam, "lens")
121                 elif cam.lens_unit == 'FOV':
122                     row.prop(cam, "angle")
123                 row.prop(cam, "lens_unit", text="")
124
125         split = layout.split()
126
127         col = split.column(align=True)
128         col.label(text="Shift:")
129         col.prop(cam, "shift_x", text="X")
130         col.prop(cam, "shift_y", text="Y")
131
132         col = split.column(align=True)
133         col.label(text="Clipping:")
134         col.prop(cam, "clip_start", text="Start")
135         col.prop(cam, "clip_end", text="End")
136
137
138 class DATA_PT_camera_stereoscopy(CameraButtonsPanel, Panel):
139     bl_label = "Stereoscopy"
140     COMPAT_ENGINES = {'BLENDER_RENDER'}
141
142     @classmethod
143     def poll(cls, context):
144         render = context.scene.render
145         return (super().poll(context) and render.use_multiview and
146                 render.views_format == 'STEREO_3D')
147
148     def draw(self, context):
149         layout = self.layout
150         render = context.scene.render
151         st = context.camera.stereo
152         cam = context.camera
153
154         is_spherical_stereo = cam.type != 'ORTHO' and render.use_spherical_stereo
155         use_spherical_stereo = is_spherical_stereo and st.use_spherical_stereo
156
157         col = layout.column()
158         col.row().prop(st, "convergence_mode", expand=True)
159
160         sub = col.column()
161         sub.active = st.convergence_mode != 'PARALLEL'
162         sub.prop(st, "convergence_distance")
163
164         col.prop(st, "interocular_distance")
165
166         if is_spherical_stereo:
167             col.separator()
168             row = col.row()
169             row.prop(st, "use_spherical_stereo")
170             sub = row.row()
171             sub.active = st.use_spherical_stereo
172             sub.prop(st, "use_pole_merge")
173             row = col.row(align=True)
174             row.active = st.use_pole_merge
175             row.prop(st, "pole_merge_angle_from")
176             row.prop(st, "pole_merge_angle_to")
177
178         col.label(text="Pivot:")
179         row = col.row()
180         row.active = not use_spherical_stereo
181         row.prop(st, "pivot", expand=True)
182
183
184 class DATA_PT_camera(CameraButtonsPanel, Panel):
185     bl_label = "Camera"
186     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
187
188     def draw(self, context):
189         layout = self.layout
190
191         cam = context.camera
192
193         row = layout.row(align=True)
194
195         row.menu("CAMERA_MT_presets", text=bpy.types.CAMERA_MT_presets.bl_label)
196         row.operator("camera.preset_add", text="", icon='ZOOMIN')
197         row.operator("camera.preset_add", text="", icon='ZOOMOUT').remove_active = True
198
199         layout.label(text="Sensor:")
200
201         split = layout.split()
202
203         col = split.column(align=True)
204         if cam.sensor_fit == 'AUTO':
205             col.prop(cam, "sensor_width", text="Size")
206         else:
207             sub = col.column(align=True)
208             sub.active = cam.sensor_fit == 'HORIZONTAL'
209             sub.prop(cam, "sensor_width", text="Width")
210             sub = col.column(align=True)
211             sub.active = cam.sensor_fit == 'VERTICAL'
212             sub.prop(cam, "sensor_height", text="Height")
213
214         col = split.column(align=True)
215         col.prop(cam, "sensor_fit", text="")
216
217
218 class DATA_PT_camera_dof(CameraButtonsPanel, Panel):
219     bl_label = "Depth of Field"
220     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
221
222     def draw(self, context):
223         layout = self.layout
224
225         cam = context.camera
226         dof_options = cam.gpu_dof
227
228         split = layout.split()
229
230         col = split.column()
231         col.label(text="Focus:")
232         col.prop(cam, "dof_object", text="")
233         sub = col.column()
234         sub.active = (cam.dof_object is None)
235         sub.prop(cam, "dof_distance", text="Distance")
236
237         hq_support = dof_options.is_hq_supported
238         col = split.column(align=True)
239         col.label("Viewport:")
240         sub = col.column()
241         sub.active = hq_support
242         sub.prop(dof_options, "use_high_quality")
243         col.prop(dof_options, "fstop")
244         if dof_options.use_high_quality and hq_support:
245             col.prop(dof_options, "blades")
246
247
248 class DATA_PT_camera_display(CameraButtonsPanel, Panel):
249     bl_label = "Display"
250     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
251
252     def draw(self, context):
253         layout = self.layout
254
255         cam = context.camera
256
257         split = layout.split()
258
259         col = split.column()
260         col.prop(cam, "show_limits", text="Limits")
261         col.prop(cam, "show_mist", text="Mist")
262
263         col.prop(cam, "show_sensor", text="Sensor")
264         col.prop(cam, "show_name", text="Name")
265
266         col = split.column()
267         col.prop_menu_enum(cam, "show_guide")
268         col.separator()
269         col.prop(cam, "draw_size", text="Size")
270         col.separator()
271         col.prop(cam, "show_passepartout", text="Passepartout")
272         sub = col.column()
273         sub.active = cam.show_passepartout
274         sub.prop(cam, "passepartout_alpha", text="Alpha", slider=True)
275
276
277 class DATA_PT_camera_safe_areas(CameraButtonsPanel, Panel):
278     bl_label = "Safe Areas"
279     bl_options = {'DEFAULT_CLOSED'}
280     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
281
282     def draw_header(self, context):
283         cam = context.camera
284
285         self.layout.prop(cam, "show_safe_areas", text="")
286
287     def draw(self, context):
288         layout = self.layout
289         safe_data = context.scene.safe_areas
290         camera = context.camera
291
292         draw_display_safe_settings(layout, safe_data, camera)
293
294
295 class DATA_PT_custom_props_camera(CameraButtonsPanel, PropertyPanel, Panel):
296     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
297     _context_path = "object.data"
298     _property_type = bpy.types.Camera
299
300
301 def draw_display_safe_settings(layout, safe_data, settings):
302     show_safe_areas = settings.show_safe_areas
303     show_safe_center = settings.show_safe_center
304
305     split = layout.split()
306
307     col = split.column()
308     row = col.row(align=True)
309     row.menu("SAFE_AREAS_MT_presets", text=bpy.types.SAFE_AREAS_MT_presets.bl_label)
310     row.operator("safe_areas.preset_add", text="", icon='ZOOMIN')
311     row.operator("safe_areas.preset_add", text="", icon='ZOOMOUT').remove_active = True
312
313     col = split.column()
314     col.prop(settings, "show_safe_center", text="Center-Cut Safe Areas")
315
316     split = layout.split()
317     col = split.column()
318     col.active = show_safe_areas
319     col.prop(safe_data, "title", slider=True)
320     col.prop(safe_data, "action", slider=True)
321
322     col = split.column()
323     col.active = show_safe_areas and show_safe_center
324     col.prop(safe_data, "title_center", slider=True)
325     col.prop(safe_data, "action_center", slider=True)
326
327
328 classes = (
329     CAMERA_MT_presets,
330     DATA_PT_camera,
331     DATA_PT_camera_display,
332     DATA_PT_camera_dof,
333     DATA_PT_camera_safe_areas,
334     DATA_PT_camera_stereoscopy,
335     DATA_PT_context_camera,
336     DATA_PT_custom_props_camera,
337     DATA_PT_lens,
338     SAFE_AREAS_MT_presets,
339 )
340
341 if __name__ == "__main__":  # only for live edit.
342     from bpy.utils import register_class
343     for cls in classes:
344         register_class(cls)