Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2016-04-21 04:29:32 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-04-22 09:36:53 +0300
commit19e5540ff7712a45ab4ced4a4a02b12ce02637a9 (patch)
treeb43be4638a05372d802dc71580099e53f54545bc /source/blender/editors/space_view3d/view3d_walk.c
parent8dcdde52b17228601c95fed04f5bca03484d27ac (diff)
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.
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_walk.c')
-rw-r--r--source/blender/editors/space_view3d/view3d_walk.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/source/blender/editors/space_view3d/view3d_walk.c b/source/blender/editors/space_view3d/view3d_walk.c
index 5fb7b2994ed..73ec0f664da 100644
--- a/source/blender/editors/space_view3d/view3d_walk.c
+++ b/source/blender/editors/space_view3d/view3d_walk.c
@@ -306,6 +306,8 @@ typedef struct WalkInfo {
float jump_height; /* maximum jump height */
float speed_factor; /* to use for fast/slow speeds */
+ struct SnapObjectContext *snap_context;
+
struct View3DCameraControl *v3d_camera_control;
} WalkInfo;
@@ -402,12 +404,14 @@ static void walk_navigation_mode_set(bContext *C, wmOperator *op, WalkInfo *walk
/**
* \param r_distance Distance to the hit point
*/
-static bool walk_floor_distance_get(bContext *C, RegionView3D *rv3d, WalkInfo *walk, const float dvec[3], float *r_distance)
+static bool walk_floor_distance_get(
+ RegionView3D *rv3d, WalkInfo *walk, const float dvec[3],
+ float *r_distance)
{
float ray_normal[3] = {0, 0, -1}; /* down */
float ray_start[3];
float r_location[3];
- float r_normal[3];
+ float r_normal_dummy[3];
float dvec_tmp[3];
bool ret;
@@ -418,12 +422,10 @@ static bool walk_floor_distance_get(bContext *C, RegionView3D *rv3d, WalkInfo *w
mul_v3_v3fl(dvec_tmp, dvec, walk->grid);
add_v3_v3(ray_start, dvec_tmp);
- ret = snapObjectsRayEx(
- CTX_data_scene(C), NULL, NULL, NULL, NULL,
- NULL, SNAP_ALL, SCE_SNAP_MODE_FACE,
+ ret = ED_transform_snap_object_project_ray(
+ walk->snap_context,
ray_start, ray_normal, r_distance,
- r_location, r_normal, NULL, NULL,
- NULL, NULL);
+ r_location, r_normal_dummy);
/* artifically scale the distance to the scene size */
*r_distance /= walk->grid;
@@ -435,7 +437,9 @@ static bool walk_floor_distance_get(bContext *C, RegionView3D *rv3d, WalkInfo *w
* \param r_location Location of the hit point
* \param r_normal Normal of the hit surface, transformed to always face the camera
*/
-static bool walk_ray_cast(bContext *C, RegionView3D *rv3d, WalkInfo *walk, float r_location[3], float r_normal[3], float *ray_distance)
+static bool walk_ray_cast(
+ RegionView3D *rv3d, WalkInfo *walk,
+ float r_location[3], float r_normal[3], float *ray_distance)
{
float ray_normal[3] = {0, 0, -1}; /* forward */
float ray_start[3];
@@ -449,13 +453,10 @@ static bool walk_ray_cast(bContext *C, RegionView3D *rv3d, WalkInfo *walk, float
normalize_v3(ray_normal);
- ret = snapObjectsRayEx(
- 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, NULL,
- NULL, NULL);
-
+ ret = ED_transform_snap_object_project_ray(
+ walk->snap_context,
+ ray_start, ray_normal, NULL,
+ r_location, r_normal);
/* dot is positive if both rays are facing the same direction */
if (dot_v3v3(ray_normal, r_normal) > 0) {
@@ -572,6 +573,9 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op)
walk->rv3d->rflag |= RV3D_NAVIGATING;
+ walk->snap_context = ED_transform_snap_object_context_create_view3d(
+ CTX_data_main(C), walk->scene, SNAP_OBJECT_USE_CACHE,
+ walk->ar, walk->v3d);
walk->v3d_camera_control = ED_view3d_cameracontrol_acquire(
walk->scene, walk->v3d, walk->rv3d,
@@ -622,6 +626,8 @@ static int walkEnd(bContext *C, WalkInfo *walk)
ED_region_draw_cb_exit(walk->ar->type, walk->draw_handle_pixel);
+ ED_transform_snap_object_context_destroy(walk->snap_context);
+
ED_view3d_cameracontrol_release(walk->v3d_camera_control, walk->state == WALK_CANCEL);
rv3d->rflag &= ~RV3D_NAVIGATING;
@@ -894,7 +900,7 @@ static void walkEvent(bContext *C, wmOperator *op, WalkInfo *walk, const wmEvent
{
float loc[3], nor[3];
float distance;
- bool ret = walk_ray_cast(C, walk->rv3d, walk, loc, nor, &distance);
+ bool ret = walk_ray_cast(walk->rv3d, walk, loc, nor, &distance);
/* in case we are teleporting middle way from a jump */
walk->speed_jump = 0.0f;
@@ -1175,7 +1181,7 @@ static int walkApply(bContext *C, wmOperator *op, WalkInfo *walk)
float difference = -100.0f;
float fall_distance;
- ret = walk_floor_distance_get(C, rv3d, walk, dvec, &ray_distance);
+ ret = walk_floor_distance_get(rv3d, walk, dvec, &ray_distance);
if (ret) {
difference = walk->view_height - ray_distance;
@@ -1228,7 +1234,7 @@ static int walkApply(bContext *C, wmOperator *op, WalkInfo *walk)
if (t > walk->teleport.duration) {
/* check to see if we are landing */
- ret = walk_floor_distance_get(C, rv3d, walk, dvec, &ray_distance);
+ ret = walk_floor_distance_get(rv3d, walk, dvec, &ray_distance);
if (ret) {
difference = walk->view_height - ray_distance;