diff options
Diffstat (limited to 'source/blender/editors/transform')
11 files changed, 565 insertions, 667 deletions
diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index 54533bf43e5..b6383cce79c 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -58,6 +58,10 @@ static void drawObjectConstraint(TransInfo *t); +/* -------------------------------------------------------------------- */ +/** \name Internal Utilities + * \{ */ + static void projection_matrix_calc(const TransInfo *t, float r_pmtx[3][3]) { unit_m3(r_pmtx); @@ -79,7 +83,6 @@ static void projection_matrix_calc(const TransInfo *t, float r_pmtx[3][3]) mul_m3_m3m3(r_pmtx, t->spacemtx, mat); } -/* ************************** CONSTRAINTS ************************* */ #define CONSTRAIN_EPSILON 0.0001f static void constraint_plane_calc(TransInfo *t, float r_plane[4]) @@ -369,14 +372,13 @@ static void planeProjection(const TransInfo *t, const float in[3], float out[3]) add_v3_v3v3(out, in, vec); } -/* +/** * Generic callback for constant spatial constraints applied to linear motion * - * The IN vector in projected into the constrained space and then further + * The `in` vector in projected into the constrained space and then further * projected along the view vector. * (in perspective mode, the view vector is relative to the position on screen) */ - static void applyAxisConstraintVec( TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, const float in[3], float out[3]) { @@ -448,17 +450,16 @@ static void applyAxisConstraintVec( } } -/* +/** * Generic callback for object based spatial constraints applied to linear motion * * At first, the following is applied without orientation * The IN vector in projected into the constrained space and then further * projected along the view vector. - * (in perspective mode, the view vector is relative to the position on screen) + * (in perspective mode, the view vector is relative to the position on screen). * * Further down, that vector is mapped to each data's space. */ - static void applyObjectConstraintVec( TransInfo *t, TransDataContainer *tc, TransData *td, const float in[3], float out[3]) { @@ -478,10 +479,9 @@ static void applyObjectConstraintVec( } } -/* - * Generic callback for constant spatial constraints applied to resize motion +/** + * Generic callback for constant spatial constraints applied to resize motion. */ - static void applyAxisConstraintSize(TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, @@ -505,10 +505,9 @@ static void applyAxisConstraintSize(TransInfo *t, } } -/* - * Callback for object based spatial constraints applied to resize motion +/** + * Callback for object based spatial constraints applied to resize motion. */ - static void applyObjectConstraintSize(TransInfo *t, TransDataContainer *tc, TransData *td, @@ -538,109 +537,86 @@ static void applyObjectConstraintSize(TransInfo *t, } } -/* +static void constraints_rotation_imp(TransInfo *t, float r_vec[3], float *r_angle) +{ + BLI_assert(t->con.mode & CON_APPLY); + int mode = t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2); + + switch (mode) { + case CON_AXIS0: + case (CON_AXIS1 | CON_AXIS2): + negate_v3_v3(r_vec, t->spacemtx[0]); + break; + case CON_AXIS1: + case (CON_AXIS0 | CON_AXIS2): + negate_v3_v3(r_vec, t->spacemtx[1]); + break; + case CON_AXIS2: + case (CON_AXIS0 | CON_AXIS1): + negate_v3_v3(r_vec, t->spacemtx[2]); + break; + } + /* don't flip axis if asked to or if num input */ + if (r_angle && (mode & CON_NOFLIP) == 0 && hasNumInput(&t->num) == 0) { + if (dot_v3v3(r_vec, t->viewinv[2]) > 0.0f) { + *r_angle = -(*r_angle); + } + } +} + +/** * Generic callback for constant spatial constraints applied to rotations * - * The rotation axis is copied into VEC. + * The rotation axis is copied into `vec`. * * In the case of single axis constraints, the rotation axis is directly the one constrained to. * For planar constraints (2 axis), the rotation axis is the normal of the plane. * - * The following only applies when CON_NOFLIP is not set. + * The following only applies when #CON_NOFLIP is not set. * The vector is then modified to always point away from the screen (in global space) * This insures that the rotation is always logically following the mouse. * (ie: not doing counterclockwise rotations when the mouse moves clockwise). */ - static void applyAxisConstraintRot( TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, float vec[3], float *angle) { if (!td && t->con.mode & CON_APPLY) { - int mode = t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2); - - switch (mode) { - case CON_AXIS0: - case (CON_AXIS1 | CON_AXIS2): - copy_v3_v3(vec, t->spacemtx[0]); - break; - case CON_AXIS1: - case (CON_AXIS0 | CON_AXIS2): - copy_v3_v3(vec, t->spacemtx[1]); - break; - case CON_AXIS2: - case (CON_AXIS0 | CON_AXIS1): - copy_v3_v3(vec, t->spacemtx[2]); - break; - } - /* don't flip axis if asked to or if num input */ - if (angle && (mode & CON_NOFLIP) == 0 && hasNumInput(&t->num) == 0) { - if (dot_v3v3(vec, t->viewinv[2]) > 0.0f) { - *angle = -(*angle); - } - } + constraints_rotation_imp(t, vec, angle); } } -/* +/** * Callback for object based spatial constraints applied to rotations * - * The rotation axis is copied into VEC. + * The rotation axis is copied into `vec`. * * In the case of single axis constraints, the rotation axis is directly the one constrained to. * For planar constraints (2 axis), the rotation axis is the normal of the plane. * - * The following only applies when CON_NOFLIP is not set. + * The following only applies when #CON_NOFLIP is not set. * The vector is then modified to always point away from the screen (in global space) * This insures that the rotation is always logically following the mouse. * (ie: not doing counterclockwise rotations when the mouse moves clockwise). */ - static void applyObjectConstraintRot( TransInfo *t, TransDataContainer *tc, TransData *td, float vec[3], float *angle) { if (t->con.mode & CON_APPLY) { - int mode = t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2); - float tmp_axismtx[3][3]; - float(*axismtx)[3]; - /* on setup call, use first object */ if (td == NULL) { BLI_assert(tc == NULL); tc = TRANS_DATA_CONTAINER_FIRST_OK(t); td = tc->data; } - - if (t->flag & T_EDIT) { - mul_m3_m3m3(tmp_axismtx, tc->mat3_unit, td->axismtx); - axismtx = tmp_axismtx; - } - else { - axismtx = td->axismtx; - } - - switch (mode) { - case CON_AXIS0: - case (CON_AXIS1 | CON_AXIS2): - copy_v3_v3(vec, axismtx[0]); - break; - case CON_AXIS1: - case (CON_AXIS0 | CON_AXIS2): - copy_v3_v3(vec, axismtx[1]); - break; - case CON_AXIS2: - case (CON_AXIS0 | CON_AXIS1): - copy_v3_v3(vec, axismtx[2]); - break; - } - if (angle && (mode & CON_NOFLIP) == 0 && hasNumInput(&t->num) == 0) { - if (dot_v3v3(vec, t->viewinv[2]) > 0.0f) { - *angle = -(*angle); - } - } + constraints_rotation_imp(t, vec, angle); } } -/*--------------------- INTERNAL SETUP CALLS ------------------*/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Internal Setup Calls + * \{ */ void setConstraint(TransInfo *t, int mode, const char text[]) { @@ -675,7 +651,7 @@ void setAxisMatrixConstraint(TransInfo *t, int mode, const char text[]) void setLocalConstraint(TransInfo *t, int mode, const char text[]) { - if (t->flag & T_EDIT) { + if ((t->flag & T_EDIT) || t->data_len_all == 1) { /* Although in edit-mode each object has its local space, use the * orientation of the active object. */ setConstraint(t, mode, text); @@ -685,10 +661,10 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[]) } } -/* +/** * Set the constraint according to the user defined orientation * - * ftext is a format string passed to BLI_snprintf. It will add the name of + * `ftext` is a format string passed to #BLI_snprintf. It will add the name of * the orientation where %s is (logically). */ void setUserConstraint(TransInfo *t, int mode, const char ftext[]) @@ -703,40 +679,35 @@ void setUserConstraint(TransInfo *t, int mode, const char ftext[]) const char *spacename = transform_orientations_spacename_get(t, orientation); BLI_snprintf(text, sizeof(text), ftext, spacename); - if (t->modifiers & (MOD_CONSTRAINT_SELECT | MOD_CONSTRAINT_PLANE)) { - /* Force the orientation of the active object. - * Although possible, it is not convenient to use the local or axis constraint - * with the modifier to select constraint. - * This also follows the convention of older versions. */ - setConstraint(t, mode, text); - } - else { - switch (orientation) { - case V3D_ORIENT_LOCAL: - setLocalConstraint(t, mode, text); - break; - case V3D_ORIENT_NORMAL: - if (checkUseAxisMatrix(t)) { - setAxisMatrixConstraint(t, mode, text); - break; - } - ATTR_FALLTHROUGH; - case V3D_ORIENT_GLOBAL: - case V3D_ORIENT_VIEW: - case V3D_ORIENT_CURSOR: - case V3D_ORIENT_GIMBAL: - case V3D_ORIENT_CUSTOM_MATRIX: - case V3D_ORIENT_CUSTOM: - default: { - setConstraint(t, mode, text); + switch (orientation) { + case V3D_ORIENT_LOCAL: + setLocalConstraint(t, mode, text); + break; + case V3D_ORIENT_NORMAL: + if (checkUseAxisMatrix(t)) { + setAxisMatrixConstraint(t, mode, text); break; } + ATTR_FALLTHROUGH; + case V3D_ORIENT_GLOBAL: + case V3D_ORIENT_VIEW: + case V3D_ORIENT_CURSOR: + case V3D_ORIENT_GIMBAL: + case V3D_ORIENT_CUSTOM_MATRIX: + case V3D_ORIENT_CUSTOM: + default: { + setConstraint(t, mode, text); + break; } } t->con.mode |= CON_USER; } -/*----------------- DRAWING CONSTRAINTS -------------------*/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Drawing Constraints + * \{ */ void drawConstraint(TransInfo *t) { @@ -937,7 +908,11 @@ static void drawObjectConstraint(TransInfo *t) } } -/*--------------------- START / STOP CONSTRAINTS ---------------------- */ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Start / Stop Constraints + * \{ */ void startConstraint(TransInfo *t) { @@ -958,7 +933,11 @@ void stopConstraint(TransInfo *t) t->num.idx_max = t->idx_max; } -/*------------------------- MMB Select -------------------------------*/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Middle Mouse Button Select + * \{ */ void initSelectConstraint(TransInfo *t) { @@ -1105,7 +1084,11 @@ void setNearestAxis(TransInfo *t) projection_matrix_calc(t, t->con.pmtx); } -/*-------------- HELPER FUNCTIONS ----------------*/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Helper Functions + * \{ */ int constraintModeToIndex(const TransInfo *t) { @@ -1146,14 +1129,13 @@ bool isLockConstraint(TransInfo *t) return false; } -/* +/** * Returns the dimension of the constraint space. * * For that reason, the flags always needs to be set to properly evaluate here, - * even if they aren't actually used in the callback function. (Which could happen - * for weird constraints not yet designed. Along a path for example.) + * even if they aren't actually used in the callback function. + * (Which could happen for weird constraints not yet designed. Along a path for example.) */ - int getConstraintSpaceDimension(TransInfo *t) { int n = 0; @@ -1171,11 +1153,12 @@ int getConstraintSpaceDimension(TransInfo *t) } return n; - /* - * Someone willing to do it cryptically could do the following instead: + /* Someone willing to do it cryptically could do the following instead: * - * return t->con & (CON_AXIS0|CON_AXIS1|CON_AXIS2); + * `return t->con & (CON_AXIS0|CON_AXIS1|CON_AXIS2);` * * Based on the assumptions that the axis flags are one after the other and start at 1 */ } + +/** \} */ diff --git a/source/blender/editors/transform/transform_convert_gpencil.c b/source/blender/editors/transform/transform_convert_gpencil.c index 0a742ec4470..17362ae65e5 100644 --- a/source/blender/editors/transform/transform_convert_gpencil.c +++ b/source/blender/editors/transform/transform_convert_gpencil.c @@ -135,7 +135,7 @@ static void createTransGPencil_curves(bContext *C, continue; } /* Check if the color is editable. */ - if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) { + if (ED_gpencil_stroke_material_editable(obact, gpl, gps) == false) { continue; } /* Check if stroke has an editcurve */ @@ -242,7 +242,7 @@ static void createTransGPencil_curves(bContext *C, } /* Calculate difference matrix. */ - BKE_gpencil_parent_matrix_get(depsgraph, obact, gpl, diff_mat); + BKE_gpencil_layer_transform_matrix_get(depsgraph, obact, gpl, diff_mat); copy_m3_m4(mtx, diff_mat); pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); @@ -263,7 +263,7 @@ static void createTransGPencil_curves(bContext *C, continue; } /* Check if the color is editable. */ - if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) { + if (ED_gpencil_stroke_material_editable(obact, gpl, gps) == false) { continue; } /* Check if stroke has an editcurve */ @@ -436,7 +436,7 @@ static void createTransGPencil_strokes(bContext *C, continue; } /* Check if the color is editable. */ - if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) { + if (ED_gpencil_stroke_material_editable(obact, gpl, gps) == false) { continue; } @@ -507,7 +507,7 @@ static void createTransGPencil_strokes(bContext *C, } /* Calculate difference matrix. */ - BKE_gpencil_parent_matrix_get(depsgraph, obact, gpl, diff_mat); + BKE_gpencil_layer_transform_matrix_get(depsgraph, obact, gpl, diff_mat); /* Undo matrix. */ invert_m4_m4(inverse_diff_mat, diff_mat); @@ -551,7 +551,7 @@ static void createTransGPencil_strokes(bContext *C, continue; } /* check if the color is editable */ - if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) { + if (ED_gpencil_stroke_material_editable(obact, gpl, gps) == false) { continue; } /* What we need to include depends on proportional editing settings... */ diff --git a/source/blender/editors/transform/transform_convert_mesh.c b/source/blender/editors/transform/transform_convert_mesh.c index b3bd6b31879..ce74c5f5a36 100644 --- a/source/blender/editors/transform/transform_convert_mesh.c +++ b/source/blender/editors/transform/transform_convert_mesh.c @@ -251,29 +251,55 @@ void transform_convert_mesh_islanddata_free(struct TransIslandData *island_data) * * \{ */ -static bool bmesh_test_dist_add(BMVert *v, - BMVert *v_other, +/* Propagate distance from v1 and v2 to v0. */ +static bool bmesh_test_dist_add(BMVert *v0, + BMVert *v1, + BMVert *v2, float *dists, - const float *dists_prev, /* optionally track original index */ int *index, - const int *index_prev, const float mtx[3][3]) { - if ((BM_elem_flag_test(v_other, BM_ELEM_SELECT) == 0) && - (BM_elem_flag_test(v_other, BM_ELEM_HIDDEN) == 0)) { - const int i = BM_elem_index_get(v); - const int i_other = BM_elem_index_get(v_other); - float vec[3]; - float dist_other; - sub_v3_v3v3(vec, v->co, v_other->co); - mul_m3_v3(mtx, vec); - - dist_other = dists_prev[i] + len_v3(vec); - if (dist_other < dists[i_other]) { - dists[i_other] = dist_other; + if ((BM_elem_flag_test(v0, BM_ELEM_SELECT) == 0) && + (BM_elem_flag_test(v0, BM_ELEM_HIDDEN) == 0)) { + const int i0 = BM_elem_index_get(v0); + const int i1 = BM_elem_index_get(v1); + + BLI_assert(dists[i1] != FLT_MAX); + if (dists[i0] <= dists[i1]) { + return false; + } + + float dist0; + + if (v2) { + /* Distance across triangle. */ + const int i2 = BM_elem_index_get(v2); + BLI_assert(dists[i2] != FLT_MAX); + if (dists[i0] <= dists[i2]) { + return false; + } + + float vm0[3], vm1[3], vm2[3]; + mul_v3_m3v3(vm0, mtx, v0->co); + mul_v3_m3v3(vm1, mtx, v1->co); + mul_v3_m3v3(vm2, mtx, v2->co); + + dist0 = geodesic_distance_propagate_across_triangle(vm0, vm1, vm2, dists[i1], dists[i2]); + } + else { + /* Distance along edge. */ + float vec[3]; + sub_v3_v3v3(vec, v1->co, v0->co); + mul_m3_v3(mtx, vec); + + dist0 = dists[i1] + len_v3(vec); + } + + if (dist0 < dists[i0]) { + dists[i0] = dist0; if (index != NULL) { - index[i_other] = index_prev[i]; + index[i0] = index[i1]; } return true; } @@ -292,15 +318,16 @@ void transform_convert_mesh_connectivity_distance(struct BMesh *bm, float *dists, int *index) { - BLI_LINKSTACK_DECLARE(queue, BMVert *); + BLI_LINKSTACK_DECLARE(queue, BMEdge *); - /* any BM_ELEM_TAG'd vertex is in 'queue_next', so we don't add in twice */ - BLI_LINKSTACK_DECLARE(queue_next, BMVert *); + /* any BM_ELEM_TAG'd edge is in 'queue_next', so we don't add in twice */ + BLI_LINKSTACK_DECLARE(queue_next, BMEdge *); BLI_LINKSTACK_INIT(queue); BLI_LINKSTACK_INIT(queue_next); { + /* Set indexes and initial distances for selected vertices. */ BMIter viter; BMVert *v; int i; @@ -308,7 +335,6 @@ void transform_convert_mesh_connectivity_distance(struct BMesh *bm, BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, i) { float dist; BM_elem_index_set(v, i); /* set_inline */ - BM_elem_flag_disable(v, BM_ELEM_TAG); if (BM_elem_flag_test(v, BM_ELEM_SELECT) == 0 || BM_elem_flag_test(v, BM_ELEM_HIDDEN)) { dist = FLT_MAX; @@ -317,7 +343,6 @@ void transform_convert_mesh_connectivity_distance(struct BMesh *bm, } } else { - BLI_LINKSTACK_PUSH(queue, v); dist = 0.0f; if (index != NULL) { index[i] = i; @@ -329,103 +354,99 @@ void transform_convert_mesh_connectivity_distance(struct BMesh *bm, bm->elem_index_dirty &= ~BM_VERT; } - /* need to be very careful of feedback loops here, store previous dist's to avoid feedback */ - float *dists_prev = MEM_dupallocN(dists); - int *index_prev = MEM_dupallocN(index); /* may be NULL */ + { + /* Add edges with at least one selected vertex to the queue. */ + BMIter eiter; + BMEdge *e; + + BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) { + BMVert *v1 = e->v1; + BMVert *v2 = e->v2; + int i1 = BM_elem_index_get(v1); + int i2 = BM_elem_index_get(v2); + + if (dists[i1] != FLT_MAX || dists[i2] != FLT_MAX) { + BLI_LINKSTACK_PUSH(queue, e); + } + BM_elem_flag_disable(e, BM_ELEM_TAG); + } + } do { - BMVert *v; - LinkNode *lnk; - - /* this is correct but slow to do each iteration, - * instead sync the dist's while clearing BM_ELEM_TAG (below) */ -#if 0 - memcpy(dists_prev, dists, sizeof(float) * bm->totvert); -#endif - - while ((v = BLI_LINKSTACK_POP(queue))) { - BLI_assert(dists[BM_elem_index_get(v)] != FLT_MAX); - - /* connected edge-verts */ - if (v->e != NULL) { - BMEdge *e_iter, *e_first; - - e_iter = e_first = v->e; - - /* would normally use BM_EDGES_OF_VERT, but this runs so often, - * its faster to iterate on the data directly */ - do { - - if (BM_elem_flag_test(e_iter, BM_ELEM_HIDDEN) == 0) { + BMEdge *e; + + while ((e = BLI_LINKSTACK_POP(queue))) { + BMVert *v1 = e->v1; + BMVert *v2 = e->v2; + int i1 = BM_elem_index_get(v1); + int i2 = BM_elem_index_get(v2); + + if (e->l == NULL || (dists[i1] == FLT_MAX || dists[i2] == FLT_MAX)) { + /* Propagate along edge from vertex with smallest to largest distance. */ + if (dists[i1] > dists[i2]) { + SWAP(int, i1, i2); + SWAP(BMVert *, v1, v2); + } - /* edge distance */ - { - BMVert *v_other = BM_edge_other_vert(e_iter, v); - if (bmesh_test_dist_add(v, v_other, dists, dists_prev, index, index_prev, mtx)) { - if (BM_elem_flag_test(v_other, BM_ELEM_TAG) == 0) { - BM_elem_flag_enable(v_other, BM_ELEM_TAG); - BLI_LINKSTACK_PUSH(queue_next, v_other); - } - } + if (bmesh_test_dist_add(v2, v1, NULL, dists, index, mtx)) { + /* Add adjacent loose edges to the queue, or all edges if this is a loose edge. + * Other edges are handled by propagation across edges below. */ + BMEdge *e_other; + BMIter eiter; + BM_ITER_ELEM (e_other, &eiter, v2, BM_EDGES_OF_VERT) { + if (e_other != e && BM_elem_flag_test(e_other, BM_ELEM_TAG) == 0 && + (e->l == NULL || e_other->l == NULL)) { + BM_elem_flag_enable(e_other, BM_ELEM_TAG); + BLI_LINKSTACK_PUSH(queue_next, e_other); } + } + } + } - /* face distance */ - if (e_iter->l) { - BMLoop *l_iter_radial, *l_first_radial; - /** - * imaginary edge diagonally across quad. - * \note This takes advantage of the rules of winding that we - * know 2 or more of a verts edges wont reference the same face twice. - * Also, if the edge is hidden, the face will be hidden too. - */ - l_iter_radial = l_first_radial = e_iter->l; - - do { - if ((l_iter_radial->v == v) && (l_iter_radial->f->len == 4) && - (BM_elem_flag_test(l_iter_radial->f, BM_ELEM_HIDDEN) == 0)) { - BMVert *v_other = l_iter_radial->next->next->v; - if (bmesh_test_dist_add(v, v_other, dists, dists_prev, index, index_prev, mtx)) { - if (BM_elem_flag_test(v_other, BM_ELEM_TAG) == 0) { - BM_elem_flag_enable(v_other, BM_ELEM_TAG); - BLI_LINKSTACK_PUSH(queue_next, v_other); - } - } + if (e->l != NULL) { + /* Propagate across edge to vertices in adjacent faces. */ + BMLoop *l; + BMIter liter; + BM_ITER_ELEM (l, &liter, e, BM_LOOPS_OF_EDGE) { + for (BMLoop *l_other = l->next->next; l_other != l; l_other = l_other->next) { + BMVert *v_other = l_other->v; + BLI_assert(!ELEM(v_other, v1, v2)); + + if (bmesh_test_dist_add(v_other, v1, v2, dists, index, mtx)) { + /* Add adjacent edges to the queue, if they are ready to propagate across/along. + * Always propagate along loose edges, and for other edges only propagate across + * if both vertices have a known distances. */ + BMEdge *e_other; + BMIter eiter; + BM_ITER_ELEM (e_other, &eiter, v_other, BM_EDGES_OF_VERT) { + if (e_other != e && BM_elem_flag_test(e_other, BM_ELEM_TAG) == 0 && + (e_other->l == NULL || + dists[BM_elem_index_get(BM_edge_other_vert(e_other, v_other))] != FLT_MAX)) { + BM_elem_flag_enable(e_other, BM_ELEM_TAG); + BLI_LINKSTACK_PUSH(queue_next, e_other); } - } while ((l_iter_radial = l_iter_radial->radial_next) != l_first_radial); + } } } - } while ((e_iter = BM_DISK_EDGE_NEXT(e_iter, v)) != e_first); + } } } - /* clear for the next loop */ - for (lnk = queue_next; lnk; lnk = lnk->next) { - BMVert *v_link = lnk->link; - const int i = BM_elem_index_get(v_link); + /* Clear for the next loop. */ + for (LinkNode *lnk = queue_next; lnk; lnk = lnk->next) { + BMEdge *e_link = lnk->link; - BM_elem_flag_disable(v_link, BM_ELEM_TAG); - - /* keep in sync, avoid having to do full memcpy each iteration */ - dists_prev[i] = dists[i]; - if (index != NULL) { - index_prev[i] = index[i]; - } + BM_elem_flag_disable(e_link, BM_ELEM_TAG); } BLI_LINKSTACK_SWAP(queue, queue_next); - /* none should be tagged now since 'queue_next' is empty */ - BLI_assert(BM_iter_mesh_count_flag(BM_VERTS_OF_MESH, bm, BM_ELEM_TAG, true) == 0); - + /* None should be tagged now since 'queue_next' is empty. */ + BLI_assert(BM_iter_mesh_count_flag(BM_EDGES_OF_MESH, bm, BM_ELEM_TAG, true) == 0); } while (BLI_LINKSTACK_SIZE(queue)); BLI_LINKSTACK_FREE(queue); BLI_LINKSTACK_FREE(queue_next); - - MEM_freeN(dists_prev); - if (index_prev != NULL) { - MEM_freeN(index_prev); - } } /** \} */ @@ -1445,7 +1466,7 @@ static void mesh_customdatacorrect_apply_vert(struct TransCustomDataLayer *tcld, * * Interpolate from every other loop (not ideal) * However values will only be taken from loops which overlap other mdisps. - * */ + */ const bool update_loop_mdisps = is_moved && do_loop_mdisps && (tcld->cd_loop_mdisp_offset != -1); if (update_loop_mdisps) { float(*faces_center)[3] = BLI_array_alloca(faces_center, l_num); diff --git a/source/blender/editors/transform/transform_convert_mesh_skin.c b/source/blender/editors/transform/transform_convert_mesh_skin.c index 1807e9adcd1..b1024f5efe4 100644 --- a/source/blender/editors/transform/transform_convert_mesh_skin.c +++ b/source/blender/editors/transform/transform_convert_mesh_skin.c @@ -55,9 +55,7 @@ static float *mesh_skin_transdata_center(const struct TransIslandData *island_da if (island_data->center && island_index != -1) { return island_data->center[island_index]; } - else { - return eve->co; - } + return eve->co; } static void mesh_skin_transdata_create(TransDataBasic *td, diff --git a/source/blender/editors/transform/transform_convert_tracking.c b/source/blender/editors/transform/transform_convert_tracking.c index c3f48adca68..b25af709981 100644 --- a/source/blender/editors/transform/transform_convert_tracking.c +++ b/source/blender/editors/transform/transform_convert_tracking.c @@ -52,6 +52,7 @@ typedef struct TransDataTracking { float (*smarkers)[2]; int markersnr; + int framenr; MovieTrackingMarker *markers; /* marker transformation from curves editor */ @@ -73,9 +74,25 @@ enum transDataTracking_Mode { * * \{ */ -static void markerToTransDataInit(TransData *td, - TransData2D *td2d, - TransDataTracking *tdt, +typedef struct TransformInitContext { + SpaceClip *space_clip; + + TransInfo *t; + TransDataContainer *tc; + + /* NOTE: These pointers will be `nullptr` during counting step. + * This means, that the transformation data initialization functions are to increment + * `tc->data_len` instead of filling in the transformation data when these pointers are + * `nullptr`. For simplicity, check the `current.td` against `nullptr`. + * Do not `tc->data_len` when filling in the transformation data. */ + struct { + TransData *td; + TransData2D *td2d; + TransDataTracking *tdt; + } current; +} TransformInitContext; + +static void markerToTransDataInit(TransformInitContext *init_context, MovieTrackingTrack *track, MovieTrackingMarker *marker, int area, @@ -84,8 +101,19 @@ static void markerToTransDataInit(TransData *td, const float off[2], const float aspect[2]) { + TransData *td = init_context->current.td; + TransData2D *td2d = init_context->current.td2d; + TransDataTracking *tdt = init_context->current.tdt; + + if (td == NULL) { + init_context->tc->data_len++; + return; + } + int anchor = area == TRACK_AREA_POINT && off; + tdt->flag = marker->flag; + tdt->framenr = marker->framenr; tdt->mode = transDataTracking_ModeTracks; if (anchor) { @@ -143,23 +171,20 @@ static void markerToTransDataInit(TransData *td, unit_m3(td->mtx); unit_m3(td->smtx); + + init_context->current.td++; + init_context->current.td2d++; + init_context->current.tdt++; } -static void trackToTransData(const int framenr, - TransData *td, - TransData2D *td2d, - TransDataTracking *tdt, +static void trackToTransData(TransformInitContext *init_context, + const int framenr, MovieTrackingTrack *track, const float aspect[2]) { MovieTrackingMarker *marker = BKE_tracking_marker_ensure(track, framenr); - tdt->flag = marker->flag; - marker->flag &= ~(MARKER_DISABLED | MARKER_TRACKED); - - markerToTransDataInit(td++, - td2d++, - tdt++, + markerToTransDataInit(init_context, track, marker, TRACK_AREA_POINT, @@ -170,16 +195,14 @@ static void trackToTransData(const int framenr, if (track->flag & SELECT) { markerToTransDataInit( - td++, td2d++, tdt++, track, marker, TRACK_AREA_POINT, marker->pos, NULL, NULL, aspect); + init_context, track, marker, TRACK_AREA_POINT, marker->pos, NULL, NULL, aspect); } if (track->pat_flag & SELECT) { int a; for (a = 0; a < 4; a++) { - markerToTransDataInit(td++, - td2d++, - tdt++, + markerToTransDataInit(init_context, track, marker, TRACK_AREA_PAT, @@ -191,9 +214,7 @@ static void trackToTransData(const int framenr, } if (track->search_flag & SELECT) { - markerToTransDataInit(td++, - td2d++, - tdt++, + markerToTransDataInit(init_context, track, marker, TRACK_AREA_SEARCH, @@ -202,9 +223,7 @@ static void trackToTransData(const int framenr, NULL, aspect); - markerToTransDataInit(td++, - td2d++, - tdt++, + markerToTransDataInit(init_context, track, marker, TRACK_AREA_SEARCH, @@ -213,15 +232,43 @@ static void trackToTransData(const int framenr, NULL, aspect); } + + if (init_context->current.td != NULL) { + marker->flag &= ~(MARKER_DISABLED | MARKER_TRACKED); + } } -static void planeMarkerToTransDataInit(TransData *td, - TransData2D *td2d, - TransDataTracking *tdt, +static void trackToTransDataIfNeeded(TransformInitContext *init_context, + const int framenr, + MovieTrackingTrack *track, + const float aspect[2]) +{ + if (!TRACK_VIEW_SELECTED(init_context->space_clip, track)) { + return; + } + if (track->flag & TRACK_LOCKED) { + return; + } + trackToTransData(init_context, framenr, track, aspect); +} + +static void planeMarkerToTransDataInit(TransformInitContext *init_context, MovieTrackingPlaneTrack *plane_track, + MovieTrackingPlaneMarker *plane_marker, float corner[2], const float aspect[2]) { + TransData *td = init_context->current.td; + TransData2D *td2d = init_context->current.td2d; + TransDataTracking *tdt = init_context->current.tdt; + + if (td == NULL) { + init_context->tc->data_len++; + return; + } + + tdt->flag = plane_marker->flag; + tdt->framenr = plane_marker->framenr; tdt->mode = transDataTracking_ModePlaneTracks; tdt->plane_track = plane_track; @@ -247,24 +294,38 @@ static void planeMarkerToTransDataInit(TransData *td, unit_m3(td->mtx); unit_m3(td->smtx); + + init_context->current.td++; + init_context->current.td2d++; + init_context->current.tdt++; } -static void planeTrackToTransData(const int framenr, - TransData *td, - TransData2D *td2d, - TransDataTracking *tdt, +static void planeTrackToTransData(TransformInitContext *init_context, + const int framenr, MovieTrackingPlaneTrack *plane_track, const float aspect[2]) { MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_ensure(plane_track, framenr); - int i; - tdt->flag = plane_marker->flag; - plane_marker->flag &= ~PLANE_MARKER_TRACKED; + for (int i = 0; i < 4; i++) { + planeMarkerToTransDataInit( + init_context, plane_track, plane_marker, plane_marker->corners[i], aspect); + } - for (i = 0; i < 4; i++) { - planeMarkerToTransDataInit(td++, td2d++, tdt++, plane_track, plane_marker->corners[i], aspect); + if (init_context->current.td != NULL) { + plane_marker->flag &= ~PLANE_MARKER_TRACKED; + } +} + +static void planeTrackToTransDataIfNeeded(TransformInitContext *init_context, + const int framenr, + MovieTrackingPlaneTrack *plane_track, + const float aspect[2]) +{ + if (!PLANE_TRACK_VIEW_SELECTED(plane_track)) { + return; } + planeTrackToTransData(init_context, framenr, plane_track, aspect); } static void transDataTrackingFree(TransInfo *UNUSED(t), @@ -284,101 +345,53 @@ static void transDataTrackingFree(TransInfo *UNUSED(t), static void createTransTrackingTracksData(bContext *C, TransInfo *t) { - TransData *td; - TransData2D *td2d; - SpaceClip *sc = CTX_wm_space_clip(C); - MovieClip *clip = ED_space_clip_get_clip(sc); - ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking); - ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(&clip->tracking); - MovieTrackingTrack *track; - MovieTrackingPlaneTrack *plane_track; - TransDataTracking *tdt; - int framenr = ED_space_clip_get_clip_frame_number(sc); + SpaceClip *space_clip = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(space_clip); + const ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking); + const ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(&clip->tracking); + const int framenr = ED_space_clip_get_clip_frame_number(space_clip); TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); - /* count */ - tc->data_len = 0; - - track = tracksbase->first; - while (track) { - if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED) == 0) { - tc->data_len++; /* offset */ + TransformInitContext init_context = {NULL}; + init_context.space_clip = space_clip; + init_context.t = t; + init_context.tc = tc; - if (track->flag & SELECT) { - tc->data_len++; - } + /* Count required tranformation data. */ - if (track->pat_flag & SELECT) { - tc->data_len += 4; - } - - if (track->search_flag & SELECT) { - tc->data_len += 2; - } - } + tc->data_len = 0; - track = track->next; + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { + trackToTransDataIfNeeded(&init_context, framenr, track, t->aspect); } - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { - if (PLANE_TRACK_VIEW_SELECTED(plane_track)) { - tc->data_len += 4; - } + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { + planeTrackToTransDataIfNeeded(&init_context, framenr, plane_track, t->aspect); } if (tc->data_len == 0) { return; } - td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransTracking TransData"); - td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), - "TransTracking TransData2D"); - tdt = tc->custom.type.data = MEM_callocN(tc->data_len * sizeof(TransDataTracking), - "TransTracking TransDataTracking"); - + tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransTracking TransData"); + tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransTracking TransData2D"); + tc->custom.type.data = MEM_callocN(tc->data_len * sizeof(TransDataTracking), + "TransTracking TransDataTracking"); tc->custom.type.free_cb = transDataTrackingFree; - /* create actual data */ - track = tracksbase->first; - while (track) { - if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED) == 0) { - trackToTransData(framenr, td, td2d, tdt, track, t->aspect); - - /* offset */ - td++; - td2d++; - tdt++; + init_context.current.td = tc->data; + init_context.current.td2d = tc->data_2d; + init_context.current.tdt = tc->custom.type.data; - if (track->flag & SELECT) { - td++; - td2d++; - tdt++; - } - - if (track->pat_flag & SELECT) { - td += 4; - td2d += 4; - tdt += 4; - } + /* Create actual transformation data. */ - if (track->search_flag & SELECT) { - td += 2; - td2d += 2; - tdt += 2; - } - } - - track = track->next; + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { + trackToTransDataIfNeeded(&init_context, framenr, track, t->aspect); } - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { - if (PLANE_TRACK_VIEW_SELECTED(plane_track)) { - planeTrackToTransData(framenr, td, td2d, tdt, plane_track, t->aspect); - td += 4; - td2d += 4; - tdt += 4; - } + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { + planeTrackToTransDataIfNeeded(&init_context, framenr, plane_track, t->aspect); } } @@ -560,17 +573,17 @@ void createTransTrackingData(bContext *C, TransInfo *t) static void cancelTransTracking(TransInfo *t) { TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); - SpaceClip *sc = t->area->spacedata.first; - int i, framenr = ED_space_clip_get_clip_frame_number(sc); TransDataTracking *tdt_array = tc->custom.type.data; - i = 0; + int i = 0; while (i < tc->data_len) { TransDataTracking *tdt = &tdt_array[i]; if (tdt->mode == transDataTracking_ModeTracks) { MovieTrackingTrack *track = tdt->track; - MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr); + MovieTrackingMarker *marker = BKE_tracking_marker_get_exact(track, tdt->framenr); + + BLI_assert(marker != NULL); marker->flag = tdt->flag; @@ -606,7 +619,10 @@ static void cancelTransTracking(TransInfo *t) } else if (tdt->mode == transDataTracking_ModePlaneTracks) { MovieTrackingPlaneTrack *plane_track = tdt->plane_track; - MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr); + MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get_exact(plane_track, + tdt->framenr); + + BLI_assert(plane_marker != NULL); plane_marker->flag = tdt->flag; i += 3; diff --git a/source/blender/editors/transform/transform_draw_cursors.c b/source/blender/editors/transform/transform_draw_cursors.c index 84fc45e2b45..b4b28ea0ac0 100644 --- a/source/blender/editors/transform/transform_draw_cursors.c +++ b/source/blender/editors/transform/transform_draw_cursors.c @@ -45,103 +45,49 @@ enum eArrowDirection { RIGHT, }; -struct ArrowDims { - int offset; - int length; - int size; -}; - -#define POS_INDEX 0 -/* NOTE: this --^ is a bit hackish, but simplifies GPUVertFormat usage among functions - * private to this file - merwin - */ +#define ARROW_WIDTH (2.0f * U.pixelsize) +#define DASH_WIDTH (1.0f) +#define DASH_LENGTH (8.0f * DASH_WIDTH * U.pixelsize) -static void drawArrow(enum eArrowDirection dir, const struct ArrowDims *arrow_dims) +static void drawArrow(const uint pos_id, const enum eArrowDirection dir) { - int offset = arrow_dims->offset; - int length = arrow_dims->length; - int size = arrow_dims->size; + int offset = 5.0f * UI_DPI_FAC; + int length = (6.0f * UI_DPI_FAC) + (4.0f * U.pixelsize); + int size = (3.0f * UI_DPI_FAC) + (2.0f * U.pixelsize); + + /* To line up the arrow point nicely, one end has to be extended by half its width. But + * being on a 45 degree angle, Pythagoras says a movement of sqrt(2)/2 * (line width /2) */ + float adjust = (M_SQRT2 * ARROW_WIDTH / 4.0f); + + if (ELEM(dir, LEFT, DOWN)) { + offset = -offset; + length = -length; + size = -size; + adjust = -adjust; + } immBegin(GPU_PRIM_LINES, 6); - switch (dir) { - case LEFT: - offset = -offset; - length = -length; - size = -size; - ATTR_FALLTHROUGH; - case RIGHT: - immVertex2f(POS_INDEX, offset, 0); - immVertex2f(POS_INDEX, offset + length, 0); - immVertex2f(POS_INDEX, offset + length, 0); - immVertex2f(POS_INDEX, offset + length - size, -size); - immVertex2f(POS_INDEX, offset + length, 0); - immVertex2f(POS_INDEX, offset + length - size, size); - break; - - case DOWN: - offset = -offset; - length = -length; - size = -size; - ATTR_FALLTHROUGH; - case UP: - immVertex2f(POS_INDEX, 0, offset); - immVertex2f(POS_INDEX, 0, offset + length); - immVertex2f(POS_INDEX, 0, offset + length); - immVertex2f(POS_INDEX, -size, offset + length - size); - immVertex2f(POS_INDEX, 0, offset + length); - immVertex2f(POS_INDEX, size, offset + length - size); - break; + if (ELEM(dir, LEFT, RIGHT)) { + immVertex2f(pos_id, offset, 0); + immVertex2f(pos_id, offset + length, 0); + immVertex2f(pos_id, offset + length + adjust, adjust); + immVertex2f(pos_id, offset + length - size, -size); + immVertex2f(pos_id, offset + length, 0); + immVertex2f(pos_id, offset + length - size, size); } - - immEnd(); -} - -static void drawArrowHead(enum eArrowDirection dir, int size) -{ - immBegin(GPU_PRIM_LINES, 4); - - switch (dir) { - case LEFT: - size = -size; - ATTR_FALLTHROUGH; - case RIGHT: - immVertex2f(POS_INDEX, 0, 0); - immVertex2f(POS_INDEX, -size, -size); - immVertex2f(POS_INDEX, 0, 0); - immVertex2f(POS_INDEX, -size, size); - break; - - case DOWN: - size = -size; - ATTR_FALLTHROUGH; - case UP: - immVertex2f(POS_INDEX, 0, 0); - immVertex2f(POS_INDEX, -size, -size); - immVertex2f(POS_INDEX, 0, 0); - immVertex2f(POS_INDEX, size, -size); - break; + else { + immVertex2f(pos_id, 0, offset); + immVertex2f(pos_id, 0, offset + length); + immVertex2f(pos_id, adjust, offset + length + adjust); + immVertex2f(pos_id, -size, offset + length - size); + immVertex2f(pos_id, 0, offset + length); + immVertex2f(pos_id, size, offset + length - size); } immEnd(); } -static void drawArc(float angle_start, float angle_end, int segments, float size) -{ - float delta = (angle_end - angle_start) / segments; - float angle; - int a; - - immBegin(GPU_PRIM_LINE_STRIP, segments + 1); - - for (angle = angle_start, a = 0; a < segments; angle += delta, a++) { - immVertex2f(POS_INDEX, cosf(angle) * size, sinf(angle) * size); - } - immVertex2f(POS_INDEX, cosf(angle_end) * size, sinf(angle_end) * size); - - immEnd(); -} - /** * Poll callback for cursor drawing: * #WM_paint_cursor_activate @@ -149,11 +95,7 @@ static void drawArc(float angle_start, float angle_end, int segments, float size bool transform_draw_cursor_poll(bContext *C) { ARegion *region = CTX_wm_region(C); - - if (region && region->regiontype == RGN_TYPE_WINDOW) { - return 1; - } - return 0; + return (region && region->regiontype == RGN_TYPE_WINDOW) ? 1 : 0; } /** @@ -164,181 +106,115 @@ void transform_draw_cursor_draw(bContext *UNUSED(C), int x, int y, void *customd { TransInfo *t = (TransInfo *)customdata; - if (t->helpline != HLP_NONE) { - struct ArrowDims arrow_dims = { - .offset = 5 * UI_DPI_FAC, - .length = 10 * UI_DPI_FAC, - .size = 5 * UI_DPI_FAC, - }; - - float cent[2]; - const float mval[3] = {x, y, 0.0f}; - float tmval[2] = { - (float)t->mval[0], - (float)t->mval[1], - }; - - projectFloatViewEx(t, t->center_global, cent, V3D_PROJ_TEST_CLIP_ZERO); - /* Offset the values for the area region. */ - const float offset[2] = { - t->region->winrct.xmin, - t->region->winrct.ymin, - }; - - for (int i = 0; i < 2; i++) { - cent[i] += offset[i]; - tmval[i] += offset[i]; - } - - GPU_line_smooth(true); - GPU_blend(GPU_BLEND_ALPHA); - - GPU_matrix_push(); - - /* Dashed lines first. */ - if (ELEM(t->helpline, HLP_SPRING, HLP_ANGLE)) { - const uint shdr_pos = GPU_vertformat_attr_add( - immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - - UNUSED_VARS_NDEBUG(shdr_pos); /* silence warning */ - BLI_assert(shdr_pos == POS_INDEX); + if (t->helpline == HLP_NONE) { + return; + } - GPU_line_width(1.0f); + float cent[2]; + const float mval[3] = {x, y, 0.0f}; + float tmval[2] = { + (float)t->mval[0], + (float)t->mval[1], + }; + + projectFloatViewEx(t, t->center_global, cent, V3D_PROJ_TEST_CLIP_ZERO); + /* Offset the values for the area region. */ + const float offset[2] = { + t->region->winrct.xmin, + t->region->winrct.ymin, + }; + + for (int i = 0; i < 2; i++) { + cent[i] += offset[i]; + tmval[i] += offset[i]; + } - immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR); + float viewport_size[4]; + GPU_viewport_size_get_f(viewport_size); + + GPU_line_smooth(true); + GPU_blend(GPU_BLEND_ALPHA); + const uint pos_id = GPU_vertformat_attr_add( + immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + + /* Dashed lines first. */ + if (ELEM(t->helpline, HLP_SPRING, HLP_ANGLE)) { + GPU_line_width(DASH_WIDTH); + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR); + immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); + immUniform1i("colors_len", 0); /* "simple" mode */ + immUniformThemeColor3(TH_VIEW_OVERLAY); + immUniform1f("dash_width", DASH_LENGTH); + immUniform1f("dash_factor", 0.5f); + immBegin(GPU_PRIM_LINES, 2); + immVertex2fv(pos_id, cent); + immVertex2f(pos_id, tmval[0], tmval[1]); + immEnd(); + immUnbindProgram(); + } - float viewport_size[4]; - GPU_viewport_size_get_f(viewport_size); - immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); + /* And now, solid lines. */ - immUniform1i("colors_len", 0); /* "simple" mode */ - immUniformThemeColor3(TH_VIEW_OVERLAY); - immUniform1f("dash_width", 6.0f * UI_DPI_FAC); - immUniform1f("dash_factor", 0.5f); + immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR); + immUniformThemeColor3(TH_VIEW_OVERLAY); + immUniform2fv("viewportSize", &viewport_size[2]); + immUniform1f("lineWidth", ARROW_WIDTH); - immBegin(GPU_PRIM_LINES, 2); - immVertex2fv(POS_INDEX, cent); - immVertex2f(POS_INDEX, tmval[0], tmval[1]); - immEnd(); + GPU_matrix_push(); + GPU_matrix_translate_3fv(mval); - immUnbindProgram(); + switch (t->helpline) { + case HLP_SPRING: + GPU_matrix_rotate_axis(-RAD2DEGF(atan2f(cent[0] - tmval[0], cent[1] - tmval[1])), 'Z'); + drawArrow(pos_id, UP); + drawArrow(pos_id, DOWN); + break; + case HLP_HARROW: + drawArrow(pos_id, RIGHT); + drawArrow(pos_id, LEFT); + break; + case HLP_VARROW: + drawArrow(pos_id, UP); + drawArrow(pos_id, DOWN); + break; + case HLP_CARROW: { + /* Draw arrow based on direction defined by custom-points. */ + const int *data = t->mouse.data; + const float angle = -atan2f(data[2] - data[0], data[3] - data[1]); + GPU_matrix_rotate_axis(RAD2DEGF(angle), 'Z'); + drawArrow(pos_id, UP); + drawArrow(pos_id, DOWN); + break; } - - /* And now, solid lines. */ - uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - UNUSED_VARS_NDEBUG(pos); /* silence warning */ - BLI_assert(pos == POS_INDEX); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - - switch (t->helpline) { - case HLP_SPRING: - immUniformThemeColor3(TH_VIEW_OVERLAY); - - GPU_matrix_translate_3fv(mval); - GPU_matrix_rotate_axis(-RAD2DEGF(atan2f(cent[0] - tmval[0], cent[1] - tmval[1])), 'Z'); - - GPU_line_width(3.0f); - drawArrow(UP, &arrow_dims); - drawArrow(DOWN, &arrow_dims); - break; - case HLP_HARROW: - immUniformThemeColor3(TH_VIEW_OVERLAY); - GPU_matrix_translate_3fv(mval); - - GPU_line_width(3.0f); - drawArrow(RIGHT, &arrow_dims); - drawArrow(LEFT, &arrow_dims); - break; - case HLP_VARROW: - immUniformThemeColor3(TH_VIEW_OVERLAY); - - GPU_matrix_translate_3fv(mval); - - GPU_line_width(3.0f); - drawArrow(UP, &arrow_dims); - drawArrow(DOWN, &arrow_dims); - break; - case HLP_CARROW: { - /* Draw arrow based on direction defined by custom-points. */ - immUniformThemeColor3(TH_VIEW_OVERLAY); - - GPU_matrix_translate_3fv(mval); - - GPU_line_width(3.0f); - - const int *data = t->mouse.data; - const float dx = data[2] - data[0], dy = data[3] - data[1]; - const float angle = -atan2f(dx, dy); - - GPU_matrix_push(); - - GPU_matrix_rotate_axis(RAD2DEGF(angle), 'Z'); - - drawArrow(UP, &arrow_dims); - drawArrow(DOWN, &arrow_dims); - - GPU_matrix_pop(); - break; - } - case HLP_ANGLE: { - float dx = tmval[0] - cent[0], dy = tmval[1] - cent[1]; - float angle = atan2f(dy, dx); - float dist = hypotf(dx, dy); - float delta_angle = min_ff(15.0f / (dist / UI_DPI_FAC), (float)M_PI / 4.0f); - float spacing_angle = min_ff(5.0f / (dist / UI_DPI_FAC), (float)M_PI / 12.0f); - - immUniformThemeColor3(TH_VIEW_OVERLAY); - - GPU_matrix_translate_3f(cent[0] - tmval[0] + mval[0], cent[1] - tmval[1] + mval[1], 0); - - GPU_line_width(3.0f); - drawArc(angle - delta_angle, angle - spacing_angle, 10, dist); - drawArc(angle + spacing_angle, angle + delta_angle, 10, dist); - - GPU_matrix_push(); - - GPU_matrix_translate_3f( - cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0); - GPU_matrix_rotate_axis(RAD2DEGF(angle - delta_angle), 'Z'); - - drawArrowHead(DOWN, arrow_dims.size); - - GPU_matrix_pop(); - - GPU_matrix_translate_3f( - cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0); - GPU_matrix_rotate_axis(RAD2DEGF(angle + delta_angle), 'Z'); - - drawArrowHead(UP, arrow_dims.size); - break; - } - case HLP_TRACKBALL: { - uchar col[3], col2[3]; - UI_GetThemeColor3ubv(TH_GRID, col); - - GPU_matrix_translate_3fv(mval); - - GPU_line_width(3.0f); - - UI_make_axis_color(col, col2, 'X'); - immUniformColor3ubv(col2); - - drawArrow(RIGHT, &arrow_dims); - drawArrow(LEFT, &arrow_dims); - - UI_make_axis_color(col, col2, 'Y'); - immUniformColor3ubv(col2); - - drawArrow(UP, &arrow_dims); - drawArrow(DOWN, &arrow_dims); - break; - } + case HLP_ANGLE: { + GPU_matrix_push(); + float angle = atan2f(tmval[1] - cent[1], tmval[0] - cent[0]); + GPU_matrix_translate_3f(cosf(angle), sinf(angle), 0); + GPU_matrix_rotate_axis(RAD2DEGF(angle), 'Z'); + drawArrow(pos_id, DOWN); + GPU_matrix_pop(); + GPU_matrix_translate_3f(cosf(angle), sinf(angle), 0); + GPU_matrix_rotate_axis(RAD2DEGF(angle), 'Z'); + drawArrow(pos_id, UP); + break; + } + case HLP_TRACKBALL: { + uchar col[3], col2[3]; + UI_GetThemeColor3ubv(TH_GRID, col); + UI_make_axis_color(col, col2, 'X'); + immUniformColor3ubv(col2); + drawArrow(pos_id, RIGHT); + drawArrow(pos_id, LEFT); + UI_make_axis_color(col, col2, 'Y'); + immUniformColor3ubv(col2); + drawArrow(pos_id, UP); + drawArrow(pos_id, DOWN); + break; } - - immUnbindProgram(); - GPU_matrix_pop(); - - GPU_line_smooth(false); - GPU_blend(GPU_BLEND_NONE); } + + GPU_matrix_pop(); + immUnbindProgram(); + GPU_line_smooth(false); + GPU_blend(GPU_BLEND_NONE); } diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c index 3c82365fdb4..5b9d73a10fe 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.c @@ -704,7 +704,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, if (BKE_gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) { /* calculate difference matrix */ - BKE_gpencil_parent_matrix_get(depsgraph, ob, gpl, diff_mat); + BKE_gpencil_layer_transform_matrix_get(depsgraph, ob, gpl, diff_mat); LISTBASE_FOREACH (bGPDstroke *, gps, &gpl->actframe->strokes) { /* skip strokes that are invalid for current view */ @@ -1322,21 +1322,21 @@ void drawDial3d(const TransInfo *t) if (tc->mode & CON_APPLY) { if (tc->mode & CON_AXIS0) { axis_idx = MAN_AXIS_ROT_X; - negate_v3_v3(mat_basis[2], t->spacemtx[0]); + copy_v3_v3(mat_basis[2], t->spacemtx[0]); } else if (tc->mode & CON_AXIS1) { axis_idx = MAN_AXIS_ROT_Y; - negate_v3_v3(mat_basis[2], t->spacemtx[1]); + copy_v3_v3(mat_basis[2], t->spacemtx[1]); } else { BLI_assert((tc->mode & CON_AXIS2) != 0); axis_idx = MAN_AXIS_ROT_Z; - negate_v3_v3(mat_basis[2], t->spacemtx[2]); + copy_v3_v3(mat_basis[2], t->spacemtx[2]); } } else { axis_idx = MAN_AXIS_ROT_C; - negate_v3_v3(mat_basis[2], t->spacemtx[t->orient_axis]); + copy_v3_v3(mat_basis[2], t->spacemtx[t->orient_axis]); scale *= 1.2f; line_with -= 1.0f; } diff --git a/source/blender/editors/transform/transform_mode_rotate.c b/source/blender/editors/transform/transform_mode_rotate.c index e81ea8b0a0d..fa02e5382a7 100644 --- a/source/blender/editors/transform/transform_mode_rotate.c +++ b/source/blender/editors/transform/transform_mode_rotate.c @@ -200,12 +200,7 @@ static void applyRotation(TransInfo *t, const int UNUSED(mval[2])) t->con.applyRot(t, NULL, NULL, axis_final, NULL); } else { - copy_v3_v3(axis_final, t->spacemtx[t->orient_axis]); - if (!(t->flag & T_INPUT_IS_VALUES_FINAL) && (dot_v3v3(axis_final, t->viewinv[2]) > 0.0f)) { - /* The input is obtained according to the position of the mouse. - * Flip to better match the movement. */ - final *= -1; - } + negate_v3_v3(axis_final, t->spacemtx[t->orient_axis]); } if (applyNumInput(&t->num, &final)) { diff --git a/source/blender/editors/transform/transform_mode_shear.c b/source/blender/editors/transform/transform_mode_shear.c index 0ccea9c396e..a41c49710b9 100644 --- a/source/blender/editors/transform/transform_mode_shear.c +++ b/source/blender/editors/transform/transform_mode_shear.c @@ -56,12 +56,12 @@ static void initShear_mouseInputMode(TransInfo *t) /* Needed for axis aligned view gizmo. */ if (t->orient[t->orient_curr].type == V3D_ORIENT_VIEW) { if (t->orient_axis_ortho == 0) { - if (t->center2d[1] < t->mouse.imval[1]) { + if (t->center2d[1] > t->mouse.imval[1]) { dir_flip = !dir_flip; } } else if (t->orient_axis_ortho == 1) { - if (t->center2d[0] < t->mouse.imval[0]) { + if (t->center2d[0] > t->mouse.imval[0]) { dir_flip = !dir_flip; } } diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 90b2ce2a385..3b39f4d06ad 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -561,7 +561,6 @@ short ED_transform_calc_orientation_from_type_ex(const bContext *C, if (rv3d != NULL) { copy_m3_m4(r_mat, rv3d->viewinv); normalize_m3(r_mat); - negate_v3(r_mat[2]); } else { unit_m3(r_mat); diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index c19dd4598cf..508189c5d77 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -299,83 +299,93 @@ eRedrawFlag handleSnapping(TransInfo *t, const wmEvent *event) void applyProject(TransInfo *t) { - /* XXX FLICKER IN OBJECT MODE */ - if ((t->tsnap.project) && activeSnap(t) && (t->flag & T_NO_PROJECT) == 0) { - float tvec[3]; - int i; + if (!t->tsnap.project) { + return; + } - FOREACH_TRANS_DATA_CONTAINER (t, tc) { - TransData *td = tc->data; - for (i = 0; i < tc->data_len; i++, td++) { - float iloc[3], loc[3], no[3]; - float mval_fl[2]; - if (td->flag & TD_SKIP) { - continue; - } + if (!activeSnap(t) || (t->flag & T_NO_PROJECT)) { + return; + } - if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) { - continue; - } + if (doForceIncrementSnap(t)) { + return; + } - copy_v3_v3(iloc, td->loc); - if (tc->use_local_mat) { - mul_m4_v3(tc->mat, iloc); - } - else if (t->flag & T_OBJECT) { - BKE_object_eval_transform_all(t->depsgraph, t->scene, td->ob); - copy_v3_v3(iloc, td->ob->obmat[3]); - } + float tvec[3]; + int i; + + /* XXX FLICKER IN OBJECT MODE */ + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + float iloc[3], loc[3], no[3]; + float mval_fl[2]; + if (td->flag & TD_SKIP) { + continue; + } + + if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) { + continue; + } - if (ED_view3d_project_float_global(t->region, iloc, mval_fl, V3D_PROJ_TEST_NOP) == - V3D_PROJ_RET_OK) { - if (ED_transform_snap_object_project_view3d( - t->tsnap.object_context, - t->depsgraph, - SCE_SNAP_MODE_FACE, - &(const struct SnapObjectParams){ - .snap_select = t->tsnap.modeSelect, - .use_object_edit_cage = (t->flag & T_EDIT) != 0, - .use_occlusion_test = false, - .use_backface_culling = t->tsnap.use_backface_culling, - }, - mval_fl, - NULL, - 0, - loc, - no)) { + copy_v3_v3(iloc, td->loc); + if (tc->use_local_mat) { + mul_m4_v3(tc->mat, iloc); + } + else if (t->flag & T_OBJECT) { + BKE_object_eval_transform_all(t->depsgraph, t->scene, td->ob); + copy_v3_v3(iloc, td->ob->obmat[3]); + } + + if (ED_view3d_project_float_global(t->region, iloc, mval_fl, V3D_PROJ_TEST_NOP) == + V3D_PROJ_RET_OK) { + if (ED_transform_snap_object_project_view3d( + t->tsnap.object_context, + t->depsgraph, + SCE_SNAP_MODE_FACE, + &(const struct SnapObjectParams){ + .snap_select = t->tsnap.modeSelect, + .use_object_edit_cage = (t->flag & T_EDIT) != 0, + .use_occlusion_test = false, + .use_backface_culling = t->tsnap.use_backface_culling, + }, + mval_fl, + NULL, + 0, + loc, + no)) { #if 0 if (tc->use_local_mat) { mul_m4_v3(tc->imat, loc); } #endif - sub_v3_v3v3(tvec, loc, iloc); + sub_v3_v3v3(tvec, loc, iloc); - mul_m3_v3(td->smtx, tvec); + mul_m3_v3(td->smtx, tvec); - add_v3_v3(td->loc, tvec); + add_v3_v3(td->loc, tvec); - if (t->tsnap.align && (t->flag & T_OBJECT)) { - /* handle alignment as well */ - const float *original_normal; - float mat[3][3]; + if (t->tsnap.align && (t->flag & T_OBJECT)) { + /* handle alignment as well */ + const float *original_normal; + float mat[3][3]; - /* In pose mode, we want to align normals with Y axis of bones... */ - original_normal = td->axismtx[2]; + /* In pose mode, we want to align normals with Y axis of bones... */ + original_normal = td->axismtx[2]; - rotation_between_vecs_to_mat3(mat, original_normal, no); + rotation_between_vecs_to_mat3(mat, original_normal, no); - transform_data_ext_rotate(td, mat, true); + transform_data_ext_rotate(td, mat, true); - /* TODO support constraints for rotation too? see ElementRotation */ - } + /* TODO support constraints for rotation too? see ElementRotation */ } } + } #if 0 /* TODO: sipport this? */ constraintTransLim(t, td); #endif - } } } } |