Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Tönne <lukas.toenne@gmail.com>2017-08-19 14:02:03 +0300
committerLukas Tönne <lukas.toenne@gmail.com>2017-08-19 14:02:03 +0300
commit45f0f3dc0457a53a25103784f0e0d100c7a17cbe (patch)
tree94767d8e4fa6ea23f2bbd2274f239ecbbdc5931a /source/blender/editors/manipulator_library
parent0d67f8d5c46fcc97cbb0544ef7d8c3c0056025c4 (diff)
parent9a262ed47ecb1c9f43053b0653364c59d9595fdf (diff)
Merge branch 'blender2.8' into strand_editmode
Diffstat (limited to 'source/blender/editors/manipulator_library')
-rw-r--r--source/blender/editors/manipulator_library/manipulator_draw_utils.c6
-rw-r--r--source/blender/editors/manipulator_library/manipulator_library_intern.h4
-rw-r--r--source/blender/editors/manipulator_library/manipulator_library_presets.c6
-rw-r--r--source/blender/editors/manipulator_library/manipulator_library_utils.c22
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c23
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c62
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c119
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c34
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c194
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c37
10 files changed, 336 insertions, 171 deletions
diff --git a/source/blender/editors/manipulator_library/manipulator_draw_utils.c b/source/blender/editors/manipulator_library/manipulator_draw_utils.c
index 26f9ebbe54e..f15cd9c9793 100644
--- a/source/blender/editors/manipulator_library/manipulator_draw_utils.c
+++ b/source/blender/editors/manipulator_library/manipulator_draw_utils.c
@@ -95,8 +95,8 @@ void wm_manipulator_geometryinfo_draw(const ManipulatorGeomInfo *info, const boo
GWN_vertbuf_attr_fill(vbo, nor_id, info->normals);
}
- batch = GWN_batch_create(GWN_PRIM_TRIS, vbo, el);
- Batch_set_builtin_program(batch, GPU_SHADER_3D_UNIFORM_COLOR);
+ batch = GWN_batch_create_ex(GWN_PRIM_TRIS, vbo, el, GWN_BATCH_OWNS_VBO | GWN_BATCH_OWNS_INDEX);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_3D_UNIFORM_COLOR);
GWN_batch_uniform_4fv(batch, "color", color);
@@ -115,7 +115,7 @@ void wm_manipulator_geometryinfo_draw(const ManipulatorGeomInfo *info, const boo
#endif
- GWN_batch_discard_all(batch);
+ GWN_batch_discard(batch);
}
void wm_manipulator_vec_draw(
diff --git a/source/blender/editors/manipulator_library/manipulator_library_intern.h b/source/blender/editors/manipulator_library/manipulator_library_intern.h
index a22afda8730..92ca195f21d 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_mval[2];
float init_offset;
- float init_scale;
+ float init_matrix_final[4][4];
+ float init_matrix_basis[4][4];
/* offset of last handling step */
float prev_offset;
diff --git a/source/blender/editors/manipulator_library/manipulator_library_presets.c b/source/blender/editors/manipulator_library/manipulator_library_presets.c
index e8111bda657..e552a7a6aa3 100644
--- a/source/blender/editors/manipulator_library/manipulator_library_presets.c
+++ b/source/blender/editors/manipulator_library/manipulator_library_presets.c
@@ -46,6 +46,7 @@
#include "MEM_guardedalloc.h"
+#include "DEG_depsgraph.h"
#include "RNA_access.h"
@@ -139,9 +140,12 @@ void ED_manipulator_draw_preset_facemap(
GPU_select_load_id(select_id);
}
+ EvaluationContext eval_ctx;
+ CTX_data_eval_ctx(C, &eval_ctx);
+
gpuPushMatrix();
gpuMultMatrix(ob->obmat);
- ED_draw_object_facemap(C, scene, ob, color, facemap);
+ ED_draw_object_facemap(&eval_ctx, scene, ob, color, facemap);
gpuPopMatrix();
if (is_select) {
diff --git a/source/blender/editors/manipulator_library/manipulator_library_utils.c b/source/blender/editors/manipulator_library/manipulator_library_utils.c
index 58999a82bba..d807ee07917 100644
--- a/source/blender/editors/manipulator_library/manipulator_library_utils.c
+++ b/source/blender/editors/manipulator_library/manipulator_library_utils.c
@@ -173,11 +173,23 @@ bool manipulator_window_project_2d(
float r_co[2])
{
float mat[4][4];
- if (use_offset) {
- mul_m4_series(mat, mpr->matrix_space, mpr->matrix_basis, mpr->matrix_offset);
- }
- else {
- mul_m4_series(mat, mpr->matrix_space, mpr->matrix_basis);
+ {
+ float matrix_basis_buf[4][4];
+ const void *matrix_basis;
+ if (mpr->type->matrix_basis_get) {
+ mpr->type->matrix_basis_get(mpr, matrix_basis_buf);
+ matrix_basis = &matrix_basis_buf[0][0];
+ }
+ else {
+ matrix_basis = &mpr->matrix_basis[0][0];
+ }
+
+ if (use_offset) {
+ mul_m4_series(mat, mpr->matrix_space, matrix_basis, mpr->matrix_offset);
+ }
+ else {
+ mul_m4_series(mat, mpr->matrix_space, matrix_basis);
+ }
}
/* rotate mouse in relation to the center and relocate it */
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..1185bec2a2d 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c
@@ -66,18 +66,12 @@ static void arrow2d_draw_geom(wmManipulator *mpr, const float matrix[4][4], cons
const float size_h = size / 2.0f;
const float arrow_length = RNA_float_get(mpr->ptr, "length");
const float arrow_angle = RNA_float_get(mpr->ptr, "angle");
- const float draw_line_ofs = (mpr->line_width * 0.5f) / mpr->scale_final;
uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
gpuPushMatrix();
gpuMultMatrix(matrix);
- gpuScaleUniform(mpr->scale_final);
gpuRotate2D(RAD2DEGF(arrow_angle));
- /* local offset */
- gpuTranslate2f(
- mpr->matrix_offset[3][0] + draw_line_ofs,
- mpr->matrix_offset[3][1]);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
@@ -101,20 +95,25 @@ static void arrow2d_draw_geom(wmManipulator *mpr, const float matrix[4][4], cons
static void manipulator_arrow2d_draw(const bContext *UNUSED(C), wmManipulator *mpr)
{
- float col[4];
+ float color[4];
- manipulator_color_get(mpr, mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT, col);
+ float matrix_final[4][4];
+
+ manipulator_color_get(mpr, mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT, color);
glLineWidth(mpr->line_width);
+
+ WM_manipulator_calc_matrix_final(mpr, matrix_final);
+
glEnable(GL_BLEND);
- arrow2d_draw_geom(mpr, mpr->matrix_basis, col);
+ arrow2d_draw_geom(mpr, matrix_final, color);
glDisable(GL_BLEND);
if (mpr->interaction_data) {
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_final, (const float[4]){0.5f, 0.5f, 0.5f, 0.5f});
glDisable(GL_BLEND);
}
}
@@ -129,7 +128,9 @@ 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);
+ WM_manipulator_calc_matrix_final(mpr, inter->init_matrix_final);
+
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..61f5a7b2786 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"
@@ -81,7 +79,7 @@ typedef struct ArrowManipulator3D {
/* -------------------------------------------------------------------- */
-static void manipulator_arrow_matrix_world_get(wmManipulator *mpr, float r_matrix[4][4])
+static void manipulator_arrow_matrix_basis_get(const wmManipulator *mpr, float r_matrix[4][4])
{
ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
@@ -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,33 @@ 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];
- float final_matrix[4][4];
+ wmManipulator *mpr = &arrow->manipulator;
+ float color[4];
+ float matrix_basis_adjust[4][4];
+ float matrix_final[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_basis_get(mpr, matrix_basis_adjust);
- mul_mat3_m4_fl(final_matrix, arrow->manipulator.scale_final);
- mul_m4_m4m4(final_matrix, final_matrix, arrow->manipulator.matrix_offset);
+ WM_manipulator_calc_matrix_final_params(
+ mpr, &((struct WM_ManipulatorMatrixParams) {
+ .matrix_basis = matrix_basis_adjust,
+ }), matrix_final);
gpuPushMatrix();
- gpuMultMatrix(final_matrix);
+ gpuMultMatrix(matrix_final);
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];
-
- copy_m4_m4(offset_matrix, inter->init_matrix);
- mul_mat3_m4_fl(offset_matrix, inter->init_scale);
+ if (mpr->interaction_data) {
+ ManipulatorInteraction *inter = mpr->interaction_data;
gpuPushMatrix();
- gpuMultMatrix(offset_matrix);
- gpuMultMatrix(arrow->manipulator.matrix_offset);
+ gpuMultMatrix(inter->init_matrix_final);
+
glEnable(GL_BLEND);
arrow_draw_geom(arrow, select, (const float [4]){0.5f, 0.5f, 0.5f, 0.5f});
@@ -255,7 +253,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 +297,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 +380,8 @@ 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;
-
- manipulator_arrow_matrix_world_get(mpr, inter->init_matrix);
+ manipulator_arrow_matrix_basis_get(mpr, inter->init_matrix_basis);
+ WM_manipulator_calc_matrix_final(mpr, inter->init_matrix_final);
mpr->interaction_data = inter;
}
@@ -400,14 +397,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;
}
@@ -458,7 +460,7 @@ static void MANIPULATOR_WT_arrow_3d(wmManipulatorType *wt)
/* api callbacks */
wt->draw = manipulator_arrow_draw;
wt->draw_select = manipulator_arrow_draw_select;
- wt->matrix_world_get = manipulator_arrow_matrix_world_get;
+ wt->matrix_basis_get = manipulator_arrow_matrix_basis_get;
wt->modal = manipulator_arrow_modal;
wt->setup = manipulator_arrow_setup;
wt->invoke = manipulator_arrow_invoke;
diff --git a/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c
index ee8d0e85dfd..40ef5f48492 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c
@@ -111,7 +111,7 @@ static void rect_transform_draw_corners(
}
static void rect_transform_draw_interaction(
- const float col[4], const int highlighted,
+ const float color[4], const int highlighted,
const float half_w, const float half_h,
const float w, const float h, const float line_width)
{
@@ -163,34 +163,65 @@ static void rect_transform_draw_interaction(
verts[3][1] = half_h - h;
break;
+ /* Only used for 3D view selection, never displayed to the user. */
+ case ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_TRANSLATE:
+ verts[0][0] = -half_w;
+ verts[0][1] = -half_h;
+
+ verts[1][0] = -half_w;
+ verts[1][1] = half_h;
+
+ verts[2][0] = half_w;
+ verts[2][1] = half_h;
+
+ verts[3][0] = half_w;
+ verts[3][1] = -half_h;
+ break;
+
default:
return;
}
Gwn_VertFormat *format = immVertexFormat();
- uint pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- uint color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ struct {
+ uint pos, col;
+ } attr_id = {
+ .pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT),
+ .col = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 3, GWN_FETCH_FLOAT),
+ };
immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
- glLineWidth(line_width + 3.0f);
+ if (highlighted == ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_TRANSLATE) {
+ immBegin(GWN_PRIM_TRI_FAN, 4);
+ immAttrib3f(attr_id.col, 0.0f, 0.0f, 0.0f);
+ immVertex2fv(attr_id.pos, verts[0]);
+ immVertex2fv(attr_id.pos, verts[1]);
+ immVertex2fv(attr_id.pos, verts[2]);
+ immVertex2fv(attr_id.pos, verts[3]);
+ immEnd();
+ }
+ else {
+ glLineWidth(line_width + 3.0f);
- immBegin(GWN_PRIM_LINE_STRIP, 3);
- immAttrib3f(color, 0.0f, 0.0f, 0.0f);
- immVertex2fv(pos, verts[0]);
- immVertex2fv(pos, verts[1]);
- immVertex2fv(pos, verts[2]);
- immEnd();
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+ immAttrib3f(attr_id.col, 0.0f, 0.0f, 0.0f);
+ immVertex2fv(attr_id.pos, verts[0]);
+ immVertex2fv(attr_id.pos, verts[1]);
+ immVertex2fv(attr_id.pos, verts[2]);
+ immEnd();
- glLineWidth(line_width);
+ glLineWidth(line_width);
- immBegin(GWN_PRIM_LINE_STRIP, 3);
- immAttrib3fv(color, col);
- immVertex2fv(pos, verts[0]);
- immVertex2fv(pos, verts[1]);
- immVertex2fv(pos, verts[2]);
- immEnd();
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+ immAttrib3fv(attr_id.col, color);
+ immVertex2fv(attr_id.pos, verts[0]);
+ immVertex2fv(attr_id.pos, verts[1]);
+ immVertex2fv(attr_id.pos, verts[2]);
+ immEnd();
+ }
immUnbindProgram();
+
}
static void manipulator_rect_transform_draw_intern(
@@ -242,16 +273,16 @@ static void manipulator_rect_transform_draw_intern(
/* corner manipulators */
{
- float col[4];
- manipulator_color_get(mpr, highlight, col);
+ float color[4];
+ manipulator_color_get(mpr, highlight, color);
glLineWidth(mpr->line_width);
- rect_transform_draw_corners(&r, w, h, col);
+ rect_transform_draw_corners(&r, w, h, color);
}
if (select) {
if (transform_flag & ED_MANIPULATOR_RECT_TRANSFORM_FLAG_SCALE) {
int scale_parts[] = {
- ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_SCALEX_LEFT,
+ ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_SCALEX_LEFT,
ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_SCALEX_RIGHT,
ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_SCALEY_UP,
ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_SCALEY_DOWN,
@@ -263,11 +294,21 @@ static void manipulator_rect_transform_draw_intern(
w, h, mpr->line_width);
}
}
+ if (transform_flag & ED_MANIPULATOR_RECT_TRANSFORM_FLAG_TRANSLATE) {
+ const int transform_part = ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_TRANSLATE;
+ GPU_select_load_id(select_id | transform_part);
+ rect_transform_draw_interaction(
+ mpr->color, transform_part, half_w, half_h,
+ w, h, mpr->line_width);
+ }
}
else {
- rect_transform_draw_interaction(
- mpr->color, mpr->highlight_part, half_w, half_h,
- w, h, mpr->line_width);
+ /* Don't draw translate (only for selection). */
+ if (mpr->highlight_part != ED_MANIPULATOR_RECT_TRANSFORM_INTERSECT_TRANSLATE) {
+ rect_transform_draw_interaction(
+ mpr->color, mpr->highlight_part, half_w, half_h,
+ w, h, mpr->line_width);
+ }
}
glLineWidth(1.0);
@@ -572,11 +613,6 @@ static void manipulator_rect_transform_modal(
wmManipulatorProperty *mpr_prop;
- mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
- if (mpr_prop->type != NULL) {
- WM_manipulator_target_property_value_set_array(C, mpr, mpr_prop, offset);
- }
-
mpr_prop = WM_manipulator_target_property_find(mpr, "scale");
if (mpr_prop->type != NULL) {
if (transform_flag & ED_MANIPULATOR_RECT_TRANSFORM_FLAG_SCALE_UNIFORM) {
@@ -593,21 +629,26 @@ static void manipulator_rect_transform_modal(
}
}
+ mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
+ if (mpr_prop->type != NULL) {
+ WM_manipulator_target_property_value_set_array(C, mpr, mpr_prop, offset);
+ }
+
/* tag the region for redraw */
ED_region_tag_redraw(CTX_wm_region(C));
}
static void manipulator_rect_transform_property_update(wmManipulator *mpr, wmManipulatorProperty *mpr_prop)
{
- if (STREQ(mpr_prop->type->idname, "offset")) {
- manipulator_rect_transform_get_prop_value(mpr, mpr_prop, mpr->matrix_offset[3]);
- }
- else if (STREQ(mpr_prop->type->idname, "scale")) {
+ if (STREQ(mpr_prop->type->idname, "scale")) {
float scale[2];
manipulator_rect_transform_get_prop_value(mpr, mpr_prop, scale);
mpr->matrix_offset[0][0] = scale[0];
mpr->matrix_offset[1][1] = scale[1];
}
+ else if (STREQ(mpr_prop->type->idname, "offset")) {
+ manipulator_rect_transform_get_prop_value(mpr, mpr_prop, mpr->matrix_offset[3]);
+ }
else {
BLI_assert(0);
}
@@ -623,11 +664,6 @@ static void manipulator_rect_transform_exit(bContext *C, wmManipulator *mpr, con
wmManipulatorProperty *mpr_prop;
/* reset properties */
- mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
- if (mpr_prop->type != NULL) {
- WM_manipulator_target_property_value_set_array(C, mpr, mpr_prop, data->orig_matrix_offset[3]);
- }
-
mpr_prop = WM_manipulator_target_property_find(mpr, "scale");
if (mpr_prop->type != NULL) {
const float orig_scale[2] = {data->orig_matrix_offset[0][0], data->orig_matrix_offset[1][1]};
@@ -645,6 +681,11 @@ static void manipulator_rect_transform_exit(bContext *C, wmManipulator *mpr, con
}
}
+ mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
+ if (mpr_prop->type != NULL) {
+ WM_manipulator_target_property_value_set_array(C, mpr, mpr_prop, data->orig_matrix_offset[3]);
+ }
+
copy_m4_m4(mpr->matrix_offset, data->orig_matrix_offset);
}
@@ -662,11 +703,11 @@ static void MANIPULATOR_WT_cage_2d(wmManipulatorType *wt)
/* api callbacks */
wt->draw = manipulator_rect_transform_draw;
wt->draw_select = manipulator_rect_transform_draw_select;
+ wt->test_select = manipulator_rect_transform_test_select;
wt->setup = manipulator_rect_transform_setup;
wt->invoke = manipulator_rect_transform_invoke;
wt->property_update = manipulator_rect_transform_property_update;
wt->modal = manipulator_rect_transform_modal;
- wt->test_select = manipulator_rect_transform_test_select;
wt->exit = manipulator_rect_transform_exit;
wt->cursor_get = manipulator_rect_transform_get_cursor;
diff --git a/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
index 742b4c70613..f7511c581ed 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
@@ -36,8 +36,6 @@
* - `matrix[0]` is derived from Y and Z.
* - `matrix[1]` is 'up' when DialManipulator.use_start_y_axis is set.
* - `matrix[2]` is the axis the dial rotates around (all dials).
- *
- * TODO: use matrix_space
*/
#include "BIF_gl.h"
@@ -107,13 +105,12 @@ static void dial_calc_matrix(const wmManipulator *mpr, float mat[4][4])
rotation_between_vecs_to_mat3(rot, up, mpr->matrix_basis[2]);
copy_m4_m3(mat, rot);
copy_v3_v3(mat[3], mpr->matrix_basis[3]);
- mul_mat3_m4_fl(mat, mpr->scale_final);
}
/* -------------------------------------------------------------------- */
static void dial_geom_draw(
- const wmManipulator *mpr, const float col[4], const bool select,
+ const wmManipulator *mpr, const float color[4], const bool select,
float axis_modal_mat[4][4], float clip_plane[4])
{
#ifdef USE_MANIPULATOR_CUSTOM_DIAL
@@ -138,7 +135,7 @@ static void dial_geom_draw(
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
}
- immUniformColor4fv(col);
+ immUniformColor4fv(color);
if (filled) {
imm_draw_circle_fill(pos, 0, 0, 1.0, DIAL_RESOLUTION);
@@ -156,7 +153,7 @@ static void dial_geom_draw(
/**
* Draws a line from (0, 0, 0) to \a co_outer, at \a angle.
*/
-static void dial_ghostarc_draw_helpline(const float angle, const float co_outer[3], const float col[4])
+static void dial_ghostarc_draw_helpline(const float angle, const float co_outer[3], const float color[4])
{
glLineWidth(1.0f);
@@ -167,7 +164,7 @@ static void dial_ghostarc_draw_helpline(const float angle, const float co_outer[
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- immUniformColor4fv(col);
+ immUniformColor4fv(color);
immBegin(GWN_PRIM_LINE_STRIP, 2);
immVertex3f(pos, 0.0f, 0.0f, 0.0f);
@@ -275,18 +272,23 @@ static void dial_draw_intern(
const bContext *C, wmManipulator *mpr,
const bool select, const bool highlight, float clip_plane[4])
{
- float mat[4][4];
- float col[4];
+ float matrix_basis_adjust[4][4];
+ float matrix_final[4][4];
+ float color[4];
BLI_assert(CTX_wm_area(C)->spacetype == SPACE_VIEW3D);
- manipulator_color_get(mpr, highlight, col);
+ manipulator_color_get(mpr, highlight, color);
+
+ dial_calc_matrix(mpr, matrix_basis_adjust);
- dial_calc_matrix(mpr, mat);
+ WM_manipulator_calc_matrix_final_params(
+ mpr, &((struct WM_ManipulatorMatrixParams) {
+ .matrix_basis = (void *)matrix_basis_adjust,
+ }), matrix_final);
gpuPushMatrix();
- gpuMultMatrix(mat);
- gpuMultMatrix(mpr->matrix_offset);
+ gpuMultMatrix(matrix_final);
/* draw rotation indicator arc first */
if ((mpr->flag & WM_MANIPULATOR_DRAW_VALUE) &&
@@ -309,8 +311,8 @@ static void dial_draw_intern(
for (int i = 0; i < 2; i++) {
dial_ghostarc_draw(mpr, angle_ofs, angle_delta, (const float [4]){0.8f, 0.8f, 0.8f, 0.4f});
- dial_ghostarc_draw_helpline(angle_ofs, co_outer, col); /* starting position */
- dial_ghostarc_draw_helpline(angle_ofs + angle_delta, co_outer, col); /* starting position + current value */
+ dial_ghostarc_draw_helpline(angle_ofs, co_outer, color); /* starting position */
+ dial_ghostarc_draw_helpline(angle_ofs + angle_delta, co_outer, color); /* starting position + current value */
if (i == 0) {
const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
@@ -324,7 +326,7 @@ static void dial_draw_intern(
}
/* draw actual dial manipulator */
- dial_geom_draw(mpr, col, select, mat, clip_plane);
+ dial_geom_draw(mpr, color, select, matrix_basis_adjust, clip_plane);
gpuPopMatrix();
}
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..38e350762c1 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"
@@ -65,6 +63,20 @@
#include "../manipulator_geometry.h"
#include "../manipulator_library_intern.h"
+typedef struct GrabManipulator3D {
+ wmManipulator manipulator;
+ /* Added to 'matrix_basis' when calculating the matrix. */
+ float prop_co[3];
+} GrabManipulator3D;
+
+static void manipulator_grab_matrix_basis_get(const wmManipulator *mpr, float r_matrix[4][4])
+{
+ GrabManipulator3D *grab = (GrabManipulator3D *)mpr;
+
+ copy_m4_m4(r_matrix, grab->manipulator.matrix_basis);
+ add_v3_v3(r_matrix[3], grab->prop_co);
+}
+
static void manipulator_grab_modal(
bContext *C, wmManipulator *mpr, const wmEvent *event,
eWM_ManipulatorTweak tweak_flag);
@@ -75,11 +87,7 @@ typedef struct GrabInteraction {
/* only for when using properties */
float init_prop_co[3];
- /* final output values, used for drawing */
- struct {
- float co_ofs[3];
- float co_final[3];
- } output;
+ float init_matrix_final[4][4];
} GrabInteraction;
#define DIAL_RESOLUTION 32
@@ -87,13 +95,13 @@ typedef struct GrabInteraction {
/* -------------------------------------------------------------------- */
static void grab_geom_draw(
- const wmManipulator *mpr, const float col[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_options = RNA_enum_get(mpr->ptr, "draw_options");
+ const int draw_style = RNA_enum_get(mpr->ptr, "draw_style");
const bool filled = (draw_options & ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL) != 0;
glLineWidth(mpr->line_width);
@@ -103,13 +111,27 @@ static void grab_geom_draw(
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- immUniformColor4fv(col);
+ immUniformColor4fv(color);
- if (filled) {
- imm_draw_circle_fill(pos, 0, 0, 1.0, DIAL_RESOLUTION);
+ if (draw_style == ED_MANIPULATOR_GRAB_STYLE_RING_2D) {
+ 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 if (draw_style == ED_MANIPULATOR_GRAB_STYLE_CROSS_2D) {
+ 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();
}
else {
- imm_draw_circle_wire(pos, 0, 0, 1.0, DIAL_RESOLUTION);
+ BLI_assert(0);
}
immUnbindProgram();
@@ -129,45 +151,68 @@ static void grab3d_get_translate(
};
RegionView3D *rv3d = ar->regiondata;
- const float *co_ref = inter->init_prop_co;
+ float co_ref[3];
+ mul_v3_mat3_m4v3(co_ref, mpr->matrix_space, inter->init_prop_co);
const float zfac = ED_view3d_calc_zfac(rv3d, co_ref, NULL);
ED_view3d_win_to_delta(ar, mval_delta, co_delta, zfac);
+
+ float matrix_space_inv[3][3];
+ copy_m3_m4(matrix_space_inv, mpr->matrix_space);
+ invert_m3(matrix_space_inv);
+ mul_m3_v3(matrix_space_inv, co_delta);
}
static void grab3d_draw_intern(
const bContext *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);
-
- manipulator_color_get(mpr, highlight, col);
-
- copy_m4_m4(mat, mpr->matrix_basis);
- mul_mat3_m4_fl(mat, mpr->scale_final);
+ GrabInteraction *inter = mpr->interaction_data;
+ 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 matrix_align[4][4];
+
+ manipulator_color_get(mpr, highlight, color);
+
+ {
+ float matrix_basis_adjust[4][4];
+ manipulator_grab_matrix_basis_get(mpr, matrix_basis_adjust);
+ WM_manipulator_calc_matrix_final_params(
+ mpr, &((struct WM_ManipulatorMatrixParams) {
+ .matrix_basis = matrix_basis_adjust,
+ }), matrix_final);
+ }
gpuPushMatrix();
- if (mpr->interaction_data) {
- GrabInteraction *inter = mpr->interaction_data;
- gpuTranslate3fv(inter->output.co_ofs);
+ gpuMultMatrix(matrix_final);
+
+ 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);
}
- gpuMultMatrix(mat);
- gpuMultMatrix(mpr->matrix_offset);
+
glEnable(GL_BLEND);
- grab_geom_draw(mpr, col, select);
+ grab_geom_draw(mpr, color, select, draw_options);
glDisable(GL_BLEND);
gpuPopMatrix();
if (mpr->interaction_data) {
gpuPushMatrix();
- gpuMultMatrix(mat);
- gpuMultMatrix(mpr->matrix_offset);
+ gpuMultMatrix(inter->init_matrix_final);
+
+ if (align_view) {
+ gpuMultMatrix(matrix_align);
+ }
+
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();
}
@@ -195,17 +240,35 @@ static void manipulator_grab_modal(
bContext *C, wmManipulator *mpr, const wmEvent *event,
eWM_ManipulatorTweak UNUSED(tweak_flag))
{
+ GrabManipulator3D *grab = (GrabManipulator3D *)mpr;
GrabInteraction *inter = mpr->interaction_data;
+ ARegion *ar = CTX_wm_region(C);
- grab3d_get_translate(mpr, event, CTX_wm_region(C), inter->output.co_ofs);
-
- add_v3_v3v3(inter->output.co_final, inter->init_prop_co, inter->output.co_ofs);
+ float prop_delta[3];
+ if (CTX_wm_area(C)->spacetype == SPACE_VIEW3D) {
+ grab3d_get_translate(mpr, event, ar, prop_delta);
+ }
+ else {
+ float mval_proj_init[2], mval_proj_curr[2];
+ if ((manipulator_window_project_2d(
+ C, mpr, inter->init_mval, 2, false, mval_proj_init) == false) ||
+ (manipulator_window_project_2d(
+ C, mpr, (const float[2]){UNPACK2(event->mval)}, 2, false, mval_proj_curr) == false))
+ {
+ return;
+ }
+ sub_v2_v2v2(prop_delta, mval_proj_curr, mval_proj_init);
+ prop_delta[2] = 0.0f;
+ }
+ add_v3_v3v3(grab->prop_co, inter->init_prop_co, prop_delta);
/* set the property for the operator and call its modal function */
wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
if (WM_manipulator_target_property_is_valid(mpr_prop)) {
- WM_manipulator_target_property_value_set_array(C, mpr, mpr_prop, inter->output.co_final);
+ WM_manipulator_target_property_value_set_array(C, mpr, mpr_prop, grab->prop_co);
}
+
+ ED_region_tag_redraw(ar);
}
static void manipulator_grab_invoke(
@@ -216,14 +279,57 @@ static void manipulator_grab_invoke(
inter->init_mval[0] = event->mval[0];
inter->init_mval[1] = event->mval[1];
+#if 0
+ copy_v3_v3(inter->init_prop_co, grab->prop_co);
+#else
wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
if (WM_manipulator_target_property_is_valid(mpr_prop)) {
WM_manipulator_target_property_value_get_array(mpr, mpr_prop, inter->init_prop_co);
}
+#endif
+
+ {
+ float matrix_basis_adjust[4][4];
+ manipulator_grab_matrix_basis_get(mpr, matrix_basis_adjust);
+ WM_manipulator_calc_matrix_final_params(
+ mpr, &((struct WM_ManipulatorMatrixParams) {
+ .matrix_basis = matrix_basis_adjust,
+ }), inter->init_matrix_final);
+ }
mpr->interaction_data = inter;
}
+
+static int manipulator_grab_test_select(
+ bContext *C, wmManipulator *mpr, const wmEvent *event)
+{
+ float point_local[2];
+
+ if (manipulator_window_project_2d(
+ C, mpr, (const float[2]){UNPACK2(event->mval)}, 2, true, point_local) == false)
+ {
+ return 0;
+ }
+
+ if (len_squared_v2(point_local) < SQUARE(mpr->scale_final)) {
+ return true;
+ }
+
+ return 0;
+}
+
+static void manipulator_grab_property_update(wmManipulator *mpr, wmManipulatorProperty *mpr_prop)
+{
+ GrabManipulator3D *grab = (GrabManipulator3D *)mpr;
+ WM_manipulator_target_property_value_get_array(mpr, mpr_prop, grab->prop_co);
+}
+
+static int manipulator_grab_cursor_get(wmManipulator *UNUSED(mpr))
+{
+ return BC_HANDCURSOR;
+}
+
/* -------------------------------------------------------------------- */
/** \name Grab Manipulator API
*
@@ -237,22 +343,28 @@ static void MANIPULATOR_WT_grab_3d(wmManipulatorType *wt)
/* api callbacks */
wt->draw = manipulator_grab_draw;
wt->draw_select = manipulator_grab_draw_select;
+ wt->test_select = manipulator_grab_test_select;
+ wt->matrix_basis_get = manipulator_grab_matrix_basis_get;
wt->invoke = manipulator_grab_invoke;
+ wt->property_update = manipulator_grab_property_update;
wt->modal = manipulator_grab_modal;
+ wt->cursor_get = manipulator_grab_cursor_get;
- wt->struct_size = sizeof(wmManipulator);
+ wt->struct_size = sizeof(GrabManipulator3D);
/* rna */
static EnumPropertyItem rna_enum_draw_style[] = {
- {ED_MANIPULATOR_GRAB_STYLE_RING, "RING", 0, "Ring", ""},
+ {ED_MANIPULATOR_GRAB_STYLE_RING_2D, "RING_2D", 0, "Ring", ""},
+ {ED_MANIPULATOR_GRAB_STYLE_CROSS_2D, "CROSS_2D", 0, "Ring", ""},
{0, NULL, 0, NULL, NULL}
};
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}
};
- RNA_def_enum(wt->srna, "draw_style", rna_enum_draw_style, ED_MANIPULATOR_GRAB_STYLE_RING, "Draw Style", "");
+ RNA_def_enum(wt->srna, "draw_style", rna_enum_draw_style, ED_MANIPULATOR_GRAB_STYLE_RING_2D, "Draw Style", "");
RNA_def_enum_flag(wt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", "");
WM_manipulatortype_target_property_def(wt, "offset", PROP_FLOAT, 3);
diff --git a/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c
index 6a7fde5a5b5..44878a24430 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c
@@ -27,8 +27,6 @@
*
* \brief Manipulator with primitive drawing type (plane, cube, etc.).
* Currently only plane primitive supported without own handling, use with operator only.
- *
- * TODO: use matrix_space
*/
#include "BIF_gl.h"
@@ -90,23 +88,21 @@ static void manipulator_primitive_draw_intern(
wmManipulator *mpr, const bool UNUSED(select),
const bool highlight)
{
- float col_inner[4], col_outer[4];
- float mat[4][4];
+ float color_inner[4], color_outer[4];
+ float matrix_final[4][4];
const int draw_style = RNA_enum_get(mpr->ptr, "draw_style");
- manipulator_color_get(mpr, highlight, col_outer);
- copy_v4_v4(col_inner, col_outer);
- col_inner[3] *= 0.5f;
+ manipulator_color_get(mpr, highlight, color_outer);
+ copy_v4_v4(color_inner, color_outer);
+ color_inner[3] *= 0.5f;
- copy_m4_m4(mat, mpr->matrix_basis);
- mul_mat3_m4_fl(mat, mpr->scale_final);
+ WM_manipulator_calc_matrix_final(mpr, matrix_final);
gpuPushMatrix();
- gpuMultMatrix(mat);
+ gpuMultMatrix(matrix_final);
glEnable(GL_BLEND);
- gpuMultMatrix(mpr->matrix_offset);
- manipulator_primitive_draw_geom(col_inner, col_outer, draw_style);
+ manipulator_primitive_draw_geom(color_inner, color_outer, draw_style);
glDisable(GL_BLEND);
gpuPopMatrix();
@@ -114,19 +110,15 @@ static void manipulator_primitive_draw_intern(
if (mpr->interaction_data) {
ManipulatorInteraction *inter = mpr->interaction_data;
- copy_v4_fl(col_inner, 0.5f);
- copy_v3_fl(col_outer, 0.5f);
- col_outer[3] = 0.8f;
-
- copy_m4_m4(mat, inter->init_matrix);
- mul_mat3_m4_fl(mat, inter->init_scale);
+ copy_v4_fl(color_inner, 0.5f);
+ copy_v3_fl(color_outer, 0.5f);
+ color_outer[3] = 0.8f;
gpuPushMatrix();
- gpuMultMatrix(mat);
+ gpuMultMatrix(inter->init_matrix_final);
glEnable(GL_BLEND);
- gpuMultMatrix(mpr->matrix_offset);
- manipulator_primitive_draw_geom(col_inner, col_outer, draw_style);
+ manipulator_primitive_draw_geom(color_inner, color_outer, draw_style);
glDisable(GL_BLEND);
gpuPopMatrix();
@@ -158,8 +150,7 @@ static void manipulator_primitive_invoke(
{
ManipulatorInteraction *inter = MEM_callocN(sizeof(ManipulatorInteraction), __func__);
- copy_m4_m4(inter->init_matrix, mpr->matrix_basis);
- inter->init_scale = mpr->scale_final;
+ WM_manipulator_calc_matrix_final(mpr, inter->init_matrix_final);
mpr->interaction_data = inter;
}