Commit: 7ff586b15170208cd76e649142f6a20b58f676b9
Author: Julian Eisel
Date:   Wed May 18 13:49:54 2016 +0200
Branches: temp_widgets_update_tagging
https://developer.blender.org/rB7ff586b15170208cd76e649142f6a20b58f676b9

Optimize transform manipulator drawing a bit more

Avoid unnecessary operations on each redraw, also avoid ugly variable caching 
in RegionView3D struct memory.

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

M       source/blender/editors/transform/transform_manipulator.c
M       source/blender/makesdna/DNA_view3d_types.h

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

diff --git a/source/blender/editors/transform/transform_manipulator.c 
b/source/blender/editors/transform/transform_manipulator.c
index b0fc83d..336c7cd 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -248,7 +248,7 @@ static short manipulator_get_axis_type(const 
ManipulatorGroup *man, const wmWidg
 }
 
 /* get index within axis type, so that x == 0, y == 1 and z == 2, no matter 
which axis type */
-static int manipulator_index_normalize(const int axis_idx)
+static unsigned int manipulator_index_normalize(const int axis_idx)
 {
        if (axis_idx > MAN_AXIS_TRANS_ZX) {
                return axis_idx - 16;
@@ -268,8 +268,14 @@ static int manipulator_index_normalize(const int axis_idx)
 
 static bool manipulator_is_axis_visible(
         const View3D *v3d, const RegionView3D *rv3d,
-        const int axis_type, const int axis_idx)
+        const float idot[3], const int axis_type, const int axis_idx)
 {
+       const unsigned int aidx_norm = manipulator_index_normalize(axis_idx);
+       /* don't draw axis perpendicular to the view */
+       if (aidx_norm < 3 && idot[aidx_norm] < TW_AXIS_DOT_MIN) {
+               return false;
+       }
+
        if ((axis_type == MAN_AXES_TRANSLATE && !(v3d->twtype & 
V3D_MANIP_TRANSLATE)) ||
            (axis_type == MAN_AXES_ROTATE && !(v3d->twtype & V3D_MANIP_ROTATE)) 
||
            (axis_type == MAN_AXES_SCALE && !(v3d->twtype & V3D_MANIP_SCALE)))
@@ -334,7 +340,9 @@ static bool manipulator_is_axis_visible(
        return false;
 }
 
-static void manipulator_get_axis_color(const RegionView3D *rv3d, const int 
axis_idx, float r_col[4], float r_col_hi[4])
+static void manipulator_get_axis_color(
+        const int axis_idx, const float idot[3],
+        float r_col[4], float r_col_hi[4])
 {
        /* alpha values for normal/highlighted states */
        const float alpha = 0.6f;
@@ -344,10 +352,10 @@ static void manipulator_get_axis_color(const RegionView3D 
*rv3d, const int axis_
        const int axis_idx_norm = manipulator_index_normalize(axis_idx);
        /* get alpha fac based on axis angle, to fade axis out when hiding it 
because it points towards view */
        if (axis_idx_norm < 3) {
-               const float idot = rv3d->tw_idot[axis_idx_norm];
-               alpha_fac = (idot > TW_AXIS_DOT_MAX) ?
-                       1.0f : (idot < TW_AXIS_DOT_MIN) ?
-                       0.0f : ((idot - TW_AXIS_DOT_MIN) / (TW_AXIS_DOT_MAX - 
TW_AXIS_DOT_MIN));
+               const float idot_axis = idot[axis_idx_norm];
+               alpha_fac = (idot_axis > TW_AXIS_DOT_MAX) ?
+                       1.0f : (idot_axis < TW_AXIS_DOT_MIN) ?
+                       0.0f : ((idot_axis - TW_AXIS_DOT_MIN) / 
(TW_AXIS_DOT_MAX - TW_AXIS_DOT_MIN));
        }
        else {
                /* trackball rotation axis is a special case, we only draw a 
slight overlay */
@@ -1009,21 +1017,15 @@ static void drawflags_editmode(Object *obedit, View3D 
*v3d, RegionView3D *rv3d)
        }
 }
 
-/* don't draw axis perpendicular to the view */
+/**
+ * Refresh RegionView3D.twdrawflag based on protect-flags.
+ */
 static void manipulator_drawflags_refresh(const bContext *C, View3D *v3d, 
RegionView3D *rv3d)
 {
        Scene *scene = CTX_data_scene(C);
        Object *ob = OBACT, *obedit = CTX_data_edit_object(C);
        bGPdata *gpd = CTX_data_gpencil_data(C);
        const bool is_gp_edit = ((gpd) && (gpd->flag & 
GP_DATA_STROKE_EDITMODE));
-       float view_vec[3], axis_vec[3];
-       float idot;
-       int i;
-
-       const int twdrawflag_axis[3] = {
-           (MAN_TRANS_X | MAN_SCALE_X),
-           (MAN_TRANS_Y | MAN_SCALE_Y),
-           (MAN_TRANS_Z | MAN_SCALE_Z)};
 
        /* all enabled */
        rv3d->twdrawflag = 0xFFFF;
@@ -1047,15 +1049,15 @@ static void manipulator_drawflags_refresh(const 
bContext *C, View3D *v3d, Region
                        }
                }
        }
+}
 
+static void manipulator_get_idot(RegionView3D *rv3d, float r_idot[3])
+{
+       float view_vec[3], axis_vec[3];
        ED_view3d_global_to_vector(rv3d, rv3d->twmat[3], view_vec);
-
-       for (i = 0; i < 3; i++) {
+       for (int i = 0; i < 3; i++) {
                normalize_v3_v3(axis_vec, rv3d->twmat[i]);
-               rv3d->tw_idot[i] = idot = 1.0f - fabsf(dot_v3v3(view_vec, 
axis_vec));
-               if (idot < TW_AXIS_DOT_MIN) {
-                       rv3d->twdrawflag &= ~twdrawflag_axis[i];
-               }
+               r_idot[i] = 1.0f - fabsf(dot_v3v3(view_vec, axis_vec));
        }
 }
 
@@ -1089,8 +1091,6 @@ static void manipulator_prepare_mat(const bContext *C, 
View3D *v3d, RegionView3D
                        copy_v3_v3(rv3d->twmat[3], 
ED_view3d_cursor3d_get(scene, v3d));
                        break;
        }
-
-       mul_mat3_m4_fl(rv3d->twmat, ED_view3d_pixel_size(rv3d, rv3d->twmat[3]) 
* U.widget_scale);
 }
 
 /**
@@ -1333,10 +1333,11 @@ void WIDGETGROUP_manipulator_draw_prepare(const 
bContext *C, wmWidgetGroup *wgro
        ARegion *ar = CTX_wm_region(C);
        View3D *v3d = sa->spacedata.first;
        RegionView3D *rv3d = ar->regiondata;
+       float idot[3];
 
        /* when looking through a selected camera, the manipulator can be at the
         * exact same position as the view, skip so we don't break selection */
-       if (man->all_hidden || fabsf(mat4_to_scale(rv3d->twmat)) < 1e-7f) {
+       if (man->all_hidden || fabsf(ED_view3d_pixel_size(rv3d, 
rv3d->twmat[3])) < 1e-6f) {
                MAN_ITER_AXES_BEGIN(axis, axis_idx)
                {
                        WM_widget_set_flag(axis, WM_WIDGET_HIDDEN, true);
@@ -1344,8 +1345,7 @@ void WIDGETGROUP_manipulator_draw_prepare(const bContext 
*C, wmWidgetGroup *wgro
                MAN_ITER_AXES_END;
                return;
        }
-       manipulator_drawflags_refresh(C, v3d, rv3d);
-
+       manipulator_get_idot(rv3d, idot);
 
        /* *** set properties for axes *** */
 
@@ -1353,7 +1353,7 @@ void WIDGETGROUP_manipulator_draw_prepare(const bContext 
*C, wmWidgetGroup *wgro
        {
                const short axis_type = manipulator_get_axis_type(man, axis);
                /* XXX maybe unset _HIDDEN flag on redraw? */
-               if (manipulator_is_axis_visible(v3d, rv3d, axis_type, 
axis_idx)) {
+               if (manipulator_is_axis_visible(v3d, rv3d, idot, axis_type, 
axis_idx)) {
                        WM_widget_set_flag(axis, WM_WIDGET_HIDDEN, false);
                }
                else {
@@ -1362,7 +1362,7 @@ void WIDGETGROUP_manipulator_draw_prepare(const bContext 
*C, wmWidgetGroup *wgro
                }
 
                float col[4], col_hi[4];
-               manipulator_get_axis_color(rv3d, axis_idx, col, col_hi);
+               manipulator_get_axis_color(axis_idx, idot, col, col_hi);
                WM_widget_set_colors(axis, col, col_hi);
 
                switch (axis_idx) {
diff --git a/source/blender/makesdna/DNA_view3d_types.h 
b/source/blender/makesdna/DNA_view3d_types.h
index 3a38e3f..707c567 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -111,8 +111,7 @@ typedef struct RegionView3D {
        struct wmTimer *smooth_timer;
 
 
-       /* transform widget matrix */
-       float twmat[4][4];
+       float twmat[4][4];          /* transform widget matrix (no scale 
applied) */
 
        float viewquat[4];                      /* view rotation, must be kept 
normalized */
        float dist;                                     /* distance from 'ofs' 
along -viewinv[2] vector, where result is negative as is 'ofs' */
@@ -130,7 +129,7 @@ typedef struct RegionView3D {
        char pad[3];
        float ofs_lock[2];                      /* normalized offset for locked 
view: (-1, -1) bottom left, (1, 1) upper right */
 
-       short twdrawflag;
+       short twdrawflag; /* XXX can easily get rid of this (Julian) */
        short rflag;
 
 
@@ -139,13 +138,13 @@ typedef struct RegionView3D {
        short lpersp, lview; /* lpersp can never be set to 'RV3D_CAMOB' */
 
        float gridview;
-       float tw_idot[3];  /* manipulator runtime: (1 - dot) product with view 
vector (used to check view alignment) */
 
 
        /* active rotation from NDOF or elsewhere */
        float rot_angle;
        float rot_axis[3];
 
+       int pad2;
        struct GPUFX *compositor;
 } RegionView3D;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to