[Bf-blender-cvs] [e1f4003e8dc] tmp-transform-navigate: Merge remote-tracking branch 'origin/master' into tmp-transform-navigate

Germano Cavalcante noreply at git.blender.org
Wed Feb 23 21:18:31 CET 2022


Commit: e1f4003e8dc50ec739c574a3891c7f729dab2d67
Author: Germano Cavalcante
Date:   Wed Feb 23 09:40:29 2022 -0300
Branches: tmp-transform-navigate
https://developer.blender.org/rBe1f4003e8dc50ec739c574a3891c7f729dab2d67

Merge remote-tracking branch 'origin/master' into tmp-transform-navigate

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



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

diff --cc source/blender/editors/transform/transform.h
index 63bc58d92cf,757c11f1179..c670ba646b8
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@@ -377,10 -376,10 +377,12 @@@ typedef struct MouseInput 
  
    /** Initial mouse position. */
    int imval[2];
--  bool precision;
--  float precision_factor;
++  float imval_unproj[3];
    float center[2];
    float factor;
++  float precision_factor;
++  bool precision;
++
    /** Additional data, if needed by the particular function. */
    void *data;
  
diff --cc source/blender/editors/transform/transform_generics.c
index 9dd1f815bbe,2b523461800..de614de8688
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@@ -1130,33 -1120,6 +1130,33 @@@ static void calculateCenter_FromAround(
    }
  }
  
 +static void calculateZfac(TransInfo *t)
 +{
 +  /* ED_view3d_calc_zfac() defines a factor for perspective depth correction,
 +   * used in ED_view3d_win_to_delta() */
 +
 +  /* zfac is only used convertViewVec only in cases operator was invoked in RGN_TYPE_WINDOW
 +   * and never used in other cases.
 +   *
 +   * We need special case here as well, since ED_view3d_calc_zfac will crash when called
 +   * for a region different from RGN_TYPE_WINDOW.
 +   */
-   if (t->spacetype == SPACE_VIEW3D) {
++  if ((t->spacetype == SPACE_VIEW3D) && (t->region->regiontype == RGN_TYPE_WINDOW)) {
 +    t->zfac = ED_view3d_calc_zfac(t->region->regiondata, t->center_global, NULL);
 +  }
 +  else if (t->spacetype == SPACE_IMAGE) {
 +    SpaceImage *sima = t->area->spacedata.first;
 +    t->zfac = 1.0f / sima->zoom;
 +  }
 +  else {
 +    View2D *v2d = &t->region->v2d;
 +    /* Get zoom fac the same way as in
 +     * `ui_view2d_curRect_validate_resize` - better keep in sync! */
 +    const float zoomx = (float)(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur);
 +    t->zfac = 1.0f / zoomx;
 +  }
 +}
 +
  void calculateCenter(TransInfo *t)
  {
    if ((t->flag & T_OVERRIDE_CENTER) == 0) {
@@@ -1191,37 -1154,23 +1191,37 @@@
      }
    }
  
 -  if (t->spacetype == SPACE_VIEW3D) {
 -    /* ED_view3d_calc_zfac() defines a factor for perspective depth correction,
 -     * used in ED_view3d_win_to_delta() */
 -
 -    /* zfac is only used convertViewVec only in cases operator was invoked in RGN_TYPE_WINDOW
 -     * and never used in other cases.
 -     *
 -     * We need special case here as well, since ED_view3d_calc_zfac will crash when called
 -     * for a region different from RGN_TYPE_WINDOW.
 -     */
 -    if (t->region->regiontype == RGN_TYPE_WINDOW) {
 -      t->zfac = ED_view3d_calc_zfac(t->region->regiondata, t->center_global, NULL);
 -    }
 -    else {
 -      t->zfac = 0.0f;
 +  calculateZfac(t);
 +}
 +
 +/* Called every time the view changes due to navigation.
 + * Adjusts the mouse position relative to the object. */
 +void tranformViewUpdate(TransInfo *t)
 +{
-   if (t->spacetype == SPACE_VIEW3D) {
++  if ((t->spacetype == SPACE_VIEW3D) && (t->region->regiontype == RGN_TYPE_WINDOW)) {
 +    setTransformViewMatrices(t);
 +
 +    for (int i = 0; i < ARRAY_SIZE(t->orient); i++) {
 +      if (t->orient[i].type == V3D_ORIENT_VIEW) {
 +        copy_m3_m4(t->orient[i].matrix, t->viewinv);
 +        normalize_m3(t->orient[i].matrix);
 +        if (t->orient_curr == i) {
 +          copy_m3_m3(t->spacemtx, t->orient[i].matrix);
 +          invert_m3_m3_safe_ortho(t->spacemtx_inv, t->spacemtx);
 +        }
 +      }
      }
    }
 +
 +  float fac = 1.0f;
 +  if (ELEM(t->spacetype, SPACE_VIEW3D, SPACE_IMAGE, SPACE_NODE)) {
 +    float zfac_prev = t->zfac;
 +    calculateZfac(t);
 +    fac = zfac_prev / t->zfac;
 +  }
 +
 +  calculateCenter2D(t);
 +  transform_input_update(t, fac);
  }
  
  void calculatePropRatio(TransInfo *t)
diff --cc source/blender/editors/transform/transform_input.c
index 4e34df7bc5b,3b320ff51d5..4a4077c4619
--- a/source/blender/editors/transform/transform_input.c
+++ b/source/blender/editors/transform/transform_input.c
@@@ -8,6 -8,6 +8,7 @@@
  #include <stdlib.h>
  
  #include "DNA_screen_types.h"
++#include "DNA_space_types.h"
  
  #include "BKE_context.h"
  
@@@ -251,11 -251,11 +252,8 @@@ void setCustomPointsFromDirection(Trans
  /** \name Setup & Handle Mouse Input
   * \{ */
  
--void initMouseInput(TransInfo *UNUSED(t),
--                    MouseInput *mi,
--                    const float center[2],
--                    const int mval[2],
--                    const bool precision)
++void initMouseInput(
++    TransInfo *t, MouseInput *mi, const float center[2], const int mval[2], const bool precision)
  {
    mi->factor = 0;
    mi->precision = precision;
@@@ -266,14 -266,14 +264,21 @@@
    mi->imval[0] = mval[0];
    mi->imval[1] = mval[1];
  
++  if ((t->spacetype == SPACE_VIEW3D) && (t->region->regiontype == RGN_TYPE_WINDOW)) {
++    RegionView3D *rv3d = t->region->regiondata;
++    float z = dot_m4_v3_row_z(rv3d->persmat, t->center_global) + rv3d->persmat[3][2];
++    float z_ndc = 0.5f * (1.0f + (z / t->zfac));
++    ED_view3d_depth_unproject_v3(t->region, mval, z_ndc, mi->imval_unproj);
++  }
++
    mi->post = NULL;
  }
  
  static void calcSpringFactor(MouseInput *mi)
  {
--  mi->factor = sqrtf(
--      ((float)(mi->center[1] - mi->imval[1])) * ((float)(mi->center[1] - mi->imval[1])) +
--      ((float)(mi->center[0] - mi->imval[0])) * ((float)(mi->center[0] - mi->imval[0])));
++  float mdir[2] = {(float)(mi->center[1] - mi->imval[1]), (float)(mi->center[0] - mi->imval[0])};
++
++  mi->factor = len_v2(mdir);
  
    if (mi->factor == 0.0f) {
      mi->factor = 1.0f; /* prevent Inf */
@@@ -441,30 -441,4 +446,38 @@@ void applyMouseInput(TransInfo *t, Mous
    }
  }
  
 +void transform_input_update(TransInfo *t, const float fac)
 +{
 +  MouseInput *mi = &t->mouse;
-   int offset[2], center_2d_int[2] = {mi->center[0], mi->center[1]};
-   sub_v2_v2v2_int(offset, mi->imval, center_2d_int);
-   offset[0] *= fac;
-   offset[1] *= fac;
 +  t->mouse.factor *= fac;
- 
-   center_2d_int[0] = t->center2d[0];
-   center_2d_int[1] = t->center2d[1];
-   add_v2_v2v2_int(mi->imval, center_2d_int, offset);
++  if ((t->spacetype == SPACE_VIEW3D) && (t->region->regiontype == RGN_TYPE_WINDOW)) {
++    projectIntView(t, mi->imval_unproj, mi->imval);
++  }
++  else {
++    int offset[2], center_2d_int[2] = {mi->center[0], mi->center[1]};
++    sub_v2_v2v2_int(offset, mi->imval, center_2d_int);
++    offset[0] *= fac;
++    offset[1] *= fac;
++
++    center_2d_int[0] = t->center2d[0];
++    center_2d_int[1] = t->center2d[1];
++    add_v2_v2v2_int(mi->imval, center_2d_int, offset);
++  }
 +
 +  float center_old[2];
 +  copy_v2_v2(center_old, mi->center);
 +  copy_v2_v2(mi->center, t->center2d);
 +
 +  if (ELEM(mi->apply, InputAngle, InputAngleSpring)) {
 +    float offset_center[2];
 +    sub_v2_v2v2(offset_center, mi->center, center_old);
 +    struct InputAngle_Data *data = mi->data;
 +    data->mval_prev[0] += offset_center[0];
 +    data->mval_prev[1] += offset_center[1];
 +  }
++  else if (ELEM(mi->apply, InputSpringFlip)) {
++    /* Pass. */
++  }
 +}
 +
  /** \} */
diff --cc source/blender/editors/transform/transform_ops.c
index e6cbc737070,936aca7d2e0..9cf9ff7895c
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@@ -415,23 -412,6 +415,26 @@@ static int transform_modal(bContext *C
    }
  #endif
  
 +  if (event->type == MOUSEMOVE) {
 +    /* Call before #tranformViewUpdate. */
 +    copy_v2_v2_int(t->mval, event->mval);
 +  }
 +
 +  /* Allow navigation while transforming */
 +  if (!(t->flag & T_RELEASE_CONFIRM) && ED_view3d_navigation_do(C, t->vod, event)) {
 +    RegionView3D *rv3d = t->region->regiondata;
-     if (rv3d->rflag & RV3D_NAVIGATING) {
++    if (event->type == EVT_MODAL_MAP) {
++      /* Pass. These events can cancel modifiers. */
++    }
++    else if (rv3d->rflag & RV3D_NAVIGATING) {
 +      /* Do not update transform while navigating. This can be distracting. */
 +      return OPERATOR_RUNNING_MODAL;
 +    }
 +
 +    /* Call before #applyMouseInput. */
 +    tranformViewUpdate(t);
 +  }
 +
    /* XXX insert keys are called here, and require context */
    t->context = C;
    exit_code = transformEvent(t, event);



More information about the Bf-blender-cvs mailing list