1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 /** \file
18  * \ingroup RNA
19  */
20 
21 #include <stdlib.h>
22 
23 #include "DNA_camera_types.h"
24 
25 #include "BLI_math.h"
26 
27 #include "RNA_access.h"
28 #include "RNA_define.h"
29 
30 #include "rna_internal.h"
31 
32 #include "WM_api.h"
33 #include "WM_types.h"
34 
35 #ifdef RNA_RUNTIME
36 
37 #  include "BKE_camera.h"
38 #  include "BKE_object.h"
39 #  include "BKE_sequencer.h"
40 
41 #  include "DEG_depsgraph.h"
42 #  include "DEG_depsgraph_build.h"
43 
rna_Camera_angle_get(PointerRNA * ptr)44 static float rna_Camera_angle_get(PointerRNA *ptr)
45 {
46   Camera *cam = (Camera *)ptr->owner_id;
47   float sensor = BKE_camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y);
48   return focallength_to_fov(cam->lens, sensor);
49 }
50 
rna_Camera_angle_set(PointerRNA * ptr,float value)51 static void rna_Camera_angle_set(PointerRNA *ptr, float value)
52 {
53   Camera *cam = (Camera *)ptr->owner_id;
54   float sensor = BKE_camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y);
55   cam->lens = fov_to_focallength(value, sensor);
56 }
57 
rna_Camera_angle_x_get(PointerRNA * ptr)58 static float rna_Camera_angle_x_get(PointerRNA *ptr)
59 {
60   Camera *cam = (Camera *)ptr->owner_id;
61   return focallength_to_fov(cam->lens, cam->sensor_x);
62 }
63 
rna_Camera_angle_x_set(PointerRNA * ptr,float value)64 static void rna_Camera_angle_x_set(PointerRNA *ptr, float value)
65 {
66   Camera *cam = (Camera *)ptr->owner_id;
67   cam->lens = fov_to_focallength(value, cam->sensor_x);
68 }
69 
rna_Camera_angle_y_get(PointerRNA * ptr)70 static float rna_Camera_angle_y_get(PointerRNA *ptr)
71 {
72   Camera *cam = (Camera *)ptr->owner_id;
73   return focallength_to_fov(cam->lens, cam->sensor_y);
74 }
75 
rna_Camera_angle_y_set(PointerRNA * ptr,float value)76 static void rna_Camera_angle_y_set(PointerRNA *ptr, float value)
77 {
78   Camera *cam = (Camera *)ptr->owner_id;
79   cam->lens = fov_to_focallength(value, cam->sensor_y);
80 }
81 
rna_Camera_update(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)82 static void rna_Camera_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
83 {
84   Camera *camera = (Camera *)ptr->owner_id;
85 
86   DEG_id_tag_update(&camera->id, 0);
87 }
88 
rna_Camera_dependency_update(Main * bmain,Scene * UNUSED (scene),PointerRNA * ptr)89 static void rna_Camera_dependency_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
90 {
91   Camera *camera = (Camera *)ptr->owner_id;
92   DEG_relations_tag_update(bmain);
93   DEG_id_tag_update(&camera->id, 0);
94 }
95 
rna_Camera_background_images_new(Camera * cam)96 static CameraBGImage *rna_Camera_background_images_new(Camera *cam)
97 {
98   CameraBGImage *bgpic = BKE_camera_background_image_new(cam);
99 
100   WM_main_add_notifier(NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, cam);
101 
102   return bgpic;
103 }
104 
rna_Camera_background_images_remove(Camera * cam,ReportList * reports,PointerRNA * bgpic_ptr)105 static void rna_Camera_background_images_remove(Camera *cam,
106                                                 ReportList *reports,
107                                                 PointerRNA *bgpic_ptr)
108 {
109   CameraBGImage *bgpic = bgpic_ptr->data;
110   if (BLI_findindex(&cam->bg_images, bgpic) == -1) {
111     BKE_report(reports, RPT_ERROR, "Background image cannot be removed");
112   }
113 
114   BKE_camera_background_image_remove(cam, bgpic);
115   RNA_POINTER_INVALIDATE(bgpic_ptr);
116 
117   WM_main_add_notifier(NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, cam);
118 }
119 
rna_Camera_background_images_clear(Camera * cam)120 static void rna_Camera_background_images_clear(Camera *cam)
121 {
122   BKE_camera_background_image_clear(cam);
123 
124   WM_main_add_notifier(NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, cam);
125 }
126 
rna_Camera_dof_update(Main * bmain,Scene * scene,PointerRNA * UNUSED (ptr))127 static void rna_Camera_dof_update(Main *bmain, Scene *scene, PointerRNA *UNUSED(ptr))
128 {
129   BKE_sequence_invalidate_scene_strips(bmain, scene);
130   WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene);
131 }
132 
rna_CameraDOFSettings_path(PointerRNA * ptr)133 char *rna_CameraDOFSettings_path(PointerRNA *ptr)
134 {
135   /* if there is ID-data, resolve the path using the index instead of by name,
136    * since the name used is the name of the texture assigned, but the texture
137    * may be used multiple times in the same stack
138    */
139   if (ptr->owner_id) {
140     if (GS(ptr->owner_id->name) == ID_CA) {
141       return BLI_strdup("dof");
142     }
143   }
144 
145   return BLI_strdup("");
146 }
147 
rna_CameraDOFSettings_aperture_blades_set(PointerRNA * ptr,const int value)148 static void rna_CameraDOFSettings_aperture_blades_set(PointerRNA *ptr, const int value)
149 {
150   CameraDOFSettings *dofsettings = (CameraDOFSettings *)ptr->data;
151 
152   if (value == 1 || value == 2) {
153     if (dofsettings->aperture_blades == 0) {
154       dofsettings->aperture_blades = 3;
155     }
156     else {
157       dofsettings->aperture_blades = 0;
158     }
159   }
160   else {
161     dofsettings->aperture_blades = value;
162   }
163 }
164 
165 #else
166 
rna_def_camera_background_image(BlenderRNA * brna)167 static void rna_def_camera_background_image(BlenderRNA *brna)
168 {
169   StructRNA *srna;
170   PropertyRNA *prop;
171 
172   static const EnumPropertyItem bgpic_source_items[] = {
173       {CAM_BGIMG_SOURCE_IMAGE, "IMAGE", 0, "Image", ""},
174       {CAM_BGIMG_SOURCE_MOVIE, "MOVIE_CLIP", 0, "Movie Clip", ""},
175       {0, NULL, 0, NULL, NULL},
176   };
177 
178   static const EnumPropertyItem bgpic_camera_frame_items[] = {
179       {0, "STRETCH", 0, "Stretch", ""},
180       {CAM_BGIMG_FLAG_CAMERA_ASPECT, "FIT", 0, "Fit", ""},
181       {CAM_BGIMG_FLAG_CAMERA_ASPECT | CAM_BGIMG_FLAG_CAMERA_CROP, "CROP", 0, "Crop", ""},
182       {0, NULL, 0, NULL, NULL},
183   };
184 
185   static const EnumPropertyItem bgpic_display_depth_items[] = {
186       {0, "BACK", 0, "Back", ""},
187       {CAM_BGIMG_FLAG_FOREGROUND, "FRONT", 0, "Front", ""},
188       {0, NULL, 0, NULL, NULL},
189   };
190 
191   srna = RNA_def_struct(brna, "CameraBackgroundImage", NULL);
192   RNA_def_struct_sdna(srna, "CameraBGImage");
193   RNA_def_struct_ui_text(
194       srna, "Background Image", "Image and settings for display in the 3D View background");
195 
196   RNA_define_lib_overridable(true);
197 
198   prop = RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE);
199   RNA_def_property_enum_sdna(prop, NULL, "source");
200   RNA_def_property_enum_items(prop, bgpic_source_items);
201   RNA_def_property_ui_text(prop, "Background Source", "Data source used for background");
202   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
203 
204   prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
205   RNA_def_property_pointer_sdna(prop, NULL, "ima");
206   RNA_def_property_ui_text(prop, "Image", "Image displayed and edited in this space");
207   RNA_def_property_flag(prop, PROP_EDITABLE);
208   RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
209   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
210 
211   prop = RNA_def_property(srna, "clip", PROP_POINTER, PROP_NONE);
212   RNA_def_property_pointer_sdna(prop, NULL, "clip");
213   RNA_def_property_ui_text(prop, "MovieClip", "Movie clip displayed and edited in this space");
214   RNA_def_property_flag(prop, PROP_EDITABLE);
215   RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
216   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
217 
218   prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE);
219   RNA_def_property_flag(prop, PROP_NEVER_NULL);
220   RNA_def_property_pointer_sdna(prop, NULL, "iuser");
221   RNA_def_property_ui_text(
222       prop,
223       "Image User",
224       "Parameters defining which layer, pass and frame of the image is displayed");
225   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
226 
227   prop = RNA_def_property(srna, "clip_user", PROP_POINTER, PROP_NONE);
228   RNA_def_property_flag(prop, PROP_NEVER_NULL);
229   RNA_def_property_struct_type(prop, "MovieClipUser");
230   RNA_def_property_pointer_sdna(prop, NULL, "cuser");
231   RNA_def_property_ui_text(
232       prop, "Clip User", "Parameters defining which frame of the movie clip is displayed");
233   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
234 
235   prop = RNA_def_property(srna, "offset", PROP_FLOAT, PROP_XYZ);
236   RNA_def_property_float_sdna(prop, NULL, "offset");
237   RNA_def_property_ui_text(prop, "Offset", "");
238   RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 0.1, RNA_TRANSLATION_PREC_DEFAULT);
239   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
240 
241   prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
242   RNA_def_property_float_sdna(prop, NULL, "scale");
243   RNA_def_property_ui_text(prop, "Scale", "Scale the background image");
244   RNA_def_property_range(prop, 0.0, FLT_MAX);
245   RNA_def_property_ui_range(prop, 0.0, 10.0, 0.100, RNA_TRANSLATION_PREC_DEFAULT);
246   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
247 
248   prop = RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_ANGLE);
249   RNA_def_property_float_sdna(prop, NULL, "rotation");
250   RNA_def_property_ui_text(
251       prop, "Rotation", "Rotation for the background image (ortho view only)");
252   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
253 
254   prop = RNA_def_property(srna, "use_flip_x", PROP_BOOLEAN, PROP_NONE);
255   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_FLIP_X);
256   RNA_def_property_ui_text(prop, "Flip Horizontally", "Flip the background image horizontally");
257   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
258 
259   prop = RNA_def_property(srna, "use_flip_y", PROP_BOOLEAN, PROP_NONE);
260   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_FLIP_Y);
261   RNA_def_property_ui_text(prop, "Flip Vertically", "Flip the background image vertically");
262   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
263 
264   prop = RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_NONE);
265   RNA_def_property_float_sdna(prop, NULL, "alpha");
266   RNA_def_property_ui_text(
267       prop, "Opacity", "Image opacity to blend the image against the background color");
268   RNA_def_property_range(prop, 0.0, 1.0);
269   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
270 
271   prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
272   RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE);
273   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_EXPANDED);
274   RNA_def_property_ui_text(prop, "Show Expanded", "Show the expanded in the user interface");
275   RNA_def_property_ui_icon(prop, ICON_DISCLOSURE_TRI_RIGHT, 1);
276 
277   prop = RNA_def_property(srna, "use_camera_clip", PROP_BOOLEAN, PROP_NONE);
278   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_CAMERACLIP);
279   RNA_def_property_ui_text(prop, "Camera Clip", "Use movie clip from active scene camera");
280   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
281 
282   prop = RNA_def_property(srna, "show_background_image", PROP_BOOLEAN, PROP_NONE);
283   RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_DISABLED);
284   RNA_def_property_ui_text(prop, "Show Background Image", "Show this image as background");
285   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
286 
287   prop = RNA_def_property(srna, "show_on_foreground", PROP_BOOLEAN, PROP_NONE);
288   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_FOREGROUND);
289   RNA_def_property_ui_text(
290       prop, "Show On Foreground", "Show this image in front of objects in viewport");
291   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
292 
293   /* expose 1 flag as a enum of 2 items */
294   prop = RNA_def_property(srna, "display_depth", PROP_ENUM, PROP_NONE);
295   RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
296   RNA_def_property_enum_items(prop, bgpic_display_depth_items);
297   RNA_def_property_ui_text(prop, "Depth", "Display under or over everything");
298   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
299 
300   /* expose 2 flags as a enum of 3 items */
301   prop = RNA_def_property(srna, "frame_method", PROP_ENUM, PROP_NONE);
302   RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
303   RNA_def_property_enum_items(prop, bgpic_camera_frame_items);
304   RNA_def_property_ui_text(prop, "Frame Method", "How the image fits in the camera frame");
305   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
306 
307   RNA_define_lib_overridable(false);
308 }
309 
rna_def_camera_background_images(BlenderRNA * brna,PropertyRNA * cprop)310 static void rna_def_camera_background_images(BlenderRNA *brna, PropertyRNA *cprop)
311 {
312   StructRNA *srna;
313   FunctionRNA *func;
314   PropertyRNA *parm;
315 
316   RNA_def_property_srna(cprop, "CameraBackgroundImages");
317   srna = RNA_def_struct(brna, "CameraBackgroundImages", NULL);
318   RNA_def_struct_sdna(srna, "Camera");
319   RNA_def_struct_ui_text(srna, "Background Images", "Collection of background images");
320 
321   func = RNA_def_function(srna, "new", "rna_Camera_background_images_new");
322   RNA_def_function_ui_description(func, "Add new background image");
323   parm = RNA_def_pointer(
324       func, "image", "CameraBackgroundImage", "", "Image displayed as viewport background");
325   RNA_def_function_return(func, parm);
326 
327   func = RNA_def_function(srna, "remove", "rna_Camera_background_images_remove");
328   RNA_def_function_ui_description(func, "Remove background image");
329   RNA_def_function_flag(func, FUNC_USE_REPORTS);
330   parm = RNA_def_pointer(
331       func, "image", "CameraBackgroundImage", "", "Image displayed as viewport background");
332   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
333   RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
334 
335   func = RNA_def_function(srna, "clear", "rna_Camera_background_images_clear");
336   RNA_def_function_ui_description(func, "Remove all background images");
337 }
338 
rna_def_camera_stereo_data(BlenderRNA * brna)339 static void rna_def_camera_stereo_data(BlenderRNA *brna)
340 {
341   StructRNA *srna;
342   PropertyRNA *prop;
343 
344   static const EnumPropertyItem convergence_mode_items[] = {
345       {CAM_S3D_OFFAXIS, "OFFAXIS", 0, "Off-Axis", "Off-axis frustums converging in a plane"},
346       {CAM_S3D_PARALLEL, "PARALLEL", 0, "Parallel", "Parallel cameras with no convergence"},
347       {CAM_S3D_TOE, "TOE", 0, "Toe-in", "Rotated cameras, looking at the convergence distance"},
348       {0, NULL, 0, NULL, NULL},
349   };
350 
351   static const EnumPropertyItem pivot_items[] = {
352       {CAM_S3D_PIVOT_LEFT, "LEFT", 0, "Left", ""},
353       {CAM_S3D_PIVOT_RIGHT, "RIGHT", 0, "Right", ""},
354       {CAM_S3D_PIVOT_CENTER, "CENTER", 0, "Center", ""},
355       {0, NULL, 0, NULL, NULL},
356   };
357 
358   srna = RNA_def_struct(brna, "CameraStereoData", NULL);
359   RNA_def_struct_sdna(srna, "CameraStereoSettings");
360   RNA_def_struct_nested(brna, srna, "Camera");
361   RNA_def_struct_ui_text(srna, "Stereo", "Stereoscopy settings for a Camera data-block");
362 
363   RNA_define_lib_overridable(true);
364 
365   prop = RNA_def_property(srna, "convergence_mode", PROP_ENUM, PROP_NONE);
366   RNA_def_property_enum_items(prop, convergence_mode_items);
367   RNA_def_property_ui_text(prop, "Mode", "");
368   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
369 
370   prop = RNA_def_property(srna, "pivot", PROP_ENUM, PROP_NONE);
371   RNA_def_property_enum_items(prop, pivot_items);
372   RNA_def_property_ui_text(prop, "Pivot", "");
373   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
374 
375   prop = RNA_def_property(srna, "interocular_distance", PROP_FLOAT, PROP_DISTANCE);
376   RNA_def_property_range(prop, 0.0f, FLT_MAX);
377   RNA_def_property_ui_range(prop, 0.0f, 1e4f, 1, 3);
378   RNA_def_property_ui_text(
379       prop,
380       "Interocular Distance",
381       "Set the distance between the eyes - the stereo plane distance / 30 should be fine");
382   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
383 
384   prop = RNA_def_property(srna, "convergence_distance", PROP_FLOAT, PROP_DISTANCE);
385   RNA_def_property_range(prop, 0.00001f, FLT_MAX);
386   RNA_def_property_ui_range(prop, 0.00001f, 15.f, 1, 3);
387   RNA_def_property_ui_text(prop,
388                            "Convergence Plane Distance",
389                            "The converge point for the stereo cameras "
390                            "(often the distance between a projector and the projection screen)");
391   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
392 
393   prop = RNA_def_property(srna, "use_spherical_stereo", PROP_BOOLEAN, PROP_NONE);
394   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_S3D_SPHERICAL);
395   RNA_def_property_ui_text(prop,
396                            "Spherical Stereo",
397                            "Render every pixel rotating the camera around the "
398                            "middle of the interocular distance");
399   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
400 
401   prop = RNA_def_property(srna, "use_pole_merge", PROP_BOOLEAN, PROP_NONE);
402   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_S3D_POLE_MERGE);
403   RNA_def_property_ui_text(
404       prop, "Use Pole Merge", "Fade interocular distance to 0 after the given cutoff angle");
405   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
406 
407   prop = RNA_def_property(srna, "pole_merge_angle_from", PROP_FLOAT, PROP_ANGLE);
408   RNA_def_property_range(prop, 0.0f, M_PI / 2.0);
409   RNA_def_property_ui_text(
410       prop, "Pole Merge Start Angle", "Angle at which interocular distance starts to fade to 0");
411   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
412 
413   prop = RNA_def_property(srna, "pole_merge_angle_to", PROP_FLOAT, PROP_ANGLE);
414   RNA_def_property_range(prop, 0.0f, M_PI / 2.0);
415   RNA_def_property_ui_text(
416       prop, "Pole Merge End Angle", "Angle at which interocular distance is 0");
417   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
418 
419   RNA_define_lib_overridable(false);
420 }
421 
rna_def_camera_dof_settings_data(BlenderRNA * brna)422 static void rna_def_camera_dof_settings_data(BlenderRNA *brna)
423 {
424   StructRNA *srna;
425   PropertyRNA *prop;
426 
427   srna = RNA_def_struct(brna, "CameraDOFSettings", NULL);
428   RNA_def_struct_sdna(srna, "CameraDOFSettings");
429   RNA_def_struct_path_func(srna, "rna_CameraDOFSettings_path");
430   RNA_def_struct_ui_text(srna, "Depth of Field", "Depth of Field settings");
431 
432   RNA_define_lib_overridable(true);
433 
434   prop = RNA_def_property(srna, "use_dof", PROP_BOOLEAN, PROP_NONE);
435   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_DOF_ENABLED);
436   RNA_def_property_ui_text(prop, "Depth of Field", "Use Depth of Field");
437   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_dof_update");
438 
439   prop = RNA_def_property(srna, "focus_object", PROP_POINTER, PROP_NONE);
440   RNA_def_property_struct_type(prop, "Object");
441   RNA_def_property_pointer_sdna(prop, NULL, "focus_object");
442   RNA_def_property_flag(prop, PROP_EDITABLE);
443   RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
444   RNA_def_property_ui_text(
445       prop, "Focus Object", "Use this object to define the depth of field focal point");
446   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_dependency_update");
447 
448   prop = RNA_def_property(srna, "focus_distance", PROP_FLOAT, PROP_DISTANCE);
449   // RNA_def_property_pointer_sdna(prop, NULL, "focus_distance");
450   RNA_def_property_range(prop, 0.0f, FLT_MAX);
451   RNA_def_property_ui_range(prop, 0.0f, 5000.0f, 1, 2);
452   RNA_def_property_ui_text(
453       prop, "Focus Distance", "Distance to the focus point for depth of field");
454   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_dof_update");
455 
456   prop = RNA_def_property(srna, "aperture_fstop", PROP_FLOAT, PROP_NONE);
457   RNA_def_property_ui_text(
458       prop,
459       "F-Stop",
460       "F-Stop ratio (lower numbers give more defocus, higher numbers give a sharper image)");
461   RNA_def_property_range(prop, 0.0f, FLT_MAX);
462   RNA_def_property_ui_range(prop, 0.1f, 128.0f, 10, 1);
463   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_dof_update");
464 
465   prop = RNA_def_property(srna, "aperture_blades", PROP_INT, PROP_NONE);
466   RNA_def_property_ui_text(
467       prop, "Blades", "Number of blades in aperture for polygonal bokeh (at least 3)");
468   RNA_def_property_range(prop, 0, 16);
469   RNA_def_property_int_funcs(prop, NULL, "rna_CameraDOFSettings_aperture_blades_set", NULL);
470   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_dof_update");
471 
472   prop = RNA_def_property(srna, "aperture_rotation", PROP_FLOAT, PROP_ANGLE);
473   RNA_def_property_ui_text(prop, "Rotation", "Rotation of blades in aperture");
474   RNA_def_property_range(prop, -M_PI, M_PI);
475   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_dof_update");
476 
477   prop = RNA_def_property(srna, "aperture_ratio", PROP_FLOAT, PROP_NONE);
478   RNA_def_property_ui_text(prop, "Ratio", "Distortion to simulate anamorphic lens bokeh");
479   RNA_def_property_range(prop, 0.01f, FLT_MAX);
480   RNA_def_property_ui_range(prop, 1.0f, 2.0f, 0.1, 3);
481   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_dof_update");
482 
483   RNA_define_lib_overridable(false);
484 }
485 
RNA_def_camera(BlenderRNA * brna)486 void RNA_def_camera(BlenderRNA *brna)
487 {
488   StructRNA *srna;
489   PropertyRNA *prop;
490   static const EnumPropertyItem prop_type_items[] = {
491       {CAM_PERSP, "PERSP", 0, "Perspective", ""},
492       {CAM_ORTHO, "ORTHO", 0, "Orthographic", ""},
493       {CAM_PANO, "PANO", 0, "Panoramic", ""},
494       {0, NULL, 0, NULL, NULL},
495   };
496   static const EnumPropertyItem prop_lens_unit_items[] = {
497       {0, "MILLIMETERS", 0, "Millimeters", "Specify the lens in millimeters"},
498       {CAM_ANGLETOGGLE,
499        "FOV",
500        0,
501        "Field of View",
502        "Specify the lens as the field of view's angle"},
503       {0, NULL, 0, NULL, NULL},
504   };
505   static const EnumPropertyItem sensor_fit_items[] = {
506       {CAMERA_SENSOR_FIT_AUTO,
507        "AUTO",
508        0,
509        "Auto",
510        "Fit to the sensor width or height depending on image resolution"},
511       {CAMERA_SENSOR_FIT_HOR, "HORIZONTAL", 0, "Horizontal", "Fit to the sensor width"},
512       {CAMERA_SENSOR_FIT_VERT, "VERTICAL", 0, "Vertical", "Fit to the sensor height"},
513       {0, NULL, 0, NULL, NULL},
514   };
515 
516   srna = RNA_def_struct(brna, "Camera", "ID");
517   RNA_def_struct_ui_text(srna, "Camera", "Camera data-block for storing camera settings");
518   RNA_def_struct_ui_icon(srna, ICON_CAMERA_DATA);
519 
520   RNA_define_lib_overridable(true);
521 
522   /* Enums */
523   prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
524   RNA_def_property_enum_items(prop, prop_type_items);
525   RNA_def_property_ui_text(prop, "Type", "Camera types");
526   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_update");
527 
528   prop = RNA_def_property(srna, "sensor_fit", PROP_ENUM, PROP_NONE);
529   RNA_def_property_enum_sdna(prop, NULL, "sensor_fit");
530   RNA_def_property_enum_items(prop, sensor_fit_items);
531   RNA_def_property_ui_text(
532       prop, "Sensor Fit", "Method to fit image and field of view angle inside the sensor");
533   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_update");
534 
535   /* Number values */
536 
537   prop = RNA_def_property(srna, "passepartout_alpha", PROP_FLOAT, PROP_FACTOR);
538   RNA_def_property_float_sdna(prop, NULL, "passepartalpha");
539   RNA_def_property_ui_text(
540       prop, "Passepartout Alpha", "Opacity (alpha) of the darkened overlay in Camera view");
541   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
542 
543   prop = RNA_def_property(srna, "angle_x", PROP_FLOAT, PROP_ANGLE);
544   RNA_def_property_range(prop, DEG2RAD(0.367), DEG2RAD(172.847));
545   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
546   RNA_def_property_ui_text(prop, "Horizontal FOV", "Camera lens horizontal field of view");
547   RNA_def_property_float_funcs(prop, "rna_Camera_angle_x_get", "rna_Camera_angle_x_set", NULL);
548   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_update");
549 
550   prop = RNA_def_property(srna, "angle_y", PROP_FLOAT, PROP_ANGLE);
551   RNA_def_property_range(prop, DEG2RAD(0.367), DEG2RAD(172.847));
552   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
553   RNA_def_property_ui_text(prop, "Vertical FOV", "Camera lens vertical field of view");
554   RNA_def_property_float_funcs(prop, "rna_Camera_angle_y_get", "rna_Camera_angle_y_set", NULL);
555   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_update");
556 
557   prop = RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE);
558   RNA_def_property_range(prop, DEG2RAD(0.367), DEG2RAD(172.847));
559   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
560   RNA_def_property_ui_text(prop, "Field of View", "Camera lens field of view");
561   RNA_def_property_float_funcs(prop, "rna_Camera_angle_get", "rna_Camera_angle_set", NULL);
562   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_update");
563 
564   prop = RNA_def_property(srna, "clip_start", PROP_FLOAT, PROP_DISTANCE);
565   RNA_def_property_range(prop, 1e-6f, FLT_MAX);
566   RNA_def_property_ui_range(prop, 0.001f, FLT_MAX, 10, 3);
567   RNA_def_property_ui_text(prop, "Clip Start", "Camera near clipping distance");
568   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
569 
570   prop = RNA_def_property(srna, "clip_end", PROP_FLOAT, PROP_DISTANCE);
571   RNA_def_property_range(prop, 1e-6f, FLT_MAX);
572   RNA_def_property_ui_range(prop, 0.001f, FLT_MAX, 10, 3);
573   RNA_def_property_ui_text(prop, "Clip End", "Camera far clipping distance");
574   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
575 
576   prop = RNA_def_property(srna, "lens", PROP_FLOAT, PROP_DISTANCE_CAMERA);
577   RNA_def_property_float_sdna(prop, NULL, "lens");
578   RNA_def_property_range(prop, 1.0f, FLT_MAX);
579   RNA_def_property_ui_range(prop, 1.0f, 5000.0f, 100, 4);
580   RNA_def_property_ui_text(prop, "Focal Length", "Perspective Camera lens value in millimeters");
581   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_update");
582 
583   prop = RNA_def_property(srna, "sensor_width", PROP_FLOAT, PROP_DISTANCE_CAMERA);
584   RNA_def_property_float_sdna(prop, NULL, "sensor_x");
585   RNA_def_property_range(prop, 1.0f, FLT_MAX);
586   RNA_def_property_ui_range(prop, 1.0f, 100.f, 100, 4);
587   RNA_def_property_ui_text(
588       prop, "Sensor Width", "Horizontal size of the image sensor area in millimeters");
589   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_update");
590 
591   prop = RNA_def_property(srna, "sensor_height", PROP_FLOAT, PROP_DISTANCE_CAMERA);
592   RNA_def_property_float_sdna(prop, NULL, "sensor_y");
593   RNA_def_property_range(prop, 1.0f, FLT_MAX);
594   RNA_def_property_ui_range(prop, 1.0f, 100.f, 100, 4);
595   RNA_def_property_ui_text(
596       prop, "Sensor Height", "Vertical size of the image sensor area in millimeters");
597   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_update");
598 
599   prop = RNA_def_property(srna, "ortho_scale", PROP_FLOAT, PROP_NONE);
600   RNA_def_property_float_sdna(prop, NULL, "ortho_scale");
601   RNA_def_property_range(prop, FLT_MIN, FLT_MAX);
602   RNA_def_property_ui_range(prop, 0.001f, 10000.0f, 10, 3);
603   RNA_def_property_ui_text(
604       prop, "Orthographic Scale", "Orthographic Camera scale (similar to zoom)");
605   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_update");
606 
607   prop = RNA_def_property(srna, "display_size", PROP_FLOAT, PROP_DISTANCE);
608   RNA_def_property_float_sdna(prop, NULL, "drawsize");
609   RNA_def_property_range(prop, 0.01f, 1000.0f);
610   RNA_def_property_ui_range(prop, 0.01, 100, 1, 2);
611   RNA_def_property_ui_text(
612       prop, "Display Size", "Apparent size of the Camera object in the 3D View");
613   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
614 
615   prop = RNA_def_property(srna, "shift_x", PROP_FLOAT, PROP_NONE);
616   RNA_def_property_float_sdna(prop, NULL, "shiftx");
617   RNA_def_property_range(prop, -10.0f, 10.0f);
618   RNA_def_property_ui_range(prop, -2.0, 2.0, 1, 3);
619   RNA_def_property_ui_text(prop, "Shift X", "Camera horizontal shift");
620   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_update");
621 
622   prop = RNA_def_property(srna, "shift_y", PROP_FLOAT, PROP_NONE);
623   RNA_def_property_float_sdna(prop, NULL, "shifty");
624   RNA_def_property_range(prop, -10.0f, 10.0f);
625   RNA_def_property_ui_range(prop, -2.0, 2.0, 1, 3);
626   RNA_def_property_ui_text(prop, "Shift Y", "Camera vertical shift");
627   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_update");
628 
629   /* Stereo Settings */
630   prop = RNA_def_property(srna, "stereo", PROP_POINTER, PROP_NONE);
631   RNA_def_property_flag(prop, PROP_NEVER_NULL);
632   RNA_def_property_pointer_sdna(prop, NULL, "stereo");
633   RNA_def_property_struct_type(prop, "CameraStereoData");
634   RNA_def_property_ui_text(prop, "Stereo", "");
635 
636   /* flag */
637   prop = RNA_def_property(srna, "show_limits", PROP_BOOLEAN, PROP_NONE);
638   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWLIMITS);
639   RNA_def_property_ui_text(
640       prop, "Show Limits", "Display the clipping range and focus point on the camera");
641   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
642 
643   prop = RNA_def_property(srna, "show_mist", PROP_BOOLEAN, PROP_NONE);
644   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWMIST);
645   RNA_def_property_ui_text(
646       prop, "Show Mist", "Display a line from the Camera to indicate the mist area");
647   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
648 
649   prop = RNA_def_property(srna, "show_passepartout", PROP_BOOLEAN, PROP_NONE);
650   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWPASSEPARTOUT);
651   RNA_def_property_ui_text(
652       prop, "Show Passepartout", "Show a darkened overlay outside the image area in Camera view");
653   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
654 
655   prop = RNA_def_property(srna, "show_safe_areas", PROP_BOOLEAN, PROP_NONE);
656   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOW_SAFE_MARGINS);
657   RNA_def_property_ui_text(
658       prop, "Show Safe Areas", "Show TV title safe and action safe areas in Camera view");
659   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
660 
661   prop = RNA_def_property(srna, "show_safe_center", PROP_BOOLEAN, PROP_NONE);
662   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOW_SAFE_CENTER);
663   RNA_def_property_ui_text(prop,
664                            "Show Center-cut safe areas",
665                            "Show safe areas to fit content in a different aspect ratio");
666   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
667 
668   prop = RNA_def_property(srna, "show_name", PROP_BOOLEAN, PROP_NONE);
669   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWNAME);
670   RNA_def_property_ui_text(prop, "Show Name", "Show the active Camera's name in Camera view");
671   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
672 
673   prop = RNA_def_property(srna, "show_sensor", PROP_BOOLEAN, PROP_NONE);
674   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWSENSOR);
675   RNA_def_property_ui_text(
676       prop, "Show Sensor Size", "Show sensor size (film gate) in Camera view");
677   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
678 
679   prop = RNA_def_property(srna, "show_background_images", PROP_BOOLEAN, PROP_NONE);
680   RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOW_BG_IMAGE);
681   RNA_def_property_ui_text(
682       prop, "Display Background Images", "Display reference images behind objects in the 3D View");
683   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
684 
685   prop = RNA_def_property(srna, "lens_unit", PROP_ENUM, PROP_NONE);
686   RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
687   RNA_def_property_enum_items(prop, prop_lens_unit_items);
688   RNA_def_property_ui_text(prop, "Lens Unit", "Unit to edit lens in for the user interface");
689 
690   /* dtx */
691   prop = RNA_def_property(srna, "show_composition_center", PROP_BOOLEAN, PROP_NONE);
692   RNA_def_property_boolean_sdna(prop, NULL, "dtx", CAM_DTX_CENTER);
693   RNA_def_property_ui_text(
694       prop, "Center", "Display center composition guide inside the camera view");
695   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
696 
697   prop = RNA_def_property(srna, "show_composition_center_diagonal", PROP_BOOLEAN, PROP_NONE);
698   RNA_def_property_boolean_sdna(prop, NULL, "dtx", CAM_DTX_CENTER_DIAG);
699   RNA_def_property_ui_text(
700       prop, "Center Diagonal", "Display diagonal center composition guide inside the camera view");
701   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
702 
703   prop = RNA_def_property(srna, "show_composition_thirds", PROP_BOOLEAN, PROP_NONE);
704   RNA_def_property_boolean_sdna(prop, NULL, "dtx", CAM_DTX_THIRDS);
705   RNA_def_property_ui_text(
706       prop, "Thirds", "Display rule of thirds composition guide inside the camera view");
707   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
708 
709   prop = RNA_def_property(srna, "show_composition_golden", PROP_BOOLEAN, PROP_NONE);
710   RNA_def_property_boolean_sdna(prop, NULL, "dtx", CAM_DTX_GOLDEN);
711   RNA_def_property_ui_text(
712       prop, "Golden Ratio", "Display golden ratio composition guide inside the camera view");
713   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
714 
715   prop = RNA_def_property(srna, "show_composition_golden_tria_a", PROP_BOOLEAN, PROP_NONE);
716   RNA_def_property_boolean_sdna(prop, NULL, "dtx", CAM_DTX_GOLDEN_TRI_A);
717   RNA_def_property_ui_text(prop,
718                            "Golden Triangle A",
719                            "Display golden triangle A composition guide inside the camera view");
720   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
721 
722   prop = RNA_def_property(srna, "show_composition_golden_tria_b", PROP_BOOLEAN, PROP_NONE);
723   RNA_def_property_boolean_sdna(prop, NULL, "dtx", CAM_DTX_GOLDEN_TRI_B);
724   RNA_def_property_ui_text(prop,
725                            "Golden Triangle B",
726                            "Display golden triangle B composition guide inside the camera view");
727   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
728 
729   prop = RNA_def_property(srna, "show_composition_harmony_tri_a", PROP_BOOLEAN, PROP_NONE);
730   RNA_def_property_boolean_sdna(prop, NULL, "dtx", CAM_DTX_HARMONY_TRI_A);
731   RNA_def_property_ui_text(
732       prop, "Harmonious Triangle A", "Display harmony A composition guide inside the camera view");
733   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
734 
735   prop = RNA_def_property(srna, "show_composition_harmony_tri_b", PROP_BOOLEAN, PROP_NONE);
736   RNA_def_property_boolean_sdna(prop, NULL, "dtx", CAM_DTX_HARMONY_TRI_B);
737   RNA_def_property_ui_text(
738       prop, "Harmonious Triangle B", "Display harmony B composition guide inside the camera view");
739   RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
740 
741   /* pointers */
742   prop = RNA_def_property(srna, "dof", PROP_POINTER, PROP_NONE);
743   RNA_def_property_struct_type(prop, "CameraDOFSettings");
744   RNA_def_property_ui_text(prop, "Depth Of Field", "");
745   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
746 
747   prop = RNA_def_property(srna, "background_images", PROP_COLLECTION, PROP_NONE);
748   RNA_def_property_collection_sdna(prop, NULL, "bg_images", NULL);
749   RNA_def_property_struct_type(prop, "CameraBackgroundImage");
750   RNA_def_property_ui_text(prop, "Background Images", "List of background images");
751   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
752 
753   RNA_define_lib_overridable(false);
754 
755   rna_def_animdata_common(srna);
756 
757   rna_def_camera_background_image(brna);
758   rna_def_camera_background_images(brna, prop);
759 
760   /* Nested Data  */
761   RNA_define_animate_sdna(true);
762 
763   /* *** Animated *** */
764   rna_def_camera_stereo_data(brna);
765   rna_def_camera_dof_settings_data(brna);
766 
767   /* Camera API */
768   RNA_api_camera(srna);
769 }
770 
771 #endif
772