Fix T55165: Driving camera lens with property behaves unexpectedly
authorDalai Felinto <dfelinto@gmail.com>
Fri, 25 May 2018 09:05:51 +0000 (11:05 +0200)
committerDalai Felinto <dfelinto@gmail.com>
Fri, 25 May 2018 10:48:33 +0000 (12:48 +0200)
Differential Revision: https://developer.blender.org/D3438

15 files changed:
source/blender/blenkernel/BKE_camera.h
source/blender/blenkernel/BKE_constraint.h
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/camera.c
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/object_update.c
source/blender/editors/include/ED_view3d.h
source/blender/editors/sculpt_paint/paint_image_proj.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_utils.c
source/blender/editors/space_view3d/view3d_view.c
source/blender/makesrna/intern/rna_object_api.c
source/blender/modifiers/intern/MOD_uvproject.c

index c647dd3..eb05e66 100644 (file)
@@ -129,9 +129,9 @@ bool BKE_camera_view_frame_fit_to_scene(
         struct Scene *scene, struct ViewLayer *view_layer, struct Object *camera_ob,
         float r_co[3], float *r_scale);
 bool BKE_camera_view_frame_fit_to_coords(
-        const struct Scene *scene,
+        const struct Depsgraph *depsgraph,
         const float (*cos)[3], int num_cos,
-        const struct Object *camera_ob,
+        struct Object *camera_ob,
         float r_co[3], float *r_scale);
 
 void BKE_camera_to_gpu_dof(struct Object *camera, struct GPUFXSettings *r_fx_settings);
