Merge branch 'blender-v4.4-release'
This commit is contained in:
@@ -7,13 +7,45 @@
|
||||
#include "BKE_camera.h"
|
||||
|
||||
#include "DNA_camera_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_view3d_types.h"
|
||||
|
||||
#include "DEG_depsgraph_query.hh"
|
||||
|
||||
#include "hydra/object.hh"
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
static void gf_camera_fill_dof_data(const Object *camera_obj, pxr::GfCamera *gf_camera)
|
||||
{
|
||||
if (camera_obj == nullptr || camera_obj->type != OB_CAMERA) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Camera *camera = static_cast<Camera *>(camera_obj->data);
|
||||
if (!(camera->dof.flag & CAM_DOF_ENABLED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* World units. Handles DoF object and value. Object takes precedence. */
|
||||
const float focus_distance = BKE_camera_object_dof_distance(camera_obj);
|
||||
gf_camera->SetFocusDistance(focus_distance);
|
||||
|
||||
/*
|
||||
* F-stop is unit-less, however it's a ratio between focal length and aperture diameter.
|
||||
* The aperture must be in the same unit for correctness.
|
||||
* Focal length in GfCamera is defined in tenths of a world unit.
|
||||
*
|
||||
* Following the logic of USD camera data writer:
|
||||
* tenth_unit_to_meters = 1 / 10
|
||||
* tenth_unit_to_millimeters = 1000 * tenth_unit_to_meters = 100
|
||||
* Scene's units scale is not used for camera's focal length.
|
||||
*/
|
||||
gf_camera->SetFStop(camera->dof.aperture_fstop * 100.0);
|
||||
}
|
||||
|
||||
static pxr::GfCamera gf_camera(const CameraParams ¶ms,
|
||||
const pxr::GfVec2i &res,
|
||||
const pxr::GfVec4f &border)
|
||||
@@ -60,6 +92,7 @@ pxr::GfCamera gf_camera(const Depsgraph *depsgraph,
|
||||
const pxr::GfVec4f &border)
|
||||
{
|
||||
const RegionView3D *region_data = (const RegionView3D *)region->regiondata;
|
||||
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
||||
|
||||
CameraParams params;
|
||||
BKE_camera_params_init(¶ms);
|
||||
@@ -68,6 +101,11 @@ pxr::GfCamera gf_camera(const Depsgraph *depsgraph,
|
||||
pxr::GfCamera camera = gf_camera(params, pxr::GfVec2i(region->winx, region->winy), border);
|
||||
camera.SetTransform(io::hydra::gf_matrix_from_transform(region_data->viewmat).GetInverse());
|
||||
|
||||
/* Ensure viewport is in active camera view mode. */
|
||||
if (region_data->persp == RV3D_CAMOB) {
|
||||
gf_camera_fill_dof_data(scene->camera, &camera);
|
||||
}
|
||||
|
||||
return camera;
|
||||
}
|
||||
|
||||
@@ -82,6 +120,8 @@ pxr::GfCamera gf_camera(const Object *camera_obj,
|
||||
pxr::GfCamera camera = gf_camera(params, res, border);
|
||||
camera.SetTransform(io::hydra::gf_matrix_from_transform(camera_obj->object_to_world().ptr()));
|
||||
|
||||
gf_camera_fill_dof_data(camera_obj, &camera);
|
||||
|
||||
return camera;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include "GPU_matrix.hh"
|
||||
|
||||
#include "DEG_depsgraph_query.hh"
|
||||
|
||||
#include "RE_engine.h"
|
||||
|
||||
namespace blender::render::hydra {
|
||||
@@ -44,20 +46,19 @@ ViewSettings::ViewSettings(bContext *context)
|
||||
View3D *view3d = CTX_wm_view3d(context);
|
||||
RegionView3D *region_data = static_cast<RegionView3D *>(CTX_wm_region_data(context));
|
||||
ARegion *region = CTX_wm_region(context);
|
||||
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(context);
|
||||
Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
||||
|
||||
screen_width = region->winx;
|
||||
screen_height = region->winy;
|
||||
|
||||
Scene *scene = CTX_data_scene(context);
|
||||
|
||||
/* Getting render border. */
|
||||
int x1 = 0, y1 = 0;
|
||||
int x2 = screen_width, y2 = screen_height;
|
||||
|
||||
if (region_data->persp == RV3D_CAMOB) {
|
||||
if (scene->r.mode & R_BORDER) {
|
||||
Object *camera_obj = scene->camera;
|
||||
|
||||
Object *camera_obj = scene->camera;
|
||||
if ((scene->r.mode & R_BORDER) && camera_obj && camera_obj->type == OB_CAMERA) {
|
||||
float camera_points[4][3];
|
||||
BKE_camera_view_frame(scene, static_cast<Camera *>(camera_obj->data), camera_points);
|
||||
|
||||
@@ -113,7 +114,7 @@ ViewSettings::ViewSettings(bContext *context)
|
||||
|
||||
border = pxr::GfVec4i(x1, y1, x2, y2);
|
||||
|
||||
camera = gf_camera(CTX_data_ensure_evaluated_depsgraph(context),
|
||||
camera = gf_camera(depsgraph,
|
||||
view3d,
|
||||
region,
|
||||
pxr::GfVec4f(float(border[0]) / screen_width,
|
||||
|
||||
Reference in New Issue
Block a user