[Bf-blender-cvs] [19e5540] master: Transform Snap: initial snap context refactor

Campbell Barton noreply at git.blender.org
Fri Apr 22 08:40:39 CEST 2016


Commit: 19e5540ff7712a45ab4ced4a4a02b12ce02637a9
Author: Campbell Barton
Date:   Thu Apr 21 11:29:32 2016 +1000
Branches: master
https://developer.blender.org/rB19e5540ff7712a45ab4ced4a4a02b12ce02637a9

Transform Snap: initial snap context refactor

This introduces a snap-context that can be re-used for casting rays into the scene
(by operators such as walk-mode, ruler and transform code).

This can be used to cache data between calls too.

===================================================================

M	source/blender/editors/armature/editarmature_sketch.c
M	source/blender/editors/curve/editcurve.c
M	source/blender/editors/include/ED_transform.h
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/mesh/editmesh_tools.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_ruler.c
M	source/blender/editors/space_view3d/view3d_walk.c
M	source/blender/editors/transform/CMakeLists.txt
M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_generics.c
M	source/blender/editors/transform/transform_snap.c
A	source/blender/editors/transform/transform_snap_object.c
M	source/blender/makesrna/intern/rna_scene_api.c
M	source/blenderplayer/bad_level_call_stubs/stubs.c

===================================================================

diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c
index 87d75aa..b627147 100644
--- a/source/blender/editors/armature/editarmature_sketch.c
+++ b/source/blender/editors/armature/editarmature_sketch.c
@@ -1086,9 +1086,23 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S
 		mval[1] = dd->mval[1];
 
 		/* try to snap to closer object */
