Animation: blend offset slider #106518

Closed
AresDeveaux wants to merge 12 commits from AresDeveaux/blender:blend_offset_slider into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 11 additions and 12 deletions
Showing only changes of commit 960b6c41e2 - Show all commits

View File

@ -496,28 +496,24 @@ void blend_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const floa
const BezTriple *left_key = fcurve_segment_start_get(fcu, segment->start_index);
const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length);
const BezTriple *segment_first_key = fcurve_segment_start_get(fcu, segment->start_index + 1);
const BezTriple *segment_last_key = fcurve_segment_end_get(
fcu, segment->start_index + segment->length - 1);
/* The calculation needs diferent values for each side of the slider. */
const bool slider_right_side = factor > 0.5;
const BezTriple segment_first_key = fcu->bezt[segment->start_index];

this can be simplified to fcu->bezt[segment->start_index]
same for getting the segment end

this can be simplified to `fcu->bezt[segment->start_index]` same for getting the segment end

Since ``y_delta * fabs(factor)` doesnt' change over the course of this loop, take it out of the loop:

const float weighted_delta = y_delta * fabs(factor);
Since ``y_delta * fabs(factor)` doesnt' change over the course of this loop, take it out of the loop: ```c const float weighted_delta = y_delta * fabs(factor); ```
const BezTriple segment_last_key = fcu->bezt[segment->start_index + segment->length - 1];
/* For this tool the calculations are made easier if each side of the slider goes from 0 to
* porisive 1. */
const float ping_pong_factor = fabs(factor * 2 - 1);
* positive 1. */
const float bidirectional_factor = fabs(factor * 2 - 1);
float y_delta;

watch out for typos poritive -> positive

watch out for typos poritive -> positive
if (slider_right_side) {
y_delta = right_key->vec[1][1] - segment_last_key->vec[1][1];
if (factor > 0.5) {
y_delta = right_key->vec[1][1] - segment_last_key.vec[1][1];
}
else {
y_delta = left_key->vec[1][1] - segment_first_key->vec[1][1];
y_delta = left_key->vec[1][1] - segment_first_key.vec[1][1];

if you use ED_slider_is_bidirectional_set you can just say factor > 0 and remove the boolean
That way this function doesn't even need to have an implicit notion of where the value came from

if you use `ED_slider_is_bidirectional_set` you can just say `factor > 0` and remove the boolean That way this function doesn't even need to have an implicit notion of where the value came from

I just tried this. One problem with a bidirectional slider is that the factor is always going to be more than zero, so the else part of the if statement is never executed. I still need to know what side of the slider the value is coming from. If the factor is from 0 to 1 I can, and by using ping_pong_factor = fabs(factor * 2 - 1) I have been simulating what now I should call "bidirectional_factor" instead of "ping_pong_factor"

If there is a way to know what side of the slider the value is coming from I could use ED_slider_is_bidirectional_set

I just tried this. One problem with a bidirectional slider is that the factor is always going to be more than zero, so the `else` part of the if statement is never executed. I still need to know what side of the slider the value is coming from. If the factor is from 0 to 1 I can, and by using `ping_pong_factor = fabs(factor * 2 - 1)` I have been simulating what now I should call "bidirectional_factor" instead of "ping_pong_factor" If there is a way to know what side of the slider the value is coming from I could use `ED_slider_is_bidirectional_set`

hm sorry I think that was my bad. I thought this would set the slider to a -1/1 range but it does not. It just allows negative values.
In that case your implementation is correct until we add that feature to the slider :)

hm sorry I think that was my bad. I thought this would set the slider to a -1/1 range but it does not. It just allows negative values. In that case your implementation is correct until we add that feature to the slider :)
}
for (int i = segment->start_index; i < segment->start_index + segment->length; i++) {
const float key_y_value = fcu->bezt[i].vec[1][1] + y_delta * ping_pong_factor;
const float key_y_value = fcu->bezt[i].vec[1][1] + y_delta * bidirectional_factor;
move_key(&fcu->bezt[i], key_y_value);
}
}

View File

@ -1135,6 +1135,9 @@ static int blend_offset_invoke(bContext *C, wmOperator *op, const wmEvent *event
gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
blend_offset_draw_status_header(C, gso);
// ED_slider_is_bidirectional_set(gso->slider, true);
// ED_slider_factor_set(gso->slider, 0.0f);
return invoke_result;
}