Transform Snap: add optional face index arg
authorCampbell Barton <ideasman42@gmail.com>
Wed, 2 Dec 2015 07:46:14 +0000 (18:46 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 2 Dec 2015 07:46:14 +0000 (18:46 +1100)
source/blender/editors/include/ED_transform.h
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_walk.c
source/blender/editors/transform/transform_snap.c
source/blender/makesrna/intern/rna_scene_api.c
source/blenderplayer/bad_level_call_stubs/stubs.c

index 874c6934f6d14ea03d5a34f6e4a3429043e737b7..19bfb94e1302875fd432aae50a21771887f234ed 100644 (file)
@@ -205,7 +205,7 @@ bool snapObjectsRayEx(
         const float mval[2], SnapSelect snap_select, short snap_mode,
         const float ray_start[3], const float ray_normal[3], float *ray_depth,
         /* return args */
-        float r_loc[3], float r_no[3], float *r_dist_px,
+        float r_loc[3], float r_no[3], float *r_dist_px, int *r_index,
         struct Object **r_ob, float r_obmat[4][4]);
 
 bool snapNodesTransform(
index 498aa3a523003cb27fc27e5afc2d84327860444a..b09cbedb6fa6c55060f50bbc773a50f863be855e 100644 (file)
@@ -5171,7 +5171,7 @@ bool ED_view3d_snap_from_ray(
                scene, NULL, NULL, NULL, obedit,
                NULL, SNAP_ALL, SCE_SNAP_MODE_FACE,
                ray_start, ray_normal, &ray_dist,
-               r_co, r_no_dummy, NULL,
+               r_co, r_no_dummy, NULL, NULL,
                NULL, NULL);
 
        return ret;
index b71b6b86356c434cf0a4c7e32cd37c1b1a4b1a57..8b3ea2a1fee34cca2da55631c92e75e856144f80 100644 (file)
@@ -421,7 +421,7 @@ static bool walk_floor_distance_get(bContext *C, RegionView3D *rv3d, WalkInfo *w
                CTX_data_scene(C), NULL, NULL, NULL, NULL,
                NULL, SNAP_ALL, SCE_SNAP_MODE_FACE,
                ray_start, ray_normal, r_distance,
-               r_location, r_normal, NULL,
+               r_location, r_normal, NULL, NULL,
                NULL, NULL);
 
        /* artifically scale the distance to the scene size */
@@ -455,7 +455,7 @@ static bool walk_ray_cast(bContext *C, RegionView3D *rv3d, WalkInfo *walk, float
                CTX_data_scene(C), NULL, NULL, NULL, NULL,
                NULL, SNAP_ALL, SCE_SNAP_MODE_FACE,
                ray_start, ray_normal, ray_distance,
-               r_location, r_normal, NULL,
+               r_location, r_normal, NULL, NULL,
                NULL, NULL);
 
 
index bdf85b089a465b67dc81ac0d0b8b1f4492b48d6f..359e191c90dae6494a227a9ddab5b52638d1b63c 100644 (file)
@@ -1523,11 +1523,17 @@ static bool snapCurve(
        return retval;
 }
 
+static int dm_looptri_to_poly_index(DerivedMesh *dm, const MLoopTri *lt)
+{
+       const int *index_mp_to_orig = dm->getPolyDataArray(dm, CD_ORIGINDEX);
+       return index_mp_to_orig ? index_mp_to_orig[lt->poly] : lt->poly;
+}
+
 static bool snapDerivedMesh(
         ARegion *ar, Object *ob, DerivedMesh *dm, BMEditMesh *em, float obmat[4][4],
         const float mval[2], const short snap_to, bool do_bb,
         const float ray_start[3], const float ray_normal[3], const float ray_origin[3], float *ray_depth,
-        float r_loc[3], float r_no[3], float *r_dist_px)
+        float r_loc[3], float r_no[3], float *r_dist_px, int *r_index)
 {
        bool retval = false;
        const bool do_ray_start_correction = (
@@ -1653,6 +1659,10 @@ static bool snapDerivedMesh(
                                                normalize_v3(r_no);
 
                                                retval = true;
+
+                                               if (r_index) {
+                                                       *r_index = dm_looptri_to_poly_index(dm, &treeData.looptri[hit.index]);
+                                               }
                                        }
                                }
                                free_bvhtree_from_mesh(&treeData);
@@ -1897,7 +1907,7 @@ static bool snapObject(
         const float mval[2], const short snap_to,
         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], float *r_dist_px,
+        float r_loc[3], float r_no[3], float *r_dist_px, int *r_index,
         Object **r_ob, float r_obmat[4][4])
 {
        bool retval = false;
@@ -1928,7 +1938,7 @@ static bool snapObject(
                retval = snapDerivedMesh(
                        ar, ob, dm, em, obmat, mval, snap_to, do_bb,
                        ray_start, ray_normal, ray_origin, ray_depth,
-                       r_loc, r_no, r_dist_px);
+                       r_loc, r_no, r_dist_px, r_index);
 
                dm->release(dm);
        }
@@ -1972,7 +1982,7 @@ static bool snapObjectsRay(
         const float mval[2], SnapSelect snap_select, const short snap_to,
         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], float *r_dist_px,
+        float r_loc[3], float r_no[3], float *r_dist_px, int *r_index,
         Object **r_ob, float r_obmat[4][4])
 {
        Base *base;
@@ -1985,7 +1995,7 @@ static bool snapObjectsRay(
                        scene, ar, ob, ob->obmat, true,
                        mval, snap_to,
                        ray_start, ray_normal, ray_origin, ray_depth,
-                       r_loc, r_no, r_dist_px, r_ob, r_obmat);
+                       r_loc, r_no, r_dist_px, r_index, r_ob, r_obmat);
        }
 
        /* Need an exception for particle edit because the base is flagged with BA_HAS_RECALC_DATA
@@ -2000,7 +2010,7 @@ static bool snapObjectsRay(
                        scene, ar, ob, ob->obmat, false,
                        mval, snap_to,
                        ray_start, ray_normal, ray_origin, ray_depth,
-                       r_loc, r_no, r_dist_px, r_ob, r_obmat);
+                       r_loc, r_no, r_dist_px, r_index, r_ob, r_obmat);
        }
 
        for (base = FIRSTBASE; base != NULL; base = base->next) {
@@ -2032,7 +2042,7 @@ static bool snapObjectsRay(
                                                scene, ar, dupli_snap, dupli_ob->mat, use_obedit_dupli,
                                                mval, snap_to,
                                                ray_start, ray_normal, ray_origin, ray_depth,
-                                               r_loc, r_no, r_dist_px, r_ob, r_obmat);
+                                               r_loc, r_no, r_dist_px, r_index, r_ob, r_obmat);
                                }
                                
                                free_object_duplilist(lb);
@@ -2042,7 +2052,7 @@ static bool snapObjectsRay(
                                scene, ar, ob_snap, ob->obmat, use_obedit,
                                mval, snap_to,
                                ray_start, ray_normal, ray_origin, ray_depth,
-                               r_loc, r_no, r_dist_px, r_ob, r_obmat);
+                               r_loc, r_no, r_dist_px, r_index, r_ob, r_obmat);
                }
        }
        
@@ -2052,7 +2062,7 @@ static bool snapObjects(
         Scene *scene, View3D *v3d, ARegion *ar, Base *base_act, Object *obedit,
         const float mval[2], SnapSelect snap_select, const short snap_to,
         float *ray_depth,
-        float r_loc[3], float r_no[3], float *r_dist_px)
+        float r_loc[3], float r_no[3], float *r_dist_px, int *r_index)
 {
        float ray_start[3], ray_normal[3], ray_orgigin[3];
 
@@ -2064,7 +2074,7 @@ static bool snapObjects(
                scene, v3d, ar, base_act, obedit,
                mval, snap_select, snap_to,
                ray_start, ray_normal, ray_orgigin, ray_depth,
-               r_loc, r_no, r_dist_px, NULL, NULL);
+               r_loc, r_no, r_dist_px, r_index, NULL, NULL);
 }
 
 bool snapObjectsTransform(
@@ -2087,7 +2097,7 @@ bool snapObjectsTransform(
                t->scene, t->view, t->ar, base_act, obedit,
                mval, snap_select, t->scene->toolsettings->snap_mode,
                &ray_dist,
-               r_loc, r_no, r_dist_px);
+               r_loc, r_no, r_dist_px, NULL);
 }
 
 bool snapObjectsContext(
@@ -2105,7 +2115,7 @@ bool snapObjectsContext(
                scene, v3d, ar, scene->basact, obedit,
                mval, snap_select, scene->toolsettings->snap_mode,
                &ray_dist,
-               r_loc, r_no, r_dist_px);
+               r_loc, r_no, r_dist_px, NULL);
 }
 
 bool snapObjectsEx(
@@ -2118,20 +2128,20 @@ bool snapObjectsEx(
                scene, v3d, ar, base_act, obedit,
                mval, snap_select, snap_to,
                ray_depth,
-               r_loc, r_no, r_dist_px);
+               r_loc, r_no, r_dist_px, NULL);
 }
 bool snapObjectsRayEx(
         Scene *scene, View3D *v3d, ARegion *ar, Base *base_act, Object *obedit,
         const float mval[2], SnapSelect snap_select, const short snap_to,
         const float ray_start[3], const float ray_normal[3], float *ray_depth,
-        float r_loc[3], float r_no[3], float *r_dist_px,
+        float r_loc[3], float r_no[3], float *r_dist_px, int *r_index,
         Object **r_ob, float r_obmat[4][4])
 {
        return snapObjectsRay(
                scene, v3d, ar, base_act, obedit,
                mval, snap_select, snap_to,
                ray_start, ray_normal, ray_start, ray_depth,
-               r_loc, r_no, r_dist_px,
+               r_loc, r_no, r_dist_px, r_index,
                r_ob, r_obmat);
 }
 
index 6c5a29c02cd076808187e5d6d8c04e60feb8e068..cc56f5e477dd8216fc23dce77a2df32d064b4cb6 100644 (file)
@@ -151,7 +151,7 @@ static void rna_Scene_ray_cast(Scene *scene, float ray_start[3], float ray_end[3
                scene, NULL, NULL, NULL, NULL,
                NULL, SNAP_ALL, SCE_SNAP_MODE_FACE,
                ray_start, ray_nor, &ray_dist,
-               r_location, r_normal, NULL,
+               r_location, r_normal, NULL, NULL,
                r_ob, (float(*)[4])r_obmat))
        {
                *r_success = true;
index 07c48c008775403b41f5c6715af66cf1c6c59665..c277a0436dd3a6e78c55bd084146bd7eebbf34a2 100644 (file)
@@ -516,7 +516,7 @@ bool snapObjectsRayEx(
         struct Scene *scene, struct View3D *v3d, struct ARegion *ar, struct Base *base_act, struct Object *obedit,
         const float mval[2], SnapSelect snap_select, short snap_mode,
         const float ray_start[3], const float ray_normal[3], float *ray_dist,
-        float r_loc[3], float r_no[3], float *r_dist_px,
+        float r_loc[3], float r_no[3], float *r_dist_px, int *r_index,
         struct Object **r_ob, float r_obmat[4][4]) RET_ZERO
 
 void ED_lattice_editlatt_make(struct Object *obedit) RET_NONE