-		found = snapObjectsContext(
-		        C, mval, SNAP_NOT_SELECTED,
-		        vec, no, &dist_px);
+		{
+			struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d(
+			        CTX_data_main(C), CTX_data_scene(C), 0,
+			        CTX_wm_region(C), CTX_wm_view3d(C));
+
+			found = ED_transform_snap_object_project_view3d_mixed(
+			        snap_context,
+			        &(const struct SnapObjectParams){
+			            .snap_select = SNAP_NOT_SELECTED,
+			            .snap_to_flag = SCE_SELECT_FACE,
+			        },
+			        mval, &dist_px, true,
+			        vec, no);
+
+			ED_transform_snap_object_context_destroy(snap_context);
+		}
+
 		if (found == 1) {
 			pt->type = dd->type;
 			pt->mode = PT_SNAP;
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index 9df611b..395da2c 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -4993,11 +4993,22 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
 		if (use_proj) {
 			const float mval[2] = {UNPACK2(event->mval)};
-			float no_dummy[3];
-			float dist_px_dummy;
-			snapObjectsContext(
-			        C, mval, SNAP_NOT_OBEDIT,
-			        location, no_dummy, &dist_px_dummy);
+
+			struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d(
+			        CTX_data_main(C), vc.scene, 0,
+			        vc.ar, vc.v3d);
+
+			ED_transform_snap_object_project_view3d_mixed(
+			        snap_context,
+			        &(const struct SnapObjectParams){
+			            .snap_select = SNAP_NOT_OBEDIT,
+			            .snap_to_flag = SCE_SELECT_FACE,
+			        },
+			        mval, NULL, true,
+			        location, NULL);
+
+
+			ED_transform_snap_object_context_destroy(snap_context);
 		}
 
 		if ((cu->flag & CU_3D) == 0) {
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index db8085a..39df52e 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -43,6 +43,8 @@ struct wmEvent;
 struct wmKeyConfig;
 struct wmKeyMap;
 struct wmOperatorType;
+struct Main;
+struct SnapObjectContext;
 
 void transform_keymap_for_space(struct wmKeyConfig *keyconf, struct wmKeyMap *keymap, int spaceid);
 void transform_operatortypes(void);
@@ -187,27 +189,9 @@ bool peelObjectsContext(
         struct ListBase *r_depth_peels);
 bool snapObjectsTransform(
         struct TransInfo *t, const float mval[2], SnapSelect snap_select,
+        float *dist_px,
         /* return args */
-        float r_loc[3], float r_no[3], float *r_dist_px);
-bool snapObjectsContext(
-        struct bContext *C, const float mval[2], SnapSelect snap_select,
-        /* return args */
-        float r_loc[3], float r_no[3], float *r_dist_px);
-/* taks args for all settings */
-bool snapObjectsEx(
-        struct Scene *scene, struct View3D *v3d, struct ARegion *ar, struct Base *base_act, struct Object *obedit,
-        const float mval[2], SnapSelect snap_select, const short snap_mode,
-        float *ray_depth,
-        /* return args */
-        float r_loc[3], float r_no[3], float *r_dist_px);
-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, const 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, int *r_index,
-        struct Object **r_ob, float r_obmat[4][4]);
-
+        float r_loc[3], float r_no[3]);
 bool snapNodesTransform(
         struct TransInfo *t, const int mval[2], SnapSelect snap_select,
         /* return args */
@@ -217,4 +201,67 @@ bool snapNodesContext(
         /* return args */
         float r_loc[2], float *r_dist_px, char *r_node_border);
 
+
+/* transform_snap_object.c */
+
+/* ED_transform_snap_object_*** API */
+struct SnapObjectParams {
+	SnapSelect snap_select;
+	union {
+		unsigned int snap_to : 4;
+		/* snap_target_flag: Snap to vert/edge/face. */
+		unsigned int snap_to_flag : 4;
+	};
+	/* use editmode cage */
+	unsigned int use_object_edit : 1;
+	/* special context sensitive handling for the active object */
+	unsigned int use_object_active : 1;
+};
+
+enum {
+	SNAP_OBJECT_USE_CACHE = (1 << 0),
+};
+
+typedef struct SnapObjectContext SnapObjectContext;
+SnapObjectContext *ED_transform_snap_object_context_create(
+        struct Main *bmain, struct Scene *scene, int flag);
+SnapObjectContext *ED_transform_snap_object_context_create_view3d(
+        struct Main *bmain, struct Scene *scene, int flag,
+        /* extra args for view3d */
+        struct ARegion *ar, struct View3D *v3d);
+void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx);
+
+bool ED_transform_snap_object_project_ray_ex(
+        struct SnapObjectContext *sctx,
+        const struct SnapObjectParams *params,
+        const float ray_start[3], const float ray_normal[3], float *ray_depth,
+        /* return args */
+        float r_loc[3], float r_no[3], int *r_index,
+        struct Object **r_ob, float r_obmat[4][4]);
+bool ED_transform_snap_object_project_ray(
+        SnapObjectContext *sctx,
+        const float ray_origin[3], const float ray_direction[3], float *ray_dist,
+        float r_co[3], float r_no[3]);
+
+bool ED_transform_snap_object_project_view3d_ex(
+        struct SnapObjectContext *sctx,
+        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 struct SnapObjectParams *params,
+        const float mval[2], float *dist_px,
+        float *ray_depth,
+        /* return args */
+        float r_loc[3], float r_no[3]);
+bool ED_transform_snap_object_project_view3d_mixed(
+        SnapObjectContext *sctx,
+        const struct SnapObjectParams *params,
+        const float mval_fl[2], float *dist_px,
+        bool use_depth,
+        float r_co[3], float r_no[3]);
+
+
 #endif  /* __ED_TRANSFORM_H__ */
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index d8a3f5e..c23c2ee 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -396,18 +396,6 @@ void ED_view3d_operator_properties_viewmat_set(struct bContext *C, struct wmOper
 void ED_view3d_operator_properties_viewmat_get(struct wmOperator *op, int *winx, int *winy, float persmat[4][4]);
 #endif
 
-bool ED_view3d_snap_from_region(
-        struct Scene *scene, struct View3D *v3d, struct ARegion *ar,
-        const float mval[2], float dist_px,
-        bool use_depth, bool use_obedit,
-        bool use_vert, bool use_edge, bool use_face,
-        float r_co[3], float r_no[3]);
-
-bool ED_view3d_snap_from_ray(
-        struct Scene *scene,
-        const float ray_start[3], const float ray_normal[3],
-        float r_co[3]);
-
 /* render */
 void ED_view3d_stop_render_preview(struct wmWindowManager *wm, struct ARegion *ar);
 void ED_view3d_shade_update(struct Main *bmain, struct Scene *scene, struct View3D *v3d, struct ScrArea *sa);
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index ee33f5f..c06bf7b 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -301,20 +301,30 @@ void EMBM_project_snap_verts(bContext *C, ARegion *ar, BMEditMesh *em)
 
 	ED_view3d_init_mats_rv3d(obedit, ar->regiondata);
 
+	struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d(
+	        CTX_data_main(C), CTX_data_scene(C), SNAP_OBJECT_USE_CACHE,
+	        ar, CTX_wm_view3d(C));
+
 	BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
 		if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
-			float mval[2], co_proj[3], no_dummy[3];
-			float dist_px_dummy;
+			float mval[2], co_proj[3];
 			if (ED_view3d_project_float_object(ar, eve->co, mval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
-				if (snapObjectsContext(
-				        C, mval, SNAP_NOT_OBEDIT,
-				        co_proj, no_dummy, &dist_px_dummy))
+				if (ED_transform_snap_object_project_view3d_mixed(
+				        snap_context,
+				        &(const struct SnapObjectParams){
+				            .snap_select = SNAP_NOT_OBEDIT,
+				            .snap_to_flag = SCE_SELECT_FACE,
+				        },
+				        mval, NULL, true,
+				        co_proj, NULL))
 				{
 					mul_v3_m4v3(eve->co, obedit->imat, co_proj);
 				}
 			}
 		}
 	}
+
+	ED_transform_snap_object_context_destroy(snap_context);
 }
 
 
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 7cd2040..8ca7331 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -5171,85 +5171,3 @@ void ED_view3D_lock_clear(View3D *v3d)
 	v3d->ob_centre_cursor = false;
 	v3d->flag2 &= ~V3D_LOCK_CAMERA;
 }
-
-/**
- * Convenience function for snap ray-casting.
- *
- * Given a ray, cast it into the scene (snapping to faces).
- *
- * \return Snap success
- */
-bool ED_view3d_snap_from_ray(
-        Scene *scene,
-        const float ray_start[3], const float ray_normal[3],
-        float r_co[3])
-{
-	float r_no_dummy[3];
-	float ray_dist = BVH_RAYCAST_DIST_MAX;
-	bool ret;
-
-	struct Object *obedit = scene->obedit;
-
-	/* try snap edge, then face if it fails */
-	ret = snapObjectsRayEx(
-	        scene, NULL, NULL, NULL, obedit,
-	  

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list