Manipulator: grab3d option to align to view
authorCampbell Barton <ideasman42@gmail.com>
Thu, 10 Aug 2017 06:35:45 +0000 (16:35 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 10 Aug 2017 06:35:45 +0000 (16:35 +1000)
Use for lamp-target, makes it easier to click on.

source/blender/editors/include/ED_manipulator_library.h
source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
source/blender/editors/space_view3d/view3d_manipulator_lamp.c

index a713202fc4b65c3ba4a41bf6ab63a9d29994eee2..84e8f7d14c7f3313d90636d31de6526f108a9005 100644 (file)
@@ -116,6 +116,7 @@ enum {
        ED_MANIPULATOR_GRAB_DRAW_FLAG_NOP               = 0,
        /* only for solid shapes */
        ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL              = (1 << 0),
        ED_MANIPULATOR_GRAB_DRAW_FLAG_NOP               = 0,
        /* only for solid shapes */
        ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL              = (1 << 0),
+       ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW        = (1 << 1),
 };
 
 enum {
 };
 
 enum {
index 7a002a9cfc8b0f57279a949aaee7307fdc56c67d..01376cf61841ae168839f853aa72c777c61f5a7d 100644 (file)
@@ -87,14 +87,13 @@ typedef struct GrabInteraction {
 /* -------------------------------------------------------------------- */
 
 static void grab_geom_draw(
 /* -------------------------------------------------------------------- */
 
 static void grab_geom_draw(
-        const wmManipulator *mpr, const float color[4], const bool select)
+        const wmManipulator *mpr, const float color[4], const bool select, const int draw_options)
 {
 #ifdef USE_MANIPULATOR_CUSTOM_DIAL
        UNUSED_VARS(grab3d, col, axis_modal_mat);
        wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_grab3d, select);
 #else
        const int draw_style = RNA_enum_get(mpr->ptr, "draw_style");
 {
 #ifdef USE_MANIPULATOR_CUSTOM_DIAL
        UNUSED_VARS(grab3d, col, axis_modal_mat);
        wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_grab3d, select);
 #else
        const int draw_style = RNA_enum_get(mpr->ptr, "draw_style");
-       const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
        const bool filled = (draw_options & ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL) != 0;
 
        glLineWidth(mpr->line_width);
        const bool filled = (draw_options & ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL) != 0;
 
        glLineWidth(mpr->line_width);
@@ -151,11 +150,14 @@ static void grab3d_get_translate(
 }
 
 static void grab3d_draw_intern(
 }
 
 static void grab3d_draw_intern(
-        const bContext *UNUSED(C), wmManipulator *mpr,
+        const bContext *C, wmManipulator *mpr,
         const bool select, const bool highlight)
 {
         const bool select, const bool highlight)
 {
+       const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
+       const bool align_view = (draw_options & ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW) != 0;
        float color[4];
        float matrix_final[4][4];
        float color[4];
        float matrix_final[4][4];
+       float matrix_align[4][4];
 
        manipulator_color_get(mpr, highlight, color);
 
 
        manipulator_color_get(mpr, highlight, color);
 
@@ -163,9 +165,19 @@ static void grab3d_draw_intern(
 
        gpuPushMatrix();
        gpuMultMatrix(matrix_final);
 
        gpuPushMatrix();
        gpuMultMatrix(matrix_final);
-       glEnable(GL_BLEND);
 
 
-       grab_geom_draw(mpr, color, select);
+       if (align_view) {
+               float matrix_final_unit[4][4];
+               RegionView3D *rv3d = CTX_wm_region_view3d(C);
+               normalize_m4_m4(matrix_final_unit, matrix_final);
+               mul_m4_m4m4(matrix_align, rv3d->viewmat, matrix_final_unit);
+               zero_v3(matrix_align[3]);
+               transpose_m4(matrix_align);
+               gpuMultMatrix(matrix_align);
+       }
+
+       glEnable(GL_BLEND);
+       grab_geom_draw(mpr, color, select, draw_options);
        glDisable(GL_BLEND);
        gpuPopMatrix();
 
        glDisable(GL_BLEND);
        gpuPopMatrix();
 
@@ -180,8 +192,13 @@ static void grab3d_draw_intern(
 
                gpuPushMatrix();
                gpuMultMatrix(matrix_final);
 
                gpuPushMatrix();
                gpuMultMatrix(matrix_final);
+
+               if (align_view) {
+                       gpuMultMatrix(matrix_align);
+               }
+
                glEnable(GL_BLEND);
                glEnable(GL_BLEND);
-               grab_geom_draw(mpr, (const float [4]){0.5f, 0.5f, 0.5f, 0.5f}, select);
+               grab_geom_draw(mpr, (const float [4]){0.5f, 0.5f, 0.5f, 0.5f}, select, draw_options);
                glDisable(GL_BLEND);
                gpuPopMatrix();
        }
                glDisable(GL_BLEND);
                gpuPopMatrix();
        }
@@ -313,6 +330,7 @@ static void MANIPULATOR_WT_grab_3d(wmManipulatorType *wt)
        };
        static EnumPropertyItem rna_enum_draw_options[] = {
                {ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL, "FILL", 0, "Filled", ""},
        };
        static EnumPropertyItem rna_enum_draw_options[] = {
                {ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL, "FILL", 0, "Filled", ""},
+               {ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW, "ALIGN_VIEW", 0, "Align View", ""},
                {0, NULL, 0, NULL, NULL}
        };
 
                {0, NULL, 0, NULL, NULL}
        };
 
index dfe06ec4e665c4f2d988a672f5f7ebabe49452dc..9454ff1e1589f1dca2e0986b0d452202765226fd 100644 (file)
@@ -260,9 +260,13 @@ static void WIDGETGROUP_lamp_target_setup(const bContext *UNUSED(C), wmManipulat
        UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, mpr->color);
        UI_GetThemeColor3fv(TH_MANIPULATOR_HI, mpr->color_hi);
 
        UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, mpr->color);
        UI_GetThemeColor3fv(TH_MANIPULATOR_HI, mpr->color_hi);
 
-       mpr->scale_basis = 0.05f;
+       mpr->scale_basis = 0.06f;
 
        wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_transform_axis_target", true);
 
        wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_transform_axis_target", true);
+
+       RNA_enum_set(mpr->ptr, "draw_options",
+                    ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL | ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW);
+
        WM_manipulator_set_operator(mpr, ot, NULL);
 }
 
        WM_manipulator_set_operator(mpr, ot, NULL);
 }