@@ -139,11 +139,11 @@ void BKE_camera_to_gpu_dof(struct Object *camera, struct GPUFXSettings *r_fx_set
 /* Camera multi-view API */
 
 struct Object *BKE_camera_multiview_render(struct Scene *scene, struct Object *camera, const char *viewname);
-void           BKE_camera_multiview_view_matrix(struct RenderData *rd, struct Object *camera, const bool is_left, float r_viewmat[4][4]);
-void           BKE_camera_multiview_model_matrix(struct RenderData *rd, struct Object *camera, const char *viewname, float r_modelmat[4][4]);
-float          BKE_camera_multiview_shift_x(struct RenderData *rd, struct Object *camera, const char *viewname);
-void           BKE_camera_multiview_params(struct RenderData *rd, struct CameraParams *params, struct Object *camera, const char *viewname);
-bool           BKE_camera_multiview_spherical_stereo(struct RenderData *rd, struct Object *camera);
+void           BKE_camera_multiview_view_matrix(struct RenderData *rd, const struct Object *camera, const bool is_left, float r_viewmat[4][4]);
+void           BKE_camera_multiview_model_matrix(struct RenderData *rd, const struct Object *camera, const char *viewname, float r_modelmat[4][4]);
+float          BKE_camera_multiview_shift_x(struct RenderData *rd, const struct Object *camera, const char *viewname);
+void           BKE_camera_multiview_params(struct RenderData *rd, struct CameraParams *params, const struct Object *camera, const char *viewname);
+bool           BKE_camera_multiview_spherical_stereo(struct RenderData *rd, const struct Object *camera);
 
 /* Camera background image API */
 struct CameraBGImage *BKE_camera_background_image_new(struct Camera *cam);
index 18f6301..98ba0f6 100644 (file)
@@ -49,6 +49,7 @@ extern "C" {
 
 /* special struct for use in constraint evaluation */
 typedef struct bConstraintOb {
+       struct Depsgraph *depsgraph;/* to get evaluated armature. */
        struct Scene *scene;        /* for system time, part of deglobalization, code nicer later with local time (ton) */
        struct Object *ob;          /* if pchan, then armature that it comes from, otherwise constraint owner */
        struct bPoseChannel *pchan; /* pose channel that owns the constraints being evaluated */
@@ -144,7 +145,7 @@ void BKE_constraints_proxylocal_extract(struct ListBase *dst, struct ListBase *s
 bool BKE_constraints_proxylocked_owner(struct Object *ob, struct bPoseChannel *pchan);
 
 /* Constraint Evaluation function prototypes */
-struct bConstraintOb *BKE_constraints_make_evalob(struct Scene *scene, struct Object *ob, void *subdata, short datatype);
+struct bConstraintOb *BKE_constraints_make_evalob(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, void *subdata, short datatype);
 void                  BKE_constraints_clear_evalob(struct bConstraintOb *cob);
 
 void BKE_constraint_mat_convertspace(
index f80096b..8dbfc35 100644 (file)
@@ -2239,7 +2239,7 @@ void BKE_pose_where_is_bone(
                        /* prepare PoseChannel for Constraint solving
                         * - makes a copy of matrix, and creates temporary struct to use
                         */
-                       cob = BKE_constraints_make_evalob(scene, ob, pchan, CONSTRAINT_OBTYPE_BONE);
+                       cob = BKE_constraints_make_evalob(depsgraph, scene, ob, pchan, CONSTRAINT_OBTYPE_BONE);
 
                        /* Solve PoseChannel's Constraints */
                        BKE_constraints_solve(depsgraph, &pchan->constraints, cob, ctime); /* ctime doesnt alter objects */
index f365ff0..b1b4f18 100644 (file)
@@ -268,7 +268,7 @@ void BKE_camera_params_from_view3d(CameraParams *params, Depsgraph *depsgraph, c
 
        if (rv3d->persp == RV3D_CAMOB) {
                /* camera view */
-               Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, v3d->camera);
+               const Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, v3d->camera);
                BKE_camera_params_from_object(params, ob_camera_eval);
 
                params->zoom = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom);
@@ -666,16 +666,18 @@ bool BKE_camera_view_frame_fit_to_scene(
 }
 
 bool BKE_camera_view_frame_fit_to_coords(
-        const Scene *scene, const float (*cos)[3], int num_cos, const Object *camera_ob,
+        const Depsgraph *depsgraph, const float (*cos)[3], int num_cos, Object *camera_ob,
         float r_co[3], float *r_scale)
 {
+       Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
+       Object *camera_ob_eval = DEG_get_evaluated_object(depsgraph, camera_ob);
        CameraParams params;
        CameraViewFrameData data_cb;
 
        /* just in case */
        *r_scale = 1.0f;
 
-       camera_frame_fit_data_init(scene, camera_ob, &params, &data_cb);
+       camera_frame_fit_data_init(scene_eval, camera_ob_eval, &params, &data_cb);
 
        /* run callback on all given coordinates */
        while (num_cos--) {
@@ -687,12 +689,12 @@ bool BKE_camera_view_frame_fit_to_coords(
 
 /******************* multiview matrix functions ***********************/
 
-static void camera_model_matrix(Object *camera, float r_modelmat[4][4])
+static void camera_model_matrix(const Object *camera, float r_modelmat[4][4])
 {
        copy_m4_m4(r_modelmat, camera->obmat);
 }
 
-static void camera_stereo3d_model_matrix(Object *camera, const bool is_left, float r_modelmat[4][4])
+static void camera_stereo3d_model_matrix(const Object *camera, const bool is_left, float r_modelmat[4][4])
 {
        Camera *data = (Camera *)camera->data;
        float interocular_distance, convergence_distance;
@@ -790,7 +792,7 @@ static void camera_stereo3d_model_matrix(Object *camera, const bool is_left, flo
 }
 
 /* the view matrix is used by the viewport drawing, it is basically the inverted model matrix */
-void BKE_camera_multiview_view_matrix(RenderData *rd, Object *camera, const bool is_left, float r_viewmat[4][4])
+void BKE_camera_multiview_view_matrix(RenderData *rd, const Object *camera, const bool is_left, float r_viewmat[4][4])
 {
        BKE_camera_multiview_model_matrix(rd, camera, is_left ? STEREO_LEFT_NAME : STEREO_RIGHT_NAME, r_viewmat);
        invert_m4(r_viewmat);
@@ -805,7 +807,7 @@ static bool camera_is_left(const char *viewname)
        return true;
 }
 
-void BKE_camera_multiview_model_matrix(RenderData *rd, Object *camera, const char *viewname, float r_modelmat[4][4])
+void BKE_camera_multiview_model_matrix(RenderData *rd, const Object *camera, const char *viewname, float r_modelmat[4][4])
 {
        const bool is_multiview = (rd && rd->scemode & R_MULTIVIEW) != 0;
 
@@ -822,7 +824,7 @@ void BKE_camera_multiview_model_matrix(RenderData *rd, Object *camera, const cha
        normalize_m4(r_modelmat);
 }
 
-bool BKE_camera_multiview_spherical_stereo(RenderData *rd, Object *camera)
+bool BKE_camera_multiview_spherical_stereo(RenderData *rd, const Object *camera)
 {
        Camera *cam;
        const bool is_multiview = (rd && rd->scemode & R_MULTIVIEW) != 0;
@@ -895,7 +897,7 @@ Object *BKE_camera_multiview_render(Scene *scene, Object *camera, const char *vi
        }
 }
 
-static float camera_stereo3d_shift_x(Object *camera, const char *viewname)
+static float camera_stereo3d_shift_x(const Object *camera, const char *viewname)
 {
        Camera *data = camera->data;
        float shift = data->shiftx;
@@ -933,7 +935,7 @@ static float camera_stereo3d_shift_x(Object *camera, const char *viewname)
        return shift;
 }
 
-float BKE_camera_multiview_shift_x(RenderData *rd, Object *camera, const char *viewname)
+float BKE_camera_multiview_shift_x(RenderData *rd, const Object *camera, const char *viewname)
 {
        const bool is_multiview = (rd && rd->scemode & R_MULTIVIEW) != 0;
        Camera *data = camera->data;
@@ -951,7 +953,7 @@ float BKE_camera_multiview_shift_x(RenderData *rd, Object *camera, const char *v
        }
 }
 
-void BKE_camera_multiview_params(RenderData *rd, CameraParams *params, Object *camera, const char *viewname)
+void BKE_camera_multiview_params(RenderData *rd, CameraParams *params, const Object *camera, const char *viewname)
 {
        if (camera->type == OB_CAMERA) {
                params->shiftx = BKE_camera_multiview_shift_x(rd, camera, viewname);
index 6a477c9..5cdf011 100644 (file)
@@ -84,6 +84,9 @@
 
 #include "BIK_api.h"
 
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
 #ifdef WITH_PYTHON
 #  include "BPY_extern.h"
 #endif
@@ -116,7 +119,7 @@ void BKE_constraint_unique_name(bConstraint *con, ListBase *list)
 
 /* package an object/bone for use in constraint evaluation */
 /* This function MEM_calloc's a bConstraintOb struct, that will need to be freed after evaluation */
-bConstraintOb *BKE_constraints_make_evalob(Scene *scene, Object *ob, void *subdata, short datatype)
+bConstraintOb *BKE_constraints_make_evalob(Depsgraph *depsgraph, Scene *scene, Object *ob, void *subdata, short datatype)
 {
        bConstraintOb *cob;
        
@@ -125,6 +128,7 @@ bConstraintOb *BKE_constraints_make_evalob(Scene *scene, Object *ob, void *subda
        
        /* for system time, part of deglobalization, code nicer later with local time (ton) */
        cob->scene = scene;
+       cob->depsgraph = depsgraph;
        
        /* based on type of available data */
        switch (datatype) {
@@ -3903,20 +3907,25 @@ static void followtrack_id_looper(bConstraint *con, ConstraintIDFunc func, void
 
 static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
 {
+       Depsgraph *depsgraph = cob->depsgraph;
        Scene *scene = cob->scene;
        bFollowTrackConstraint *data = con->data;
        MovieClip *clip = data->clip;
        MovieTracking *tracking;
        MovieTrackingTrack *track;
        MovieTrackingObject *tracking_object;
-       Object *camob = data->camera ? data->camera : scene->camera;
+
+       Object *camob_eval = DEG_get_evaluated_object(
+                                depsgraph,
+                                data->camera ? data->camera : scene->camera);
+
        float ctime = BKE_scene_frame_get(scene);
        float framenr;
 
        if (data->flag & FOLLOWTRACK_ACTIVECLIP)
                clip = scene->clip;
 
-       if (!clip || !data->track[0] || !camob)
+       if (!clip || !data->track[0] || !camob_eval)
                return;
 
        tracking = &clip->tracking;
@@ -3945,7 +3954,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase
                        if ((tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0) {
                                float imat[4][4];
 
-                               copy_m4_m4(mat, camob->obmat);
+                               copy_m4_m4(mat, camob_eval->obmat);
 
                                BKE_tracking_camera_get_reconstructed_interpolate(tracking, tracking_object, framenr, imat);
                                invert_m4(imat);
@@ -3954,7 +3963,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase
                                translate_m4(cob->matrix, track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
                        }
                        else {
-                               BKE_tracking_get_camera_object_matrix(cob->scene, camob, mat);
+                               BKE_tracking_get_camera_object_matrix(cob->scene, camob_eval, mat);
 
                                mul_m4_m4m4(cob->matrix, obmat, mat);
                                translate_m4(cob->matrix, track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
@@ -3966,7 +3975,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase
                float aspect = (scene->r.xsch * scene->r.xasp) / (scene->r.ysch * scene->r.yasp);
                float len, d;
 
-               BKE_object_where_is_calc_mat4(scene, camob, mat);
+               BKE_object_where_is_calc_mat4(scene, camob_eval, mat);
 
                /* camera axis */
                vec[0] = 0.0f;
@@ -4034,7 +4043,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase
                        }
 
                        BKE_camera_params_init(&params);
-                       BKE_camera_params_from_object(&params, camob);
+                       BKE_camera_params_from_object(&params, camob_eval);
 
                        if (params.is_ortho) {
                                vec[0] = params.ortho_scale * (pos[0] - 0.5f + params.shiftx);
@@ -4046,9 +4055,9 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase
                                else
                                        vec[0] *= aspect;
 
-                               mul_v3_m4v3(disp, camob->obmat, vec);
+                               mul_v3_m4v3(disp, camob_eval->obmat, vec);
 
-                               copy_m4_m4(rmat, camob->obmat);
+                               copy_m4_m4(rmat, camob_eval->obmat);
                                zero_v3(rmat[3]);
                                mul_m4_m4m4(cob->matrix, cob->matrix, rmat);
 
@@ -4066,10 +4075,10 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase
                                else
                                        vec[0] *= aspect;
 
-                               mul_v3_m4v3(disp, camob->obmat, vec);
+                               mul_v3_m4v3(disp, camob_eval->obmat, vec);
 
                                /* apply camera rotation so Z-axis would be co-linear */
-                               copy_m4_m4(rmat, camob->obmat);
+                               copy_m4_m4(rmat, camob_eval->obmat);
                                zero_v3(rmat[3]);
                                mul_m4_m4m4(cob->matrix, cob->matrix, rmat);
 
@@ -4088,7 +4097,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase
 
                                        invert_m4_m4(imat, depth_ob->obmat);
 
-                                       mul_v3_m4v3(ray_start, imat, camob->obmat[3]);
+                                       mul_v3_m4v3(ray_start, imat, camob_eval->obmat[3]);
                                        mul_v3_m4v3(ray_end, imat, cob->matrix[3]);
 
                                        sub_v3_v3v3(ray_nor, ray_end, ray_start);
@@ -4811,6 +4820,7 @@ void BKE_constraint_target_matrix_get(struct Depsgraph *depsgraph, Scene *scene,
                cob = MEM_callocN(sizeof(bConstraintOb), "tempConstraintOb");
                cob->type = ownertype;
                cob->scene = scene;
+               cob->depsgraph = depsgraph;
                switch (ownertype) {
                        case CONSTRAINT_OBTYPE_OBJECT: /* it is usually this case */
                        {
index e36e527..39e1906 100644 (file)
@@ -2132,7 +2132,7 @@ void BKE_object_where_is_calc_time_ex(
        /* solve constraints */
        if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) {
                bConstraintOb *cob;
-               cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
+               cob = BKE_constraints_make_evalob(depsgraph, scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
                BKE_constraints_solve(depsgraph, &ob->constraints, cob, ctime);
                BKE_constraints_clear_evalob(cob);
        }
index 91571e8..2d499e4 100644 (file)
@@ -128,7 +128,7 @@ void BKE_object_eval_constraints(Depsgraph *depsgraph,
         * Not sure why, this is from Joshua - sergey
         *
         */
-       cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
+       cob = BKE_constraints_make_evalob(depsgraph, scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
        BKE_constraints_solve(depsgraph, &ob->constraints, cob, ctime);
        BKE_constraints_clear_evalob(cob);
 }
index 0a8eced..e1a6d59 100644 (file)
@@ -106,9 +106,11 @@ void   ED_view3d_cursor3d_update(struct bContext *C, const int mval[2]);
 struct Camera *ED_view3d_camera_data_get(struct View3D *v3d, struct RegionView3D *rv3d);
 
 void ED_view3d_to_m4(float mat[4][4], const float ofs[3], const float quat[4], const float dist);
-void ED_view3d_from_m4(float mat[4][4], float ofs[3], float quat[4], float *dist);
+void ED_view3d_from_m4(const float mat[4][4], float ofs[3], float quat[4], float *dist);
 
-void ED_view3d_from_object(struct Object *ob, float ofs[3], float quat[4], float *dist, float *lens);
+void ED_view3d_from_object(
+        const struct Object *ob,
+        float ofs[3], float quat[4], float *dist, float *lens);
 void ED_view3d_to_object(
         const struct Depsgraph *depsgraph, struct Object *ob,
         const float ofs[3], const float quat[4], const float dist);
@@ -305,6 +307,7 @@ float ED_view3d_radius_to_dist_persp(const float angle, const float radius);
 float ED_view3d_radius_to_dist_ortho(const float lens, const float radius);
 float ED_view3d_radius_to_dist(
         const struct View3D *v3d, const struct ARegion *ar,
+        const struct Depsgraph *depsgraph,
         const char persp, const bool use_aspect,
         const float radius);
 
index a1435d5..76449b6 100644 (file)
@@ -81,6 +81,7 @@
 #include "BKE_texture.h"
 
 #include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
 
 #include "UI_interface.h"
 
@@ -3083,7 +3084,7 @@ static void proj_paint_state_non_cddm_init(ProjPaintState *ps)
 }
 
 static void proj_paint_state_viewport_init(
-        ProjPaintState *ps, const char symmetry_flag)
+        ProjPaintState *ps, const Depsgraph *depsgraph, const char symmetry_flag)
 {
        float mat[3][3];
        float viewmat[4][4];
@@ -3144,17 +3145,17 @@ static void proj_paint_state_viewport_init(
                        invert_m4_m4(viewinv, viewmat);
                }
                else if (ps->source == PROJ_SRC_IMAGE_CAM) {
-                       Object *cam_ob = ps->scene->camera;
+                       Object *cam_ob_eval = DEG_get_evaluated_object(depsgraph, ps->scene->camera);
                        CameraParams params;
 
                        /* viewmat & viewinv */
-                       copy_m4_m4(viewinv, cam_ob->obmat);
+                       copy_m4_m4(viewinv, cam_ob_eval->obmat);
                        normalize_m4(viewinv);
                        invert_m4_m4(viewmat, viewinv);
 
                        /* window matrix, clipping and ortho */
                        BKE_camera_params_init(&params);
-                       BKE_camera_params_from_object(&params, cam_ob);
+                       BKE_camera_params_from_object(&params, cam_ob_eval);
                        BKE_camera_params_compute_viewplane(&params, ps->winx, ps->winy, 1.0f, 1.0f);
                        BKE_camera_params_compute_matrix(&params);
 
@@ -3858,7 +3859,7 @@ static void project_paint_begin(
                proj_paint_state_cavity_init(ps);
        }
 
-       proj_paint_state_viewport_init(ps, symmetry_flag);
+       proj_paint_state_viewport_init(ps, CTX_data_depsgraph(C), symmetry_flag);
 
        /* calculate vert screen coords
         * run this early so we can calculate the x/y resolution of our bucket rect */
index 1695063..b44e2da 100644 (file)
@@ -302,6 +302,7 @@ static void view3d_camera_border(
 {
        CameraParams params;
        rctf rect_view, rect_camera;
+       Object *camera_eval = DEG_get_evaluated_object(depsgraph, v3d->camera);
 
        /* get viewport viewplane */
        BKE_camera_params_init(&params);
@@ -316,7 +317,7 @@ static void view3d_camera_border(
        /* fallback for non camera objects */
        params.clipsta = v3d->near;
        params.clipend = v3d->far;
-       BKE_camera_params_from_object(&params, v3d->camera);
+       BKE_camera_params_from_object(&params, camera_eval);
        if (no_shift) {
                params.shiftx = 0.0f;
                params.shifty = 0.0f;
@@ -1417,13 +1418,16 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
        if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
                CameraParams params;
                Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
+               const Object *camera_eval = DEG_get_evaluated_object(
+                                               depsgraph,
+                                               camera);
 
                BKE_camera_params_init(&params);
                /* fallback for non camera objects */
                params.clipsta = v3d->near;
                params.clipend = v3d->far;
-               BKE_camera_params_from_object(&params, camera);
-               BKE_camera_multiview_params(&scene->r, &params, camera, viewname);
+               BKE_camera_params_from_object(&params, camera_eval);
+               BKE_camera_multiview_params(&scene->r, &params, camera_eval, viewname);
                BKE_camera_params_compute_viewplane(&params, sizex, sizey, scene->r.xasp, scene->r.yasp);
                BKE_camera_params_compute_matrix(&params);
 
@@ -1597,11 +1601,13 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
 
        {
                CameraParams params;
-               Object *view_camera = BKE_camera_multiview_render(scene, v3d.camera, viewname);
+               const Object *view_camera_eval = DEG_get_evaluated_object(
+                                                    depsgraph,
+                                                    BKE_camera_multiview_render(scene, v3d.camera, viewname));
 
                BKE_camera_params_init(&params);
-               BKE_camera_params_from_object(&params, view_camera);
-               BKE_camera_multiview_params(&scene->r, &params, view_camera, viewname);
+               BKE_camera_params_from_object(&params, view_camera_eval);
+               BKE_camera_multiview_params(&scene->r, &params, view_camera_eval, viewname);
                BKE_camera_params_compute_viewplane(&params, width, height, scene->r.xasp, scene->r.yasp);
                BKE_camera_params_compute_matrix(&params);
 
index cd5a18b..66eaf34 100644 (file)
@@ -2654,7 +2654,7 @@ static void view3d_from_minmax(
                }
 
                if (ok_dist) {
-                       new_dist = ED_view3d_radius_to_dist(v3d, ar, persp, true, (size / 2) * VIEW3D_MARGIN);
+                       new_dist = ED_view3d_radius_to_dist(v3d, ar, CTX_data_depsgraph(C), persp, true, (size / 2) * VIEW3D_MARGIN);
                        if (rv3d->is_persp) {
                                /* don't zoom closer than the near clipping plane */
                                new_dist = max_ff(new_dist, v3d->near * 1.5f);
@@ -3678,7 +3678,8 @@ static void axis_set_view(
                dist = rv3d->dist;
 
                /* so we animate _from_ the camera location */
-               ED_view3d_from_object(v3d->camera, rv3d->ofs, NULL, &rv3d->dist, NULL);
+               Object *camera_eval = DEG_get_evaluated_object(CTX_data_depsgraph(C), v3d->camera);
+               ED_view3d_from_object(camera_eval, rv3d->ofs, NULL, &rv3d->dist, NULL);
 
                ED_view3d_smooth_view(
                        C, v3d, ar, smooth_viewtx,
index e18370d..90b1b04 100644 (file)
@@ -1067,6 +1067,7 @@ float ED_view3d_radius_to_dist_ortho(const float lens, const float radius)
  */
 float ED_view3d_radius_to_dist(
         const View3D *v3d, const ARegion *ar,
+        const struct Depsgraph *depsgraph,
         const char persp, const bool use_aspect,
         const float radius)
 {
@@ -1087,7 +1088,8 @@ float ED_view3d_radius_to_dist(
                        BKE_camera_params_init(&params);
                        params.clipsta = v3d->near;
                        params.clipend = v3d->far;
-                       BKE_camera_params_from_object(&params, v3d->camera);
+                       Object *camera_eval = DEG_get_evaluated_object(depsgraph, v3d->camera);
+                       BKE_camera_params_from_object(&params, camera_eval);
 
                        lens = params.lens;
                        sensor_size = BKE_camera_sensor_size(params.sensor_fit, params.sensor_x, params.sensor_y);
@@ -1277,7 +1279,7 @@ bool ED_view3d_lock(RegionView3D *rv3d)
  * \param quat The view rotation, quaternion normally from RegionView3D.viewquat.
  * \param dist The view distance from ofs, normally from RegionView3D.dist.
  */
-void ED_view3d_from_m4(float mat[4][4], float ofs[3], float quat[4], float *dist)
+void ED_view3d_from_m4(const float mat[4][4], float ofs[3], float quat[4], float *dist)
 {
        float nmat[3][3];
 
@@ -1322,13 +1324,14 @@ void ED_view3d_to_m4(float mat[4][4], const float ofs[3], const float quat[4], c
 
 /**
  * Set the RegionView3D members from an objects transformation and optionally lens.
+ * \param depsgraph The depsgraph to get the evaluated object for the lens calculation.
  * \param ob The object to set the view to.
  * \param ofs The view offset to be set, normally from RegionView3D.ofs.
  * \param quat The view rotation to be set, quaternion normally from RegionView3D.viewquat.
  * \param dist The view distance from ofs to be set, normally from RegionView3D.dist.
  * \param lens The view lens angle set for cameras and lamps, normally from View3D.lens.
  */
-void ED_view3d_from_object(Object *ob, float ofs[3], float quat[4], float *dist, float *lens)
+void ED_view3d_from_object(const Object *ob, float ofs[3], float quat[4], float *dist, float *lens)
 {
        ED_view3d_from_m4(ob->obmat, ofs, quat, dist);
 
@@ -1343,6 +1346,7 @@ void ED_view3d_from_object(Object *ob, float ofs[3], float quat[4], float *dist,
 
 /**
  * Set the object transformation from RegionView3D members.
+ * \param depsgraph The depsgraph to get the evaluated object parent for the transformation calculation.
  * \param ob The object which has the transformation assigned.
  * \param ofs The view offset, normally from RegionView3D.ofs.
  * \param quat The view rotation, quaternion normally from RegionView3D.viewquat.
index 2fe95f5..abf6146 100644 (file)
@@ -48,6 +48,7 @@
 #include "BKE_scene.h"
 
 #include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
 
 #include "UI_resources.h"
 
@@ -513,25 +514,26 @@ static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op)
        ViewLayer *view_layer = CTX_data_view_layer(C);
        View3D *v3d = CTX_wm_view3d(C);  /* can be NULL */
        Object *camera_ob = v3d ? v3d->camera : scene->camera;
+       Object *camera_ob_eval = DEG_get_evaluated_object(depsgraph, camera_ob);
 
        float r_co[3]; /* the new location to apply */
        float r_scale; /* only for ortho cameras */
 
-       if (camera_ob == NULL) {
+       if (camera_ob_eval == NULL) {
                BKE_report(op->reports, RPT_ERROR, "No active camera");
                return OPERATOR_CANCELLED;
        }
 
        /* this function does all the important stuff */
-       if (BKE_camera_view_frame_fit_to_scene(depsgraph, scene, view_layer, camera_ob, r_co, &r_scale)) {
+       if (BKE_camera_view_frame_fit_to_scene(depsgraph, scene, view_layer, camera_ob_eval, r_co, &r_scale)) {
                ObjectTfmProtectedChannels obtfm;
                float obmat_new[4][4];
 
-               if ((camera_ob->type == OB_CAMERA) && (((Camera *)camera_ob->data)->type == CAM_ORTHO)) {
+               if ((camera_ob_eval->type == OB_CAMERA) && (((Camera *)camera_ob_eval->data)->type == CAM_ORTHO)) {
                        ((Camera *)camera_ob->data)->ortho_scale = r_scale;
                }
 
-               copy_m4_m4(obmat_new, camera_ob->obmat);
+               copy_m4_m4(obmat_new, camera_ob_eval->obmat);
                copy_v3_v3(obmat_new[3], r_co);
 
                /* only touch location */
index 04507d1..a01192d 100644 (file)
@@ -89,6 +89,8 @@ static const EnumPropertyItem space_items[] = {
 #include "DNA_scene_types.h"
 #include "DNA_view3d_types.h"
 
+#include "DEG_depsgraph_query.h"
+
 #include "MEM_guardedalloc.h"
 
 static void rna_Object_select_set(Object *ob, bContext *C, ReportList *reports, int action)
@@ -173,13 +175,14 @@ static void rna_Object_mat_convert_space(Object *ob, ReportList *reports, bPoseC
 }
 
 static void rna_Object_calc_matrix_camera(
-        Object *ob, float mat_ret[16], int width, int height, float scalex, float scaley)
+        Object *ob, Depsgraph *depsgraph, float mat_ret[16], int width, int height, float scalex, float scaley)
 {
+       const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
        CameraParams params;
 
        /* setup parameters */
        BKE_camera_params_init(&params);
-       BKE_camera_params_from_object(&params, ob);
+       BKE_camera_params_from_object(&params, ob_eval);
 
        /* compute matrix, viewplane, .. */
        BKE_camera_params_compute_viewplane(&params, width, height, scalex, scaley);
@@ -189,9 +192,9 @@ static void rna_Object_calc_matrix_camera(
 }
 
 static void rna_Object_camera_fit_coords(
-        Object *ob, Scene *scene, int num_cos, float *cos, float co_ret[3], float *scale_ret)
+        Object *ob, Depsgraph *depsgraph, int num_cos, float *cos, float co_ret[3], float *scale_ret)
 {
-       BKE_camera_view_frame_fit_to_coords(scene, (const float (*)[3])cos, num_cos / 3, ob, co_ret, scale_ret);
+       BKE_camera_view_frame_fit_to_coords(depsgraph, (const float (*)[3])cos, num_cos / 3, ob, co_ret, scale_ret);
 }
 
 /* copied from Mesh_getFromObject and adapted to RNA interface */
@@ -518,6 +521,9 @@ void RNA_api_object(StructRNA *srna)
        func = RNA_def_function(srna, "calc_matrix_camera", "rna_Object_calc_matrix_camera");
        RNA_def_function_ui_description(func, "Generate the camera projection matrix of this object "
                                              "(mostly useful for Camera and Lamp types)");
+       parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "",
+                              "Depsgraph to get evaluated data from");
+       RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
        parm = RNA_def_property(func, "result", PROP_FLOAT, PROP_MATRIX);
        RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
        RNA_def_property_ui_text(parm, "", "The camera projection matrix");
@@ -530,7 +536,8 @@ void RNA_api_object(StructRNA *srna)
        func = RNA_def_function(srna, "camera_fit_coords", "rna_Object_camera_fit_coords");
        RNA_def_function_ui_description(func, "Compute the coordinate (and scale for ortho cameras) "
                                              "given object should be to 'see' all given coordinates");
-       parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene to get render size information from, if available");
+       parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "",
+                              "Depsgraph to get evaluated data from");
        RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
        parm = RNA_def_float_array(func, "coordinates", 1, NULL, -FLT_MAX, FLT_MAX, "", "Coordinates to fit in",
                                   -FLT_MAX, FLT_MAX);
index 207c692..b491496 100644 (file)
@@ -55,7 +55,9 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DEG_depsgraph.h"
 #include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
 
 static void initData(ModifierData *md)
 {
@@ -111,7 +113,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
 }
 
 typedef struct Projector {
-       Object *ob;             /* object this projector is derived from */
+       Object *ob_eval;             /* object this projector is derived from */
        float projmat[4][4];    /* projection matrix */
        float normal[3];        /* projector normal in world space */
        void *uci;              /* optional uv-project info (panorama projection) */
@@ -119,6 +121,7 @@ typedef struct Projector {
 
 static Mesh *uvprojectModifier_do(
         UVProjectModifierData *umd,
+        Depsgraph *depsgraph,
         Object *ob, Mesh *mesh)
 {
        float (*coords)[3], (*co)[3];
@@ -137,7 +140,7 @@ static Mesh *uvprojectModifier_do(
 
        for (i = 0; i < umd->num_projectors; ++i)
                if (umd->projectors[i])
-                       projectors[num_projectors++].ob = umd->projectors[i];
+                       projectors[num_projectors++].ob_eval = DEG_get_evaluated_object(depsgraph, umd->projectors[i]);
 
        if (num_projectors == 0) return mesh;
 
@@ -154,15 +157,14 @@ static Mesh *uvprojectModifier_do(
                float offsetmat[4][4];
                Camera *cam = NULL;
                /* calculate projection matrix */
-               invert_m4_m4(projectors[i].projmat, projectors[i].ob->obmat);
+               invert_m4_m4(projectors[i].projmat, projectors[i].ob_eval->obmat);
 
                projectors[i].uci = NULL;
 
-               if (projectors[i].ob->type == OB_CAMERA) {
-                       
-                       cam = (Camera *)projectors[i].ob->data;
+               if (projectors[i].ob_eval->type == OB_CAMERA) {
+                       cam = (Camera *)projectors[i].ob_eval->data;
                        if (cam->type == CAM_PANO) {
-                               projectors[i].uci = BLI_uvproject_camera_info(projectors[i].ob, NULL, aspx, aspy);
+                               projectors[i].uci = BLI_uvproject_camera_info(projectors[i].ob_eval, NULL, aspx, aspy);
                                BLI_uvproject_camera_info_scale(projectors[i].uci, scax, scay);
                                free_uci = 1;
                        }
@@ -171,7 +173,7 @@ static Mesh *uvprojectModifier_do(
 
                                /* setup parameters */
                                BKE_camera_params_init(&params);
-                               BKE_camera_params_from_object(&params, projectors[i].ob);
+                               BKE_camera_params_from_object(&params, projectors[i].ob_eval);
 
                                /* compute matrix, viewplane, .. */
                                BKE_camera_params_compute_viewplane(&params, 1, 1, aspx, aspy);
@@ -200,7 +202,7 @@ static Mesh *uvprojectModifier_do(
                projectors[i].normal[0] = 0;
                projectors[i].normal[1] = 0;
                projectors[i].normal[2] = 1;
-               mul_mat3_m4_v3(projectors[i].ob->obmat, projectors[i].normal);
+               mul_mat3_m4_v3(projectors[i].ob_eval->obmat, projectors[i].normal);
        }
 
        numPolys = mesh->totpoly;
@@ -312,7 +314,7 @@ static Mesh *applyModifier(
        Mesh *result;
        UVProjectModifierData *umd = (UVProjectModifierData *) md;
 
-       result = uvprojectModifier_do(umd, ctx->object, mesh);
+       result = uvprojectModifier_do(umd, ctx->depsgraph, ctx->object, mesh);
 
        return result;
 }