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.
First-time contributor

New operator for the slider tool in the Graph Editor.

It shifts selected keys to the value of the neighboring keys as a block. It is used to keep the animation of the selected segment but match the values to the chosen neighboring pose.

It uses the structure already created by @ChrisLend. The main functionality chancge is in 'keyframes_general.c', the rest for the most part just follows what hi did.

New operator for the slider tool in the Graph Editor. It shifts selected keys to the value of the neighboring keys as a block. It is used to keep the animation of the selected segment but match the values to the chosen neighboring pose. It uses the structure already created by @ChrisLend. The main functionality chancge is in 'keyframes_general.c', the rest for the most part just follows what hi did.
AresDeveaux added 4 commits 2023-04-04 05:02:05 +02:00
Nate Rupsis added the
Interest
Animation & Rigging
label 2023-04-06 20:57:34 +02:00
Nate Rupsis added this to the Animation & Rigging project 2023-04-06 20:57:42 +02:00
Nate Rupsis added
Module
Animation & Rigging
and removed
Interest
Animation & Rigging
labels 2023-04-06 20:59:02 +02:00
AresDeveaux changed title from WIP: Animation&Rigging: blend_offset_slider to Animation: blend offset slider 2023-04-10 05:33:57 +02:00
AresDeveaux added 1 commit 2023-04-11 00:45:13 +02:00
Christoph Lendenfeld requested changes 2023-04-13 12:33:24 +02:00
Christoph Lendenfeld left a comment
Member

minor comments :)

minor comments :)
@ -494,0 +496,4 @@
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);

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
@ -494,0 +504,4 @@
const bool slider_right_side = factor > 0.5;
/* For this tool the calculations are made easier if each side of the slider goes from 0 to
* porisive 1. */

watch out for typos poritive -> positive

watch out for typos poritive -> positive
@ -494,0 +509,4 @@
float y_delta;
if (slider_right_side) {

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
Author
First-time contributor

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 :)
AresDeveaux added 1 commit 2023-04-14 08:08:48 +02:00
AresDeveaux added 1 commit 2023-04-14 11:18:30 +02:00
AresDeveaux added 1 commit 2023-04-14 11:20:34 +02:00
AresDeveaux requested review from Christoph Lendenfeld 2023-04-14 19:44:52 +02:00
Author
First-time contributor

I simplified the code as per your suggestions.

I simplified the code as per your suggestions.
AresDeveaux added 1 commit 2023-04-18 06:04:56 +02:00
Author
First-time contributor

So, I was wrong (no surprise there). Bidirectional slider work as expected. I did something wrong before for it not to work. I'm guessing I left fabs(factor) before the if statement. Anyway, it doesn't matter because I just added it and it works like a charm.

So, I was wrong (no surprise there). Bidirectional slider work as expected. I did something wrong before for it not to work. I'm guessing I left `fabs(factor)` before the `if` statement. Anyway, it doesn't matter because I just added it and it works like a charm.
Christoph Lendenfeld approved these changes 2023-04-20 12:36:57 +02:00
Christoph Lendenfeld left a comment
Member

thanks for the work!
this also gets my green tick and I'll let sybren have a final look

thanks for the work! this also gets my green tick and I'll let sybren have a final look
Christoph Lendenfeld requested review from Sybren A. Stüvel 2023-04-20 12:37:05 +02:00
AresDeveaux added 1 commit 2023-04-20 21:47:14 +02:00
Sybren A. Stüvel added 2 commits 2023-05-09 16:23:59 +02:00
Sybren A. Stüvel requested changes 2023-05-09 16:53:06 +02:00
@ -482,0 +485,4 @@
const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length);
const BezTriple segment_first_key = fcu->bezt[segment->start_index];
const BezTriple segment_last_key = fcu->bezt[segment->start_index + segment->length - 1];

left_key and segment_first_key are only used when factor <= 0, and right_key and segment_last_key otherwise. Move these into the corresponding if/else bodies, so that their scope is clear.

