WIP: Fix #112395: Transform with Proportional Influence in Graph editor only works horizontally #112401

Draft
Germano Cavalcante wants to merge 1 commits from mano-wii/blender:transform_graph_PET into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 46 additions and 128 deletions

View File

@ -131,7 +131,10 @@ void setTransformViewAspect(TransInfo *t, float r_aspect[3])
}
}
else if (t->spacetype == SPACE_GRAPH) {
/* Depends on context of usage. */
View2D *v2d = &t->region->v2d;
float xscale, yscale;
UI_view2d_scale_get(v2d, &xscale, &yscale);
r_aspect[1] = yscale / xscale;
}
}

View File

@ -170,10 +170,45 @@ static void sort_trans_data_selected_first(TransInfo *t)
}
}
static void prop_dist_get_loc(const TransDataContainer *tc,
const TransData *td,
const bool use_island,
const float aspect[3],
const float proj_vec[3],
float r_vec[3])
{
if (use_island) {
if (tc->use_local_mat) {
mul_v3_m4v3(r_vec, tc->mat, td->iloc);
}
else {
mul_v3_m3v3(r_vec, td->mtx, td->iloc);
}
}
else {
if (tc->use_local_mat) {
mul_v3_m4v3(r_vec, tc->mat, td->center);
}
else {
mul_v3_m3v3(r_vec, td->mtx, td->center);
}
}
if (aspect) {
mul_v3_v3(r_vec, aspect);
}
if (proj_vec) {
float vec_p[3];
project_v3_v3v3(vec_p, r_vec, proj_vec);
sub_v3_v3(r_vec, vec_p);
}
}
/**
* Distance calculated from not-selected vertex to nearest selected vertex.
*/
static void set_prop_dist(TransInfo *t, const bool with_dist)
static void set_prop_dist(TransInfo *t, const bool with_dist, const bool use_aspect = false)
{
int a;
@ -223,28 +258,7 @@ static void set_prop_dist(TransInfo *t, const bool with_dist)
float vec[3];
td->rdist = 0.0f;
if (use_island) {
if (tc->use_local_mat) {
mul_v3_m4v3(vec, tc->mat, td->iloc);
}
else {
mul_v3_m3v3(vec, td->mtx, td->iloc);
}
}
else {
if (tc->use_local_mat) {
mul_v3_m4v3(vec, tc->mat, td->center);
}
else {
mul_v3_m3v3(vec, td->mtx, td->center);
}
}
if (proj_vec) {
float vec_p[3];
project_v3_v3v3(vec_p, vec, proj_vec);
sub_v3_v3(vec, vec_p);
}
prop_dist_get_loc(tc, td, use_island, use_aspect ? t->aspect : nullptr, proj_vec, vec);
BLI_kdtree_3d_insert(td_tree, td_table_index, vec);
td_table[td_table_index++] = td;
@ -266,28 +280,7 @@ static void set_prop_dist(TransInfo *t, const bool with_dist)
if ((td->flag & TD_SELECTED) == 0) {
float vec[3];
if (use_island) {
if (tc->use_local_mat) {
mul_v3_m4v3(vec, tc->mat, td->iloc);
}
else {
mul_v3_m3v3(vec, td->mtx, td->iloc);
}
}
else {
if (tc->use_local_mat) {
mul_v3_m4v3(vec, tc->mat, td->center);
}
else {
mul_v3_m3v3(vec, td->mtx, td->center);
}
}
if (proj_vec) {
float vec_p[3];
project_v3_v3v3(vec_p, vec, proj_vec);
sub_v3_v3(vec, vec_p);
}
prop_dist_get_loc(tc, td, use_island, use_aspect ? t->aspect : nullptr, proj_vec, vec);
KDTreeNearest_3d nearest;
const int td_index = BLI_kdtree_3d_find_nearest(td_tree, vec, &nearest);
@ -756,7 +749,7 @@ static void init_proportional_edit(TransInfo *t)
sort_trans_data_selected_first(t);
}
if (ELEM(t->data_type, &TransConvertType_Action, &TransConvertType_Graph)) {
if (ELEM(t->data_type, &TransConvertType_Action)) {
/* Distance has already been set. */
}
else if (ELEM(t->data_type,
@ -778,6 +771,9 @@ static void init_proportional_edit(TransInfo *t)
BLI_assert(t->obedit_type == OB_CURVES_LEGACY || t->obedit_type == OB_CURVES);
set_prop_dist(t, false);
}
else if (t->data_type == &TransConvertType_Graph) {
set_prop_dist(t, true, true);
}
else {
set_prop_dist(t, true);
}

View File

@ -180,28 +180,6 @@ static void graph_bezt_get_transform_selection(const TransInfo *t,
*r_right_handle = right;
}
static void graph_key_shortest_dist(
TransInfo *t, FCurve *fcu, TransData *td_start, TransData *td, int cfra, bool use_handle)
{
int j = 0;
TransData *td_iter = td_start;
bool sel_key, sel_left, sel_right;
td->dist = FLT_MAX;
for (; j < fcu->totvert; j++) {
BezTriple *bezt = fcu->bezt + j;
if (FrameOnMouseSide(t->frame_side, bezt->vec[1][0], cfra)) {
graph_bezt_get_transform_selection(t, bezt, use_handle, &sel_left, &sel_key, &sel_right);
if (sel_left || sel_key || sel_right) {
td->dist = td->rdist = min_ff(td->dist, fabs(td_iter->center[0] - td->center[0]));
}
td_iter += 3;
}
}
}
/**
* It is important to note that this doesn't always act on the selection (like it's usually done),
* it acts on a subset of it. E.g. the selection code may leave a hint that we just dragged on a
@ -557,65 +535,6 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
testhandles_fcurve(fcu, BEZT_FLAG_TEMP_TAG, use_handle);
}
if (is_prop_edit) {
/* loop 2: build transdata arrays */
td = tc->data;
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
AnimData *adt = ANIM_nla_mapping_get(&ac, ale);
FCurve *fcu = (FCurve *)ale->key_data;
TransData *td_start = td;
float cfra;
/* F-Curve may not have any keyframes */
if (fcu->bezt == nullptr || (ale->tag == 0)) {
continue;
}
/* convert current-frame to action-time (slightly less accurate, especially under
* higher scaling ratios, but is faster than converting all points)
*/
if (adt) {
cfra = BKE_nla_tweakedit_remap(adt, float(scene->r.cfra), NLATIME_CONVERT_UNMAP);
}
else {
cfra = float(scene->r.cfra);
}
for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) {
/* only include BezTriples whose 'keyframe' occurs on the
* same side of the current frame as mouse (if applicable) */
if (FrameOnMouseSide(t->frame_side, bezt->vec[1][0], cfra)) {
graph_bezt_get_transform_selection(t, bezt, use_handle, &sel_left, &sel_key, &sel_right);
if (sel_left || sel_key) {
td->dist = td->rdist = 0.0f;
}
else {
graph_key_shortest_dist(t, fcu, td_start, td, cfra, use_handle);
}
td++;
if (sel_key) {
td->dist = td->rdist = 0.0f;
}
else {
graph_key_shortest_dist(t, fcu, td_start, td, cfra, use_handle);
}
td++;
if (sel_right || sel_key) {
td->dist = td->rdist = 0.0f;
}
else {
graph_key_shortest_dist(t, fcu, td_start, td, cfra, use_handle);
}
td++;
}
}
}
}
/* cleanup temp list */
ANIM_animdata_freelist(&anim_data);
}