Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Fri, 22 Jun 2018 10:56:02 +0000 (12:56 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 22 Jun 2018 10:58:29 +0000 (12:58 +0200)
1  2 
source/blender/editors/include/ED_view3d.h
source/blender/editors/object/object_add.c
source/blender/editors/space_view3d/view3d_edit.c

index 343bffa0082ae1e1bf1a31ad3e72b8dbf3837ace,fe1fc7dc0cc8c23d6ba3dd73f76694779641d66e..bc131b45d37dfb31116d34370e2616df58b2a33c
@@@ -98,11 -91,9 +98,11 @@@ typedef struct ViewDepths 
        bool damaged;
  } ViewDepths;
  
 -float *ED_view3d_cursor3d_get(struct Scene *scene, struct View3D *v3d);
 -void   ED_view3d_cursor3d_position(struct bContext *C, const int mval[2], float cursor_co[3]);
 -void   ED_view3d_cursor3d_update(struct bContext *C, const int mval[2]);
 +struct View3DCursor *ED_view3d_cursor3d_get(struct Scene *scene, struct View3D *v3d);
- void   ED_view3d_cursor3d_calc_mat3(const struct Scene *scene, const struct View3D *v3d, float mat[3][3]);
- void   ED_view3d_cursor3d_calc_mat4(const struct Scene *scene, const struct View3D *v3d, float mat[4][4]);
- void   ED_view3d_cursor3d_position(struct bContext *C, float fp[3], const int mval[2]);
- void   ED_view3d_cursor3d_update(struct bContext *C, const int mval[2]);
++void ED_view3d_cursor3d_calc_mat3(const struct Scene *scene, const struct View3D *v3d, float mat[3][3]);
++void ED_view3d_cursor3d_calc_mat4(const struct Scene *scene, const struct View3D *v3d, float mat[4][4]);
++void ED_view3d_cursor3d_position(struct bContext *C, const int mval[2], float cursor_co[3]);
++void ED_view3d_cursor3d_update(struct bContext *C, const int mval[2]);
  
  struct Camera *ED_view3d_camera_data_get(struct View3D *v3d, struct RegionView3D *rv3d);
  
index 21ace255a4c50dbdc60ab1b7c38defaa553e6267,9f016e13f49862ea21ccfa7680e06d09803f0a13..f8399558dbc8cfa290a485f247c5b0c3355a8653
@@@ -2421,11 -2384,11 +2421,11 @@@ static int add_named_exec(bContext *C, 
                const int mval[2] = {event->x - ar->winrct.xmin,
                                     event->y - ar->winrct.ymin};
                ED_object_location_from_view(C, basen->object->loc);
-               ED_view3d_cursor3d_position(C, basen->object->loc, mval);
+               ED_view3d_cursor3d_position(C, mval, basen->object->loc);
        }
  
 -      ED_base_object_select(basen, BA_SELECT);
 -      ED_base_object_activate(C, basen);
 +      ED_object_base_select(basen, BA_SELECT);
 +      ED_object_base_activate(C, basen);
  
        copy_object_set_idnew(C);
  
