Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2011-11-04 18:36:06 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2011-11-04 18:36:06 +0400
commit4ea816837de646af124ffc82758cae37950a0a51 (patch)
tree771c7a0e084446080d6f6d12258585a479bf2887 /source/blender/makesrna/intern
parent82dc05391cdda573f1523325bfd4c6a2a5233323 (diff)
Configurable sensor size:
- Added support of variable size sensor width and height. - Added presets for most common cameras, also new presets can be defined by user. - Added option to control which dimension (vertical or horizontal) of sensor size defines FOV. Old behavior of automatic FOV calculation is also kept. - Renderer, viewport, game engine and collada importer/exporter should deal fine with this changes. Other exporters would be updated soon.
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r--source/blender/makesrna/intern/rna_camera.c122
1 files changed, 106 insertions, 16 deletions
diff --git a/source/blender/makesrna/intern/rna_camera.c b/source/blender/makesrna/intern/rna_camera.c
index 9e89c4aaab0..1e7a969caaa 100644
--- a/source/blender/makesrna/intern/rna_camera.c
+++ b/source/blender/makesrna/intern/rna_camera.c
@@ -40,19 +40,65 @@
#ifdef RNA_RUNTIME
#include "BKE_object.h"
+#include "BKE_depsgraph.h"
/* only for rad/deg conversion! can remove later */
+static float get_camera_sensor(Camera *cam)
+{
+ if(cam->sensor_fit==CAMERA_SENSOR_FIT_AUTO) {
+ return cam->sensor_x;
+ }
+ else if(cam->sensor_fit==CAMERA_SENSOR_FIT_HOR) {
+ return cam->sensor_x;
+ }
+ else {
+ return cam->sensor_y;
+ }
+}
+
static float rna_Camera_angle_get(PointerRNA *ptr)
{
Camera *cam= ptr->id.data;
-
- return lens_to_angle(cam->lens);
+ float sensor= get_camera_sensor(cam);
+ return focallength_to_fov(cam->lens, sensor);
}
static void rna_Camera_angle_set(PointerRNA *ptr, float value)
{
Camera *cam= ptr->id.data;
- cam->lens= angle_to_lens(value);
+ float sensor= get_camera_sensor(cam);
+ cam->lens= fov_to_focallength(value, sensor);
+}
+
+static float rna_Camera_angle_x_get(PointerRNA *ptr)
+{
+ Camera *cam= ptr->id.data;
+ return focallength_to_fov(cam->lens, cam->sensor_x);
+}
+
+static void rna_Camera_angle_x_set(PointerRNA *ptr, float value)
+{
+ Camera *cam= ptr->id.data;
+ cam->lens= fov_to_focallength(value, cam->sensor_x);
+}
+
+static float rna_Camera_angle_y_get(PointerRNA *ptr)
+{
+ Camera *cam= ptr->id.data;
+ return focallength_to_fov(cam->lens, cam->sensor_y);
+}
+
+static void rna_Camera_angle_y_set(PointerRNA *ptr, float value)
+{
+ Camera *cam= ptr->id.data;
+ cam->lens= fov_to_focallength(value, cam->sensor_y);
+}
+
+static void rna_Camera_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+ Camera *camera= (Camera*)ptr->id.data;
+
+ DAG_id_tag_update(&camera->id, 0);
}
#else
@@ -79,6 +125,11 @@ void RNA_def_camera(BlenderRNA *brna)
{0, "MILLIMETERS", 0, "Millimeters", ""},
{CAM_ANGLETOGGLE, "DEGREES", 0, "Degrees", ""},
{0, NULL, 0, NULL, NULL}};
+ static EnumPropertyItem sensor_fit_items[] = {
+ {CAMERA_SENSOR_FIT_AUTO, "AUTO", 0, "Auto", "Calculate field of view using sensor size, with direction depending on image resolution"},
+ {CAMERA_SENSOR_FIT_HOR, "HORIZONTAL", 0, "Horizontal", "Calculate field of view using sensor width"},
+ {CAMERA_SENSOR_FIT_VERT, "VERTICAL", 0, "Vertical", "Calculate field of view using sensor height"},
+ {0, NULL, 0, NULL, NULL}};
srna= RNA_def_struct(brna, "Camera", "ID");
RNA_def_struct_ui_text(srna, "Camera", "Camera datablock for storing camera settings");
@@ -88,7 +139,7 @@ void RNA_def_camera(BlenderRNA *brna)
prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, prop_type_items);
RNA_def_property_ui_text(prop, "Type", "Camera types");
- RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+ RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
prop= RNA_def_property(srna, "show_guide", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "dtx");
@@ -96,7 +147,13 @@ void RNA_def_camera(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_ENUM_FLAG);
RNA_def_property_ui_text(prop, "Composition Guides", "Draw overlay");
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
-
+
+ prop= RNA_def_property(srna, "sensor_fit", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "sensor_fit");
+ RNA_def_property_enum_items(prop, sensor_fit_items);
+ RNA_def_property_ui_text(prop, "Sensor Fit", "Mode of calculating field of view from sensor dimensions and focal length");
+ RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
+
/* Number values */
prop= RNA_def_property(srna, "passepartout_alpha", PROP_FLOAT, PROP_FACTOR);
@@ -104,6 +161,27 @@ void RNA_def_camera(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Passepartout Alpha", "Opacity (alpha) of the darkened overlay in Camera view");
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+ prop= RNA_def_property(srna, "angle_x", PROP_FLOAT, PROP_ANGLE);
+ RNA_def_property_range(prop, M_PI * (0.367/180.0), M_PI * (172.847/180.0));
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_ui_text(prop, "Horizontal FOV", "Camera lens horizontal field of view in degrees");
+ RNA_def_property_float_funcs(prop, "rna_Camera_angle_x_get", "rna_Camera_angle_x_set", NULL);
+ RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
+
+ prop= RNA_def_property(srna, "angle_y", PROP_FLOAT, PROP_ANGLE);
+ RNA_def_property_range(prop, M_PI * (0.367/180.0), M_PI * (172.847/180.0));
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_ui_text(prop, "Vertical FOV", "Camera lens vertical field of view in degrees");
+ RNA_def_property_float_funcs(prop, "rna_Camera_angle_y_get", "rna_Camera_angle_y_set", NULL);
+ RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
+
+ prop= RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE);
+ RNA_def_property_range(prop, M_PI * (0.367/180.0), M_PI * (172.847/180.0));
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_ui_text(prop, "Field of View", "Camera lens field of view in degrees");
+ RNA_def_property_float_funcs(prop, "rna_Camera_angle_get", "rna_Camera_angle_set", NULL);
+ RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
+
prop= RNA_def_property(srna, "clip_start", PROP_FLOAT, PROP_DISTANCE);
RNA_def_property_float_sdna(prop, NULL, "clipsta");
RNA_def_property_range(prop, 0.001f, FLT_MAX);
@@ -120,20 +198,27 @@ void RNA_def_camera(BlenderRNA *brna)
RNA_def_property_float_sdna(prop, NULL, "lens");
RNA_def_property_range(prop, 1.0f, 5000.0f);
RNA_def_property_ui_text(prop, "Focal Length", "Perspective Camera lens value in millimeters");
- RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
-
- prop= RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_range(prop, M_PI * (0.367/180.0), M_PI * (172.847/180.0));
- RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
- RNA_def_property_ui_text(prop, "Angle", "Perspective Camera lens field of view in degrees");
- RNA_def_property_float_funcs(prop, "rna_Camera_angle_get", "rna_Camera_angle_set", NULL); /* only for deg/rad conversion */
- RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+ RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
+
+ prop= RNA_def_property(srna, "sensor_width", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "sensor_x");
+ RNA_def_property_range(prop, 1.0f, FLT_MAX);
+ RNA_def_property_ui_range(prop, 1.0f, 100.f, 1, 2);
+ RNA_def_property_ui_text(prop, "Sensor Width", "Horizontal size of the image sensor area in millimeters");
+ RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
+
+ prop= RNA_def_property(srna, "sensor_height", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "sensor_y");
+ RNA_def_property_range(prop, 1.0f, FLT_MAX);
+ RNA_def_property_ui_range(prop, 1.0f, 100.f, 1, 2);
+ RNA_def_property_ui_text(prop, "Sensor Height", "Vertical size of the image sensor area in millimeters");
+ RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
prop= RNA_def_property(srna, "ortho_scale", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "ortho_scale");
RNA_def_property_range(prop, 0.01f, 4000.0f);
RNA_def_property_ui_text(prop, "Orthographic Scale", "Orthographic Camera scale (similar to zoom)");
- RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+ RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
prop= RNA_def_property(srna, "draw_size", PROP_FLOAT, PROP_DISTANCE);
RNA_def_property_float_sdna(prop, NULL, "drawsize");
@@ -147,14 +232,14 @@ void RNA_def_camera(BlenderRNA *brna)
RNA_def_property_range(prop, -10.0f, 10.0f);
RNA_def_property_ui_range(prop, -2.0, 2.0, 1, 3);
RNA_def_property_ui_text(prop, "Shift X", "Perspective Camera horizontal shift");
- RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+ RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
prop= RNA_def_property(srna, "shift_y", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "shifty");
RNA_def_property_range(prop, -10.0f, 10.0f);
RNA_def_property_ui_range(prop, -2.0, 2.0, 1, 3);
RNA_def_property_ui_text(prop, "Shift Y", "Perspective Camera vertical shift");
- RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+ RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
prop= RNA_def_property(srna, "dof_distance", PROP_FLOAT, PROP_DISTANCE);
RNA_def_property_float_sdna(prop, NULL, "YF_dofdist");
@@ -188,6 +273,11 @@ void RNA_def_camera(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Show Name", "Show the active Camera's name in Camera view");
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+ prop= RNA_def_property(srna, "show_sensor", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOWSENSOR);
+ RNA_def_property_ui_text(prop, "Show Sensor Size", "Show sensor size (film gate) in Camera view");
+ RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+
prop= RNA_def_property(srna, "lens_unit", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
RNA_def_property_enum_items(prop, prop_lens_unit_items);