[Bf-blender-cvs] [d186ab65604] blender2.8: Manipulator: grab3d - support for 2d views
Campbell Barton
noreply at git.blender.org
Wed Aug 9 10:11:54 CEST 2017
Commit: d186ab6560414d9a817a84cc31a0a73f340c571c
Author: Campbell Barton
Date: Wed Aug 9 15:27:08 2017 +1000
Branches: blender2.8
https://developer.blender.org/rBd186ab6560414d9a817a84cc31a0a73f340c571c
Manipulator: grab3d - support for 2d views
Also internal changes so arrow3d matches grab3d's behavior.
Needed to add WM_MANIPULATOR_DRAW_OFFSET_SCALE flag so
we can optionally apply offset in worldspace or screen scaled values.
===================================================================
M source/blender/editors/include/ED_manipulator_library.h
M source/blender/editors/manipulator_library/manipulator_library_intern.h
M source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c
M source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
M source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
M source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c
M source/blender/editors/transform/transform_manipulator.c
M source/blender/windowmanager/manipulators/WM_manipulator_types.h
===================================================================
diff --git a/source/blender/editors/include/ED_manipulator_library.h b/source/blender/editors/include/ED_manipulator_library.h
index b8981acf1da..5d0f1526050 100644
--- a/source/blender/editors/include/ED_manipulator_library.h
+++ b/source/blender/editors/include/ED_manipulator_library.h
@@ -114,11 +114,13 @@ enum {
/* draw_options */
enum {
ED_MANIPULATOR_GRAB_DRAW_FLAG_NOP = 0,
+ /* only for solid shapes */
ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL = (1 << 0),
};
enum {
ED_MANIPULATOR_GRAB_STYLE_RING = 0,
+ ED_MANIPULATOR_GRAB_STYLE_CROSS = 1,
};
diff --git a/source/blender/editors/manipulator_library/manipulator_library_intern.h b/source/blender/editors/manipulator_library/manipulator_library_intern.h
index a22afda8730..3a504ebe1d2 100644
--- a/source/blender/editors/manipulator_library/manipulator_library_intern.h
+++ b/source/blender/editors/manipulator_library/manipulator_library_intern.h
@@ -50,10 +50,10 @@ typedef struct ManipulatorCommonData {
typedef struct ManipulatorInteraction {
float init_value; /* initial property value */
- float init_matrix[4][4];
+ float init_matrix_basis[4][4];
float init_mval[2];
float init_offset;
- float init_scale;
+ float init_scale_final;
/* offset of last handling step */
float prev_offset;
diff --git a/source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c
index 59a1e08d95a..61fb7e45533 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c
@@ -114,7 +114,7 @@ static void manipulator_arrow2d_draw(const bContext *UNUSED(C), wmManipulator *m
ManipulatorInteraction *inter = mpr->interaction_data;
glEnable(GL_BLEND);
- arrow2d_draw_geom(mpr, inter->init_matrix, (const float[4]){0.5f, 0.5f, 0.5f, 0.5f});
+ arrow2d_draw_geom(mpr, inter->init_matrix_basis, (const float[4]){0.5f, 0.5f, 0.5f, 0.5f});
glDisable(GL_BLEND);
}
}
@@ -129,7 +129,7 @@ static void manipulator_arrow2d_invoke(
{
ManipulatorInteraction *inter = MEM_callocN(sizeof(ManipulatorInteraction), __func__);
- copy_m4_m4(inter->init_matrix, mpr->matrix_basis);
+ copy_m4_m4(inter->init_matrix_basis, mpr->matrix_basis);
mpr->interaction_data = inter;
}
diff --git a/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
index 923eca27e7c..f9d6770bdb3 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
@@ -36,8 +36,6 @@
* - `matrix[0]` is derived from Y and Z.
* - `matrix[1]` is 'up' for manipulator types that have an up.
* - `matrix[2]` is the arrow direction (for all arrowes).
- *
- * TODO: use matrix_space
*/
#include "BIF_gl.h"
@@ -130,7 +128,7 @@ static void arrow_draw_geom(const ArrowManipulator3D *arrow, const bool select,
const float vec[2][3] = {
{0.0f, 0.0f, 0.0f},
- {0.0f, 0.0f, RNA_float_get(arrow->manipulator.ptr, "length")},
+ {0.0f, 0.0f, arrow_length},
};
glLineWidth(arrow->manipulator.line_width);
@@ -184,33 +182,46 @@ static void arrow_draw_geom(const ArrowManipulator3D *arrow, const bool select,
static void arrow_draw_intern(ArrowManipulator3D *arrow, const bool select, const bool highlight)
{
- float col[4];
+ wmManipulator *mpr = &arrow->manipulator;
+ float color[4];
float final_matrix[4][4];
- manipulator_color_get(&arrow->manipulator, highlight, col);
- manipulator_arrow_matrix_world_get(&arrow->manipulator, final_matrix);
+ manipulator_color_get(mpr, highlight, color);
+ manipulator_arrow_matrix_world_get(mpr, final_matrix);
- mul_mat3_m4_fl(final_matrix, arrow->manipulator.scale_final);
- mul_m4_m4m4(final_matrix, final_matrix, arrow->manipulator.matrix_offset);
+ if (mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) {
+ mul_mat3_m4_fl(final_matrix, arrow->manipulator.scale_final);
+ }
+ mul_m4_m4m4(final_matrix, final_matrix, mpr->matrix_offset);
+ if ((mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) == 0) {
+ mul_mat3_m4_fl(final_matrix, arrow->manipulator.scale_final);
+ }
gpuPushMatrix();
+ gpuMultMatrix(mpr->matrix_space);
gpuMultMatrix(final_matrix);
glEnable(GL_BLEND);
- arrow_draw_geom(arrow, select, col);
+ arrow_draw_geom(arrow, select, color);
glDisable(GL_BLEND);
gpuPopMatrix();
- if (arrow->manipulator.interaction_data) {
- ManipulatorInteraction *inter = arrow->manipulator.interaction_data;
- float offset_matrix[4][4];
+ if (mpr->interaction_data) {
+ ManipulatorInteraction *inter = mpr->interaction_data;
- copy_m4_m4(offset_matrix, inter->init_matrix);
- mul_mat3_m4_fl(offset_matrix, inter->init_scale);
+ copy_m4_m4(final_matrix, inter->init_matrix_basis);
+ if (mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) {
+ mul_mat3_m4_fl(final_matrix, inter->init_scale_final);
+ }
+ mul_m4_m4m4(final_matrix, final_matrix, mpr->matrix_offset);
+ if ((mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) == 0) {
+ mul_mat3_m4_fl(final_matrix, inter->init_scale_final);
+ }
gpuPushMatrix();
- gpuMultMatrix(offset_matrix);
- gpuMultMatrix(arrow->manipulator.matrix_offset);
+ gpuMultMatrix(mpr->matrix_space);
+
+ gpuMultMatrix(final_matrix);
glEnable(GL_BLEND);
arrow_draw_geom(arrow, select, (const float [4]){0.5f, 0.5f, 0.5f, 0.5f});
@@ -255,7 +266,7 @@ static void manipulator_arrow_modal(
bool use_vertical = false;
- copy_v3_v3(orig_origin, inter->init_matrix[3]);
+ copy_v3_v3(orig_origin, inter->init_matrix_basis[3]);
orig_origin[3] = 1.0f;
add_v3_v3v3(offset, orig_origin, arrow->manipulator.matrix_basis[2]);
offset[3] = 1.0f;
@@ -299,7 +310,7 @@ static void manipulator_arrow_modal(
float zfac = ED_view3d_calc_zfac(rv3d, orig_origin, NULL);
ED_view3d_win_to_delta(ar, dir2d_final, offset, zfac);
- add_v3_v3v3(orig_origin, offset, inter->init_matrix[3]);
+ add_v3_v3v3(orig_origin, offset, inter->init_matrix_basis[3]);
/* calculate view vector for the new position */
if (rv3d->is_persp) {
@@ -382,9 +393,9 @@ static void manipulator_arrow_invoke(
inter->init_mval[0] = event->mval[0];
inter->init_mval[1] = event->mval[1];
- inter->init_scale = mpr->scale_final;
+ inter->init_scale_final = mpr->scale_final;
- manipulator_arrow_matrix_world_get(mpr, inter->init_matrix);
+ manipulator_arrow_matrix_world_get(mpr, inter->init_matrix_basis);
mpr->interaction_data = inter;
}
@@ -400,14 +411,19 @@ static void manipulator_arrow_property_update(wmManipulator *mpr, wmManipulatorP
static void manipulator_arrow_exit(bContext *C, wmManipulator *mpr, const bool cancel)
{
- if (!cancel)
- return;
-
ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
ManipulatorCommonData *data = &arrow->data;
+ wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
+
+ if (!cancel) {
+ /* Assign incase applying the opetration needs an updated offset
+ * editmesh bisect needs this. */
+ data->offset = WM_manipulator_target_property_value_get(mpr, mpr_prop);
+ return;
+ }
+
ManipulatorInteraction *inter = mpr->interaction_data;
- wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
manipulator_property_value_reset(C, mpr, inter, mpr_prop);
data->offset = inter->init_offset;
}
diff --git a/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
index d4b98ec514a..605c089f818 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
@@ -23,7 +23,7 @@
*
* \name Grab Manipulator
*
- * 3D Manipulator
+ * 3D Manipulator, also works in 2D views.
*
* \brief Simple manipulator to grab and translate.
*
@@ -31,8 +31,6 @@
* - `matrix[1]` currently not used.
* - `matrix[2]` is the widget direction (for all manipulators).
*
- * TODO: use matrix_space
- *
*/
#include "BIF_gl.h"
@@ -75,9 +73,11 @@ typedef struct GrabInteraction {
/* only for when using properties */
float init_prop_co[3];
+ float init_matrix_basis[4][4];
+ float init_scale_final;
+
/* final output values, used for drawing */
struct {
- float co_ofs[3];
float co_final[3];
} output;
} GrabInteraction;
@@ -93,6 +93,7 @@ static void grab_geom_draw(
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;
@@ -105,11 +106,22 @@ static void grab_geom_draw(
immUniformColor4fv(col);
- if (filled) {
- imm_draw_circle_fill(pos, 0, 0, 1.0, DIAL_RESOLUTION);
+ if (draw_style == ED_MANIPULATOR_GRAB_STYLE_RING) {
+ if (filled) {
+ imm_draw_circle_fill(pos, 0, 0, 1.0f, DIAL_RESOLUTION);
+ }
+ else {
+ imm_draw_circle_wire(pos, 0, 0, 1.0f, DIAL_RESOLUTION);
+ }
}
- else {
- imm_draw_circle_wire(pos, 0, 0, 1.0, DIAL_RESOLUTION);
+ else if (draw_style == ED_MANIPULATOR_GRAB_STYLE_CROSS) {
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(pos, 1.0f, 1.0f);
+ immVertex2f(pos, -1.0f, -1.0f);
+
+ immVertex2f(pos, -1.0f, 1.0f);
+ immVertex2f(pos, 1.0f, -1.0f);
+ immEnd();
}
immUnbindProgram();
@@ -136,36 +148,47 @@ static void grab3d_get_translate(
}
static void grab3d_draw_intern(
- const bContext *C, wmManipulator *mpr,
+ const bContext *UNUSED(C), wmManipulator *mpr,
const bool select, const bool highlight)
{
- float mat[4][4];
float col[4];
-
- BLI_assert(CTX_wm_area(C)->spacetype == SPACE_VIEW3D);
- UNUSED_VARS_NDEBUG(C);
+ float final_matrix[4][4];
manipulator_color_get(mpr, highlight, col);
- copy_m4_m4(mat, mpr->matrix_basis);
- mul_mat3_m4_fl(mat, mpr->scale
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list