index bae186097a86aa97747c5c870a7cb8399b9a9e82,5cf167165cdcb9a9012000613e172d1b36fbd1d0..977421e7fadb5426e3dc69140ecd121d588f9f5b
@@@ -4553,8 -4529,10 +4553,8 @@@ void VIEW3D_OT_clip_border(wmOperatorTy
  
  /* cursor position in vec, result in vec, mval in region coords */
  /* note: cannot use event->mval here (called by object_add() */
- void ED_view3d_cursor3d_position(bContext *C, float fp[3], const int mval[2])
+ void ED_view3d_cursor3d_position(bContext *C, const int mval[2], float cursor_co[3])
  {
 -      Main *bmain = CTX_data_main(C);
 -      Scene *scene = CTX_data_scene(C);
        ARegion *ar = CTX_wm_region(C);
        View3D *v3d = CTX_wm_view3d(C);
        RegionView3D *rv3d = ar->regiondata;
        }
  
        if (U.uiflag & USER_DEPTH_CURSOR) {  /* maybe this should be accessed some other way */
 +              struct Depsgraph *depsgraph = CTX_data_depsgraph(C);
 +
                view3d_operator_needs_opengl(C);
-               if (ED_view3d_autodist(depsgraph, ar, v3d, mval, fp, true, NULL)) {
 -              if (ED_view3d_autodist(bmain, scene, ar, v3d, mval, cursor_co, true, NULL))
++              if (ED_view3d_autodist(depsgraph, ar, v3d, mval, cursor_co, true, NULL)) {
                        depth_used = true;
 +              }
        }
  
        if (depth_used == false) {
  
  void ED_view3d_cursor3d_update(bContext *C, const int mval[2])
  {
 +      Main *bmain = CTX_data_main(C);
        Scene *scene = CTX_data_scene(C);
        View3D *v3d = CTX_wm_view3d(C);
 +      ARegion *ar = CTX_wm_region(C);
 +      RegionView3D *rv3d = ar->regiondata;
  
 -      float *cursor_co_curr = ED_view3d_cursor3d_get(scene, v3d);
 -      float  cursor_co_prev[3];
 +      View3DCursor *cursor_curr = ED_view3d_cursor3d_get(scene, v3d);
 +      View3DCursor  cursor_prev = *cursor_curr;
  
-       ED_view3d_cursor3d_position(C, cursor_curr->location, mval);
 -      copy_v3_v3(cursor_co_prev, cursor_co_curr);
++      ED_view3d_cursor3d_position(C, mval, cursor_curr->location);
 +      copy_qt_qt(cursor_curr->rotation, rv3d->viewquat);
 +      cursor_curr->rotation[0] *= -1.0f;
  
 -      ED_view3d_cursor3d_position(C, mval, cursor_co_curr);
 +      {
 +              const float mval_fl[2] = {UNPACK2(mval)};
 +              float ray_no[3];
 +
 +              struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d(
 +                      bmain, scene, CTX_data_depsgraph(C), 0, ar, v3d);
 +
 +              float obmat[4][4];
 +              Object *ob_dummy = NULL;
 +              float dist_px = 0;
 +              if (ED_transform_snap_object_project_view3d_ex(
 +                      snap_context,
 +                      SCE_SNAP_MODE_FACE,
 +                      &(const struct SnapObjectParams){
 +                          .snap_select = SNAP_ALL,
 +                          .use_object_edit_cage = false,
 +                      },
 +                      mval_fl, &dist_px,
 +                      cursor_curr->location, ray_no, NULL,
 +                      &ob_dummy, obmat))
 +              {
 +                      float tquat[4];
 +                      /* Math normal (Z). */
 +                      {
 +                              float z_src[3] = {0, 0, 1};
 +                              mul_qt_v3(cursor_curr->rotation, z_src);
 +                              rotation_between_vecs_to_quat(tquat, z_src, ray_no);
 +                              mul_qt_qtqt(cursor_curr->rotation, tquat, cursor_curr->rotation);
 +                      }
 +
 +                      /* Match object matrix (X). */
 +                      {
 +                              const float ortho_axis_dot[3] = {
 +                                      dot_v3v3(ray_no, obmat[0]),
 +                                      dot_v3v3(ray_no, obmat[1]),
 +                                      dot_v3v3(ray_no, obmat[2]),
 +                              };
 +                              const int ortho_axis = axis_dominant_v3_ortho_single(ortho_axis_dot);
 +                              float x_src[3] = {1, 0, 0};
 +                              float x_dst[3];
 +                              mul_qt_v3(cursor_curr->rotation, x_src);
 +                              project_plane_v3_v3v3(x_dst, obmat[ortho_axis], ray_no);
 +                              normalize_v3(x_dst);
 +                              rotation_between_vecs_to_quat(tquat, x_src, x_dst);
 +                              mul_qt_qtqt(cursor_curr->rotation, tquat, cursor_curr->rotation);
 +                      }
 +              }
 +              ED_transform_snap_object_context_destroy(snap_context);
 +      }
  
        /* offset the cursor lock to avoid jumping to new offset */
        if (v3d->ob_centre_cursor) {
 -              ARegion *ar = CTX_wm_region(C);
 -              RegionView3D *rv3d = ar->regiondata;
 -
                if (U.uiflag & USER_LOCK_CURSOR_ADJUST) {
  
-                       float co_curr[2], co_prev[2];
+                       float co_2d_curr[2], co_2d_prev[2];
  
-                       if ((ED_view3d_project_float_global(ar, cursor_prev.location, co_prev, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) &&
-                           (ED_view3d_project_float_global(ar, cursor_curr->location, co_curr, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK))
+                       if ((ED_view3d_project_float_global(
 -                                   ar, cursor_co_prev, co_2d_prev, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) &&
++                                   ar, cursor_prev.location, co_2d_prev, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) &&
+                           (ED_view3d_project_float_global(
 -                                  ar, cursor_co_curr, co_2d_curr, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK))
++                                  ar, cursor_curr->location, co_2d_curr, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK))
                        {
-                               rv3d->ofs_lock[0] += (co_curr[0] - co_prev[0]) / (ar->winx * 0.5f);
-                               rv3d->ofs_lock[1] += (co_curr[1] - co_prev[1]) / (ar->winy * 0.5f);
+                               rv3d->ofs_lock[0] += (co_2d_curr[0] - co_2d_prev[0]) / (ar->winx * 0.5f);
+                               rv3d->ofs_lock[1] += (co_2d_curr[1] - co_2d_prev[1]) / (ar->winy * 0.5f);
                        }
                }
                else {