Cleanup & simplify snapping functions
authorGermano Cavalcante <germano.costa@ig.com.br>
Fri, 3 Jun 2016 06:54:58 +0000 (16:54 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 3 Jun 2016 06:56:16 +0000 (16:56 +1000)
- the name of the enumerator `SNAP_NOT_OBEDIT` was changed to `SNAP_NOT_ACTIVE`.
- the parameter `snap_to_flag` was moved to outside `SnapObjectParams`.
- the member `use_object_edit` was renamed to `use_object_edit_cage`.
- added the arg `params` in `ED_transform_snap_object_project_ray`.
- simplifications in the loop of the function `snapObjectsRay`.

source/blender/editors/armature/editarmature_sketch.c
source/blender/editors/curve/editcurve.c
source/blender/editors/include/ED_transform.h
source/blender/editors/include/ED_transform_snap_object_context.h
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/space_view3d/view3d_ruler.c
source/blender/editors/space_view3d/view3d_walk.c
source/blender/editors/transform/transform_snap.c
source/blender/editors/transform/transform_snap_object.c
source/blender/makesrna/intern/rna_scene_api.c

index 5530e293eddeafb55e34e1f307e6feb97fd0bf15..cc4c1809fbc6eb2feb72feb94cb18ed8d0556599 100644 (file)
@@ -980,7 +980,11 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S
        if (ts->snap_mode == SCE_SNAP_MODE_VOLUME) {
                float size;
                if (peelObjectsSnapContext(
-                       snap_context, mvalf, SNAP_ALL,
+                       snap_context, mvalf,
+                       &(const struct SnapObjectParams){
+                           .snap_select = SNAP_NOT_SELECTED,
+                           .use_object_edit_cage = false,
+                       },
                        (ts->snap_flag & SCE_SNAP_PEEL_OBJECT) != 0,
                        loc, dummy_no, &size))
                {
@@ -1017,9 +1021,10 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S
                {
                        if (ED_transform_snap_object_project_view3d(
                                snap_context,
+                               ts->snap_mode,
                                &(const struct SnapObjectParams){
                                    .snap_select = SNAP_NOT_SELECTED,
-                                   .snap_to = ts->snap_mode,
+                                   .use_object_edit_cage = false,
                                },
                                mvalf, &dist_px, NULL,
                                loc, dummy_no))
index 18fdcb546b08d4d43721cabe24ef78f83dcfb4a6..420f72fedb3da6f60a811b3a36c9dbadd95a9b25 100644 (file)
@@ -5004,9 +5004,10 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
                        ED_transform_snap_object_project_view3d_mixed(
                                snap_context,
+                               SCE_SELECT_FACE,
                                &(const struct SnapObjectParams){
-                                   .snap_select = SNAP_NOT_OBEDIT,
-                                   .snap_to_flag = SCE_SELECT_FACE,
+                                   .snap_select = (vc.scene->obedit != NULL) ? SNAP_NOT_ACTIVE : SNAP_ALL,
+                                   .use_object_edit_cage = false,
                                },
                                mval, NULL, true,
                                location, NULL);
index 933f480a5545fb49c67a7eef6771914112cc3fd9..ebd2a3dcb7af3e697699915cf109f6bcb40eecf0 100644 (file)
@@ -45,6 +45,7 @@ struct wmKeyMap;
 struct wmOperatorType;
 struct Main;
 struct SnapObjectContext;
+struct SnapObjectParams;
 
 void transform_keymap_for_space(struct wmKeyConfig *keyconf, struct wmKeyMap *keymap, int spaceid);
 void transform_operatortypes(void);
@@ -161,25 +162,27 @@ void BIF_draw_manipulator(const struct bContext *C);
 typedef enum SnapSelect {
        SNAP_ALL = 0,
        SNAP_NOT_SELECTED = 1,
-       SNAP_NOT_OBEDIT = 2
+       SNAP_NOT_ACTIVE = 2,
 } SnapSelect;
 
 #define SNAP_MIN_DISTANCE 30
 
 bool peelObjectsTransform(
-        struct TransInfo *t, const float mval[2],
-        SnapSelect snap_select, bool use_peel_object,
+        struct TransInfo *t,
+        const float mval[2],
+        const bool use_peel_object,
         /* return args */
         float r_loc[3], float r_no[3], float *r_thickness);
 bool peelObjectsSnapContext(
         struct SnapObjectContext *sctx,
         const float mval[2],
-        SnapSelect snap_select, bool use_peel_object,
+        const struct SnapObjectParams *params,
+        const bool use_peel_object,
         /* return args */
         float r_loc[3], float r_no[3], float *r_thickness);
 
 bool snapObjectsTransform(
-        struct TransInfo *t, const float mval[2], SnapSelect snap_select,
+        struct TransInfo *t, const float mval[2],
         float *dist_px,
         /* return args */
         float r_loc[3], float r_no[3]);
index 900b7593f2ea3ff4e86d7f3fc9faaba5909305be..baf4ed574cfeff1f2d08a46bbd98244cbf7a5516 100644 (file)
@@ -57,17 +57,12 @@ struct SnapObjectHitDepth {
        unsigned int ob_uuid;
 };
 
+/** parameters that define which objects will be used to snap. */
 struct SnapObjectParams {
-       int snap_select;  /* SnapSelect */
-       union {
-               unsigned int snap_to : 4;
-               /* snap_target_flag: Snap to vert/edge/face. */
-               unsigned int snap_to_flag : 4;
-       };
+       /* special context sensitive handling for the active or selected object */
+       char snap_select;
        /* use editmode cage */
-       unsigned int use_object_edit : 1;
-       /* special context sensitive handling for the active object */
-       unsigned int use_object_active : 1;
+       unsigned int use_object_edit_cage : 1;
 };
 
 enum {
@@ -93,6 +88,7 @@ void ED_transform_snap_object_context_set_editmesh_callbacks(
 
 bool ED_transform_snap_object_project_ray_ex(
         struct SnapObjectContext *sctx,
+        const unsigned short snap_to,
         const struct SnapObjectParams *params,
         const float ray_start[3], const float ray_normal[3], float *ray_depth,
         /* return args */
@@ -100,11 +96,13 @@ bool ED_transform_snap_object_project_ray_ex(
         struct Object **r_ob, float r_obmat[4][4]);
 bool ED_transform_snap_object_project_ray(
         SnapObjectContext *sctx,
+        const struct SnapObjectParams *params,
         const float ray_origin[3], const float ray_direction[3], float *ray_depth,
         float r_co[3], float r_no[3]);
 
 bool ED_transform_snap_object_project_ray_all(
         SnapObjectContext *sctx,
+        const unsigned short snap_to,
         const struct SnapObjectParams *params,
         const float ray_start[3], const float ray_normal[3],
         float ray_depth, bool sort,
@@ -112,12 +110,14 @@ bool ED_transform_snap_object_project_ray_all(
 
 bool ED_transform_snap_object_project_view3d_ex(
         struct SnapObjectContext *sctx,
+        const unsigned short snap_to,
         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);
 bool ED_transform_snap_object_project_view3d(
         struct SnapObjectContext *sctx,
+        const unsigned short snap_to,
         const struct SnapObjectParams *params,
         const float mval[2], float *dist_px,
         float *ray_depth,
@@ -125,6 +125,7 @@ bool ED_transform_snap_object_project_view3d(
         float r_loc[3], float r_no[3]);
 bool ED_transform_snap_object_project_view3d_mixed(
         SnapObjectContext *sctx,
+        const unsigned short snap_to_flag,
         const struct SnapObjectParams *params,
         const float mval_fl[2], float *dist_px,
         bool use_depth,
index ba17684dd390968bb0f602866fb07e787dcc50a5..efe179790daa5cc4660cf71b191e451d119a6b14 100644 (file)
@@ -312,9 +312,10 @@ void EMBM_project_snap_verts(bContext *C, ARegion *ar, BMEditMesh *em)
                        if (ED_view3d_project_float_object(ar, eve->co, mval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
                                if (ED_transform_snap_object_project_view3d_mixed(
                                        snap_context,
+                                       SCE_SELECT_FACE,
                                        &(const struct SnapObjectParams){
-                                           .snap_select = SNAP_NOT_OBEDIT,
-                                           .snap_to_flag = SCE_SELECT_FACE,
+                                           .snap_select = SNAP_NOT_ACTIVE,
+                                           .use_object_edit_cage = false,
                                        },
                                        mval, NULL, true,
                                        co_proj, NULL))
index dfa76753f64ab1e46620a6ee553908684e7ed235..c6951c79609d9bde90d9156ff84001bce8ffa90a 100644 (file)
@@ -679,9 +679,10 @@ static bool view3d_ruler_item_mousemove(
 
                        if (ED_transform_snap_object_project_view3d_mixed(
                                ruler_info->snap_context,
+                               SCE_SELECT_FACE,
                                &(const struct SnapObjectParams){
                                    .snap_select = SNAP_ALL,
-                                   .snap_to_flag = SCE_SELECT_FACE,
+                                   .use_object_edit_cage = true,
                                },
                                mval_fl, &dist_px, true,
                                co, ray_normal))
@@ -691,6 +692,10 @@ static bool view3d_ruler_item_mousemove(
                                madd_v3_v3v3fl(ray_start, co, ray_normal, eps_bias);
                                ED_transform_snap_object_project_ray(
                                        ruler_info->snap_context,
+                                       &(const struct SnapObjectParams){
+                                           .snap_select = SNAP_ALL,
+                                           .use_object_edit_cage = true,
+                                       },
                                        ray_start, ray_normal, NULL,
                                        co_other, NULL);
                        }
@@ -703,9 +708,10 @@ static bool view3d_ruler_item_mousemove(
 
                        if (ED_transform_snap_object_project_view3d_mixed(
                                ruler_info->snap_context,
+                               (SCE_SELECT_VERTEX | SCE_SELECT_EDGE) | (use_depth ? SCE_SELECT_FACE : 0),
                                &(const struct SnapObjectParams){
                                    .snap_select = SNAP_ALL,
-                                   .snap_to_flag = (SCE_SELECT_VERTEX | SCE_SELECT_EDGE) | (use_depth ? SCE_SELECT_FACE : 0),
+                                   .use_object_edit_cage = true,
                                },
                                mval_fl, &dist_px, use_depth,
                                co, NULL))
index 47f816786990c68bc4d9be1b8c2d133c6e56de7f..6859ffe5175893c342513cfbfd618afb454da2c7 100644 (file)
@@ -424,6 +424,7 @@ static bool walk_floor_distance_get(
 
        ret = ED_transform_snap_object_project_ray(
                walk->snap_context,
+               &(const struct SnapObjectParams){},
                ray_start, ray_normal, r_distance,
                r_location, r_normal_dummy);
 
@@ -455,6 +456,7 @@ static bool walk_ray_cast(
 
        ret = ED_transform_snap_object_project_ray(
                walk->snap_context,
+               &(const struct SnapObjectParams){},
                ray_start, ray_normal, NULL,
                r_location, r_normal);
 
index e72db4105a4727934e7603c17771257fadaf5bac..e1cf743623668207013c7cccd992cf69df0ead1c 100644 (file)
@@ -324,7 +324,7 @@ void applyProject(TransInfo *t)
                        
                        if (ED_view3d_project_float_global(t->ar, iloc, mval_fl, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
                                if (snapObjectsTransform(
-                                       t, mval_fl, t->tsnap.modeSelect, &dist_px,
+                                       t, mval_fl, &dist_px,
                                        loc, no))
                                {
 //                                     if (t->flag & (T_EDIT|T_POSE)) {
@@ -553,10 +553,10 @@ static void initSnappingMode(TransInfo *t)
                {
                        /* Exclude editmesh if using proportional edit */
                        if ((obedit->type == OB_MESH) && (t->flag & T_PROP_EDIT)) {
-                               t->tsnap.modeSelect = SNAP_NOT_OBEDIT;
+                               t->tsnap.modeSelect = SNAP_NOT_ACTIVE;
                        }
                        else {
-                               t->tsnap.modeSelect = t->tsnap.snap_self ? SNAP_ALL : SNAP_NOT_OBEDIT;
+                               t->tsnap.modeSelect = t->tsnap.snap_self ? SNAP_ALL : SNAP_NOT_ACTIVE;
                        }
                }
                /* Particles edit mode*/
@@ -964,14 +964,14 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec))
                
                if (t->tsnap.mode == SCE_SNAP_MODE_VOLUME) {
                        found = peelObjectsTransform(
-                               t, mval, t->tsnap.modeSelect,
+                               t, mval,
                                (t->settings->snap_flag & SCE_SNAP_PEEL_OBJECT) != 0,
                                loc, no, NULL);
                }
                else {
                        zero_v3(no);  /* objects won't set this */
                        found = snapObjectsTransform(
-                               t, mval, t->tsnap.modeSelect, &dist_px,
+                               t, mval, &dist_px,
                                loc, no);
                }
                
@@ -1207,17 +1207,16 @@ static void TargetSnapClosest(TransInfo *t)
 }
 
 bool snapObjectsTransform(
-        TransInfo *t, const float mval[2], SnapSelect snap_select,
+        TransInfo *t, const float mval[2],
         float *dist_px,
         float r_loc[3], float r_no[3])
 {
        return ED_transform_snap_object_project_view3d_ex(
                t->tsnap.object_context,
+               t->scene->toolsettings->snap_mode,
                &(const struct SnapObjectParams){
-                   .snap_select = snap_select,
-                   .snap_to = t->scene->toolsettings->snap_mode,
-                   .use_object_edit = (t->flag & T_EDIT) != 0,
-                   .use_object_active = (t->options & CTX_GPENCIL_STROKES) == 0,
+                   .snap_select = ((t->options & CTX_GPENCIL_STROKES) != 0) ? SNAP_NOT_ACTIVE : t->tsnap.modeSelect,
+                   .use_object_edit_cage = (t->flag & T_EDIT) != 0,
                },
                mval, dist_px, NULL,
                r_loc, r_no, NULL);
@@ -1228,18 +1227,16 @@ bool snapObjectsTransform(
 
 bool peelObjectsSnapContext(
         SnapObjectContext *sctx,
-        const float mval[2], SnapSelect snap_select, bool use_peel_object,
+        const float mval[2],
+        const struct SnapObjectParams *params,
+        const bool use_peel_object,
         /* return args */
         float r_loc[3], float r_no[3], float *r_thickness)
 {
        ListBase depths_peel = {0};
        ED_transform_snap_object_project_all_view3d_ex(
                sctx,
-               &(const struct SnapObjectParams){
-                   .snap_to = SCE_SNAP_MODE_FACE,
-                   .snap_select = snap_select,
-                   .use_object_edit = true,
-               },
+               params,
                mval, -1.0f, false,
                &depths_peel);
 
@@ -1299,13 +1296,19 @@ bool peelObjectsSnapContext(
 
 bool peelObjectsTransform(
         TransInfo *t,
-        const float mval[2], SnapSelect snap_select, bool use_peel_object,
+        const float mval[2],
+        const bool use_peel_object,
         /* return args */
         float r_loc[3], float r_no[3], float *r_thickness)
 {
        return peelObjectsSnapContext(
                t->tsnap.object_context,
-               mval, snap_select, use_peel_object,
+               mval,
+               &(const struct SnapObjectParams){
+                   .snap_select = ((t->options & CTX_GPENCIL_STROKES) != 0) ? SNAP_NOT_ACTIVE : t->tsnap.modeSelect,
+                   .use_object_edit_cage = (t->flag & T_EDIT) != 0,
+               },
+               use_peel_object,
                r_loc, r_no, r_thickness);
 }
 
index 4a79310b75362ff9bf352942c310bf1cd3d5e501..d7486372c3679052f82ad662c72581460977e6c1 100644 (file)
@@ -1314,39 +1314,28 @@ static bool snapObject(
 
 static bool snapObjectsRay(
         SnapObjectContext *sctx,
-        SnapSelect snap_select, const short snap_to,
+        const unsigned short snap_to, const SnapSelect snap_select,
+        const bool use_object_edit_cage,
         const float mval[2], float *dist_px,
-        /* special handling of active and edit objects */
-        Base *base_act, Object *obedit,
         const float ray_start[3], const float ray_normal[3], const float ray_origin[3], float *ray_depth,
         /* return args */
         float r_loc[3], float r_no[3], int *r_index,
         Object **r_ob, float r_obmat[4][4],
         ListBase *r_hit_list)
 {
-       Base *base;
        bool retval = false;
-       bool snap_obedit_first = snap_select == SNAP_ALL && obedit;
        unsigned int ob_index = 0;
-
-       if (snap_obedit_first) {
-               Object *ob = obedit;
-
-               retval |= snapObject(
-                       sctx, ob, ob->obmat, true, snap_to,
-                       mval, dist_px, ob_index++,
-                       ray_start, ray_normal, ray_origin, ray_depth,
-                       r_loc, r_no, r_index, r_ob, r_obmat, r_hit_list);
-       }
+       Object *obedit = use_object_edit_cage ? sctx->scene->obedit : NULL;
 
        /* Need an exception for particle edit because the base is flagged with BA_HAS_RECALC_DATA
         * which makes the loop skip it, even the derived mesh will never change
         *
         * To solve that problem, we do it first as an exception.
         * */
-       base = base_act;
-       if (base && base->object && base->object->mode & OB_MODE_PARTICLE_EDIT) {
-               Object *ob = base->object;
+       Base *base_act = sctx->scene->basact;
+       if (base_act && base_act->object && base_act->object->mode & OB_MODE_PARTICLE_EDIT) {
+               Object *ob = base_act->object;
+
                retval |= snapObject(
                        sctx, ob, ob->obmat, false, snap_to,
                        mval, dist_px, ob_index++,
@@ -1354,16 +1343,25 @@ static bool snapObjectsRay(
                        r_loc, r_no, r_index, r_ob, r_obmat, r_hit_list);
        }
 
-       for (base = sctx->scene->base.first; base != NULL; base = base->next) {
+       bool ignore_object_selected = false, ignore_object_active = false;
+       switch (snap_select) {
+               case SNAP_ALL:
+                       break;
+               case SNAP_NOT_SELECTED:
+                       ignore_object_selected = true;
+                       break;
+               case SNAP_NOT_ACTIVE:
+                       ignore_object_active = true;
+                       break;
+       }
+       for (Base *base = sctx->scene->base.first; base != NULL; base = base->next) {
                if ((BASE_VISIBLE_BGMODE(sctx->v3d_data.v3d, sctx->scene, base)) &&
                    (base->flag & (BA_HAS_RECALC_OB | BA_HAS_RECALC_DATA)) == 0 &&
 
-                   ((snap_select == SNAP_NOT_SELECTED && (base->flag & (SELECT | BA_WAS_SEL)) == 0) ||
-                    (ELEM(snap_select, SNAP_ALL, SNAP_NOT_OBEDIT) && base != base_act)))
+                   !((ignore_object_selected && (base->flag & (SELECT | BA_WAS_SEL))) ||
+                     (ignore_object_active && base == base_act)))
                {
                        Object *ob = base->object;
-                       Object *ob_snap = ob;
-                       bool use_obedit = false;
 
                        if (ob->transflag & OB_DUPLI) {
                                DupliObject *dupli_ob;
@@ -1383,19 +1381,8 @@ static bool snapObjectsRay(
                                free_object_duplilist(lb);
                        }
 
-                       if (obedit) {
-                               if ((ob == obedit) &&
-                                  (snap_obedit_first || (snap_select == SNAP_NOT_OBEDIT)))
-                               {
-                                       continue;
-                               }
-
-                               if (ob->data == obedit->data) {
-                                       /* for linked objects, use the same object but a different matrix */
-                                       use_obedit = true;
-                                       ob_snap = obedit;
-                               }
-                       }
+                       bool use_obedit = (obedit != NULL) && (ob->data == obedit->data);
+                       Object *ob_snap = use_obedit ? obedit : ob;
 
                        retval |= snapObject(
                                sctx, ob_snap, ob->obmat, use_obedit, snap_to,
@@ -1500,22 +1487,18 @@ void ED_transform_snap_object_context_set_editmesh_callbacks(
 
 bool ED_transform_snap_object_project_ray_ex(
         SnapObjectContext *sctx,
+        const unsigned short snap_to,
         const struct SnapObjectParams *params,
         const float ray_start[3], const float ray_normal[3], float *ray_depth,
         float r_loc[3], float r_no[3], int *r_index,
         Object **r_ob, float r_obmat[4][4])
 {
-       Base *base_act = params->use_object_active ? sctx->scene->basact : NULL;
-       Object *obedit = params->use_object_edit ? sctx->scene->obedit : NULL;
-
        return snapObjectsRay(
                sctx,
-               params->snap_select, params->snap_to,
+               snap_to, params->snap_select, params->use_object_edit_cage,
                NULL, NULL,
-               base_act, obedit,
                ray_start, ray_normal, ray_start, ray_depth,
-               r_loc, r_no, r_index,
-               r_ob, r_obmat, NULL);
+               r_loc, r_no, r_index, r_ob, r_obmat, NULL);
 }
 
 /**
@@ -1527,14 +1510,12 @@ bool ED_transform_snap_object_project_ray_ex(
  */
 bool ED_transform_snap_object_project_ray_all(
         SnapObjectContext *sctx,
+        const unsigned short snap_to,
         const struct SnapObjectParams *params,
         const float ray_start[3], const float ray_normal[3],
         float ray_depth, bool sort,
         ListBase *r_hit_list)
 {
-       Base *base_act = params->use_object_active ? sctx->scene->basact : NULL;
-       Object *obedit = params->use_object_edit ? sctx->scene->obedit : NULL;
-
        if (ray_depth == -1.0f) {
                ray_depth = BVH_RAYCAST_DIST_MAX;
        }
@@ -1545,9 +1526,8 @@ bool ED_transform_snap_object_project_ray_all(
 
        bool retval = snapObjectsRay(
                sctx,
-               params->snap_select, params->snap_to,
+               snap_to, params->snap_select, params->use_object_edit_cage,
                NULL, NULL,
-               base_act, obedit,
                ray_start, ray_normal, ray_start, &ray_depth,
                NULL, NULL, NULL, NULL, NULL,
                r_hit_list);
@@ -1573,6 +1553,7 @@ bool ED_transform_snap_object_project_ray_all(
  */
 static bool transform_snap_context_project_ray_impl(
         SnapObjectContext *sctx,
+        const struct SnapObjectParams *params,
         const float ray_start[3], const float ray_normal[3], float *ray_depth,
         float r_co[3], float r_no[3])
 {
@@ -1581,11 +1562,8 @@ static bool transform_snap_context_project_ray_impl(
        /* try snap edge, then face if it fails */
        ret = ED_transform_snap_object_project_ray_ex(
                sctx,
-               &(const struct SnapObjectParams){
-                   .snap_select = SNAP_ALL,
-                   .snap_to = SCE_SNAP_MODE_FACE,
-                   .use_object_edit = (sctx->scene->obedit != NULL),
-               },
+               SCE_SNAP_MODE_FACE,
+               params,
                ray_start, ray_normal, ray_depth,
                r_co, r_no, NULL,
                NULL, NULL);
@@ -1595,6 +1573,7 @@ static bool transform_snap_context_project_ray_impl(
 
 bool ED_transform_snap_object_project_ray(
         SnapObjectContext *sctx,
+        const struct SnapObjectParams *params,
         const float ray_origin[3], const float ray_direction[3], float *ray_depth,
         float r_co[3], float r_no[3])
 {
@@ -1611,12 +1590,14 @@ bool ED_transform_snap_object_project_ray(
 
        return transform_snap_context_project_ray_impl(
                sctx,
+               params,
                ray_origin, ray_direction, ray_depth,
                r_co, r_no);
 }
 
 static bool transform_snap_context_project_view3d_mixed_impl(
         SnapObjectContext *sctx,
+        const unsigned short snap_to_flag,
         const struct SnapObjectParams *params,
         const float mval[2], float *dist_px,
         bool use_depth,
@@ -1632,22 +1613,18 @@ static bool transform_snap_context_project_view3d_mixed_impl(
 
        const int  elem_type[3] = {SCE_SNAP_MODE_VERTEX, SCE_SNAP_MODE_EDGE, SCE_SNAP_MODE_FACE};
 
-       BLI_assert(params->snap_to_flag != 0);
-       BLI_assert((params->snap_to_flag & ~(1 | 2 | 4)) == 0);
-
-       struct SnapObjectParams params_temp = *params;
+       BLI_assert(snap_to_flag != 0);
+       BLI_assert((snap_to_flag & ~(1 | 2 | 4)) == 0);
 
        for (int i = 0; i < 3; i++) {
-               if ((params->snap_to_flag & (1 << i)) && (is_hit == false || use_depth)) {
+               if ((snap_to_flag & (1 << i)) && (is_hit == false || use_depth)) {
                        if (use_depth == false) {
                                ray_depth = BVH_RAYCAST_DIST_MAX;
                        }
 
-                       params_temp.snap_to = elem_type[i];
-
                        if (ED_transform_snap_object_project_view3d(
                                sctx,
-                               &params_temp,
+                               elem_type[i], params,
                                mval, dist_px, &ray_depth,
                                r_co, r_no))
                        {
@@ -1674,6 +1651,7 @@ static bool transform_snap_context_project_view3d_mixed_impl(
  */
 bool ED_transform_snap_object_project_view3d_mixed(
         SnapObjectContext *sctx,
+        const unsigned short snap_to_flag,
         const struct SnapObjectParams *params,
         const float mval_fl[2], float *dist_px,
         bool use_depth,
@@ -1681,13 +1659,14 @@ bool ED_transform_snap_object_project_view3d_mixed(
 {
        return transform_snap_context_project_view3d_mixed_impl(
                sctx,
-               params,
+               snap_to_flag, params,
                mval_fl, dist_px, use_depth,
                r_co, r_no);
 }
 
 bool ED_transform_snap_object_project_view3d_ex(
         SnapObjectContext *sctx,
+        const unsigned short snap_to,
         const struct SnapObjectParams *params,
         const float mval[2], float *dist_px,
         float *ray_depth,
@@ -1708,19 +1687,17 @@ bool ED_transform_snap_object_project_view3d_ex(
                return false;
        }
 
-       Base *base_act = params->use_object_active ? sctx->scene->basact : NULL;
-       Object *obedit = params->use_object_edit ? sctx->scene->obedit : NULL;
        return snapObjectsRay(
                sctx,
-               params->snap_select, params->snap_to,
+               snap_to, params->snap_select, params->use_object_edit_cage,
                mval, dist_px,
-               base_act, obedit,
                ray_start, ray_normal, ray_orgigin, ray_depth,
                r_loc, r_no, r_index, NULL, NULL, NULL);
 }
 
 bool ED_transform_snap_object_project_view3d(
         SnapObjectContext *sctx,
+        const unsigned short snap_to,
         const struct SnapObjectParams *params,
         const float mval[2], float *dist_px,
         float *ray_depth,
@@ -1728,6 +1705,7 @@ bool ED_transform_snap_object_project_view3d(
 {
        return ED_transform_snap_object_project_view3d_ex(
                sctx,
+               snap_to,
                params,
                mval, dist_px,
                ray_depth,
@@ -1746,8 +1724,6 @@ bool ED_transform_snap_object_project_all_view3d_ex(
 {
        float ray_start[3], ray_normal[3];
 
-       BLI_assert(params->snap_to == SCE_SNAP_MODE_FACE);
-
        if (!ED_view3d_win_to_ray_ex(
                sctx->v3d_data.ar, sctx->v3d_data.v3d,
                mval, NULL, ray_normal, ray_start, true))
@@ -1757,6 +1733,7 @@ bool ED_transform_snap_object_project_all_view3d_ex(
 
        return ED_transform_snap_object_project_ray_all(
                sctx,
+               SCE_SNAP_MODE_FACE,
                params,
                ray_start, ray_normal, ray_depth, sort,
                r_hit_list);
index e1216e3c85f9e0763e7ba62ff10046c4613e1d43..c3c66625c84c10d85fdd1a825492ce416c12040c 100644 (file)
@@ -151,9 +151,9 @@ static void rna_Scene_ray_cast(
 
        bool ret = ED_transform_snap_object_project_ray_ex(
                sctx,
+               SCE_SNAP_MODE_FACE,
                &(const struct SnapObjectParams){
                    .snap_select = SNAP_ALL,
-                   .snap_to = SCE_SNAP_MODE_FACE,
                },
                origin, direction, &ray_dist,
                r_location, r_normal, r_index,