112 BL::Camera &b_camera,
115 BL::Object b_dof_object = b_camera.dof().focus_object();
118 return b_camera.dof().focus_distance();
123 const string focus_subtarget = b_camera.dof().focus_subtarget();
124 if (b_dof_object.pose() && !focus_subtarget.empty()) {
125 BL::PoseBone b_bone = b_dof_object.pose().bones[focus_subtarget];
132 BL::Array<float, 16> b_ob_matrix;
137 return fabsf(
dot(view_dir, dof_dir));
143 case BL::Camera::panorama_type_EQUIRECTANGULAR:
145 case BL::Camera::panorama_type_EQUIANGULAR_CUBEMAP_FACE:
147 case BL::Camera::panorama_type_MIRRORBALL:
149 case BL::Camera::panorama_type_FISHEYE_EQUIDISTANT:
151 case BL::Camera::panorama_type_FISHEYE_EQUISOLID:
153 case BL::Camera::panorama_type_FISHEYE_LENS_POLYNOMIAL:
155 case BL::Camera::panorama_type_CENTRAL_CYLINDRICAL:
163 BL::RenderEngine &b_engine,
165 BL::BlendData &b_data,
166 bool skip_panorama =
false)
168 BL::ID b_ob_data = b_ob.data();
170 if (b_ob_data.is_a(&RNA_Camera)) {
171 BL::Camera b_camera(b_ob_data);
173 bcam->
nearclip = b_camera.clip_start();
174 bcam->
farclip = b_camera.clip_end();
176 switch (b_camera.type()) {
177 case BL::Camera::type_ORTHO:
180 case BL::Camera::type_CUSTOM:
183 case BL::Camera::type_PANO:
186 case BL::Camera::type_PERSP:
213 if (b_camera.stereo().convergence_mode() == BL::CameraStereoData::convergence_mode_PARALLEL) {
227 bcam->
lens = b_camera.lens();
229 bcam->
passepartout_alpha = b_camera.show_passepartout() ? b_camera.passepartout_alpha() : 0.0f;
231 if (b_camera.dof().use_dof()) {
234 float fstop = b_camera.dof().aperture_fstop();
235 fstop =
max(fstop, 1e-5f);
259 bcam->
shift.
y = b_camera.shift_y();
264 if (b_camera.sensor_fit() == BL::Camera::sensor_fit_AUTO) {
267 else if (b_camera.sensor_fit() == BL::Camera::sensor_fit_HORIZONTAL) {
282 b_data, b_camera, b_camera.custom_filepath());
286 else if (b_ob_data.is_a(&RNA_Light)) {
288 BL::SpotLight b_light(b_ob_data);
289 const float lens = 16.0f /
tanf(b_light.spot_size() * 0.5f);
310 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
318 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f);
346 horizontal_fit = (xratio > yratio);
350 horizontal_fit =
true;
354 horizontal_fit =
false;
358 if (horizontal_fit) {
359 aspectratio = xratio / yratio;
363 aspectratio = yratio / xratio;
369 aspect *= bcam->
ortho_scale / (aspectratio * 2.0f);
385 const float2 dv = 2.0f * (aspectratio * bcam->
shift + bcam->
offset * aspect * 2.0f);
432 std::copy(bool_data.
begin(), bool_data.
end(), std::back_inserter(
data));
439 const char *identifier =
"";
442 data.push_back(atoi(identifier));
445 data.push_back(value);
450 data.resize(array_len);
485 const char *viewname,
495 cam->set_viewplane_left(viewplane.
left);
496 cam->set_viewplane_right(viewplane.
right);
497 cam->set_viewplane_top(viewplane.
top);
498 cam->set_viewplane_bottom(viewplane.
bottom);
500 cam->set_full_width(width);
501 cam->set_full_height(height);
515 horizontal_fit = (fit_xratio > fit_yratio);
519 horizontal_fit =
true;
523 horizontal_fit =
false;
527 if (horizontal_fit) {
528 cam->set_sensorwidth(sensor_size);
529 cam->set_sensorheight(sensor_size * fit_yratio / fit_xratio);
532 cam->set_sensorwidth(sensor_size * fit_xratio / fit_yratio);
533 cam->set_sensorheight(sensor_size);
538 if (scene !=
nullptr) {
551 cam->set_farclip(bcam->
farclip);
554 cam->set_camera_type(bcam->
type);
584 if (cam->get_use_spherical_stereo()) {
585 if (strcmp(viewname,
"left") == 0) {
588 else if (strcmp(viewname,
"right") == 0) {
604 cam->set_fov(2.0f *
atanf((0.5f * sensor_size) / bcam->
lens / aspectratio));
615 cam->set_motion(motion);
616 cam->set_use_perspective_motion(
false);
619 cam->set_fov_pre(cam->get_fov());
620 cam->set_fov_post(cam->get_fov());
646 const BL::RenderSettings::motion_blur_position_enum type)
649 case BL::RenderSettings::motion_blur_position_START:
651 case BL::RenderSettings::motion_blur_position_CENTER:
653 case BL::RenderSettings::motion_blur_position_END:
663 const char *viewname)
672 b_render.motion_blur_position());
674 BL::CurveMapping b_shutter_curve(b_render.motion_blur_shutter_curve());
680 "rolling_shutter_type",
686 if (b_render.use_border()) {
690 bcam.
border.
top = b_render.border_max_y();
697 BL::Array<float, 16> b_ob_matrix;
701 scene->bake_manager->set_use_camera(b_render.bake().view_from() ==
702 BL::BakeSettings::view_from_ACTIVE_CAMERA);
705 scene->bake_manager->set_use_camera(
false);
709 Camera *cam = scene->camera;
715 BL::Array<float, 16> b_ob_matrix;
720 blender_camera_sync(scene->dicing_camera,
nullptr, &bcam, width, height, viewname, &cscene);
723 *scene->dicing_camera = *cam;
727BL::Object BlenderSync::get_camera_object(BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d)
729 BL::Object b_camera_override = b_engine.camera_override();
730 if (b_camera_override) {
731 return b_camera_override;
734 if (b_v3d && b_rv3d && b_rv3d.view_perspective() == BL::RegionView3D::view_perspective_CAMERA &&
735 b_v3d.use_local_camera())
737 return b_v3d.camera();
740 return b_scene.camera();
743BL::Object BlenderSync::get_dicing_camera_object(BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d)
746 BL::Object b_ob = BL::Object(
RNA_pointer_get(&cscene,
"dicing_camera"));
751 return get_camera_object(b_v3d, b_rv3d);
754void BlenderSync::sync_camera_motion(BL::RenderSettings &b_render,
758 const float motion_time)
764 Camera *cam = scene->camera;
765 BL::Array<float, 16> b_ob_matrix;
766 b_engine.camera_model_matrix(b_ob, cam->get_use_spherical_stereo(), b_ob_matrix);
770 if (motion_time == 0.0f) {
772 cam->set_matrix(tfm);
776 const int motion_step = cam->
motion_step(motion_time);
777 if (motion_step >= 0) {
778 array<Transform> motion = cam->get_motion();
779 motion[motion_step] = tfm;
780 cam->set_motion(motion);
784 BlenderCamera bcam(b_render);
787 bcam.pixelaspect.x = b_render.pixel_aspect_x();
788 bcam.pixelaspect.y = b_render.pixel_aspect_y();
792 BoundBox2D viewplane;
797 const float fov = 2.0f *
atanf((0.5f * sensor_size) / bcam.lens / aspectratio);
798 if (fov != cam->get_fov()) {
799 LOG_DEBUG <<
"Camera " << b_ob.name() <<
" FOV change detected.";
800 if (motion_time == 0.0f) {
803 else if (motion_time == -1.0f) {
804 cam->set_fov_pre(fov);
805 cam->set_use_perspective_motion(
true);
807 else if (motion_time == 1.0f) {
808 cam->set_fov_post(fov);
809 cam->set_use_perspective_motion(
true);
818 BL::RenderSettings &b_render,
820 BL::BlendData &b_data,
822 BL::SpaceView3D &b_v3d,
823 BL::RegionView3D &b_rv3d,
831 BL::RenderEngine &b_engine,
833 BL::BlendData &b_data,
834 BL::SpaceView3D &b_v3d,
835 BL::RegionView3D &b_rv3d,
838 bool skip_panorama =
false)
841 bcam->
nearclip = b_v3d.clip_start();
842 bcam->
farclip = b_v3d.clip_end();
843 bcam->
lens = b_v3d.lens();
844 bcam->
shuttertime = b_scene.render().motion_blur_shutter();
846 BL::CurveMapping b_shutter_curve(b_scene.render().motion_blur_shutter_curve());
849 if (b_rv3d.view_perspective() == BL::RegionView3D::view_perspective_CAMERA) {
851 BL::Object b_ob = (b_v3d.use_local_camera()) ? b_v3d.camera() : b_scene.camera();
862 BL::RenderSettings b_render_settings(b_scene.render());
881 bcam->
zoom = b_rv3d.view_camera_zoom();
882 bcam->
zoom = (1.41421f + bcam->
zoom / 50.0f);
891 else if (b_rv3d.view_perspective() == BL::RegionView3D::view_perspective_ORTHO) {
905 bcam->
ortho_scale = b_rv3d.view_distance() * sensor_size / b_v3d.lens();
919 BL::RenderSettings &b_render,
921 BL::BlendData &b_data,
923 BL::SpaceView3D &b_v3d,
924 BL::RegionView3D &b_rv3d,
939 &view_bcam, b_engine, b_scene, b_data, b_v3d, b_rv3d, width, height,
true);
955 view_box =
view * (1.0f / view_aspect);
956 cam_box = cam * (1.0f / cam_aspect);
960 BL::RenderSettings &b_render,
962 BL::BlendData &b_data,
963 BL::SpaceView3D &b_v3d,
964 BL::RegionView3D &b_rv3d,
994 BL::RenderEngine &b_engine,
995 BL::RenderSettings &b_render,
997 BL::BlendData &b_data,
998 BL::SpaceView3D &b_v3d,
999 BL::RegionView3D &b_rv3d,
1003 bool is_camera_view;
1006 is_camera_view = b_rv3d.view_perspective() == BL::RegionView3D::view_perspective_CAMERA;
1008 if (!is_camera_view) {
1013 if (b_v3d.use_render_border()) {
1014 bcam->
border.
left = b_v3d.render_border_min_x();
1017 bcam->
border.
top = b_v3d.render_border_max_y();
1022 BL::Object b_ob = (b_v3d.use_local_camera()) ? b_v3d.camera() : b_scene.camera();
1042 if (b_render.use_border()) {
1046 bcam->
border.
top = b_render.border_max_y();
1049 bcam->
border = full_border;
1071 BL::RegionView3D &b_rv3d,
1075 BL::RenderSettings b_render_settings(b_scene.render());
1079 &bcam, b_engine, b_render_settings, b_scene, b_data, b_v3d, b_rv3d, width, height);
1084 BL::Object b_ob = BL::Object(
RNA_pointer_get(&cscene,
"dicing_camera"));
1086 BL::Array<float, 16> b_ob_matrix;
1094 *scene->dicing_camera = *scene->camera;
1099 BL::RegionView3D &b_rv3d,
1105 bool use_border =
false;
1107 params.full_width = width;
1108 params.full_height = height;
1110 if (b_v3d && b_rv3d && b_rv3d.view_perspective() != BL::RegionView3D::view_perspective_CAMERA) {
1111 use_border = b_v3d.use_render_border();
1122 params.full_x = (int)(border.
left * (
float)width);
static float blender_camera_focal_distance(BL::RenderEngine &b_engine, BL::Object &b_ob, BL::Camera &b_camera, BlenderCamera *bcam)
static void blender_camera_border_subset(BL::RenderEngine &b_engine, BL::RenderSettings &b_render, BL::Scene &b_scene, BL::BlendData &b_data, BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, BL::Object &b_ob, const int width, const int height, const BoundBox2D &border, BoundBox2D *result)
static void blender_camera_sync(Camera *cam, Scene *scene, BlenderCamera *bcam, const int width, const int height, const char *viewname, PointerRNA *cscene)
static MotionPosition blender_motion_blur_position_type_to_cycles(const BL::RenderSettings::motion_blur_position_enum type)
static void blender_camera_from_object(BlenderCamera *bcam, BL::RenderEngine &b_engine, BL::Object &b_ob, BL::BlendData &b_data, bool skip_panorama=false)
static PanoramaType blender_panorama_type_to_cycles(const BL::Camera::panorama_type_enum type)
static void blender_camera_view_subset(BL::RenderEngine &b_engine, BL::RenderSettings &b_render, BL::Scene &b_scene, BL::BlendData &b_data, BL::Object &b_ob, BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, const int width, const int height, BoundBox2D &view_box, BoundBox2D &cam_box, float &view_aspect)
static void blender_camera_border(BlenderCamera *bcam, BL::RenderEngine &b_engine, BL::RenderSettings &b_render, BL::Scene &b_scene, BL::BlendData &b_data, BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, const int width, const int height)
static void blender_camera_viewplane(BlenderCamera *bcam, const int width, const int height, BoundBox2D &viewplane, float &aspectratio, float &sensor_size)
static Transform blender_camera_matrix(const Transform &tfm, const CameraType type, const PanoramaType panorama_type)
static void blender_camera_from_view(BlenderCamera *bcam, BL::RenderEngine &b_engine, BL::Scene &b_scene, BL::BlendData &b_data, BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, const int width, const int height, bool skip_panorama=false)
BMesh const char void * data
virtual ~BlenderCameraParamQuery()=default
bool get_string(ustring name, string &data) override
bool get_float(ustring name, vector< float > &data) override
bool get_int(ustring name, vector< int > &data) override
BlenderCameraParamQuery(PointerRNA custom_props)
float central_cylindrical_radius
float rolling_shutter_duration
float central_cylindrical_range_u_min
enum BlenderCamera::@062236323244027147140205312151046053276234130136 sensor_fit
MotionPosition motion_position
string custom_bytecode_hash
bool use_spherical_stereo
float fisheye_polynomial_k2
float fisheye_polynomial_k1
BlenderCamera(BL::RenderSettings &b_render)
array< float > shutter_curve
float fisheye_polynomial_k0
float offscreen_dicing_scale
float central_cylindrical_range_v_min
float fisheye_polynomial_k4
BoundBox2D pano_viewplane
Camera::RollingShutterType rolling_shutter_type
float convergence_distance
float central_cylindrical_range_v_max
float pole_merge_angle_from
float fisheye_polynomial_k3
PanoramaType panorama_type
float central_cylindrical_range_u_max
float pole_merge_angle_to
float interocular_distance
BoundBox2D viewport_camera_border
void sync_camera(BL::RenderSettings &b_render, const int width, const int height, const char *viewname)
void sync_view(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, const int width, const int height)
static BufferParams get_buffer_params(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, Camera *cam, const int width, const int height)
BoundBox2D clamp(const float mn=0.0f, const float mx=1.0f)
BoundBox2D make_relative_to(const BoundBox2D &other) const
BoundBox2D offset(const float2 offset) const
BoundBox2D subset(const BoundBox2D &other) const
OSLCameraParamQuery()=default
T * resize(const size_t newsize)
dot(value.rgb, luminance_coefficients)") DEFINE_VALUE("REDUCE(lhs
static void curvemapping_to_array(BL::CurveMapping &cumap, array< float > &data, const int size)
static uint object_motion_steps(BL::Object &b_parent, BL::Object &b_ob, const int max_steps=INT_MAX)
static int render_resolution_x(BL::RenderSettings &b_render)
static int render_resolution_y(BL::RenderSettings &b_render)
static int get_enum(PointerRNA &ptr, const char *name, int num_values=-1, int default_value=-1)
static string blender_absolute_path(BL::BlendData &b_data, BL::ID &b_id, const string &path)
static float2 get_float2(const BL::Array< float, 2 > &array)
static Transform get_transform(const BL::Array< float, 16 > &array)
#define CCL_NAMESPACE_END
VecBase< float, D > normalize(VecOp< float, D >) RET
@ PANORAMA_FISHEYE_EQUISOLID
@ PANORAMA_CENTRAL_CYLINDRICAL
@ PANORAMA_EQUIANGULAR_CUBEMAP_FACE
@ PANORAMA_FISHEYE_EQUIDISTANT
@ PANORAMA_FISHEYE_LENS_POLYNOMIAL
@ PANORAMA_EQUIRECTANGULAR
ccl_device_inline float2 one_float2()
CCL_NAMESPACE_BEGIN ccl_device_inline float2 zero_float2()
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_identifier)
bool RNA_property_array_check(PropertyRNA *prop)
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
PropertyType RNA_property_type(PropertyRNA *prop)
const PointerRNA PointerRNA_NULL
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
float RNA_float_get(PointerRNA *ptr, const char *name)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
@ ROLLING_SHUTTER_NUM_TYPES
int motion_step(const float time) const
void clear_osl_camera(Scene *scene)
void set_osl_camera(Scene *scene, OSLCameraParamQuery ¶ms, const std::string &filepath, const std::string &bytecode_hash="", const std::string &bytecode="")