Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * Contributor(s): Blender Foundation (2008). 00019 * 00020 * ***** END GPL LICENSE BLOCK ***** 00021 */ 00022 00028 #include <stdlib.h> 00029 00030 #include "RNA_define.h" 00031 00032 #include "rna_internal.h" 00033 00034 #include "DNA_camera_types.h" 00035 00036 #include "BLI_math.h" 00037 00038 #include "WM_types.h" 00039 00040 #ifdef RNA_RUNTIME 00041 00042 #include "BKE_camera.h" 00043 #include "BKE_object.h" 00044 #include "BKE_depsgraph.h" 00045 00046 static float rna_Camera_angle_get(PointerRNA *ptr) 00047 { 00048 Camera *cam= ptr->id.data; 00049 float sensor= camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y); 00050 return focallength_to_fov(cam->lens, sensor); 00051 } 00052 00053 static void rna_Camera_angle_set(PointerRNA *ptr, float value) 00054 { 00055 Camera *cam= ptr->id.data; 00056 float sensor= camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y); 00057 cam->lens= fov_to_focallength(value, sensor); 00058 } 00059 00060 static float rna_Camera_angle_x_get(PointerRNA *ptr) 00061 { 00062 Camera *cam= ptr->id.data; 00063 return focallength_to_fov(cam->lens, cam->sensor_x); 00064 } 00065 00066 static void rna_Camera_angle_x_set(PointerRNA *ptr, float value) 00067 { 00068 Camera *cam= ptr->id.data; 00069 cam->lens= fov_to_focallength(value, cam->sensor_x); 00070 } 00071 00072 static float rna_Camera_angle_y_get(PointerRNA *ptr) 00073 { 00074 Camera *cam= ptr->id.data; 00075 return focallength_to_fov(cam->lens, cam->sensor_y); 00076 } 00077 00078 static void rna_Camera_angle_y_set(PointerRNA *ptr, float value) 00079 { 00080 Camera *cam= ptr->id.data; 00081 cam->lens= fov_to_focallength(value, cam->sensor_y); 00082 } 00083 00084 static void rna_Camera_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) 00085 { 00086 Camera *camera= (Camera*)ptr->id.data; 00087 00088 DAG_id_tag_update(&camera->id, 0); 00089 } 00090 00091 #else 00092 00093 void RNA_def_camera(BlenderRNA *brna) 00094 { 00095 StructRNA *srna; 00096 PropertyRNA *prop; 00097 static EnumPropertyItem prop_type_items[] = { 00098 {CAM_PERSP, "PERSP", 0, "Perspective", ""}, 00099 {CAM_ORTHO, "ORTHO", 0, "Orthographic", ""}, 00100 {0, NULL, 0, NULL, NULL}}; 00101 static EnumPropertyItem prop_draw_type_extra_items[] = { 00102 {CAM_DTX_CENTER, "CENTER", 0, "Center", ""}, 00103 {CAM_DTX_CENTER_DIAG, "CENTER_DIAGONAL", 0, "Center Diagonal", ""}, 00104 {CAM_DTX_THIRDS, "THIRDS", 0, "Thirds", ""}, 00105 {CAM_DTX_GOLDEN, "GOLDEN", 0, "Golden", ""}, 00106 {CAM_DTX_GOLDEN_TRI_A, "GOLDEN_TRIANGLE_A", 0, "Golden Triangle A", ""}, 00107 {CAM_DTX_GOLDEN_TRI_B, "GOLDEN_TRIANGLE_B", 0, "Golden Triangle B", ""}, 00108 {CAM_DTX_HARMONY_TRI_A, "HARMONY_TRIANGLE_A", 0, "Harmonious Triangle A", ""}, 00109 {CAM_DTX_HARMONY_TRI_B, "HARMONY_TRIANGLE_B", 0, "Harmonious Triangle B", ""}, 00110 {0, NULL, 0, NULL, NULL}}; 00111 static EnumPropertyItem prop_lens_unit_items[] = { 00112 {0, "MILLIMETERS", 0, "Millimeters", ""}, 00113 {CAM_ANGLETOGGLE, "DEGREES", 0, "Degrees", ""}, 00114 {0, NULL, 0, NULL, NULL}}; 00115 static EnumPropertyItem sensor_fit_items[] = { 00116 {CAMERA_SENSOR_FIT_AUTO, "AUTO", 0, "Auto", "Fit to the sensor width or height depending on image resolution"}, 00117 {CAMERA_SENSOR_FIT_HOR, "HORIZONTAL", 0, "Horizontal", "Fit to the sensor width"}, 00118 {CAMERA_SENSOR_FIT_VERT, "VERTICAL", 0, "Vertical", "Fit to the sensor height"}, 00119 {0, NULL, 0, NULL, NULL}}; 00120 00121 srna= RNA_def_struct(brna, "Camera", "ID"); 00122 RNA_def_struct_ui_text(srna, "Camera", "Camera datablock for storing camera settings"); 00123 RNA_def_struct_ui_icon(srna, ICON_CAMERA_DATA); 00124 00125 /* Enums */ 00126 prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); 00127 RNA_def_property_enum_items(prop, prop_type_items); 00128 RNA_def_property_ui_text(prop, "Type", "Camera types"); 00129 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update"); 00130 00131 prop= RNA_def_property(srna, "show_guide", PROP_ENUM, PROP_NONE); 00132 RNA_def_property_enum_sdna(prop, NULL, "dtx"); 00133 RNA_def_property_enum_items(prop, prop_draw_type_extra_items); 00134 RNA_def_property_flag(prop, PROP_ENUM_FLAG); 00135 RNA_def_property_ui_text(prop, "Composition Guides", "Draw overlay"); 00136 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00137 00138 prop= RNA_def_property(srna, "sensor_fit", PROP_ENUM, PROP_NONE); 00139 RNA_def_property_enum_sdna(prop, NULL, "sensor_fit"); 00140 RNA_def_property_enum_items(prop, sensor_fit_items); 00141 RNA_def_property_ui_text(prop, "Sensor Fit", "Method to fit image and field of view angle inside the sensor"); 00142 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update"); 00143 00144 /* Number values */ 00145 00146 prop= RNA_def_property(srna, "passepartout_alpha", PROP_FLOAT, PROP_FACTOR); 00147 RNA_def_property_float_sdna(prop, NULL, "passepartalpha"); 00148 RNA_def_property_ui_text(prop, "Passepartout Alpha", "Opacity (alpha) of the darkened overlay in Camera view"); 00149 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00150 00151 prop= RNA_def_property(srna, "angle_x", PROP_FLOAT, PROP_ANGLE); 00152 RNA_def_property_range(prop, M_PI * (0.367/180.0), M_PI * (172.847/180.0)); 00153 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); 00154 RNA_def_property_ui_text(prop, "Horizontal FOV", "Camera lens horizontal field of view in degrees"); 00155 RNA_def_property_float_funcs(prop, "rna_Camera_angle_x_get", "rna_Camera_angle_x_set", NULL); 00156 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update"); 00157 00158 prop= RNA_def_property(srna, "angle_y", PROP_FLOAT, PROP_ANGLE); 00159 RNA_def_property_range(prop, M_PI * (0.367/180.0), M_PI * (172.847/180.0)); 00160 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); 00161 RNA_def_property_ui_text(prop, "Vertical FOV", "Camera lens vertical field of view in degrees"); 00162 RNA_def_property_float_funcs(prop, "rna_Camera_angle_y_get", "rna_Camera_angle_y_set", NULL); 00163 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update"); 00164 00165 prop= RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE); 00166 RNA_def_property_range(prop, M_PI * (0.367/180.0), M_PI * (172.847/180.0)); 00167 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); 00168 RNA_def_property_ui_text(prop, "Field of View", "Camera lens field of view in degrees"); 00169 RNA_def_property_float_funcs(prop, "rna_Camera_angle_get", "rna_Camera_angle_set", NULL); 00170 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update"); 00171 00172 prop= RNA_def_property(srna, "clip_start", PROP_FLOAT, PROP_DISTANCE); 00173 RNA_def_property_float_sdna(prop, NULL, "clipsta"); 00174 RNA_def_property_range(prop, 0.001f, FLT_MAX); 00175 RNA_def_property_ui_text(prop, "Clip Start", "Camera near clipping distance"); 00176 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00177 00178 prop= RNA_def_property(srna, "clip_end", PROP_FLOAT, PROP_DISTANCE); 00179 RNA_def_property_float_sdna(prop, NULL, "clipend"); 00180 RNA_def_property_range(prop, 1.0f, FLT_MAX); 00181 RNA_def_property_ui_text(prop, "Clip End", "Camera far clipping distance"); 00182 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00183 00184 prop= RNA_def_property(srna, "lens", PROP_FLOAT, PROP_NONE); 00185 RNA_def_property_float_sdna(prop, NULL, "lens"); 00186 RNA_def_property_range(prop, 1.0f, 5000.0f); 00187 RNA_def_property_ui_text(prop, "Focal Length", "Perspective Camera lens value in millimeters"); 00188 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update"); 00189 00190 prop= RNA_def_property(srna, "sensor_width", PROP_FLOAT, PROP_NONE); 00191 RNA_def_property_float_sdna(prop, NULL, "sensor_x"); 00192 RNA_def_property_range(prop, 1.0f, FLT_MAX); 00193 RNA_def_property_ui_range(prop, 1.0f, 100.f, 1, 2); 00194 RNA_def_property_ui_text(prop, "Sensor Width", "Horizontal size of the image sensor area in millimeters"); 00195 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update"); 00196 00197 prop= RNA_def_property(srna, "sensor_height", PROP_FLOAT, PROP_NONE); 00198 RNA_def_property_float_sdna(prop, NULL, "sensor_y"); 00199 RNA_def_property_range(prop, 1.0f, FLT_MAX); 00200 RNA_def_property_ui_range(prop, 1.0f, 100.f, 1, 2); 00201 RNA_def_property_ui_text(prop, "Sensor Height", "Vertical size of the image sensor area in millimeters"); 00202 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update"); 00203 00204 prop= RNA_def_property(srna, "ortho_scale", PROP_FLOAT, PROP_NONE); 00205 RNA_def_property_float_sdna(prop, NULL, "ortho_scale"); 00206 RNA_def_property_range(prop, 0.01f, 4000.0f); 00207 RNA_def_property_ui_text(prop, "Orthographic Scale", "Orthographic Camera scale (similar to zoom)"); 00208 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update"); 00209 00210 prop= RNA_def_property(srna, "draw_size", PROP_FLOAT, PROP_DISTANCE); 00211 RNA_def_property_float_sdna(prop, NULL, "drawsize"); 00212 RNA_def_property_range(prop, 0.01f, 1000.0f); 00213 RNA_def_property_ui_range(prop, 0.01, 100, 1, 2); 00214 RNA_def_property_ui_text(prop, "Draw Size", "Apparent size of the Camera object in the 3D View"); 00215 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00216 00217 prop= RNA_def_property(srna, "shift_x", PROP_FLOAT, PROP_NONE); 00218 RNA_def_property_float_sdna(prop, NULL, "shiftx"); 00219 RNA_def_property_range(prop, -10.0f, 10.0f); 00220 RNA_def_property_ui_range(prop, -2.0, 2.0, 1, 3); 00221 RNA_def_property_ui_text(prop, "Shift X", "Perspective Camera horizontal shift"); 00222 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update"); 00223 00224 prop= RNA_def_property(srna, "shift_y", PROP_FLOAT, PROP_NONE); 00225 RNA_def_property_float_sdna(prop, NULL, "shifty"); 00226 RNA_def_property_range(prop, -10.0f, 10.0f); 00227 RNA_def_property_ui_range(prop, -2.0, 2.0, 1, 3); 00228 RNA_def_property_ui_text(prop, "Shift Y", "Perspective Camera vertical shift"); 00229 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update"); 00230 00231 prop= RNA_def_property(srna, "dof_distance", PROP_FLOAT, PROP_DISTANCE); 00232 RNA_def_property_float_sdna(prop, NULL, "YF_dofdist"); 00233 RNA_def_property_range(prop, 0.0f, 5000.0f); 00234 RNA_def_property_ui_text(prop, "DOF Distance", "Distance to the focus point for depth of field"); 00235 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00236 00237 /* flag */ 00238 prop= RNA_def_property(srna, "show_limits", PROP_BOOLEAN, PROP_NONE); 00239 RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWLIMITS); 00240 RNA_def_property_ui_text(prop, "Show Limits", "Draw the clipping range and focus point on the camera"); 00241 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00242 00243 prop= RNA_def_property(srna, "show_mist", PROP_BOOLEAN, PROP_NONE); 00244 RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWMIST); 00245 RNA_def_property_ui_text(prop, "Show Mist", "Draw a line from the Camera to indicate the mist area"); 00246 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00247 00248 prop= RNA_def_property(srna, "show_passepartout", PROP_BOOLEAN, PROP_NONE); 00249 RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWPASSEPARTOUT); 00250 RNA_def_property_ui_text(prop, "Show Passepartout", "Show a darkened overlay outside the image area in Camera view"); 00251 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00252 00253 prop= RNA_def_property(srna, "show_title_safe", PROP_BOOLEAN, PROP_NONE); 00254 RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWTITLESAFE); 00255 RNA_def_property_ui_text(prop, "Show Title Safe", "Show indicators for the title safe zone in Camera view"); 00256 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00257 00258 prop= RNA_def_property(srna, "show_name", PROP_BOOLEAN, PROP_NONE); 00259 RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWNAME); 00260 RNA_def_property_ui_text(prop, "Show Name", "Show the active Camera's name in Camera view"); 00261 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00262 00263 prop= RNA_def_property(srna, "show_sensor", PROP_BOOLEAN, PROP_NONE); 00264 RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWSENSOR); 00265 RNA_def_property_ui_text(prop, "Show Sensor Size", "Show sensor size (film gate) in Camera view"); 00266 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00267 00268 prop= RNA_def_property(srna, "lens_unit", PROP_ENUM, PROP_NONE); 00269 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag"); 00270 RNA_def_property_enum_items(prop, prop_lens_unit_items); 00271 RNA_def_property_ui_text(prop, "Lens Unit", "Unit to edit lens in for the user interface"); 00272 00273 prop= RNA_def_property(srna, "use_panorama", PROP_BOOLEAN, PROP_NONE); 00274 RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_PANORAMA); 00275 RNA_def_property_ui_text(prop, "Panorama", "Render the scene with a cylindrical camera for pseudo-fisheye lens effects"); 00276 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00277 00278 /* pointers */ 00279 rna_def_animdata_common(srna); 00280 00281 prop= RNA_def_property(srna, "dof_object", PROP_POINTER, PROP_NONE); 00282 RNA_def_property_struct_type(prop, "Object"); 00283 RNA_def_property_pointer_sdna(prop, NULL, "dof_ob"); 00284 RNA_def_property_flag(prop, PROP_EDITABLE); 00285 RNA_def_property_ui_text(prop, "DOF Object", "Use this object to define the depth of field focal point"); 00286 RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); 00287 00288 /* Camera API */ 00289 RNA_api_camera(srna); 00290 } 00291 00292 #endif 00293