Files
test/source/blender/blenkernel/intern/nla.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

2422 lines
70 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2009 Blender Authors, Joshua Leung. All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later */
2002-10-12 11:37:38 +00:00
/** \file
* \ingroup bke
2011-02-27 20:40:57 +00:00
*/
#include <cfloat>
#include <cmath>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
2002-10-12 11:37:38 +00:00
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "BLI_ghash.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_string_utils.hh"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
#include "DNA_anim_types.h"
#include "DNA_scene_types.h"
#include "DNA_sound_types.h"
#include "DNA_speaker_types.h"
#include "BKE_action.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BKE_main.h"
#include "BKE_nla.h"
#include "BKE_sound.h"
2002-10-12 11:37:38 +00:00
#include "BLO_read_write.hh"
#include "RNA_access.hh"
#include "RNA_prototypes.h"
#include "nla_private.h"
static CLG_LogRef LOG = {"bke.nla"};
Big commit with work on Groups & Libraries: -> Any Group Duplicate now can get local timing and local NLA override. This enables to control the entire animation system of the Group. Two methods for this have been implemented. 1) The quick way: just give the duplicator a "Startframe" offset. 2) Advanced: in the NLA Editor you can add ActionStrips to the duplicator to override NLA/action of any Grouped Object. For "Group NLA" to work, an ActionStrip needs to know which Object in a group it controls. On adding a strip, the code checks if an Action was already used by an Object in the Group, and assigns it automatic to that Object. You can also set this in the Nkey "Properties" panel for the strip. Change in NLA: the SHIFT+A "Add strip" command now always adds strips to the active Object. (It used to check where mouse was). This allows to add NLA strips to Objects that didn't have actions/nla yet. Important note: In Blender, duplicates are fully procedural and generated on the fly for each redraw. This means that redraw speed equals to stepping through frames, when using animated Duplicated Groups. -> Recoded entire duplicator system The old method was antique and clumsy, using globals and full temporal copies of Object. The new system is nicer in control, faster, and since it doesn't use temporal object copies anymore, it works better with Derived Mesh and DisplayList and rendering. By centralizing the code for duplicating, more options can be easier added. Features to note: - Duplicates now draw selected/unselected based on its Duplicator setting. - Same goes for the drawtype (wire, solid, selection outline, etc) - Duplicated Groups can be normally selected too Bonus goodie: SHIFT+A (Toolbox) now has entry "Add group" too, with a listing of all groups, allowing to add Group instances immediate. -> Library System - SHIFT+F4 data browse now shows the entire path for linked data - Outliner draws Library Icons to denote linked data - Outliner operation added: "Make Local" for library data. - Outliner now also draws Groups in regular view, allowing to unlink too. -> Fixes - depsgraph missed signal update for bone-parented Objects - on reading file, the entire database was tagged to "recalc" fully, causing unnecessary slowdown on reading. Might have missed stuff... :)
2005-12-11 13:23:30 +00:00
/**
* Find the active track and strip.
*
* The active strip may or may not be on the active track.
*/
static void nla_tweakmode_find_active(const ListBase /* NlaTrack */ *nla_tracks,
NlaTrack **r_track_of_active_strip,
NlaStrip **r_active_strip);
/* *************************************************** */
/* Data Management */
2002-10-12 11:37:38 +00:00
/* Freeing ------------------------------------------- */
void BKE_nlastrip_free(NlaStrip *strip, const bool do_id_user)
{
NlaStrip *cs, *csn;
/* sanity checks */
if (strip == nullptr) {
2002-10-12 11:37:38 +00:00
return;
}
/* free child-strips */
for (cs = static_cast<NlaStrip *>(strip->strips.first); cs; cs = csn) {
2012-05-12 16:11:34 +00:00
csn = cs->next;
BKE_nlastrip_remove_and_free(&strip->strips, cs, do_id_user);
}
/* remove reference to action */
if (strip->act != nullptr && do_id_user) {
id_us_min(&strip->act->id);
}
/* free own F-Curves */
2020-06-05 09:30:15 +02:00
BKE_fcurves_free(&strip->fcurves);
/* free own F-Modifiers */
free_fmodifiers(&strip->modifiers);
/* free the strip itself */
MEM_freeN(strip);
}
2002-10-12 11:37:38 +00:00
void BKE_nlatrack_free(NlaTrack *nlt, const bool do_id_user)
{
NlaStrip *strip, *stripn;
/* sanity checks */
if (nlt == nullptr) {
return;
}
/* free strips */
for (strip = static_cast<NlaStrip *>(nlt->strips.first); strip; strip = stripn) {
2012-05-12 16:11:34 +00:00
stripn = strip->next;
BKE_nlastrip_remove_and_free(&nlt->strips, strip, do_id_user);
Two wonderful new NLA & Armature editing features! - FORWARD CYCLING & MATCHING Up to no now, adding multiple actions in NLA with walkcycles required to animate them standing still, as if walking on a conveyor belt. The stride option then makes the object itself move forward, trying to keep the foot stuck on the floor (with poor results!). This option now allows to make walk cycles moving forward. By indicating a reference Offset Bone, the NLA system will use that bone to detect the correct offset for the Armature Pose to make it seamlessly going forward. Best of all, this option works as for cyclic Action Strips as well as for individual Action Strips. Note that for individual strips, you have to set the strip on "Hold". (Might become automatic detected later). Here's an example edit image for NLA: http://www.blender.org/bf/nla_match-cycle.jpg And the animation for it: http://download.blender.org/demo/test/2.43/0001_0150_match.avi Blender file: http://download.blender.org/demo/test/2.43/mancandy_matching.blend Using this kind of cycling works pretty straightforward, and is a lot easier to setup than Stride Bones. To be further tested: - Blending cycles - matching rotation for the bones as well. - ACTION MODIFIERS (motion deformors) The above option was actually required for this feature. Typically walk cycles are constructed with certain Bones to be the handles, controlling for example the torso or feet. An Action Modifier allows you to use a Curve Path to deform the motion of these controlling bones. This uses the existing Curve Deformation option. Modifiers can be added per Action Strip, each controlling a channel (bone) by choice, and even allows to layer multiple modifiers on top of each other (several paths deforming motion). This option is using the dependency graph, so editing the Curve will give realtime changes in the Armature. The previous walkcycle, controlled by two curves: http://download.blender.org/demo/test/2.43/0001_0150_deform.avi Blender file: http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend Action Modifiers can be added in the NLA Properties Panel. Per Modifier you have to indicate the channel and a Curve Object. You can copy modifiers from one strip to another using CTRL+C (only copies to active Object strips). Setting up a correct Curve Path has to be carefully done: - Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated. - make sure the center point of the Curve Object is at the center of the Armature (or above) - move the first point of the curve to the center point as well. - check if the path starts from this first point, you can change it using (in Curve EditMode) the option Wkey -> "Switch Direction" - Make sure alignment uses the correct axis; if the Armature walks into the negative Y direction, you have to set in Object Buttons, "Anim settings" Panel, the correct Track option. (Note; option will probably move to the Modifier later). This is a good reason to make such paths automatic (on a command). Is on the todo list. Also note this: - the Curve Path extends in beginning and ending, that's (for now) the default, and allows to use multiple paths. Make sure paths begin and end horizontal. - Moving the Curve in Object Mode will change the "mapping" (as if the landscape a character walks over moves). Moving the Curve in Edit Mode will change the actual position of the deformation. - Speed (Ipos) on paths is not supported yet, will be done. - The Curve "Stretch" deform option doesn't work. - Modifiers are executed *after* all actions in NLA are evaluated, there's no support yet for blending multiple strips with Modifiers. - This doesn't work yet for time-mapping... This commit is mostly for review by character animators... some details or working methods might change. This feature can also be used for other modifiers, such as noise (Perlin) or the mythical "Oomph" (frequency control) and of course Python. Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
}
/* free NLA track itself now */
MEM_freeN(nlt);
2002-10-12 11:37:38 +00:00
}
void BKE_nla_tracks_free(ListBase *tracks, bool do_id_user)
2002-10-12 11:37:38 +00:00
{
NlaTrack *nlt, *nltn;
2018-06-17 17:05:51 +02:00
/* sanity checks */
if (ELEM(nullptr, tracks, tracks->first)) {
2002-10-12 11:37:38 +00:00
return;
}
2018-06-17 17:05:51 +02:00
/* free tracks one by one */
for (nlt = static_cast<NlaTrack *>(tracks->first); nlt; nlt = nltn) {
2012-05-12 16:11:34 +00:00
nltn = nlt->next;
BKE_nlatrack_remove_and_free(tracks, nlt, do_id_user);
2002-10-12 11:37:38 +00:00
}
2018-06-17 17:05:51 +02:00
/* clear the list's pointers to be safe */
BLI_listbase_clear(tracks);
2002-10-12 11:37:38 +00:00
}
/* Copying ------------------------------------------- */
NlaStrip *BKE_nlastrip_copy(Main *bmain,
NlaStrip *strip,
const bool use_same_action,
const int flag)
{
NlaStrip *strip_d;
NlaStrip *cs_d;
const bool do_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0;
/* sanity check */
if (strip == nullptr) {
return nullptr;
}
/* make a copy */
strip_d = static_cast<NlaStrip *>(MEM_dupallocN(strip));
strip_d->next = strip_d->prev = nullptr;
/* handle action */
if (strip_d->act) {
if (use_same_action) {
if (do_id_user) {
/* increase user-count of action */
id_us_plus(&strip_d->act->id);
}
}
else {
/* use a copy of the action instead (user count shouldn't have changed yet) */
BKE_id_copy_ex(bmain, &strip_d->act->id, (ID **)&strip_d->act, flag);
}
}
/* copy F-Curves and modifiers */
2020-06-05 09:30:15 +02:00
BKE_fcurves_copy(&strip_d->fcurves, &strip->fcurves);
copy_fmodifiers(&strip_d->modifiers, &strip->modifiers);
/* make a copy of all the child-strips, one at a time */
BLI_listbase_clear(&strip_d->strips);
LISTBASE_FOREACH (NlaStrip *, cs, &strip->strips) {
cs_d = BKE_nlastrip_copy(bmain, cs, use_same_action, flag);
BLI_addtail(&strip_d->strips, cs_d);
}
/* return the strip */
return strip_d;
}
NlaTrack *BKE_nlatrack_copy(Main *bmain,
NlaTrack *nlt,
const bool use_same_actions,
const int flag)
{
NlaStrip *strip_d;
NlaTrack *nlt_d;
2018-06-17 17:05:51 +02:00
/* sanity check */
if (nlt == nullptr) {
return nullptr;
}
2018-06-17 17:05:51 +02:00
/* make a copy */
nlt_d = static_cast<NlaTrack *>(MEM_dupallocN(nlt));
nlt_d->next = nlt_d->prev = nullptr;
2018-06-17 17:05:51 +02:00
/* make a copy of all the strips, one at a time */
BLI_listbase_clear(&nlt_d->strips);
2018-06-17 17:05:51 +02:00
LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) {
strip_d = BKE_nlastrip_copy(bmain, strip, use_same_actions, flag);
BLI_addtail(&nlt_d->strips, strip_d);
}
2018-06-17 17:05:51 +02:00
/* return the copy */
return nlt_d;
}
void BKE_nla_tracks_copy(Main *bmain, ListBase *dst, const ListBase *src, const int flag)
{
NlaTrack *nlt_d;
/* sanity checks */
if (ELEM(nullptr, dst, src)) {
return;
}
/* clear out the destination list first for precautions... */
BLI_listbase_clear(dst);
/* copy each NLA-track, one at a time */
LISTBASE_FOREACH (NlaTrack *, nlt, src) {
/* make a copy, and add the copy to the destination list */
/* XXX: we need to fix this sometime. */
nlt_d = BKE_nlatrack_copy(bmain, nlt, true, flag);
BLI_addtail(dst, nlt_d);
}
}
/**
* Find `active_strip` in `strips_source`, then return the strip with the same
* index from `strips_dest`.
*/
static NlaStrip *find_active_strip_from_listbase(const NlaStrip *active_strip,
const ListBase /* NlaStrip */ *strips_source,
const ListBase /* NlaStrip */ *strips_dest)
{
BLI_assert_msg(BLI_listbase_count(strips_source) == BLI_listbase_count(strips_dest),
"Expecting the same number of source and destination strips");
NlaStrip *strip_dest = static_cast<NlaStrip *>(strips_dest->first);
LISTBASE_FOREACH (const NlaStrip *, strip_source, strips_source) {
if (strip_dest == nullptr) {
/* The tracks are assumed to have an equal number of strips, but this is
* not the case. Not sure when this might happen, but it's better to not
* crash. */
break;
}
if (strip_source == active_strip) {
return strip_dest;
}
const bool src_is_meta = strip_source->type == NLASTRIP_TYPE_META;
const bool dst_is_meta = strip_dest->type == NLASTRIP_TYPE_META;
BLI_assert_msg(src_is_meta == dst_is_meta,
"Expecting topology of source and destination strips to be equal");
if (src_is_meta && dst_is_meta) {
NlaStrip *found_in_meta = find_active_strip_from_listbase(
active_strip, &strip_source->strips, &strip_dest->strips);
if (found_in_meta != nullptr) {
return found_in_meta;
}
}
strip_dest = strip_dest->next;
}
return nullptr;
}
/* Set adt_dest->actstrip to the strip with the same index as
* adt_source->actstrip. Note that this always sets `adt_dest->actstrip`; sets
* to nullptr when `adt_source->actstrip` cannot be found. */
static void update_active_strip(AnimData *adt_dest,
NlaTrack *track_dest,
const AnimData *adt_source,
const NlaTrack *track_source)
{
BLI_assert(BLI_listbase_count(&track_source->strips) == BLI_listbase_count(&track_dest->strips));
NlaStrip *active_strip = find_active_strip_from_listbase(
adt_source->actstrip, &track_source->strips, &track_dest->strips);
adt_dest->actstrip = active_strip;
}
/* Set adt_dest->act_track to the track with the same index as adt_source->act_track. */
static void update_active_track(AnimData *adt_dest, const AnimData *adt_source)
{
adt_dest->act_track = nullptr;
adt_dest->actstrip = nullptr;
if (adt_source->act_track == nullptr && adt_source->actstrip == nullptr) {
return;
}
BLI_assert(BLI_listbase_count(&adt_source->nla_tracks) ==
BLI_listbase_count(&adt_dest->nla_tracks));
NlaTrack *track_dest = static_cast<NlaTrack *>(adt_dest->nla_tracks.first);
LISTBASE_FOREACH (NlaTrack *, track_source, &adt_source->nla_tracks) {
if (track_source == adt_source->act_track) {
adt_dest->act_track = track_dest;
}
/* Only search for the active strip if it hasn't been found yet. */
if (adt_dest->actstrip == nullptr && adt_source->actstrip != nullptr) {
update_active_strip(adt_dest, track_dest, adt_source, track_source);
}
track_dest = track_dest->next;
}
#ifndef NDEBUG
{
const bool source_has_actstrip = adt_source->actstrip != nullptr;
const bool dest_has_actstrip = adt_dest->actstrip != nullptr;
BLI_assert_msg(source_has_actstrip == dest_has_actstrip,
"Active strip did not copy correctly");
}
#endif
}
void BKE_nla_tracks_copy_from_adt(Main *bmain,
AnimData *adt_dest,
const AnimData *adt_source,
const int flag)
{
adt_dest->act_track = nullptr;
adt_dest->actstrip = nullptr;
BKE_nla_tracks_copy(bmain, &adt_dest->nla_tracks, &adt_source->nla_tracks, flag);
update_active_track(adt_dest, adt_source);
}
/* Adding ------------------------------------------- */
NlaTrack *BKE_nlatrack_new()
{
/* allocate new track */
NlaTrack *nlt = static_cast<NlaTrack *>(MEM_callocN(sizeof(NlaTrack), "NlaTrack"));
2018-06-17 17:05:51 +02:00
/* set settings requiring the track to not be part of the stack yet */
nlt->flag = NLATRACK_SELECTED | NLATRACK_OVERRIDELIBRARY_LOCAL;
return nlt;
}
void BKE_nlatrack_insert_before(ListBase *nla_tracks,
NlaTrack *next,
NlaTrack *new_track,
bool is_liboverride)
{
if (is_liboverride) {
/* Currently, all library override tracks are assumed to be grouped together at the start of
* the list. Non overridden must be placed after last library track. */
if (next != nullptr && (next->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0) {
BKE_nlatrack_insert_after(nla_tracks, next, new_track, is_liboverride);
return;
}
}
BLI_insertlinkbefore(nla_tracks, next, new_track);
new_track->index = BLI_findindex(nla_tracks, new_track);
/* Must have unique name, but we need to seed this. */
2023-06-19 20:06:55 +10:00
STRNCPY(new_track->name, "NlaTrack");
BLI_uniquename(nla_tracks,
new_track,
DATA_("NlaTrack"),
'.',
offsetof(NlaTrack, name),
sizeof(new_track->name));
}
void BKE_nlatrack_insert_after(ListBase *nla_tracks,
NlaTrack *prev,
NlaTrack *new_track,
const bool is_liboverride)
{
BLI_assert(nla_tracks);
BLI_assert(new_track);
/** If nullptr, then caller intends to insert a new head. But, tracks are not allowed to be
* placed before library overrides. So it must inserted after the last override. */
if (prev == nullptr) {
NlaTrack *first_track = (NlaTrack *)nla_tracks->first;
if (first_track != nullptr && (first_track->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0) {
prev = first_track;
}
}
2018-06-17 17:05:51 +02:00
2021-01-13 13:21:29 +11:00
/* In liboverride case, we only add local tracks after all those coming from the linked data,
* so we need to find the first local track. */
if (is_liboverride && prev != nullptr && (prev->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0) {
NlaTrack *first_local = prev->next;
for (; first_local != nullptr && (first_local->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0;
first_local = first_local->next)
{
}
prev = first_local != nullptr ? first_local->prev : nullptr;
}
/* Add track to stack, and make it the active one. */
BLI_insertlinkafter(nla_tracks, prev, new_track);
new_track->index = BLI_findindex(nla_tracks, new_track);
2018-06-17 17:05:51 +02:00
/* must have unique name, but we need to seed this */
BLI_uniquename(nla_tracks,
new_track,
DATA_("NlaTrack"),
'.',
offsetof(NlaTrack, name),
sizeof(new_track->name));
}
2018-06-17 17:05:51 +02:00
NlaTrack *BKE_nlatrack_new_before(ListBase *nla_tracks, NlaTrack *next, bool is_liboverride)
{
NlaTrack *new_track = BKE_nlatrack_new();
BKE_nlatrack_insert_before(nla_tracks, next, new_track, is_liboverride);
return new_track;
}
NlaTrack *BKE_nlatrack_new_after(ListBase *nla_tracks, NlaTrack *prev, bool is_liboverride)
{
NlaTrack *new_track = BKE_nlatrack_new();
BKE_nlatrack_insert_after(nla_tracks, prev, new_track, is_liboverride);
return new_track;
}
NlaTrack *BKE_nlatrack_new_head(ListBase *nla_tracks, bool is_liboverride)
{
return BKE_nlatrack_new_before(nla_tracks, (NlaTrack *)nla_tracks->first, is_liboverride);
}
NlaTrack *BKE_nlatrack_new_tail(ListBase *nla_tracks, const bool is_liboverride)
{
return BKE_nlatrack_new_after(nla_tracks, (NlaTrack *)nla_tracks->last, is_liboverride);
}
float BKE_nla_clip_length_get_nonzero(const NlaStrip *strip)
{
if (strip->actend <= strip->actstart) {
return 1.0f;
}
return strip->actend - strip->actstart;
}
void BKE_nla_clip_length_ensure_nonzero(const float *actstart, float *r_actend)
{
if (*r_actend <= *actstart) {
*r_actend = *actstart + 1.0f;
}
}
NlaStrip *BKE_nlastrip_new(bAction *act)
{
NlaStrip *strip;
/* sanity checks */
if (act == nullptr) {
return nullptr;
}
/* allocate new strip */
strip = static_cast<NlaStrip *>(MEM_callocN(sizeof(NlaStrip), "NlaStrip"));
2018-06-17 17:05:51 +02:00
/* generic settings
2018-11-14 12:53:15 +11:00
* - selected flag to highlight this to the user
* - (XXX) disabled Auto-Blends, as this was often causing some unwanted effects
*/
strip->flag = NLASTRIP_FLAG_SELECT | NLASTRIP_FLAG_SYNC_LENGTH;
/* Disable sync for actions with a manual frame range, since it only syncs to range anyway. */
if (act->flag & ACT_FRAME_RANGE) {
strip->flag &= ~NLASTRIP_FLAG_SYNC_LENGTH;
}
/* Enable cyclic time for known cyclic actions. */
if (BKE_action_is_cyclic(act)) {
strip->flag |= NLASTRIP_FLAG_USR_TIME_CYCLIC;
}
/* assign the action reference */
2012-05-12 16:11:34 +00:00
strip->act = act;
id_us_plus(&act->id);
/* determine initial range */
BKE_action_frame_range_get(strip->act, &strip->actstart, &strip->actend);
BKE_nla_clip_length_ensure_nonzero(&strip->actstart, &strip->actend);
strip->start = strip->actstart;
strip->end = strip->actend;
/* strip should be referenced as-is */
2012-05-12 16:11:34 +00:00
strip->scale = 1.0f;
strip->repeat = 1.0f;
/* return the new strip */
return strip;
}
NlaStrip *BKE_nlastack_add_strip(AnimData *adt, bAction *act, const bool is_liboverride)
{
NLA SoC: Transition Strips + Strip Adding Operators + Bugfixes == Transitions == Transition strips are now able to be created + evaluated. Transitions allow for interpolation between the endpoints of two adjacent strips in the same track (i.e. two strips which occur in the same track one after the other, but with a gap between them). - The current behaviour when only one endpoint affects some setting is non-optimal, since it appears somewhat inconsistently extend/replace values... - Transform code needs a few fixes still to deal with these == Strip Adding Operators == * New strips referencing Actions can be added using the Shift-A hotkey while in the strips-area. You must have a track selected first though. The new strip will get added, starting from the current frame, in the selected track(s) only if there is enough space to do so. Otherwise, the new strip gets added at the top of the stack in a new track. * New transition strips can be added with the Shift-T hotkey while in the strips area. You must have two adjacent strips selected for this to work. == New Backend Methods == * Recoded the strip/track adding API to be more flexible * Added a new method for testing whether F-Curve has any modifiers of with certain attributes. Will be used in a later bugfix... == Bugfixes == - Fixed bug with strip-blending which caused the blending modes to be useless. - NLA buttons now use proper poll callbacks instead of defining checks - Commented out missing operator in menus, silencing warnings in console - Removed obsolete/incorrect comments
2009-06-19 04:45:56 +00:00
NlaStrip *strip;
NlaTrack *nlt;
/* sanity checks */
if (ELEM(nullptr, adt, act)) {
return nullptr;
}
/* create a new NLA strip */
strip = BKE_nlastrip_new(act);
if (strip == nullptr) {
return nullptr;
}
NLA SoC: Transition Strips + Strip Adding Operators + Bugfixes == Transitions == Transition strips are now able to be created + evaluated. Transitions allow for interpolation between the endpoints of two adjacent strips in the same track (i.e. two strips which occur in the same track one after the other, but with a gap between them). - The current behaviour when only one endpoint affects some setting is non-optimal, since it appears somewhat inconsistently extend/replace values... - Transform code needs a few fixes still to deal with these == Strip Adding Operators == * New strips referencing Actions can be added using the Shift-A hotkey while in the strips-area. You must have a track selected first though. The new strip will get added, starting from the current frame, in the selected track(s) only if there is enough space to do so. Otherwise, the new strip gets added at the top of the stack in a new track. * New transition strips can be added with the Shift-T hotkey while in the strips area. You must have two adjacent strips selected for this to work. == New Backend Methods == * Recoded the strip/track adding API to be more flexible * Added a new method for testing whether F-Curve has any modifiers of with certain attributes. Will be used in a later bugfix... == Bugfixes == - Fixed bug with strip-blending which caused the blending modes to be useless. - NLA buttons now use proper poll callbacks instead of defining checks - Commented out missing operator in menus, silencing warnings in console - Removed obsolete/incorrect comments
2009-06-19 04:45:56 +00:00
/* firstly try adding strip to last track, but if that fails, add to a new track */
if (BKE_nlatrack_add_strip(
static_cast<NlaTrack *>(adt->nla_tracks.last), strip, is_liboverride) == 0)
{
2018-06-17 17:05:51 +02:00
/* trying to add to the last track failed (no track or no space),
NLA SoC: Transition Strips + Strip Adding Operators + Bugfixes == Transitions == Transition strips are now able to be created + evaluated. Transitions allow for interpolation between the endpoints of two adjacent strips in the same track (i.e. two strips which occur in the same track one after the other, but with a gap between them). - The current behaviour when only one endpoint affects some setting is non-optimal, since it appears somewhat inconsistently extend/replace values... - Transform code needs a few fixes still to deal with these == Strip Adding Operators == * New strips referencing Actions can be added using the Shift-A hotkey while in the strips-area. You must have a track selected first though. The new strip will get added, starting from the current frame, in the selected track(s) only if there is enough space to do so. Otherwise, the new strip gets added at the top of the stack in a new track. * New transition strips can be added with the Shift-T hotkey while in the strips area. You must have two adjacent strips selected for this to work. == New Backend Methods == * Recoded the strip/track adding API to be more flexible * Added a new method for testing whether F-Curve has any modifiers of with certain attributes. Will be used in a later bugfix... == Bugfixes == - Fixed bug with strip-blending which caused the blending modes to be useless. - NLA buttons now use proper poll callbacks instead of defining checks - Commented out missing operator in menus, silencing warnings in console - Removed obsolete/incorrect comments
2009-06-19 04:45:56 +00:00
* so add a new track to the stack, and add to that...
*/
nlt = BKE_nlatrack_new_tail(&adt->nla_tracks, is_liboverride);
BKE_nlatrack_set_active(&adt->nla_tracks, nlt);
BKE_nlatrack_add_strip(nlt, strip, is_liboverride);
2023-05-09 12:50:37 +10:00
STRNCPY(nlt->name, act->id.name + 2);
}
/* automatically name it too */
BKE_nlastrip_validate_name(adt, strip);
/* returns the strip added */
return strip;
}
NlaStrip *BKE_nla_add_soundstrip(Main *bmain, Scene *scene, Speaker *speaker)
{
NlaStrip *strip = static_cast<NlaStrip *>(MEM_callocN(sizeof(NlaStrip), "NlaSoundStrip"));
2018-06-17 17:05:51 +02:00
/* if speaker has a sound, set the strip length to the length of the sound,
* otherwise default to length of 10 frames
*/
#ifdef WITH_AUDASPACE
if (speaker->sound) {
SoundInfo info;
if (BKE_sound_info_get(bmain, speaker->sound, &info)) {
strip->end = float(ceil(double(info.length) * FPS));
}
}
else
#endif
{
strip->end = 10.0f;
/* quiet compiler warnings */
2019-06-12 08:16:58 +10:00
UNUSED_VARS(bmain, scene, speaker);
}
2018-06-17 17:05:51 +02:00
/* general settings */
strip->type = NLASTRIP_TYPE_SOUND;
2018-06-17 17:05:51 +02:00
strip->flag = NLASTRIP_FLAG_SELECT;
strip->extendmode = NLASTRIP_EXTEND_NOTHING; /* nothing to extend... */
2018-06-17 17:05:51 +02:00
/* strip should be referenced as-is */
strip->scale = 1.0f;
strip->repeat = 1.0f;
2018-06-17 17:05:51 +02:00
/* return this strip */
return strip;
}
void BKE_nla_strip_foreach_id(NlaStrip *strip, LibraryForeachIDData *data)
{
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, strip->act, IDWALK_CB_USER);
LISTBASE_FOREACH (FCurve *, fcu, &strip->fcurves) {
BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data, BKE_fcurve_foreach_id(fcu, data));
}
BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data,
BKE_fmodifiers_foreach_id(&strip->modifiers, data));
LISTBASE_FOREACH (NlaStrip *, substrip, &strip->strips) {
BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data, BKE_nla_strip_foreach_id(substrip, data));
}
}
/* Removing ------------------------------------------ */
void BKE_nlatrack_remove(ListBase *tracks, NlaTrack *nlt)
{
BLI_assert(tracks);
BLI_remlink(tracks, nlt);
}
void BKE_nlatrack_remove_and_free(ListBase *tracks, NlaTrack *nlt, bool do_id_user)
{
BKE_nlatrack_remove(tracks, nlt);
BKE_nlatrack_free(nlt, do_id_user);
}
/* *************************************************** */
/* NLA Evaluation <-> Editing Stuff */
/* Strip Mapping ------------------------------------- */
/* non clipped mapping for strip-time <-> global time (for Action-Clips)
2018-11-14 12:53:15 +11:00
* invert = convert action-strip time to global time
*/
2012-05-12 16:11:34 +00:00
static float nlastrip_get_frame_actionclip(NlaStrip *strip, float cframe, short mode)
{
float scale;
// float repeat; // UNUSED
/* get number of repeats */
if (IS_EQF(strip->repeat, 0.0f)) {
strip->repeat = 1.0f;
}
// repeat = strip->repeat; /* UNUSED */
/* scaling */
if (IS_EQF(strip->scale, 0.0f)) {
2012-05-12 16:11:34 +00:00
strip->scale = 1.0f;
}
/* Scale must be positive - we've got a special flag for reversing. */
scale = fabsf(strip->scale);
/* length of referenced action */
const float actlength = BKE_nla_clip_length_get_nonzero(strip);
/* reversed = play strip backwards */
if (strip->flag & NLASTRIP_FLAG_REVERSE) {
2012-07-07 22:51:57 +00:00
/* FIXME: this won't work right with Graph Editor? */
if (mode == NLATIME_CONVERT_MAP) {
2012-05-12 16:11:34 +00:00
return strip->end - scale * (cframe - strip->actstart);
}
if (mode == NLATIME_CONVERT_UNMAP) {
return (strip->end + (strip->actstart * scale - cframe)) / scale;
}
/* if (mode == NLATIME_CONVERT_EVAL) */
if (IS_EQF(float(cframe), strip->end) && IS_EQF(strip->repeat, floorf(strip->repeat))) {
/* This case prevents the motion snapping back to the first frame at the end of the strip
* by catching the case where repeats is a whole number, which means that the end of the
* strip could also be interpreted as the end of the start of a repeat. */
return strip->actstart;
}
/* - the 'fmod(..., actlength * scale)' is needed to get the repeats working
* - the '/ scale' is needed to ensure that scaling influences the timing within the repeat
*/
return strip->actend - fmodf(cframe - strip->start, actlength * scale) / scale;
}
if (mode == NLATIME_CONVERT_MAP) {
return strip->start + scale * (cframe - strip->actstart);
}
if (mode == NLATIME_CONVERT_UNMAP) {
return strip->actstart + (cframe - strip->start) / scale;
}
/* if (mode == NLATIME_CONVERT_EVAL) */
if (IS_EQF(cframe, strip->end) && IS_EQF(strip->repeat, floorf(strip->repeat))) {
/* This case prevents the motion snapping back to the first frame at the end of the strip
* by catching the case where repeats is a whole number, which means that the end of the
* strip could also be interpreted as the end of the start of a repeat. */
return strip->actend;
}
/* - the 'fmod(..., actlength * scale)' is needed to get the repeats working
* - the '/ scale' is needed to ensure that scaling influences the timing within the repeat
*/
return strip->actstart + fmodf(cframe - strip->start, actlength * scale) / scale;
}
/* non clipped mapping for strip-time <-> global time (for Transitions)
2018-11-14 12:53:15 +11:00
* invert = convert action-strip time to global time
*/
2012-05-12 16:11:34 +00:00
static float nlastrip_get_frame_transition(NlaStrip *strip, float cframe, short mode)
{
float length;
/* length of strip */
2012-05-12 16:11:34 +00:00
length = strip->end - strip->start;
/* reversed = play strip backwards */
if (strip->flag & NLASTRIP_FLAG_REVERSE) {
if (mode == NLATIME_CONVERT_MAP) {
return strip->end - (length * cframe);
}
return (strip->end - cframe) / length;
}
if (mode == NLATIME_CONVERT_MAP) {
return (length * cframe) + strip->start;
}
return (cframe - strip->start) / length;
}
float nlastrip_get_frame(NlaStrip *strip, float cframe, short mode)
{
switch (strip->type) {
case NLASTRIP_TYPE_META: /* Meta - for now, does the same as transition
* (is really just an empty container). */
case NLASTRIP_TYPE_TRANSITION: /* transition */
return nlastrip_get_frame_transition(strip, cframe, mode);
case NLASTRIP_TYPE_CLIP: /* action-clip (default) */
default:
return nlastrip_get_frame_actionclip(strip, cframe, mode);
}
}
float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, short mode)
{
NlaStrip *strip;
2021-07-07 12:55:19 +10:00
/* Sanity checks:
* - Obviously we've got to have some starting data.
* - When not in tweak-mode, the active Action does not have any scaling applied :)
* - When in tweak-mode, if the no-mapping flag is set, do not map.
*/
if ((adt == nullptr) || (adt->flag & ADT_NLA_EDIT_ON) == 0 || (adt->flag & ADT_NLA_EDIT_NOMAP)) {
return cframe;
}
/* if the active-strip info has been stored already, access this, otherwise look this up
* and store for (very probable) future usage
*/
if (adt->act_track == nullptr) {
if (adt->actstrip) {
adt->act_track = BKE_nlatrack_find_tweaked(adt);
}
else {
adt->act_track = BKE_nlatrack_find_active(&adt->nla_tracks);
}
}
if (adt->actstrip == nullptr) {
adt->actstrip = BKE_nlastrip_find_active(adt->act_track);
}
2012-05-12 16:11:34 +00:00
strip = adt->actstrip;
/* Sanity checks:
* - In rare cases, we may not be able to find this strip for some reason (internal error)
* - For now, if the user has defined a curve to control the time, this correction cannot be
* performed reliably.
*/
if ((strip == nullptr) || (strip->flag & NLASTRIP_FLAG_USR_TIME)) {
return cframe;
}
/* perform the correction now... */
return nlastrip_get_frame(strip, cframe, mode);
}
/* *************************************************** */
/* NLA API */
/* List of Strips ------------------------------------ */
/* (these functions are used for NLA-Tracks and also for nested/meta-strips) */
2014-02-03 18:55:59 +11:00
bool BKE_nlastrips_has_space(ListBase *strips, float start, float end)
{
/* sanity checks */
if ((strips == nullptr) || IS_EQF(start, end)) {
2014-12-01 17:11:18 +01:00
return false;
}
if (start > end) {
puts("BKE_nlastrips_has_space() error... start and end arguments swapped");
SWAP(float, start, end);
}
/* loop over NLA strips checking for any overlaps with this area... */
LISTBASE_FOREACH (NlaStrip *, strip, strips) {
/* if start frame of strip is past the target end-frame, that means that
* we've gone past the window we need to check for, so things are fine
*/
if (strip->start >= end) {
2014-12-01 17:11:18 +01:00
return true;
}
/* if the end of the strip is greater than either of the boundaries, the range
* must fall within the extents of the strip
*/
if ((strip->end > start) || (strip->end > end)) {
2014-12-01 17:11:18 +01:00
return false;
}
}
/* if we are still here, we haven't encountered any overlapping strips */
2014-12-01 17:11:18 +01:00
return true;
}
void BKE_nlastrips_sort_strips(ListBase *strips)
{
ListBase tmp = {nullptr, nullptr};
NlaStrip *strip, *stripn;
/* sanity checks */
if (ELEM(nullptr, strips, strips->first)) {
return;
}
/* we simply perform insertion sort on this list, since it is assumed that per track,
* there are only likely to be at most 5-10 strips
*/
for (strip = static_cast<NlaStrip *>(strips->first); strip; strip = stripn) {
short not_added = 1;
2012-05-12 16:11:34 +00:00
stripn = strip->next;
2018-06-17 17:05:51 +02:00
/* remove this strip from the list, and add it to the new list, searching from the end of
* the list, assuming that the lists are in order
*/
BLI_remlink(strips, strip);
LISTBASE_FOREACH_BACKWARD (NlaStrip *, sstrip, &tmp) {
/* check if add after */
if (sstrip->start <= strip->start) {
BLI_insertlinkafter(&tmp, sstrip, strip);
2012-05-12 16:11:34 +00:00
not_added = 0;
break;
}
}
/* add before first? */
if (not_added) {
BLI_addhead(&tmp, strip);
}
}
/* reassign the start and end points of the strips */
2012-05-12 16:11:34 +00:00
strips->first = tmp.first;
strips->last = tmp.last;
}
void BKE_nlastrips_add_strip_unsafe(ListBase *strips, NlaStrip *strip)
{
2014-04-11 11:25:41 +10:00
bool not_added = true;
/* sanity checks */
BLI_assert(!ELEM(nullptr, strips, strip));
/* find the right place to add the strip to the nominated track */
LISTBASE_FOREACH (NlaStrip *, ns, strips) {
/* if current strip occurs after the new strip, add it before */
if (ns->start >= strip->start) {
BLI_insertlinkbefore(strips, ns, strip);
not_added = false;
break;
}
}
if (not_added) {
/* just add to the end of the list of the strips then... */
BLI_addtail(strips, strip);
}
}
bool BKE_nlastrips_add_strip(ListBase *strips, NlaStrip *strip)
{
if (ELEM(nullptr, strips, strip)) {
return false;
}
if (!BKE_nlastrips_has_space(strips, strip->start, strip->end)) {
return false;
}
BKE_nlastrips_add_strip_unsafe(strips, strip);
2014-12-01 17:11:18 +01:00
return true;
}
/* Meta-Strips ------------------------------------ */
2014-04-11 11:25:41 +10:00
void BKE_nlastrips_make_metas(ListBase *strips, bool is_temp)
{
NlaStrip *mstrip = nullptr;
NlaStrip *strip, *stripn;
/* sanity checks */
if (ELEM(nullptr, strips, strips->first)) {
return;
}
/* group all continuous chains of selected strips into meta-strips */
for (strip = static_cast<NlaStrip *>(strips->first); strip; strip = stripn) {
2012-05-12 16:11:34 +00:00
stripn = strip->next;
if (strip->flag & NLASTRIP_FLAG_SELECT) {
/* if there is an existing meta-strip, add this strip to it, otherwise, create a new one */
if (mstrip == nullptr) {
/* add a new meta-strip, and add it before the current strip that it will replace... */
mstrip = static_cast<NlaStrip *>(MEM_callocN(sizeof(NlaStrip), "Meta-NlaStrip"));
mstrip->type = NLASTRIP_TYPE_META;
BLI_insertlinkbefore(strips, strip, mstrip);
/* set flags */
mstrip->flag = NLASTRIP_FLAG_SELECT;
/* set temp flag if appropriate (i.e. for transform-type editing) */
if (is_temp) {
mstrip->flag |= NLASTRIP_FLAG_TEMP_META;
}
/* set default repeat/scale values to prevent warnings */
2012-05-12 16:11:34 +00:00
mstrip->repeat = mstrip->scale = 1.0f;
/* make its start frame be set to the start frame of the current strip */
2012-05-12 16:11:34 +00:00
mstrip->start = strip->start;
}
/* remove the selected strips from the track, and add to the meta */
BLI_remlink(strips, strip);
BLI_addtail(&mstrip->strips, strip);
/* expand the meta's dimensions to include the newly added strip- i.e. its last frame */
2012-05-12 16:11:34 +00:00
mstrip->end = strip->end;
}
else {
/* current strip wasn't selected, so the end of 'island' of selected strips has been
* reached, so stop adding strips to the current meta.
*/
mstrip = nullptr;
}
}
}
void BKE_nlastrips_clear_metastrip(ListBase *strips, NlaStrip *strip)
{
NlaStrip *cs, *csn;
/* sanity check */
if (ELEM(nullptr, strips, strip)) {
return;
}
/* move each one of the meta-strip's children before the meta-strip
* in the list of strips after unlinking them from the meta-strip
*/
for (cs = static_cast<NlaStrip *>(strip->strips.first); cs; cs = csn) {
2012-05-12 16:11:34 +00:00
csn = cs->next;
BLI_remlink(&strip->strips, cs);
BLI_insertlinkbefore(strips, strip, cs);
}
/* free the meta-strip now */
BKE_nlastrip_remove_and_free(strips, strip, true);
}
2014-04-11 11:25:41 +10:00
void BKE_nlastrips_clear_metas(ListBase *strips, bool only_sel, bool only_temp)
{
NlaStrip *strip, *stripn;
/* sanity checks */
if (ELEM(nullptr, strips, strips->first)) {
return;
}
/* remove meta-strips fitting the criteria of the arguments */
for (strip = static_cast<NlaStrip *>(strips->first); strip; strip = stripn) {
2012-05-12 16:11:34 +00:00
stripn = strip->next;
/* check if strip is a meta-strip */
if (strip->type == NLASTRIP_TYPE_META) {
/* if check if selection and 'temporary-only' considerations are met */
2014-04-11 11:25:41 +10:00
if ((!only_sel) || (strip->flag & NLASTRIP_FLAG_SELECT)) {
if ((!only_temp) || (strip->flag & NLASTRIP_FLAG_TEMP_META)) {
BKE_nlastrips_clear_metastrip(strips, strip);
}
}
}
}
}
2014-04-11 11:25:41 +10:00
bool BKE_nlameta_add_strip(NlaStrip *mstrip, NlaStrip *strip)
{
/* sanity checks */
if (ELEM(nullptr, mstrip, strip)) {
2014-12-01 17:11:18 +01:00
return false;
}
/* firstly, check if the meta-strip has space for this */
if (BKE_nlastrips_has_space(&mstrip->strips, strip->start, strip->end) == 0) {
2014-12-01 17:11:18 +01:00
return false;
}
/* check if this would need to be added to the ends of the meta,
2012-03-01 12:20:18 +00:00
* and subsequently, if the neighboring strips allow us enough room
*/
if (strip->start < mstrip->start) {
2018-06-17 17:05:51 +02:00
/* check if strip to the left (if it exists) ends before the
* start of the strip we're trying to add
*/
if ((mstrip->prev == nullptr) || (mstrip->prev->end <= strip->start)) {
/* add strip to start of meta's list, and expand dimensions */
BLI_addhead(&mstrip->strips, strip);
2012-05-12 16:11:34 +00:00
mstrip->start = strip->start;
2014-12-01 17:11:18 +01:00
return true;
}
/* failed... no room before */
return false;
}
if (strip->end > mstrip->end) {
2018-06-17 17:05:51 +02:00
/* check if strip to the right (if it exists) starts before the
* end of the strip we're trying to add
*/
if ((mstrip->next == nullptr) || (mstrip->next->start >= strip->end)) {
/* add strip to end of meta's list, and expand dimensions */
BLI_addtail(&mstrip->strips, strip);
2012-05-12 16:11:34 +00:00
mstrip->end = strip->end;
2014-12-01 17:11:18 +01:00
return true;
}
/* failed... no room after */
return false;
}
/* just try to add to the meta-strip (no dimension changes needed) */
return BKE_nlastrips_add_strip(&mstrip->strips, strip);
}
void BKE_nlameta_flush_transforms(NlaStrip *mstrip)
{
float oStart, oEnd, offset;
float oLen, nLen;
2012-05-12 16:11:34 +00:00
short scaleChanged = 0;
2018-06-17 17:05:51 +02:00
/* sanity checks
2018-11-14 12:53:15 +11:00
* - strip must exist
* - strip must be a meta-strip with some contents
*/
if (ELEM(nullptr, mstrip, mstrip->strips.first)) {
return;
}
if (mstrip->type != NLASTRIP_TYPE_META) {
return;
}
/* get the original start/end points, and calculate the start-frame offset
2018-11-14 12:53:15 +11:00
* - these are simply the start/end frames of the child strips,
* since we assume they weren't transformed yet
*/
2012-05-12 16:11:34 +00:00
oStart = ((NlaStrip *)mstrip->strips.first)->start;
oEnd = ((NlaStrip *)mstrip->strips.last)->end;
offset = mstrip->start - oStart;
/* check if scale changed */
oLen = oEnd - oStart;
nLen = mstrip->end - mstrip->start;
scaleChanged = !IS_EQF(oLen, nLen);
/* optimization:
* don't flush if nothing changed yet
2018-11-14 12:53:15 +11:00
* TODO: maybe we need a flag to say always flush?
*/
if (IS_EQF(oStart, mstrip->start) && IS_EQF(oEnd, mstrip->end) && !scaleChanged) {
return;
}
/* for each child-strip, calculate new start/end points based on this new info */
LISTBASE_FOREACH (NlaStrip *, strip, &mstrip->strips) {
if (scaleChanged) {
float p1, p2;
if (oLen) {
/* Compute positions of endpoints relative to old extents of strip. */
p1 = (strip->start - oStart) / oLen;
p2 = (strip->end - oStart) / oLen;
}
else {
/* WORKAROUND: in theory, a strip should never be zero length. However,
* zero-length strips are nevertheless showing up here (see issue #113552).
* This is a stop-gap fix to handle that and prevent a divide by zero. A
* proper fix will need to track down and fix the source(s) of these
* zero-length strips. */
p1 = 0.0f;
p2 = 1.0f;
}
/* Apply new strip endpoints using the proportions,
* then wait for second pass to flush scale properly. */
2012-05-12 16:11:34 +00:00
strip->start = (p1 * nLen) + mstrip->start;
strip->end = (p2 * nLen) + mstrip->start;
/* Recompute the playback scale, given the new start & end frame of the strip. */
const double action_len = strip->actend - strip->actstart;
const double repeated_len = action_len * strip->repeat;
const double strip_len = strip->end - strip->start;
strip->scale = strip_len / repeated_len;
}
else {
/* just apply the changes in offset to both ends of the strip */
strip->start += offset;
strip->end += offset;
}
}
/* apply a second pass over child strips, to finish up unfinished business */
LISTBASE_FOREACH (NlaStrip *, strip, &mstrip->strips) {
/* only if scale changed, need to perform RNA updates */
if (scaleChanged) {
/* use RNA updates to compute scale properly */
PointerRNA ptr = RNA_pointer_create(nullptr, &RNA_NlaStrip, strip);
RNA_float_set(&ptr, "frame_start", strip->start);
RNA_float_set(&ptr, "frame_end", strip->end);
}
/* finally, make sure the strip's children (if it is a meta-itself), get updated */
BKE_nlameta_flush_transforms(strip);
}
}
/* NLA-Tracks ---------------------------------------- */
2002-10-12 11:37:38 +00:00
2012-05-12 16:11:34 +00:00
NlaTrack *BKE_nlatrack_find_active(ListBase *tracks)
{
/* sanity check */
if (ELEM(nullptr, tracks, tracks->first)) {
return nullptr;
}
2018-06-17 17:05:51 +02:00
/* try to find the first active track */
LISTBASE_FOREACH (NlaTrack *, nlt, tracks) {
if (nlt->flag & NLATRACK_ACTIVE) {
return nlt;
}
Two wonderful new NLA & Armature editing features! - FORWARD CYCLING & MATCHING Up to no now, adding multiple actions in NLA with walkcycles required to animate them standing still, as if walking on a conveyor belt. The stride option then makes the object itself move forward, trying to keep the foot stuck on the floor (with poor results!). This option now allows to make walk cycles moving forward. By indicating a reference Offset Bone, the NLA system will use that bone to detect the correct offset for the Armature Pose to make it seamlessly going forward. Best of all, this option works as for cyclic Action Strips as well as for individual Action Strips. Note that for individual strips, you have to set the strip on "Hold". (Might become automatic detected later). Here's an example edit image for NLA: http://www.blender.org/bf/nla_match-cycle.jpg And the animation for it: http://download.blender.org/demo/test/2.43/0001_0150_match.avi Blender file: http://download.blender.org/demo/test/2.43/mancandy_matching.blend Using this kind of cycling works pretty straightforward, and is a lot easier to setup than Stride Bones. To be further tested: - Blending cycles - matching rotation for the bones as well. - ACTION MODIFIERS (motion deformors) The above option was actually required for this feature. Typically walk cycles are constructed with certain Bones to be the handles, controlling for example the torso or feet. An Action Modifier allows you to use a Curve Path to deform the motion of these controlling bones. This uses the existing Curve Deformation option. Modifiers can be added per Action Strip, each controlling a channel (bone) by choice, and even allows to layer multiple modifiers on top of each other (several paths deforming motion). This option is using the dependency graph, so editing the Curve will give realtime changes in the Armature. The previous walkcycle, controlled by two curves: http://download.blender.org/demo/test/2.43/0001_0150_deform.avi Blender file: http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend Action Modifiers can be added in the NLA Properties Panel. Per Modifier you have to indicate the channel and a Curve Object. You can copy modifiers from one strip to another using CTRL+C (only copies to active Object strips). Setting up a correct Curve Path has to be carefully done: - Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated. - make sure the center point of the Curve Object is at the center of the Armature (or above) - move the first point of the curve to the center point as well. - check if the path starts from this first point, you can change it using (in Curve EditMode) the option Wkey -> "Switch Direction" - Make sure alignment uses the correct axis; if the Armature walks into the negative Y direction, you have to set in Object Buttons, "Anim settings" Panel, the correct Track option. (Note; option will probably move to the Modifier later). This is a good reason to make such paths automatic (on a command). Is on the todo list. Also note this: - the Curve Path extends in beginning and ending, that's (for now) the default, and allows to use multiple paths. Make sure paths begin and end horizontal. - Moving the Curve in Object Mode will change the "mapping" (as if the landscape a character walks over moves). Moving the Curve in Edit Mode will change the actual position of the deformation. - Speed (Ipos) on paths is not supported yet, will be done. - The Curve "Stretch" deform option doesn't work. - Modifiers are executed *after* all actions in NLA are evaluated, there's no support yet for blending multiple strips with Modifiers. - This doesn't work yet for time-mapping... This commit is mostly for review by character animators... some details or working methods might change. This feature can also be used for other modifiers, such as noise (Perlin) or the mythical "Oomph" (frequency control) and of course Python. Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
}
2018-06-17 17:05:51 +02:00
/* none found */
return nullptr;
2002-10-12 11:37:38 +00:00
}
NlaTrack *BKE_nlatrack_find_tweaked(AnimData *adt)
{
/* sanity check */
if (adt == nullptr) {
return nullptr;
}
/* Since the track itself gets disabled, we want the first disabled... */
LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) {
if (nlt->flag & (NLATRACK_ACTIVE | NLATRACK_DISABLED)) {
/* For good measure, make sure that strip actually exists there */
if (BLI_findindex(&nlt->strips, adt->actstrip) != -1) {
return nlt;
}
if (G.debug & G_DEBUG) {
printf("%s: Active strip (%p, %s) not in NLA track found (%p, %s)\n",
2018-06-17 17:05:51 +02:00
__func__,
adt->actstrip,
(adt->actstrip) ? adt->actstrip->name : "<None>",
nlt,
nlt->name);
}
}
}
/* Not found! */
return nullptr;
}
void BKE_nlatrack_solo_toggle(AnimData *adt, NlaTrack *nlt)
{
/* sanity check */
if (ELEM(nullptr, adt, adt->nla_tracks.first)) {
return;
}
/* firstly, make sure 'solo' flag for all tracks is disabled */
LISTBASE_FOREACH (NlaTrack *, nt, &adt->nla_tracks) {
if (nt != nlt) {
nt->flag &= ~NLATRACK_SOLO;
}
}
/* now, enable 'solo' for the given track if appropriate */
if (nlt) {
/* toggle solo status */
nlt->flag ^= NLATRACK_SOLO;
/* set or clear solo-status on AnimData */
if (nlt->flag & NLATRACK_SOLO) {
adt->flag |= ADT_NLA_SOLO_TRACK;
}
else {
adt->flag &= ~ADT_NLA_SOLO_TRACK;
}
}
else {
adt->flag &= ~ADT_NLA_SOLO_TRACK;
}
}
void BKE_nlatrack_set_active(ListBase *tracks, NlaTrack *nlt_a)
2002-10-12 11:37:38 +00:00
{
/* sanity check */
if (ELEM(nullptr, tracks, tracks->first)) {
2002-10-12 11:37:38 +00:00
return;
}
2018-06-17 17:05:51 +02:00
/* deactivate all the rest */
LISTBASE_FOREACH (NlaTrack *, nlt, tracks) {
nlt->flag &= ~NLATRACK_ACTIVE;
}
2018-06-17 17:05:51 +02:00
/* set the given one as the active one */
if (nlt_a) {
nlt_a->flag |= NLATRACK_ACTIVE;
}
}
2002-10-12 11:37:38 +00:00
2014-02-03 18:55:59 +11:00
bool BKE_nlatrack_has_space(NlaTrack *nlt, float start, float end)
{
2018-06-17 17:05:51 +02:00
/* sanity checks
2018-11-14 12:53:15 +11:00
* - track must exist
* - track must be editable
* - bounds cannot be equal (0-length is nasty)
*/
if ((nlt == nullptr) || (nlt->flag & NLATRACK_PROTECTED) || IS_EQF(start, end)) {
2014-12-01 17:11:18 +01:00
return false;
}
if (start > end) {
puts("BKE_nlatrack_has_space() error... start and end arguments swapped");
SWAP(float, start, end);
}
/* check if there's any space left in the track for a strip of the given length */
return BKE_nlastrips_has_space(&nlt->strips, start, end);
}
bool BKE_nlatrack_has_strips(ListBase *tracks)
{
/* sanity checks */
if (BLI_listbase_is_empty(tracks)) {
return false;
}
/* Check each track for NLA strips. */
LISTBASE_FOREACH (NlaTrack *, track, tracks) {
if (BLI_listbase_count(&track->strips) > 0) {
return true;
}
}
/* none found */
return false;
}
void BKE_nlatrack_sort_strips(NlaTrack *nlt)
{
/* sanity checks */
if (ELEM(nullptr, nlt, nlt->strips.first)) {
return;
}
2018-06-17 17:05:51 +02:00
/* sort the strips with a more generic function */
BKE_nlastrips_sort_strips(&nlt->strips);
}
bool BKE_nlatrack_add_strip(NlaTrack *nlt, NlaStrip *strip, const bool is_liboverride)
NLA SoC: Transition Strips + Strip Adding Operators + Bugfixes == Transitions == Transition strips are now able to be created + evaluated. Transitions allow for interpolation between the endpoints of two adjacent strips in the same track (i.e. two strips which occur in the same track one after the other, but with a gap between them). - The current behaviour when only one endpoint affects some setting is non-optimal, since it appears somewhat inconsistently extend/replace values... - Transform code needs a few fixes still to deal with these == Strip Adding Operators == * New strips referencing Actions can be added using the Shift-A hotkey while in the strips-area. You must have a track selected first though. The new strip will get added, starting from the current frame, in the selected track(s) only if there is enough space to do so. Otherwise, the new strip gets added at the top of the stack in a new track. * New transition strips can be added with the Shift-T hotkey while in the strips area. You must have two adjacent strips selected for this to work. == New Backend Methods == * Recoded the strip/track adding API to be more flexible * Added a new method for testing whether F-Curve has any modifiers of with certain attributes. Will be used in a later bugfix... == Bugfixes == - Fixed bug with strip-blending which caused the blending modes to be useless. - NLA buttons now use proper poll callbacks instead of defining checks - Commented out missing operator in menus, silencing warnings in console - Removed obsolete/incorrect comments
2009-06-19 04:45:56 +00:00
{
/* sanity checks */
if (ELEM(nullptr, nlt, strip)) {
2014-12-01 17:11:18 +01:00
return false;
}
2018-06-17 17:05:51 +02:00
/*
* Do not allow adding strips if this track is locked, or not a local one in liboverride case.
*/
if (nlt->flag & NLATRACK_PROTECTED ||
(is_liboverride && (nlt->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0))
{
return false;
}
2018-06-17 17:05:51 +02:00
/* try to add the strip to the track using a more generic function */
return BKE_nlastrips_add_strip(&nlt->strips, strip);
NLA SoC: Transition Strips + Strip Adding Operators + Bugfixes == Transitions == Transition strips are now able to be created + evaluated. Transitions allow for interpolation between the endpoints of two adjacent strips in the same track (i.e. two strips which occur in the same track one after the other, but with a gap between them). - The current behaviour when only one endpoint affects some setting is non-optimal, since it appears somewhat inconsistently extend/replace values... - Transform code needs a few fixes still to deal with these == Strip Adding Operators == * New strips referencing Actions can be added using the Shift-A hotkey while in the strips-area. You must have a track selected first though. The new strip will get added, starting from the current frame, in the selected track(s) only if there is enough space to do so. Otherwise, the new strip gets added at the top of the stack in a new track. * New transition strips can be added with the Shift-T hotkey while in the strips area. You must have two adjacent strips selected for this to work. == New Backend Methods == * Recoded the strip/track adding API to be more flexible * Added a new method for testing whether F-Curve has any modifiers of with certain attributes. Will be used in a later bugfix... == Bugfixes == - Fixed bug with strip-blending which caused the blending modes to be useless. - NLA buttons now use proper poll callbacks instead of defining checks - Commented out missing operator in menus, silencing warnings in console - Removed obsolete/incorrect comments
2009-06-19 04:45:56 +00:00
}
void BKE_nlatrack_remove_strip(NlaTrack *track, NlaStrip *strip)
{
BLI_assert(track);
BKE_nlastrip_remove(&track->strips, strip);
}
2014-04-11 11:25:41 +10:00
bool BKE_nlatrack_get_bounds(NlaTrack *nlt, float bounds[2])
{
NlaStrip *strip;
2018-06-17 17:05:51 +02:00
/* initialize bounds */
if (bounds) {
bounds[0] = bounds[1] = 0.0f;
}
else {
2014-12-01 17:11:18 +01:00
return false;
}
2018-06-17 17:05:51 +02:00
/* sanity checks */
if (ELEM(nullptr, nlt, nlt->strips.first)) {
2014-12-01 17:11:18 +01:00
return false;
}
2018-06-17 17:05:51 +02:00
/* lower bound is first strip's start frame */
strip = static_cast<NlaStrip *>(nlt->strips.first);
bounds[0] = strip->start;
2018-06-17 17:05:51 +02:00
/* upper bound is last strip's end frame */
strip = static_cast<NlaStrip *>(nlt->strips.last);
bounds[1] = strip->end;
2018-06-17 17:05:51 +02:00
/* done */
2014-12-01 17:11:18 +01:00
return true;
}
bool BKE_nlatrack_is_nonlocal_in_liboverride(const ID *id, const NlaTrack *nlt)
{
return (ID_IS_OVERRIDE_LIBRARY(id) &&
(nlt == nullptr || (nlt->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0));
}
/* NLA Strips -------------------------------------- */
static NlaStrip *nlastrip_find_active(ListBase /* NlaStrip */ *strips)
{
LISTBASE_FOREACH (NlaStrip *, strip, strips) {
if (strip->flag & NLASTRIP_FLAG_ACTIVE) {
return strip;
}
if (strip->type != NLASTRIP_TYPE_META) {
continue;
}
NlaStrip *inner_active = nlastrip_find_active(&strip->strips);
if (inner_active != nullptr) {
return inner_active;
}
}
2018-06-17 17:05:51 +02:00
return nullptr;
}
float BKE_nlastrip_compute_frame_from_previous_strip(NlaStrip *strip)
{
float limit_prev = MINAFRAMEF;
/* Find the previous end frame, with a special case if the previous strip was a transition : */
if (strip->prev) {
if (strip->prev->type == NLASTRIP_TYPE_TRANSITION) {
limit_prev = strip->prev->start + NLASTRIP_MIN_LEN_THRESH;
}
else {
limit_prev = strip->prev->end;
}
}
return limit_prev;
}
float BKE_nlastrip_compute_frame_to_next_strip(NlaStrip *strip)
{
float limit_next = MAXFRAMEF;
/* Find the next begin frame, with a special case if the next strip's a transition : */
if (strip->next) {
if (strip->next->type == NLASTRIP_TYPE_TRANSITION) {
limit_next = strip->next->end - NLASTRIP_MIN_LEN_THRESH;
}
else {
limit_next = strip->next->start;
}
}
return limit_next;
}
NlaStrip *BKE_nlastrip_next_in_track(NlaStrip *strip, bool skip_transitions)
{
NlaStrip *next = strip->next;
while (next != nullptr) {
if (skip_transitions && (next->type == NLASTRIP_TYPE_TRANSITION)) {
next = next->next;
}
else {
return next;
}
}
return nullptr;
}
NlaStrip *BKE_nlastrip_prev_in_track(NlaStrip *strip, bool skip_transitions)
{
NlaStrip *prev = strip->prev;
while (prev != nullptr) {
if (skip_transitions && (prev->type == NLASTRIP_TYPE_TRANSITION)) {
prev = prev->prev;
}
else {
return prev;
}
}
return nullptr;
}
NlaStrip *BKE_nlastrip_find_active(NlaTrack *nlt)
{
if (nlt == nullptr) {
return nullptr;
}
return nlastrip_find_active(&nlt->strips);
}
void BKE_nlastrip_remove(ListBase *strips, NlaStrip *strip)
{
BLI_assert(strips);
BLI_remlink(strips, strip);
}
void BKE_nlastrip_remove_and_free(ListBase *strips, NlaStrip *strip, const bool do_id_user)
{
BKE_nlastrip_remove(strips, strip);
BKE_nlastrip_free(strip, do_id_user);
}
void BKE_nlastrip_set_active(AnimData *adt, NlaStrip *strip)
{
/* sanity checks */
if (adt == nullptr) {
return;
}
/* Loop over tracks, deactivating. */
LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) {
LISTBASE_FOREACH (NlaStrip *, nls, &nlt->strips) {
if (nls != strip) {
nls->flag &= ~NLASTRIP_FLAG_ACTIVE;
}
else {
nls->flag |= NLASTRIP_FLAG_ACTIVE;
}
}
}
}
2014-04-11 11:25:41 +10:00
bool BKE_nlastrip_within_bounds(NlaStrip *strip, float min, float max)
{
2012-05-12 16:11:34 +00:00
const float stripLen = (strip) ? strip->end - strip->start : 0.0f;
const float boundsLen = fabsf(max - min);
/* sanity checks */
if ((strip == nullptr) || IS_EQF(stripLen, 0.0f) || IS_EQF(boundsLen, 0.0f)) {
2014-12-01 17:11:18 +01:00
return false;
}
/* only ok if at least part of the strip is within the bounding window
2018-11-14 12:53:15 +11:00
* - first 2 cases cover when the strip length is less than the bounding area
* - second 2 cases cover when the strip length is greater than the bounding area
*/
if ((stripLen < boundsLen) &&
!(IN_RANGE(strip->start, min, max) || IN_RANGE(strip->end, min, max)))
{
2014-12-01 17:11:18 +01:00
return false;
}
if ((stripLen > boundsLen) &&
!(IN_RANGE(min, strip->start, strip->end) || IN_RANGE(max, strip->start, strip->end)))
{
2014-12-01 17:11:18 +01:00
return false;
}
/* should be ok! */
2014-12-01 17:11:18 +01:00
return true;
}
float BKE_nlastrip_distance_to_frame(const NlaStrip *strip, const float timeline_frame)
{
if (timeline_frame < strip->start) {
return strip->start - timeline_frame;
}
if (strip->end < timeline_frame) {
return timeline_frame - strip->end;
}
return 0.0f;
}
/* Ensure that strip doesn't overlap those around it after resizing
* by offsetting those which follow. */
static void nlastrip_fix_resize_overlaps(NlaStrip *strip)
{
/* next strips - do this first, since we're often just getting longer */
if (strip->next) {
NlaStrip *nls = strip->next;
float offset = 0.0f;
if (nls->type == NLASTRIP_TYPE_TRANSITION) {
/* transition strips should grow/shrink to accommodate the resized strip,
* but if the strip's bounds now exceed the transition, we're forced to
* offset everything to maintain the balance
*/
if (strip->end <= nls->start) {
/* grow the transition to fill the void */
nls->start = strip->end;
}
else if (strip->end < nls->end) {
/* shrink the transition to give the strip room */
nls->start = strip->end;
}
else {
2020-09-10 09:45:25 +10:00
/* Shrink transition down to 1 frame long (so that it can still be found),
* then offset everything else by the remaining deficit to give the strip room. */
nls->start = nls->end - 1.0f;
2020-09-10 09:45:25 +10:00
/* XXX: review whether preventing fractional values is good here... */
offset = ceilf(strip->end - nls->start);
/* apply necessary offset to ensure that the strip has enough space */
for (; nls; nls = nls->next) {
nls->start += offset;
nls->end += offset;
}
}
}
else if (strip->end > nls->start) {
/* NOTE: need to ensure we don't have a fractional frame offset, even if that leaves a gap,
* otherwise it will be very hard to get rid of later
*/
offset = ceilf(strip->end - nls->start);
/* apply to times of all strips in this direction */
for (; nls; nls = nls->next) {
nls->start += offset;
nls->end += offset;
}
}
}
/* previous strips - same routine as before */
/* NOTE: when strip bounds are recalculated, this is not considered! */
if (strip->prev) {
NlaStrip *nls = strip->prev;
float offset = 0.0f;
if (nls->type == NLASTRIP_TYPE_TRANSITION) {
/* transition strips should grow/shrink to accommodate the resized strip,
* but if the strip's bounds now exceed the transition, we're forced to
* offset everything to maintain the balance
*/
if (strip->start >= nls->end) {
/* grow the transition to fill the void */
nls->end = strip->start;
}
else if (strip->start > nls->start) {
/* shrink the transition to give the strip room */
nls->end = strip->start;
}
else {
2020-09-10 09:45:25 +10:00
/* Shrink transition down to 1 frame long (so that it can still be found),
* then offset everything else by the remaining deficit to give the strip room. */
nls->end = nls->start + 1.0f;
2020-09-10 09:45:25 +10:00
/* XXX: review whether preventing fractional values is good here... */
offset = ceilf(nls->end - strip->start);
/* apply necessary offset to ensure that the strip has enough space */
for (; nls; nls = nls->prev) {
nls->start -= offset;
nls->end -= offset;
}
}
}
else if (strip->start < nls->end) {
/* NOTE: need to ensure we don't have a fractional frame offset, even if that leaves a gap,
* otherwise it will be very hard to get rid of later
*/
offset = ceilf(nls->end - strip->start);
/* apply to times of all strips in this direction */
for (; nls; nls = nls->prev) {
nls->start -= offset;
nls->end -= offset;
}
}
}
}
void BKE_nlastrip_recalculate_bounds_sync_action(NlaStrip *strip)
{
float prev_actstart;
if (strip == nullptr || strip->type != NLASTRIP_TYPE_CLIP) {
return;
}
prev_actstart = strip->actstart;
BKE_action_frame_range_get(strip->act, &strip->actstart, &strip->actend);
BKE_nla_clip_length_ensure_nonzero(&strip->actstart, &strip->actend);
/* Set start such that key's do not visually move, to preserve the overall animation result. */
strip->start += (strip->actstart - prev_actstart) * strip->scale;
BKE_nlastrip_recalculate_bounds(strip);
}
void BKE_nlastrip_recalculate_bounds(NlaStrip *strip)
{
float mapping;
2018-06-17 17:05:51 +02:00
/* sanity checks
2018-11-14 12:53:15 +11:00
* - must have a strip
* - can only be done for action clips
*/
if ((strip == nullptr) || (strip->type != NLASTRIP_TYPE_CLIP)) {
return;
}
2018-06-17 17:05:51 +02:00
/* calculate new length factors */
const float actlen = BKE_nla_clip_length_get_nonzero(strip);
2018-06-17 17:05:51 +02:00
2012-05-12 16:11:34 +00:00
mapping = strip->scale * strip->repeat;
2018-06-17 17:05:51 +02:00
/* adjust endpoint of strip in response to this */
if (IS_EQF(mapping, 0.0f) == 0) {
strip->end = (actlen * mapping) + strip->start;
}
2018-06-17 17:05:51 +02:00
2016-07-08 00:48:03 +10:00
/* make sure we don't overlap our neighbors */
nlastrip_fix_resize_overlaps(strip);
}
void BKE_nlastrip_recalculate_blend(NlaStrip *strip)
{
/* check if values need to be re-calculated. */
if (strip->blendin == 0 && strip->blendout == 0) {
return;
}
const double strip_len = strip->end - strip->start;
double blend_in = strip->blendin;
double blend_out = strip->blendout;
double blend_in_max = strip_len - blend_out;
CLAMP_MIN(blend_in_max, 0);
/* blend-out is limited to the length of the strip. */
CLAMP(blend_in, 0, blend_in_max);
CLAMP(blend_out, 0, strip_len - blend_in);
strip->blendin = blend_in;
strip->blendout = blend_out;
}
/* Animated Strips ------------------------------------------- */
2014-04-11 11:25:41 +10:00
bool BKE_nlatrack_has_animated_strips(NlaTrack *nlt)
{
/* sanity checks */
if (ELEM(nullptr, nlt, nlt->strips.first)) {
2014-12-01 17:11:18 +01:00
return false;
}
2018-06-17 17:05:51 +02:00
/* check each strip for F-Curves only (don't care about whether the flags are set) */
LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) {
if (strip->fcurves.first) {
2014-12-01 17:11:18 +01:00
return true;
}
}
2018-06-17 17:05:51 +02:00
/* none found */
2014-12-01 17:11:18 +01:00
return false;
}
2014-04-11 11:25:41 +10:00
bool BKE_nlatracks_have_animated_strips(ListBase *tracks)
{
/* sanity checks */
if (ELEM(nullptr, tracks, tracks->first)) {
2014-12-01 17:11:18 +01:00
return false;
}
2018-06-17 17:05:51 +02:00
/* check each track, stopping on the first hit */
LISTBASE_FOREACH (NlaTrack *, nlt, tracks) {
if (BKE_nlatrack_has_animated_strips(nlt)) {
2014-12-01 17:11:18 +01:00
return true;
}
}
2018-06-17 17:05:51 +02:00
/* none found */
2014-12-01 17:11:18 +01:00
return false;
}
void BKE_nlastrip_validate_fcurves(NlaStrip *strip)
{
FCurve *fcu;
/* sanity checks */
if (strip == nullptr) {
return;
}
/* if controlling influence... */
if (strip->flag & NLASTRIP_FLAG_USR_INFLUENCE) {
/* try to get F-Curve */
2020-06-05 09:30:15 +02:00
fcu = BKE_fcurve_find(&strip->fcurves, "influence", 0);
/* add one if not found */
if (fcu == nullptr) {
/* make new F-Curve */
2020-06-05 08:41:09 +02:00
fcu = BKE_fcurve_create();
BLI_addtail(&strip->fcurves, fcu);
/* set default flags */
2012-05-12 16:11:34 +00:00
fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
fcu->auto_smoothing = U.auto_smoothing_new;
/* store path - make copy, and store that */
2012-05-12 16:11:34 +00:00
fcu->rna_path = BLI_strdupn("influence", 9);
/* insert keyframe to ensure current value stays on first refresh */
fcu->bezt = static_cast<BezTriple *>(
MEM_callocN(sizeof(BezTriple), "nlastrip influence bezt"));
fcu->totvert = 1;
fcu->bezt->vec[1][0] = strip->start;
fcu->bezt->vec[1][1] = strip->influence;
/* Respect User Preferences for default interpolation and handles. */
fcu->bezt->h1 = fcu->bezt->h2 = U.keyhandles_new;
fcu->bezt->ipo = U.ipo_new;
}
}
/* if controlling time... */
if (strip->flag & NLASTRIP_FLAG_USR_TIME) {
/* try to get F-Curve */
2020-06-05 09:30:15 +02:00
fcu = BKE_fcurve_find(&strip->fcurves, "strip_time", 0);
/* add one if not found */
if (fcu == nullptr) {
/* make new F-Curve */
2020-06-05 08:41:09 +02:00
fcu = BKE_fcurve_create();
BLI_addtail(&strip->fcurves, fcu);
/* set default flags */
2012-05-12 16:11:34 +00:00
fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
fcu->auto_smoothing = U.auto_smoothing_new;
/* store path - make copy, and store that */
2012-05-12 16:11:34 +00:00
fcu->rna_path = BLI_strdupn("strip_time", 10);
2012-07-07 22:51:57 +00:00
/* TODO: insert a few keyframes to ensure default behavior? */
}
}
}
bool BKE_nlastrip_has_curves_for_property(const PointerRNA *ptr, const PropertyRNA *prop)
{
/* sanity checks */
if (ELEM(nullptr, ptr, prop)) {
return false;
}
/* 1) Must be NLA strip */
if (ptr->type == &RNA_NlaStrip) {
/* 2) Must be one of the predefined properties */
static PropertyRNA *prop_influence = nullptr;
static PropertyRNA *prop_time = nullptr;
static bool needs_init = true;
/* Init the properties on first use */
if (needs_init) {
prop_influence = RNA_struct_type_find_property(&RNA_NlaStrip, "influence");
prop_time = RNA_struct_type_find_property(&RNA_NlaStrip, "strip_time");
needs_init = false;
}
/* Check if match */
if (ELEM(prop, prop_influence, prop_time)) {
return true;
}
}
/* No criteria met */
return false;
}
/* Sanity Validation ------------------------------------ */
static bool nla_editbone_name_check(void *arg, const char *name)
{
return BLI_ghash_haskey((GHash *)arg, (const void *)name);
}
void BKE_nlastrip_validate_name(AnimData *adt, NlaStrip *strip)
{
GHash *gh;
/* sanity checks */
if (ELEM(nullptr, adt, strip)) {
return;
}
/* give strip a default name if none already */
2012-05-12 16:11:34 +00:00
if (strip->name[0] == 0) {
switch (strip->type) {
case NLASTRIP_TYPE_CLIP: /* act-clip */
2023-05-09 12:50:37 +10:00
STRNCPY(strip->name, (strip->act) ? (strip->act->id.name + 2) : ("<No Action>"));
break;
case NLASTRIP_TYPE_TRANSITION: /* transition */
2023-05-09 12:50:37 +10:00
STRNCPY(strip->name, "Transition");
break;
case NLASTRIP_TYPE_META: /* meta */
2023-05-09 12:50:37 +10:00
STRNCPY(strip->name, "Meta");
break;
default:
2023-05-09 12:50:37 +10:00
STRNCPY(strip->name, "NLA Strip");
break;
}
}
2018-06-17 17:05:51 +02:00
/* build a hash-table of all the strips in the tracks
2018-11-14 12:53:15 +11:00
* - this is easier than iterating over all the tracks+strips hierarchy every time
* (and probably faster)
*/
gh = BLI_ghash_str_new("nlastrip_validate_name gh");
LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) {
LISTBASE_FOREACH (NlaStrip *, tstrip, &nlt->strips) {
/* don't add the strip of interest */
if (tstrip == strip) {
continue;
}
/* Use the name of the strip as the key, and the strip as the value,
* since we're mostly interested in the keys. */
BLI_ghash_insert(gh, tstrip->name, tstrip);
}
}
/* If the hash-table has a match for this name, try other names...
* - In an extreme case, it might not be able to find a name,
* but then everything else in Blender would fail too :).
*/
BLI_uniquename_cb(nla_editbone_name_check,
(void *)gh,
DATA_("NlaStrip"),
'.',
strip->name,
sizeof(strip->name));
/* free the hash... */
BLI_ghash_free(gh, nullptr, nullptr);
}
/* ---- */
2018-06-17 17:05:51 +02:00
/* Get strips which overlap the given one at the start/end of its range
2018-11-14 12:53:15 +11:00
* - strip: strip that we're finding overlaps for
* - track: nla-track that the overlapping strips should be found from
* - start, end: frames for the offending endpoints
*/
2012-05-12 16:11:34 +00:00
static void nlastrip_get_endpoint_overlaps(NlaStrip *strip,
NlaTrack *track,
float **start,
float **end)
{
/* find strips that overlap over the start/end of the given strip,
2018-06-17 17:05:51 +02:00
* but which don't cover the entire length
*/
2012-07-07 22:51:57 +00:00
/* TODO: this scheme could get quite slow for doing this on many strips... */
LISTBASE_FOREACH (NlaStrip *, nls, &track->strips) {
/* Check if strip overlaps (extends over or exactly on)
* the entire range of the strip we're validating. */
if ((nls->start <= strip->start) && (nls->end >= strip->end)) {
*start = nullptr;
*end = nullptr;
return;
}
/* check if strip doesn't even occur anywhere near... */
if (nls->end < strip->start) {
2012-05-12 16:11:34 +00:00
continue; /* skip checking this strip... not worthy of mention */
}
if (nls->start > strip->end) {
2012-05-12 16:11:34 +00:00
return; /* the range we're after has already passed */
}
/* if this strip is not part of an island of continuous strips, it can be used
2018-11-14 12:53:15 +11:00
* - this check needs to be done for each end of the strip we try and use...
*/
if ((nls->next == nullptr) || IS_EQF(nls->next->start, nls->end) == 0) {
if ((nls->end > strip->start) && (nls->end < strip->end)) {
2012-05-12 16:11:34 +00:00
*start = &nls->end;
}
}
if ((nls->prev == nullptr) || IS_EQF(nls->prev->end, nls->start) == 0) {
if ((nls->start < strip->end) && (nls->start > strip->start)) {
2012-05-12 16:11:34 +00:00
*end = &nls->start;
}
}
}
}
/* Determine auto-blending for the given strip */
2012-05-12 16:11:34 +00:00
static void BKE_nlastrip_validate_autoblends(NlaTrack *nlt, NlaStrip *nls)
{
float *ps = nullptr, *pe = nullptr;
float *ns = nullptr, *ne = nullptr;
/* sanity checks */
if (ELEM(nullptr, nls, nlt)) {
return;
}
if ((nlt->prev == nullptr) && (nlt->next == nullptr)) {
return;
}
if ((nls->flag & NLASTRIP_FLAG_AUTO_BLENDS) == 0) {
return;
}
/* get test ranges */
if (nlt->prev) {
nlastrip_get_endpoint_overlaps(nls, nlt->prev, &ps, &pe);
}
if (nlt->next) {
nlastrip_get_endpoint_overlaps(nls, nlt->next, &ns, &ne);
}
2018-06-17 17:05:51 +02:00
/* set overlaps for this strip
2018-11-14 12:53:15 +11:00
* - don't use the values obtained though if the end in question
* is directly followed/preceded by another strip, forming an
* 'island' of continuous strips
*/
if ((ps || ns) && ((nls->prev == nullptr) || IS_EQF(nls->prev->end, nls->start) == 0)) {
/* start overlaps - pick the largest overlap */
if (((ps && ns) && (*ps > *ns)) || (ps)) {
2012-05-12 16:11:34 +00:00
nls->blendin = *ps - nls->start;
}
else {
2012-05-12 16:11:34 +00:00
nls->blendin = *ns - nls->start;
}
}
else { /* no overlap allowed/needed */
2012-05-12 16:11:34 +00:00
nls->blendin = 0.0f;
}
if ((pe || ne) && ((nls->next == nullptr) || IS_EQF(nls->next->start, nls->end) == 0)) {
/* end overlaps - pick the largest overlap */
if (((pe && ne) && (*pe > *ne)) || (pe)) {
2012-05-12 16:11:34 +00:00
nls->blendout = nls->end - *pe;
}
else {
2012-05-12 16:11:34 +00:00
nls->blendout = nls->end - *ne;
}
}
else { /* no overlap allowed/needed */
2012-05-12 16:11:34 +00:00
nls->blendout = 0.0f;
}
}
/**
* Ensure every transition's start/end properly set.
* Strip will be removed / freed if it doesn't fit (invalid).
* Return value indicates if passed strip is valid/fixed or invalid/removed.
*/
static bool nlastrip_validate_transition_start_end(ListBase *strips, NlaStrip *strip)
{
if (!(strip->type == NLASTRIP_TYPE_TRANSITION)) {
return true;
}
if (strip->prev) {
strip->start = strip->prev->end;
}
if (strip->next) {
strip->end = strip->next->start;
}
if (strip->start >= strip->end || strip->prev == nullptr || strip->next == nullptr) {
BKE_nlastrip_remove_and_free(strips, strip, true);
return false;
}
return true;
}
void BKE_nla_validate_state(AnimData *adt)
{
/* sanity checks */
if (ELEM(nullptr, adt, adt->nla_tracks.first)) {
return;
}
/* Adjust blending values for auto-blending,
* and also do an initial pass to find the earliest strip. */
LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) {
LISTBASE_FOREACH_MUTABLE (NlaStrip *, strip, &nlt->strips) {
if (!nlastrip_validate_transition_start_end(&nlt->strips, strip)) {
printf(
"While moving NLA strips, a transition strip could no longer be applied to the new "
"positions and was removed.\n");
continue;
}
/* auto-blending first */
BKE_nlastrip_validate_autoblends(nlt, strip);
BKE_nlastrip_recalculate_blend(strip);
}
}
}
2015-02-28 12:49:07 +13:00
/* Action Stashing -------------------------------------- */
/* name of stashed tracks - the translation stuff is included here to save extra work */
#define STASH_TRACK_NAME DATA_("[Action Stash]")
bool BKE_nla_action_is_stashed(AnimData *adt, bAction *act)
{
LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) {
if (strstr(nlt->name, STASH_TRACK_NAME)) {
LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) {
if (strip->act == act) {
return true;
}
}
}
}
return false;
}
bool BKE_nla_action_stash(AnimData *adt, const bool is_liboverride)
2015-02-28 12:49:07 +13:00
{
NlaTrack *prev_track = nullptr;
2015-02-28 12:49:07 +13:00
NlaTrack *nlt;
NlaStrip *strip;
/* sanity check */
if (ELEM(nullptr, adt, adt->action)) {
CLOG_ERROR(&LOG, "Invalid argument - %p %p", adt, adt->action);
return false;
}
/* do not add if it is already stashed */
if (BKE_nla_action_is_stashed(adt, adt->action)) {
return false;
}
2015-02-28 12:49:07 +13:00
/* create a new track, and add this immediately above the previous stashing track */
for (prev_track = static_cast<NlaTrack *>(adt->nla_tracks.last); prev_track;
prev_track = prev_track->prev)
{
2015-02-28 12:49:07 +13:00
if (strstr(prev_track->name, STASH_TRACK_NAME)) {
break;
}
}
nlt = BKE_nlatrack_new_after(&adt->nla_tracks, prev_track, is_liboverride);
BKE_nlatrack_set_active(&adt->nla_tracks, nlt);
BLI_assert(nlt != nullptr);
/* We need to ensure that if there wasn't any previous instance,
2019-06-12 09:04:10 +10:00
* it must go to be bottom of the stack. */
if (prev_track == nullptr) {
BLI_remlink(&adt->nla_tracks, nlt);
BLI_addhead(&adt->nla_tracks, nlt);
}
2023-05-09 12:50:37 +10:00
STRNCPY(nlt->name, STASH_TRACK_NAME);
2015-02-28 12:49:07 +13:00
BLI_uniquename(
&adt->nla_tracks, nlt, STASH_TRACK_NAME, '.', offsetof(NlaTrack, name), sizeof(nlt->name));
2015-02-28 12:49:07 +13:00
/* add the action as a strip in this new track
* NOTE: a new user is created here
*/
strip = BKE_nlastrip_new(adt->action);
BLI_assert(strip != nullptr);
BKE_nlatrack_add_strip(nlt, strip, is_liboverride);
2015-02-28 12:49:07 +13:00
BKE_nlastrip_validate_name(adt, strip);
/* mark the stash track and strip so that they doesn't disturb the stack animation,
* and are unlikely to draw attention to itself (or be accidentally bumped around)
2018-06-17 17:05:51 +02:00
*
* NOTE: this must be done *after* adding the strip to the track, or else
* the strip locking will prevent the strip from getting added
*/
nlt->flag |= (NLATRACK_MUTED | NLATRACK_PROTECTED);
strip->flag &= ~(NLASTRIP_FLAG_SELECT | NLASTRIP_FLAG_ACTIVE);
/* also mark the strip for auto syncing the length, so that the strips accurately
* reflect the length of the action
* XXX: we could do with some extra flags here to prevent repeats/scaling options from working!
*/
strip->flag |= NLASTRIP_FLAG_SYNC_LENGTH;
2015-02-28 12:49:07 +13:00
/* succeeded */
return true;
}
/* Core Tools ------------------------------------------- */
2002-10-12 11:37:38 +00:00
void BKE_nla_action_pushdown(AnimData *adt, const bool is_liboverride)
{
NlaStrip *strip;
/* sanity checks */
/* TODO: need to report the error for this */
if (ELEM(nullptr, adt, adt->action)) {
return;
}
/* if the action is empty, we also shouldn't try to add to stack,
* as that will cause us grief down the track
*/
/* TODO: what about modifiers? */
if (BKE_action_has_motion(adt->action) == 0) {
CLOG_ERROR(&LOG, "action has no data");
return;
}
/* add a new NLA strip to the track, which references the active action */
strip = BKE_nlastack_add_strip(adt, adt->action, is_liboverride);
if (strip == nullptr) {
return;
}
/* clear reference to action now that we've pushed it onto the stack */
id_us_min(&adt->action->id);
adt->action = nullptr;
/* copy current "action blending" settings from adt to the strip,
* as it was keyframed with these settings, so omitting them will
* change the effect [#54233]. */
strip->blendmode = adt->act_blendmode;
strip->influence = adt->act_influence;
strip->extendmode = adt->act_extendmode;
if (adt->act_influence < 1.0f) {
/* enable "user-controlled" influence (which will insert a default keyframe)
* so that the influence doesn't get lost on the new update
*
* NOTE: An alternative way would have been to instead hack the influence
* to not get always get reset to full strength if NLASTRIP_FLAG_USR_INFLUENCE
* is disabled but auto-blending isn't being used. However, that approach
* is a bit hacky/hard to discover, and may cause backwards compatibility issues,
* so it's better to just do it this way.
*/
strip->flag |= NLASTRIP_FLAG_USR_INFLUENCE;
BKE_nlastrip_validate_fcurves(strip);
}
/* make strip the active one... */
BKE_nlastrip_set_active(adt, strip);
2002-10-12 11:37:38 +00:00
}
static void nla_tweakmode_find_active(const ListBase /* NlaTrack */ *nla_tracks,
NlaTrack **r_track_of_active_strip,
NlaStrip **r_active_strip)
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
{
NlaTrack *activeTrack = nullptr;
NlaStrip *activeStrip = nullptr;
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
/* go over the tracks, finding the active one, and its active strip
2018-11-14 12:53:15 +11:00
* - if we cannot find both, then there's nothing to do
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
*/
LISTBASE_FOREACH (NlaTrack *, nlt, nla_tracks) {
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
/* check if active */
if (nlt->flag & NLATRACK_ACTIVE) {
/* store reference to this active track */
2012-05-12 16:11:34 +00:00
activeTrack = nlt;
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
/* now try to find active strip */
2012-05-12 16:11:34 +00:00
activeStrip = BKE_nlastrip_find_active(nlt);
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
break;
}
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
}
2021-07-07 12:55:19 +10:00
/* There are situations where we may have multiple strips selected and we want to enter
* tweak-mode on all of those at once. Usually in those cases,
* it will usually just be a single strip per AnimData.
* In such cases, compromise and take the last selected track and/or last selected strip,
* #28468.
*/
if (activeTrack == nullptr) {
/* try last selected track for active strip */
LISTBASE_FOREACH_BACKWARD (NlaTrack *, nlt, nla_tracks) {
if (nlt->flag & NLATRACK_SELECTED) {
/* assume this is the active track */
2012-05-12 16:11:34 +00:00
activeTrack = nlt;
/* try to find active strip */
2012-05-12 16:11:34 +00:00
activeStrip = BKE_nlastrip_find_active(nlt);
break;
}
}
}
if ((activeTrack) && (activeStrip == nullptr)) {
/* No active strip in active or last selected track;
* compromise for first selected (assuming only single). */
LISTBASE_FOREACH (NlaStrip *, strip, &activeTrack->strips) {
2012-05-12 16:11:34 +00:00
if (strip->flag & (NLASTRIP_FLAG_SELECT | NLASTRIP_FLAG_ACTIVE)) {
activeStrip = strip;
break;
}
}
}
*r_track_of_active_strip = activeTrack;
*r_active_strip = activeStrip;
}
bool BKE_nla_tweakmode_enter(AnimData *adt)
{
NlaTrack *nlt, *activeTrack = nullptr;
NlaStrip *activeStrip = nullptr;
/* verify that data is valid */
if (ELEM(nullptr, adt, adt->nla_tracks.first)) {
return false;
}
/* If block is already in tweak-mode, just leave, but we should report
2022-11-02 10:14:37 +11:00
* that this block is in tweak-mode (as our return-code). */
if (adt->flag & ADT_NLA_EDIT_ON) {
return true;
}
nla_tweakmode_find_active(&adt->nla_tracks, &activeTrack, &activeStrip);
if (ELEM(nullptr, activeTrack, activeStrip, activeStrip->act)) {
if (G.debug & G_DEBUG) {
2021-07-07 12:55:19 +10:00
printf("NLA tweak-mode enter - neither active requirement found\n");
printf("\tactiveTrack = %p, activeStrip = %p\n", (void *)activeTrack, (void *)activeStrip);
}
2014-12-01 17:11:18 +01:00
return false;
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
}
/* Go over all the tracks, tagging each strip that uses the same
* action as the active strip, but leaving everything else alone.
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
*/
LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) {
LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) {
if (strip->act == activeStrip->act) {
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
strip->flag |= NLASTRIP_FLAG_TWEAKUSER;
}
else {
strip->flag &= ~NLASTRIP_FLAG_TWEAKUSER;
}
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
}
}
/* Untag tweaked track. This leads to non tweaked actions being drawn differently than the
* tweaked action. */
activeStrip->flag &= ~NLASTRIP_FLAG_TWEAKUSER;
2018-06-17 17:05:51 +02:00
/* go over all the tracks after AND INCLUDING the active one, tagging them as being disabled
* - the active track needs to also be tagged, otherwise, it'll overlap with the tweaks going
* on.
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
*/
NLA: Keyframe Remap Through Upper Strips Add a new operator, "Start Tweaking Strip Actions (Full Stack)", which allows you to insert keyframes and preserve the pose that you visually keyed while upper strips are evaluating, The old operator has been renamed from "Start Tweaking Strip Actions" to "Start Tweaking Strip Actions (Lower Stack)" and remains the default for the hotkey {key TAB}. **Limitations, Keyframe Remapping Failure Cases**: 1. For *transitions* above the tweaked strip, keyframe remapping will fail for channel values that are affected by the transition. A work around is to tweak the active strip without evaluating the upper NLA stack. It's not supported because it's non-trivial and I couldn't figure it out for all transition combinations of blend modes. In the future, it would be nice if transitions (and metas) supported nested tracks instead of using the left/right strips for the transitions. That would allow the transitioned strips to overlap in time. It would also allow N strips to be part of the (previously) left and right strips, or perhaps even N strips being transitioned in sequence (similar to a blend tree). Proper keyframe remapping through all that is currently beyond my mathematical ability. And even if I could figure it out, would it make sense to keyframe remap through a transition? //This case is reported to the user for failed keyframe insertions.// 2. Full replace upper strip that contains the keyed channels. //This case is reported to the user for failed keyframe insertions.// 3. When the same action clip occurs multiple times (colored Red to denote it's a linked strip) and vertically overlaps the tweaked strip, then the remapping will generally fail and is expected to fail. I don't plan on adding support for this case as it's also non-trivial and (hopefully) not a common or expected use case so it shouldn't be much of an issue to lack support here. For anyone curious on the cases that would work, it works when the linked strips aren't time-aligned and when we can insert a keyframe into the tweaked strip without modifying the current frame output of the other linked strips. Having all frames sampled and the strip non-time aligned leads to a working case. But if all key handles are AUTO, then it's likely to fail. //This case is not reported to the user for failed keyframe insertions.// 4. When using Quaternions and a small strip influence on the tweaked Combine strip. This was an existing failure case before this patch too but worth a mention in case it causes confusion. D10504 has an example file with instructions. //This case is not reported to the user for failed keyframe insertions. // 5. When an upper Replace strip with high influence and animator keys to Quaternion Combine (Replace is fine). This case is similar to (4) where Quaternion 180 degree rotation limitations prevent a solution. //This case is not reported to the user for failed keyframe insertions.// Reviewed By: sybren, RiggingDojo Differential Revision: https://developer.blender.org/D10504
2022-04-14 11:38:36 +02:00
activeTrack->flag |= NLATRACK_DISABLED;
if ((adt->flag & ADT_NLA_EVAL_UPPER_TRACKS) == 0) {
for (nlt = activeTrack->next; nlt; nlt = nlt->next) {
nlt->flag |= NLATRACK_DISABLED;
}
}
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
/* handle AnimData level changes:
* - 'real' active action to temp storage (no need to change user-counts).
2022-09-16 18:13:19 +10:00
* - Action of active strip set to be the 'active action', and have its user-count incremented.
* - Editing-flag for this AnimData block should also get turned on
* (for more efficient restoring).
* - Take note of the active strip for mapping-correction of keyframes
* in the action being edited.
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
*/
2012-05-12 16:11:34 +00:00
adt->tmpact = adt->action;
adt->action = activeStrip->act;
adt->act_track = activeTrack;
2012-05-12 16:11:34 +00:00
adt->actstrip = activeStrip;
id_us_plus(&activeStrip->act->id);
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
adt->flag |= ADT_NLA_EDIT_ON;
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
/* done! */
2014-12-01 17:11:18 +01:00
return true;
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
}
void BKE_nla_tweakmode_exit(AnimData *adt)
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
{
NlaStrip *strip;
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
/* verify that data is valid */
if (ELEM(nullptr, adt, adt->nla_tracks.first)) {
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
return;
}
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
/* hopefully the flag is correct - skip if not on */
if ((adt->flag & ADT_NLA_EDIT_ON) == 0) {
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
return;
}
/* sync the length of the user-strip with the new state of the action
* but only if the user has explicitly asked for this to happen
* (see #34645 for things to be careful about)
*/
if ((adt->actstrip) && (adt->actstrip->flag & NLASTRIP_FLAG_SYNC_LENGTH)) {
strip = adt->actstrip;
/* must be action-clip only (transitions don't have scale) */
if ((strip->type == NLASTRIP_TYPE_CLIP) && (strip->act)) {
BKE_nlastrip_recalculate_bounds_sync_action(strip);
}
}
/* for all Tracks, clear the 'disabled' flag
* for all Strips, clear the 'tweak-user' flag
*/
LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) {
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
nlt->flag &= ~NLATRACK_DISABLED;
LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) {
/* sync strip extents if this strip uses the same action */
if ((adt->actstrip) && (adt->actstrip->act == strip->act) &&
(strip->flag & NLASTRIP_FLAG_SYNC_LENGTH))
{
BKE_nlastrip_recalculate_bounds_sync_action(strip);
}
/* Clear tweak-user flag. */
strip->flag &= ~NLASTRIP_FLAG_TWEAKUSER;
}
}
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
/* handle AnimData level changes:
2022-09-16 18:13:19 +10:00
* - 'temporary' active action needs its user-count decreased,
* since we're removing this reference
2018-11-14 12:53:15 +11:00
* - 'real' active action is restored from storage
* - storage pointer gets cleared (to avoid having bad notes hanging around)
* - editing-flag for this AnimData block should also get turned off
* - clear pointer to active strip
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
*/
if (adt->action) {
id_us_min(&adt->action->id);
}
2012-05-12 16:11:34 +00:00
adt->action = adt->tmpact;
adt->tmpact = nullptr;
adt->act_track = nullptr;
adt->actstrip = nullptr;
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both) In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done. What happens when you enter 'tweak mode': 1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing. 2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack. 3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest. 4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode. 5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too. Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.: * NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance? * Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided... * When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved * Evaluation code doesn't totally take this into account yet... --- Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)
2009-06-05 05:18:07 +00:00
adt->flag &= ~ADT_NLA_EDIT_ON;
}
static void blend_write_nla_strips(BlendWriter *writer, ListBase *strips)
{
BLO_write_struct_list(writer, NlaStrip, strips);
LISTBASE_FOREACH (NlaStrip *, strip, strips) {
/* write the strip's F-Curves and modifiers */
BKE_fcurve_blend_write(writer, &strip->fcurves);
BKE_fmodifiers_blend_write(writer, &strip->modifiers);
/* write the strip's children */
blend_write_nla_strips(writer, &strip->strips);
}
}
static void blend_data_read_nla_strips(BlendDataReader *reader, ListBase *strips)
{
LISTBASE_FOREACH (NlaStrip *, strip, strips) {
/* strip's child strips */
BLO_read_list(reader, &strip->strips);
blend_data_read_nla_strips(reader, &strip->strips);
/* strip's F-Curves */
BLO_read_list(reader, &strip->fcurves);
BKE_fcurve_blend_read_data(reader, &strip->fcurves);
/* strip's F-Modifiers */
BLO_read_list(reader, &strip->modifiers);
BKE_fmodifiers_blend_read_data(reader, &strip->modifiers, nullptr);
}
}
void BKE_nla_blend_write(BlendWriter *writer, ListBase *tracks)
{
/* write all the tracks */
LISTBASE_FOREACH (NlaTrack *, nlt, tracks) {
/* write the track first */
BLO_write_struct(writer, NlaTrack, nlt);
/* write the track's strips */
blend_write_nla_strips(writer, &nlt->strips);
}
}
void BKE_nla_blend_read_data(BlendDataReader *reader, ID *id_owner, ListBase *tracks)
{
LISTBASE_FOREACH (NlaTrack *, nlt, tracks) {
/* If linking from a library, clear 'local' library override flag. */
if (ID_IS_LINKED(id_owner)) {
nlt->flag &= ~NLATRACK_OVERRIDELIBRARY_LOCAL;
}
/* relink list of strips */
BLO_read_list(reader, &nlt->strips);
/* relink strip data */
blend_data_read_nla_strips(reader, &nlt->strips);
}
}