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:
authorAlexander Gavrilov <angavrilov@gmail.com>2021-05-03 00:03:00 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2021-11-24 15:58:32 +0300
commit5d59b38605d61b2aeabfa1cb572b5a0d9158424b (patch)
tree82b0a19eb0e5dd7290ae81c10427082576d8dfb5 /source/blender/editors
parent057cb7e5e77bcf932882292a774156b5d8c90ab4 (diff)
Animation: allow manually setting the intended playback range for actions.
Some operations, e.g. adding a new action strip to NLA, require knowing the active frame range of an action. However, currently it can only be deduced by scanning the keyframes of the curves within it. This is not ideal if e.g. curves are staggered for overlap. As suggested by Nathan Vegdahl in comments to T54724, this patch adds Action properties that allow manually specifying its active frame range. The settings are exposed via a panel in the Dopesheet and Action Editor. When enabled, the range is highlighted in the background using a striped fill to distinguish it from the solid filled regular playback range. When set, the frame range is used when adding or updating NLA tracks, and by add-ons using `Action.frame_range`, e.g. FBX exporter. Differential Revision: https://developer.blender.org/D11803
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/animation/anim_draw.c68
-rw-r--r--source/blender/editors/include/ED_anim_api.h7
-rw-r--r--source/blender/editors/space_action/action_data.c2
-rw-r--r--source/blender/editors/space_action/action_draw.c55
-rw-r--r--source/blender/editors/space_action/space_action.c9
-rw-r--r--source/blender/editors/space_nla/nla_draw.c9
-rw-r--r--source/blender/editors/space_nla/nla_edit.c13
7 files changed, 158 insertions, 5 deletions
diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c
index 993d10cf303..f5a5609aa2e 100644
--- a/source/blender/editors/animation/anim_draw.c
+++ b/source/blender/editors/animation/anim_draw.c
@@ -168,6 +168,74 @@ void ANIM_draw_framerange(Scene *scene, View2D *v2d)
immUnbindProgram();
}
+/**
+ * Draw manually set intended playback frame range guides for the action in the background.
+ * Allows specifying a subset of the Y range of the view.
+ */
+void ANIM_draw_action_framerange(
+ AnimData *adt, bAction *action, View2D *v2d, float ymin, float ymax)
+{
+ if ((action->flag & ACT_FRAME_RANGE) == 0) {
+ return;
+ }
+
+ /* Compute the dimensions. */
+ CLAMP_MIN(ymin, v2d->cur.ymin);
+ CLAMP_MAX(ymax, v2d->cur.ymax);
+
+ if (ymin > ymax) {
+ return;
+ }
+
+ const float sfra = BKE_nla_tweakedit_remap(adt, action->frame_start, NLATIME_CONVERT_MAP);
+ const float efra = BKE_nla_tweakedit_remap(adt, action->frame_end, NLATIME_CONVERT_MAP);
+
+ /* Diagonal stripe filled area outside of the frame range. */
+ GPU_blend(GPU_BLEND_ALPHA);
+
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_DIAG_STRIPES);
+
+ float color[4];
+ UI_GetThemeColorShadeAlpha4fv(TH_BACK, -40, -50, color);
+
+ immUniform4f("color1", color[0], color[1], color[2], color[3]);
+ immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f);
+ immUniform1i("size1", 2 * U.dpi_fac);
+ immUniform1i("size2", 4 * U.dpi_fac);
+
+ if (sfra < efra) {
+ immRectf(pos, v2d->cur.xmin, ymin, sfra, ymax);
+ immRectf(pos, efra, ymin, v2d->cur.xmax, ymax);
+ }
+ else {
+ immRectf(pos, v2d->cur.xmin, ymin, v2d->cur.xmax, ymax);
+ }
+
+ immUnbindProgram();
+
+ GPU_blend(GPU_BLEND_NONE);
+
+ /* Thin lines where the actual frames are. */
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColorShade(TH_BACK, -60);
+
+ GPU_line_width(1.0f);
+
+ immBegin(GPU_PRIM_LINES, 4);
+
+ immVertex2f(pos, sfra, ymin);
+ immVertex2f(pos, sfra, ymax);
+
+ immVertex2f(pos, efra, ymin);
+ immVertex2f(pos, efra, ymax);
+
+ immEnd();
+ immUnbindProgram();
+}
+
/* *************************************************** */
/* NLA-MAPPING UTILITIES (required for drawing and also editing keyframes). */
diff --git a/source/blender/editors/include/ED_anim_api.h b/source/blender/editors/include/ED_anim_api.h
index 5d5d9140a24..cab4c18211d 100644
--- a/source/blender/editors/include/ED_anim_api.h
+++ b/source/blender/editors/include/ED_anim_api.h
@@ -676,6 +676,10 @@ void ANIM_draw_previewrange(const struct bContext *C, struct View2D *v2d, int en
/* main call to draw normal frame range indicators */
void ANIM_draw_framerange(struct Scene *scene, struct View2D *v2d);
+/* Draw manually set intended playback frame range indicators for the action. */
+void ANIM_draw_action_framerange(
+ struct AnimData *adt, struct bAction *action, struct View2D *v2d, float ymin, float ymax);
+
/* ************************************************* */
/* F-MODIFIER TOOLS */
@@ -864,7 +868,8 @@ void ED_operatormacros_action(void);
/* XXX: Should we be doing these here, or at all? */
/* Action Editor - Action Management */
-struct AnimData *ED_actedit_animdata_from_context(struct bContext *C, struct ID **r_adt_id_owner);
+struct AnimData *ED_actedit_animdata_from_context(const struct bContext *C,
+ struct ID **r_adt_id_owner);
void ED_animedit_unlink_action(struct bContext *C,
struct ID *id,
struct AnimData *adt,
diff --git a/source/blender/editors/space_action/action_data.c b/source/blender/editors/space_action/action_data.c
index 9ff46d96207..57f9138ec3a 100644
--- a/source/blender/editors/space_action/action_data.c
+++ b/source/blender/editors/space_action/action_data.c
@@ -71,7 +71,7 @@
/* ACTION CREATION */
/* Helper function to find the active AnimData block from the Action Editor context */
-AnimData *ED_actedit_animdata_from_context(bContext *C, ID **r_adt_id_owner)
+AnimData *ED_actedit_animdata_from_context(const bContext *C, ID **r_adt_id_owner)
{
SpaceAction *saction = (SpaceAction *)CTX_wm_space_data(C);
Object *ob = CTX_data_active_object(C);
diff --git a/source/blender/editors/space_action/action_draw.c b/source/blender/editors/space_action/action_draw.c
index 6f1a90e56a5..bc13b7f2b1b 100644
--- a/source/blender/editors/space_action/action_draw.c
+++ b/source/blender/editors/space_action/action_draw.c
@@ -131,6 +131,54 @@ void draw_channel_names(bContext *C, bAnimContext *ac, ARegion *region)
/* extra padding for lengths (to go under scrollers) */
#define EXTRA_SCROLL_PAD 100.0f
+/* Draw manually set intended playback frame ranges for actions. */
+static void draw_channel_action_ranges(bAnimContext *ac, ListBase *anim_data, View2D *v2d)
+{
+ /* Variables for coalescing the Y region of one action. */
+ bAction *cur_action = NULL;
+ AnimData *cur_adt = NULL;
+ float cur_ymax;
+
+ /* Walk through channels, grouping contiguous spans referencing the same action. */
+ float ymax = ACHANNEL_FIRST_TOP(ac) + ACHANNEL_SKIP / 2;
+ float ystep = ACHANNEL_STEP(ac);
+ float ymin = ymax - ystep;
+
+ for (bAnimListElem *ale = anim_data->first; ale; ale = ale->next, ymax = ymin, ymin -= ystep) {
+ bAction *action = NULL;
+ AnimData *adt = NULL;
+
+ /* check if visible */
+ if (IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||
+ IN_RANGE(ymax, v2d->cur.ymin, v2d->cur.ymax)) {
+ /* check if anything to show for this channel */
+ if (ale->datatype != ALE_NONE) {
+ action = ANIM_channel_action_get(ale);
+
+ if (action) {
+ adt = ale->adt;
+ }
+ }
+ }
+
+ /* Extend the current region, or flush and restart. */
+ if (action != cur_action || adt != cur_adt) {
+ if (cur_action) {
+ ANIM_draw_action_framerange(cur_adt, cur_action, v2d, ymax, cur_ymax);
+ }
+
+ cur_action = action;
+ cur_adt = adt;
+ cur_ymax = ymax;
+ }
+ }
+
+ /* Flush the last region. */
+ if (cur_action) {
+ ANIM_draw_action_framerange(cur_adt, cur_action, v2d, ymax, cur_ymax);
+ }
+}
+
/* draw keyframes in each channel */
void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *region)
{
@@ -166,6 +214,13 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *region
int height = ACHANNEL_TOT_HEIGHT(ac, items);
v2d->tot.ymin = -height;
+ /* Draw the manual frame ranges for actions in the background of the dopesheet.
+ * The action editor has already drawn the range for its action so it's not needed. */
+ if (ac->datatype == ANIMCONT_DOPESHEET) {
+ draw_channel_action_ranges(ac, &anim_data, v2d);
+ }
+
+ /* Draw the background strips. */
GPUVertFormat *format = immVertexFormat();
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
diff --git a/source/blender/editors/space_action/space_action.c b/source/blender/editors/space_action/space_action.c
index 738eeb21e2e..ebb28f3a208 100644
--- a/source/blender/editors/space_action/space_action.c
+++ b/source/blender/editors/space_action/space_action.c
@@ -25,6 +25,7 @@
#include <string.h>
#include "DNA_action_types.h"
+#include "DNA_anim_types.h"
#include "DNA_collection_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
@@ -35,6 +36,7 @@
#include "BLI_utildefines.h"
#include "BKE_context.h"
+#include "BKE_nla.h"
#include "BKE_screen.h"
#include "RNA_access.h"
@@ -204,6 +206,13 @@ static void action_main_region_draw(const bContext *C, ARegion *region)
/* start and end frame */
ANIM_draw_framerange(scene, v2d);
+ /* Draw the manually set intended playback frame range highlight in the Action editor. */
+ if (ELEM(saction->mode, SACTCONT_ACTION, SACTCONT_SHAPEKEY) && saction->action) {
+ AnimData *adt = ED_actedit_animdata_from_context(C, NULL);
+
+ ANIM_draw_action_framerange(adt, saction->action, v2d, -FLT_MAX, FLT_MAX);
+ }
+
/* data */
if (ANIM_animdata_get_context(C, &ac)) {
draw_channel_strips(&ac, saction, region);
diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c
index bf2d20cf4c9..4f335a0d13a 100644
--- a/source/blender/editors/space_nla/nla_draw.c
+++ b/source/blender/editors/space_nla/nla_draw.c
@@ -111,11 +111,11 @@ static void nla_action_draw_keyframes(
/* draw a darkened region behind the strips
* - get and reset the background color, this time without the alpha to stand out better
- * (amplified alpha is used instead)
+ * (amplified alpha is used instead, but clamped to avoid 100% opacity)
*/
float color[4];
nla_action_get_color(adt, act, color);
- color[3] *= 2.5f;
+ color[3] = min_ff(0.7f, color[3] * 2.5f);
GPUVertFormat *format = immVertexFormat();
uint pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
@@ -786,6 +786,11 @@ void draw_nla_main_data(bAnimContext *ac, SpaceNla *snla, ARegion *region)
case ANIMTYPE_NLAACTION: {
AnimData *adt = ale->adt;
+ /* Draw the manually set intended playback frame range highlight. */
+ if (ale->data) {
+ ANIM_draw_action_framerange(adt, ale->data, v2d, ymin, ymax);
+ }
+
uint pos = GPU_vertformat_attr_add(
immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c
index 62f8906d136..9f42e6378ca 100644
--- a/source/blender/editors/space_nla/nla_edit.c
+++ b/source/blender/editors/space_nla/nla_edit.c
@@ -2193,8 +2193,19 @@ static int nlaedit_apply_scale_exec(bContext *C, wmOperator *UNUSED(op))
* and recalculate the extents of the action now that it has been scaled
* but leave everything else alone
*/
+ const float start = nlastrip_get_frame(strip, strip->actstart, NLATIME_CONVERT_MAP);
+ const float end = nlastrip_get_frame(strip, strip->actend, NLATIME_CONVERT_MAP);
+
+ if (strip->act->flag & ACT_FRAME_RANGE) {
+ strip->act->frame_start = nlastrip_get_frame(
+ strip, strip->act->frame_start, NLATIME_CONVERT_MAP);
+ strip->act->frame_end = nlastrip_get_frame(
+ strip, strip->act->frame_end, NLATIME_CONVERT_MAP);
+ }
+
strip->scale = 1.0f;
- calc_action_range(strip->act, &strip->actstart, &strip->actend, 0);
+ strip->actstart = start;
+ strip->actend = end;
ale->update |= ANIM_UPDATE_DEPS;
}