`left_key` and `segment_first_key` are only used when `factor <= 0`, and `right_key` and `segment_last_key` otherwise. Move these into the corresponding `if`/`else` bodies, so that their scope is clear.
@ -482,0 +496,4 @@
}
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 * fabs(factor);

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); ```
@ -439,6 +439,7 @@ void smooth_fcurve_segment(struct FCurve *fcu,
int kernel_size,
double *kernel);
void ease_fcurve_segment(struct FCurve *fcu, struct FCurveSegment *segment, float factor);
void blend_offset_fcurve_segment(struct FCurve *fcu, struct FCurveSegment *segment, float factor);

The more functions we add here, the more important it becomes that they are documented. Could you write a doxygen-style comment for it, that explains what it does? Something like this:

/**
 * Shift the FCurve segment up/down so that it aligns with the key before/after
 * the segment.
 *
 * \param factor blend factor from -1.0 to 1.0. The sign determines whether the
 * segment is aligned with the key before or after the segment.
 */
The more functions we add here, the more important it becomes that they are documented. Could you write a doxygen-style comment for it, that explains what it does? Something like this: ```c /** * Shift the FCurve segment up/down so that it aligns with the key before/after * the segment. * * \param factor blend factor from -1.0 to 1.0. The sign determines whether the * segment is aligned with the key before or after the segment. */ ```
@ -970,0 +971,4 @@
/** \name Blend Offset Operator
* \{ */
static void blend_offset_graph_keys(bAnimContext *ac, const float factor)

I suspect that more operators will have a structure that could be described as "call a function with a factor for each selected segment".

Instead of duplicating this code and changing which function it calls, I think it would be better to abstract that away a bit. Something like this:


typedef void (*SegmentOperationFunc)(FCurve *fcu, FCurveSegment *segment, float factor);

static void fcurve_for_each_segment(bAnimContext *ac,
                                    SegmentOperationFunc operation,
                                    const float factor)
{
  ListBase anim_data = {NULL, NULL};

  ANIM_animdata_filter(ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, ac->datatype);
  LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
    FCurve *fcu = (FCurve *)ale->key_data;
    ListBase segments = find_fcurve_segments(fcu);

    LISTBASE_FOREACH (FCurveSegment *, segment, &segments) {
      operation(fcu, segment, factor);
    }

    ale->update |= ANIM_UPDATE_DEFAULT;
    BLI_freelistN(&segments);
  }

  ANIM_animdata_update(ac, &anim_data);
  ANIM_animdata_freelist(&anim_data);
}

static void blend_offset_graph_keys(bAnimContext *ac, const float factor)
{
  fcurve_for_each_segment(ac, blend_offset_fcurve_segment, factor);
}

// other operators can then have a function like:
static void other_function_name(bAnimContext *ac, const float factor)
{
  fcurve_for_each_segment(ac, other_function_name_segment, factor);
}
I suspect that more operators will have a structure that could be described as "call a function with a factor for each selected segment". Instead of duplicating this code and changing which function it calls, I think it would be better to abstract that away a bit. Something like this: ```c typedef void (*SegmentOperationFunc)(FCurve *fcu, FCurveSegment *segment, float factor); static void fcurve_for_each_segment(bAnimContext *ac, SegmentOperationFunc operation, const float factor) { ListBase anim_data = {NULL, NULL}; ANIM_animdata_filter(ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, ac->datatype); LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; ListBase segments = find_fcurve_segments(fcu); LISTBASE_FOREACH (FCurveSegment *, segment, &segments) { operation(fcu, segment, factor); } ale->update |= ANIM_UPDATE_DEFAULT; BLI_freelistN(&segments); } ANIM_animdata_update(ac, &anim_data); ANIM_animdata_freelist(&anim_data); } static void blend_offset_graph_keys(bAnimContext *ac, const float factor) { fcurve_for_each_segment(ac, blend_offset_fcurve_segment, factor); } // other operators can then have a function like: static void other_function_name(bAnimContext *ac, const float factor) { fcurve_for_each_segment(ac, other_function_name_segment, factor); } ```

this exists from a recent refactor: apply_fcu_segment_function

this exists from a recent refactor: `apply_fcu_segment_function`
@ -970,0 +992,4 @@
ANIM_animdata_freelist(&anim_data);
}
static void blend_offset_draw_status_header(bContext *C, tGraphSliderOp *gso)

I think this can be rewritten to call common_draw_status_header().

I think this can be rewritten to call `common_draw_status_header()`.
Christoph Lendenfeld self-assigned this 2023-07-27 18:57:59 +02:00

this feature has been added in this PR #110544: Animation: Blend Offset Slider

this feature has been added in this PR [#110544: Animation: Blend Offset Slider](https://projects.blender.org/blender/blender/pulls/110544)

Pull request closed

Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#106518
No description provided.