Extrude Widget: with/without axis constraint
[blender.git] / source / blender / editors / transform / transform_snap_object.c
index c336cd1d31edff5c87fc4af8d66408c244a3dd00..40b714100149d4a4f7afe67ae584940b85b2cf4c 100644 (file)
@@ -54,6 +54,7 @@
 #include "BKE_context.h"
 
 #include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
 
 #include "ED_transform.h"
 #include "ED_transform_snap_object_context.h"
@@ -108,7 +109,7 @@ typedef struct SnapObjectData_EditMesh {
 struct SnapObjectContext {
        Main *bmain;
        Scene *scene;
-       EvaluationContext eval_ctx;
+       Depsgraph *depsgraph;
 
        int flag;
 
@@ -162,8 +163,9 @@ static void iter_snap_objects(
         IterSnapObjsCallback sob_callback,
         void *data)
 {
-       Base *base_act = sctx->eval_ctx.view_layer->basact;
-       for (Base *base = sctx->eval_ctx.view_layer->object_bases.first; base != NULL; base = base->next) {
+       ViewLayer *view_layer = DEG_get_evaluated_view_layer(sctx->depsgraph);
+       Base *base_act = view_layer->basact;
+       for (Base *base = view_layer->object_bases.first; base != NULL; base = base->next) {
                if ((BASE_VISIBLE(base)) && (base->flag_legacy & BA_SNAP_FIX_DEPS_FIASCO) == 0 &&
                    !((snap_select == SNAP_NOT_SELECTED && ((base->flag & BASE_SELECTED) || (base->flag_legacy & BA_WAS_SEL))) ||
                      (snap_select == SNAP_NOT_ACTIVE && base == base_act)))
@@ -172,7 +174,7 @@ static void iter_snap_objects(
                        Object *obj = base->object;
                        if (obj->transflag & OB_DUPLI) {
                                DupliObject *dupli_ob;
-                               ListBase *lb = object_duplilist(&sctx->eval_ctx, sctx->scene, obj);
+                               ListBase *lb = object_duplilist(sctx->depsgraph, sctx->scene, obj);
                                for (dupli_ob = lb->first; dupli_ob; dupli_ob = dupli_ob->next) {
                                        use_obedit = obedit && dupli_ob->ob->data == obedit->data;
                                        sob_callback(sctx, use_obedit, use_obedit ? obedit : dupli_ob->ob, dupli_ob->mat, data);
@@ -448,7 +450,7 @@ static bool raycastDerivedMesh(
                }
 
                if (treedata->tree == NULL) {
-                       bvhtree_from_mesh_looptri(treedata, dm, 0.0f, 4, 6);
+                       bvhtree_from_mesh_get(treedata, dm, BVHTREE_FROM_LOOPTRI, 4);
 
                        if (treedata->tree == NULL) {
                                return retval;
@@ -729,10 +731,10 @@ static bool raycastObj(
                        DerivedMesh *dm;
                        em = BKE_editmesh_from_object(ob);
                        if (em) {
-                               editbmesh_get_derived_cage_and_final(&sctx->eval_ctx, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm);
+                               editbmesh_get_derived_cage_and_final(sctx->depsgraph, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm);
                        }
                        else {
-                               dm = mesh_get_derived_final(&sctx->eval_ctx, sctx->scene, ob, CD_MASK_BAREMESH);
+                               dm = mesh_get_derived_final(sctx->depsgraph, sctx->scene, ob, CD_MASK_BAREMESH);
                        }
                        retval = raycastDerivedMesh(
                                sctx,
@@ -821,7 +823,8 @@ static bool raycastObjects(
         Object **r_ob, float r_obmat[4][4],
         ListBase *r_hit_list)
 {
-       Object *obedit = use_object_edit_cage ? OBEDIT_FROM_VIEW_LAYER(sctx->eval_ctx.view_layer) : NULL;
+       ViewLayer *view_layer = DEG_get_evaluated_view_layer(sctx->depsgraph);
+       Object *obedit = use_object_edit_cage ? OBEDIT_FROM_VIEW_LAYER(view_layer) : NULL;
 
        struct RaycastObjUserData data = {
                .ray_start = ray_start,
@@ -1691,10 +1694,10 @@ static bool snapDerivedMesh(
                if (treedata->tree == NULL) {
                        switch (snapdata->snap_to) {
                                case SCE_SNAP_MODE_EDGE:
-                                       bvhtree_from_mesh_edges(treedata, dm, 0.0f, 2, 6);
+                                       bvhtree_from_mesh_get(treedata, dm, BVHTREE_FROM_EDGES, 2);
                                        break;
                                case SCE_SNAP_MODE_VERTEX:
-                                       bvhtree_from_mesh_verts(treedata, dm, 0.0f, 2, 6);
+                                       bvhtree_from_mesh_get(treedata, dm, BVHTREE_FROM_VERTS, 2);
                                        break;
                        }
                }
@@ -1936,10 +1939,10 @@ static bool snapObject(
                        DerivedMesh *dm;
                        em = BKE_editmesh_from_object(ob);
                        if (em) {
-                               editbmesh_get_derived_cage_and_final(&sctx->eval_ctx, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm);
+                               editbmesh_get_derived_cage_and_final(sctx->depsgraph, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm);
                        }
                        else {
-                               dm = mesh_get_derived_final(&sctx->eval_ctx, sctx->scene, ob, CD_MASK_BAREMESH);
+                               dm = mesh_get_derived_final(sctx->depsgraph, sctx->scene, ob, CD_MASK_BAREMESH);
                        }
                        retval = snapDerivedMesh(
                                sctx, snapdata, ob, dm, obmat,
@@ -2054,7 +2057,8 @@ static bool snapObjectsRay(
         float r_loc[3], float r_no[3],
         Object **r_ob, float r_obmat[4][4])
 {
-       Object *obedit = use_object_edit_cage ? OBEDIT_FROM_VIEW_LAYER(sctx->eval_ctx.view_layer) : NULL;
+       ViewLayer *view_layer = DEG_get_evaluated_view_layer(sctx->depsgraph);
+       Object *obedit = use_object_edit_cage ? OBEDIT_FROM_VIEW_LAYER(view_layer) : NULL;
 
        struct SnapObjUserData data = {
                .snapdata = snapdata,
@@ -2079,7 +2083,7 @@ static bool snapObjectsRay(
  * \{ */
 
 SnapObjectContext *ED_transform_snap_object_context_create(
-        Main *bmain, Scene *scene, ViewLayer *view_layer, RenderEngineType *engine_type, int flag)
+        Main *bmain, Scene *scene, Depsgraph *depsgraph, int flag)
 {
        SnapObjectContext *sctx = MEM_callocN(sizeof(*sctx), __func__);
 
@@ -2087,9 +2091,7 @@ SnapObjectContext *ED_transform_snap_object_context_create(
 
        sctx->bmain = bmain;
        sctx->scene = scene;
-
-       DEG_evaluation_context_init_from_scene(
-               &sctx->eval_ctx, scene, view_layer, engine_type, DAG_EVAL_VIEWPORT);
+       sctx->depsgraph = depsgraph;
 
        sctx->cache.object_map = BLI_ghash_ptr_new(__func__);
        sctx->cache.mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
@@ -2098,11 +2100,11 @@ SnapObjectContext *ED_transform_snap_object_context_create(
 }
 
 SnapObjectContext *ED_transform_snap_object_context_create_view3d(
-        Main *bmain, Scene *scene, ViewLayer *view_layer, RenderEngineType *engine_type, int flag,
+        Main *bmain, Scene *scene, Depsgraph *depsgraph, int flag,
         /* extra args for view3d */
         const ARegion *ar, const View3D *v3d)
 {
-       SnapObjectContext *sctx = ED_transform_snap_object_context_create(bmain, scene, view_layer, engine_type, flag);
+       SnapObjectContext *sctx = ED_transform_snap_object_context_create(bmain, scene, depsgraph, flag);
 
        sctx->use_v3d = true;
        sctx->v3d_data.ar = ar;
@@ -2354,7 +2356,8 @@ bool ED_transform_snap_object_project_view3d_ex(
         const struct SnapObjectParams *params,
         const float mval[2], float *dist_px,
         float *ray_depth,
-        float r_loc[3], float r_no[3], int *r_index)
+        float r_loc[3], float r_no[3], int *r_index,
+        Object **r_ob, float r_obmat[4][4])
 {
        float ray_origin[3], ray_start[3], ray_normal[3], depth_range[2], ray_end[3];
 
@@ -2365,7 +2368,7 @@ bool ED_transform_snap_object_project_view3d_ex(
        ED_view3d_win_to_vector(ar, mval, ray_normal);
 
        ED_view3d_clip_range_get(
-               sctx->eval_ctx.depsgraph,
+               sctx->depsgraph,
                sctx->v3d_data.v3d, sctx->v3d_data.ar->regiondata,
                &depth_range[0], &depth_range[1], false);
 
@@ -2387,7 +2390,7 @@ bool ED_transform_snap_object_project_view3d_ex(
                        sctx,
                        ray_start, ray_normal,
                        params->snap_select, params->use_object_edit_cage,
-                       ray_depth, r_loc, r_no, r_index, NULL, NULL, NULL);
+                       ray_depth, r_loc, r_no, r_index, r_ob, r_obmat, NULL);
        }
        else {
                SnapData snapdata;
@@ -2398,7 +2401,7 @@ bool ED_transform_snap_object_project_view3d_ex(
                return snapObjectsRay(
                        sctx, &snapdata,
                        params->snap_select, params->use_object_edit_cage,
-                       ray_depth, dist_px, r_loc, r_no, NULL, NULL);
+                       ray_depth, dist_px, r_loc, r_no, r_ob, r_obmat);
        }
 }
 
@@ -2416,7 +2419,8 @@ bool ED_transform_snap_object_project_view3d(
                params,
                mval, dist_px,
                ray_depth,
-               r_loc, r_no, NULL);
+               r_loc, r_no, NULL,
+               NULL, NULL);
 }
 
 /**
@@ -2432,7 +2436,7 @@ bool ED_transform_snap_object_project_all_view3d_ex(
        float ray_start[3], ray_normal[3];
 
        if (!ED_view3d_win_to_ray_ex(
-               sctx->eval_ctx.depsgraph,
+               sctx->depsgraph,
                sctx->v3d_data.ar, sctx->v3d_data.v3d,
                mval, NULL, ray_normal, ray_start, true))
        {