2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-06-23 13:25:31 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-06-23 13:25:31 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2011-02-27 20:40:57 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2009-06-23 13:25:31 +00:00
|
|
|
|
2018-12-15 16:09:27 +03:00
|
|
|
#include "BLI_bitmap.h"
|
|
|
|
|
#include "BLI_ghash.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "RNA_types.h"
|
2018-05-31 12:52:13 +02:00
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
T77086 Animation: Passing Dependency Graph to Drivers
Custom driver functions need access to the dependency graph that is
triggering the evaluation of the driver. This patch passes the
dependency graph pointer through all the animation-related calls.
Instead of passing the evaluation time to functions, the code now passes
an `AnimationEvalContext` pointer:
```
typedef struct AnimationEvalContext {
struct Depsgraph *const depsgraph;
const float eval_time;
} AnimationEvalContext;
```
These structs are read-only, meaning that the code cannot change the
evaluation time. Note that the `depsgraph` pointer itself is const, but
it points to a non-const depsgraph.
FCurves and Drivers can be evaluated at a different time than the
current scene time, for example when evaluating NLA strips. This means
that, even though the current time is stored in the dependency graph, we
need an explicit evaluation time.
There are two functions that allow creation of `AnimationEvalContext`
objects:
- `BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float
eval_time)`, which creates a new context object from scratch, and
- `BKE_animsys_eval_context_construct_at(AnimationEvalContext
*anim_eval_context, float eval_time)`, which can be used to create a
`AnimationEvalContext` with the same depsgraph, but at a different
time. This makes it possible to later add fields without changing any
of the code that just want to change the eval time.
This also provides a fix for T75553, although it does require a change
to the custom driver function. The driver should call
`custom_function(depsgraph)`, and the function should use that depsgraph
instead of information from `bpy.context`.
Reviewed By: brecht, sergey
Differential Revision: https://developer.blender.org/D8047
2020-07-17 17:38:09 +02:00
|
|
|
struct AnimationEvalContext;
|
|
|
|
|
|
2009-06-23 13:25:31 +00:00
|
|
|
/* --------------- NLA Evaluation DataTypes ----------------------- */
|
|
|
|
|
|
|
|
|
|
/* used for list of strips to accumulate at current time */
|
|
|
|
|
typedef struct NlaEvalStrip {
|
|
|
|
|
struct NlaEvalStrip *next, *prev;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
NlaTrack *track; /* track that this strip belongs to */
|
|
|
|
|
NlaStrip *strip; /* strip that's being used */
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
short track_index; /* the index of the track within the list */
|
|
|
|
|
short strip_mode; /* which end of the strip are we looking at */
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
float strip_time; /* time at which which strip is being evaluated */
|
2009-06-23 13:25:31 +00:00
|
|
|
} NlaEvalStrip;
|
|
|
|
|
|
|
|
|
|
/* NlaEvalStrip->strip_mode */
|
2013-03-22 05:46:39 +00:00
|
|
|
enum eNlaEvalStrip_StripMode {
|
2012-05-12 20:39:39 +00:00
|
|
|
/* standard evaluation */
|
2009-06-23 13:25:31 +00:00
|
|
|
NES_TIME_BEFORE = -1,
|
|
|
|
|
NES_TIME_WITHIN,
|
|
|
|
|
NES_TIME_AFTER,
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
/* transition-strip evaluations */
|
2009-06-23 13:25:31 +00:00
|
|
|
NES_TIME_TRANSITION_START,
|
|
|
|
|
NES_TIME_TRANSITION_END,
|
2013-03-22 05:46:39 +00:00
|
|
|
};
|
2009-06-23 13:25:31 +00:00
|
|
|
|
2018-12-15 16:09:27 +03:00
|
|
|
struct NlaEvalChannel;
|
|
|
|
|
struct NlaEvalData;
|
2009-06-23 13:25:31 +00:00
|
|
|
|
2018-12-15 16:09:27 +03:00
|
|
|
/* Unique channel key for GHash. */
|
|
|
|
|
typedef struct NlaEvalChannelKey {
|
|
|
|
|
struct PointerRNA ptr;
|
|
|
|
|
struct PropertyRNA *prop;
|
|
|
|
|
} NlaEvalChannelKey;
|
|
|
|
|
|
|
|
|
|
/* Bitmask of array indices touched by actions. */
|
|
|
|
|
typedef struct NlaValidMask {
|
|
|
|
|
BLI_bitmap *ptr;
|
|
|
|
|
BLI_bitmap buffer[sizeof(uint64_t) / sizeof(BLI_bitmap)];
|
|
|
|
|
} NlaValidMask;
|
|
|
|
|
|
|
|
|
|
/* Set of property values for blending. */
|
|
|
|
|
typedef struct NlaEvalChannelSnapshot {
|
|
|
|
|
struct NlaEvalChannel *channel;
|
|
|
|
|
|
2021-02-16 23:58:29 -05:00
|
|
|
/** For an upper snapshot channel, marks values that should be blended. */
|
|
|
|
|
NlaValidMask blend_domain;
|
|
|
|
|
|
2021-05-11 16:04:18 -04:00
|
|
|
/** Only used for keyframe remapping. Any values not in the \a remap_domain will not be used
|
|
|
|
|
* for keyframe remapping. */
|
|
|
|
|
NlaValidMask remap_domain;
|
|
|
|
|
|
2018-12-15 16:09:27 +03:00
|
|
|
int length; /* Number of values in the property. */
|
|
|
|
|
bool is_base; /* Base snapshot of the channel. */
|
|
|
|
|
|
|
|
|
|
float values[]; /* Item values. */
|
|
|
|
|
/* Memory over-allocated to provide space for values. */
|
|
|
|
|
} NlaEvalChannelSnapshot;
|
|
|
|
|
|
2018-12-23 18:43:01 +03:00
|
|
|
/* NlaEvalChannel->mix_mode */
|
|
|
|
|
enum eNlaEvalChannel_MixMode {
|
|
|
|
|
NEC_MIX_ADD,
|
|
|
|
|
NEC_MIX_MULTIPLY,
|
|
|
|
|
NEC_MIX_QUATERNION,
|
|
|
|
|
NEC_MIX_AXIS_ANGLE,
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-15 16:09:27 +03:00
|
|
|
/* Temp channel for accumulating data from NLA for a single property.
|
|
|
|
|
* Handles array properties as a unit to allow intelligent blending. */
|
2009-06-23 13:25:31 +00:00
|
|
|
typedef struct NlaEvalChannel {
|
|
|
|
|
struct NlaEvalChannel *next, *prev;
|
2018-12-15 16:09:27 +03:00
|
|
|
struct NlaEvalData *owner;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2018-12-15 16:09:27 +03:00
|
|
|
/* Original RNA path string and property key. */
|
2018-11-07 19:47:22 +03:00
|
|
|
const char *rna_path;
|
2018-12-15 16:09:27 +03:00
|
|
|
NlaEvalChannelKey key;
|
|
|
|
|
|
|
|
|
|
int index;
|
|
|
|
|
bool is_array;
|
2018-12-23 18:43:01 +03:00
|
|
|
char mix_mode;
|
|
|
|
|
|
2021-01-14 19:27:46 -05:00
|
|
|
/* Associated with the RNA property's value(s), marks which elements are affected by NLA. */
|
|
|
|
|
NlaValidMask domain;
|
2018-12-15 16:09:27 +03:00
|
|
|
|
|
|
|
|
/* Base set of values. */
|
|
|
|
|
NlaEvalChannelSnapshot base_snapshot;
|
|
|
|
|
/* Memory over-allocated to provide space for base_snapshot.values. */
|
2009-06-23 13:25:31 +00:00
|
|
|
} NlaEvalChannel;
|
|
|
|
|
|
2018-12-15 16:09:27 +03:00
|
|
|
/* Set of values for all channels. */
|
|
|
|
|
typedef struct NlaEvalSnapshot {
|
|
|
|
|
/* Snapshot this one defaults to. */
|
|
|
|
|
struct NlaEvalSnapshot *base;
|
|
|
|
|
|
|
|
|
|
int size;
|
|
|
|
|
NlaEvalChannelSnapshot **channels;
|
|
|
|
|
} NlaEvalSnapshot;
|
|
|
|
|
|
|
|
|
|
/* Set of all channels covered by NLA. */
|
|
|
|
|
typedef struct NlaEvalData {
|
|
|
|
|
ListBase channels;
|
|
|
|
|
|
|
|
|
|
/* Mapping of paths and NlaEvalChannelKeys to channels. */
|
|
|
|
|
GHash *path_hash;
|
|
|
|
|
GHash *key_hash;
|
|
|
|
|
|
|
|
|
|
/* Base snapshot. */
|
|
|
|
|
int num_channels;
|
|
|
|
|
NlaEvalSnapshot base_snapshot;
|
|
|
|
|
|
|
|
|
|
/* Evaluation result shapshot. */
|
|
|
|
|
NlaEvalSnapshot eval_snapshot;
|
|
|
|
|
} NlaEvalData;
|
|
|
|
|
|
2018-11-12 19:41:53 +03:00
|
|
|
/* Information about the currently edited strip and ones below it for keyframing. */
|
|
|
|
|
typedef struct NlaKeyframingContext {
|
|
|
|
|
struct NlaKeyframingContext *next, *prev;
|
|
|
|
|
|
|
|
|
|
/* AnimData for which this context was built. */
|
|
|
|
|
struct AnimData *adt;
|
|
|
|
|
|
|
|
|
|
/* Data of the currently edited strip (copy, or fake strip for the main action). */
|
|
|
|
|
NlaStrip strip;
|
|
|
|
|
NlaEvalStrip *eval_strip;
|
|
|
|
|
|
2020-12-21 13:58:36 -05:00
|
|
|
/* Evaluated NLA stack below the tweak strip. */
|
|
|
|
|
NlaEvalData lower_eval_data;
|
2018-11-12 19:41:53 +03:00
|
|
|
} NlaKeyframingContext;
|
|
|
|
|
|
2009-06-23 13:25:31 +00:00
|
|
|
/* --------------- NLA Functions (not to be used as a proper API) ----------------------- */
|
|
|
|
|
|
|
|
|
|
/* convert from strip time <-> global time */
|
2009-06-28 07:32:00 +00:00
|
|
|
float nlastrip_get_frame(NlaStrip *strip, float cframe, short mode);
|
|
|
|
|
|
2009-07-07 11:37:33 +00:00
|
|
|
/* --------------- NLA Evaluation (very-private stuff) ----------------------- */
|
2019-04-27 12:07:07 +10:00
|
|
|
/* these functions are only defined here to avoid problems with the order
|
|
|
|
|
* in which they get defined. */
|
2009-07-07 11:37:33 +00:00
|
|
|
|
T77086 Animation: Passing Dependency Graph to Drivers
Custom driver functions need access to the dependency graph that is
triggering the evaluation of the driver. This patch passes the
dependency graph pointer through all the animation-related calls.
Instead of passing the evaluation time to functions, the code now passes
an `AnimationEvalContext` pointer:
```
typedef struct AnimationEvalContext {
struct Depsgraph *const depsgraph;
const float eval_time;
} AnimationEvalContext;
```
These structs are read-only, meaning that the code cannot change the
evaluation time. Note that the `depsgraph` pointer itself is const, but
it points to a non-const depsgraph.
FCurves and Drivers can be evaluated at a different time than the
current scene time, for example when evaluating NLA strips. This means
that, even though the current time is stored in the dependency graph, we
need an explicit evaluation time.
There are two functions that allow creation of `AnimationEvalContext`
objects:
- `BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float
eval_time)`, which creates a new context object from scratch, and
- `BKE_animsys_eval_context_construct_at(AnimationEvalContext
*anim_eval_context, float eval_time)`, which can be used to create a
`AnimationEvalContext` with the same depsgraph, but at a different
time. This makes it possible to later add fields without changing any
of the code that just want to change the eval time.
This also provides a fix for T75553, although it does require a change
to the custom driver function. The driver should call
`custom_function(depsgraph)`, and the function should use that depsgraph
instead of information from `bpy.context`.
Reviewed By: brecht, sergey
Differential Revision: https://developer.blender.org/D8047
2020-07-17 17:38:09 +02:00
|
|
|
NlaEvalStrip *nlastrips_ctime_get_strip(ListBase *list,
|
|
|
|
|
ListBase *strips,
|
|
|
|
|
short index,
|
|
|
|
|
const struct AnimationEvalContext *anim_eval_context,
|
|
|
|
|
const bool flush_to_original);
|
2019-07-31 14:56:17 +02:00
|
|
|
void nlastrip_evaluate(PointerRNA *ptr,
|
2018-12-15 16:09:27 +03:00
|
|
|
NlaEvalData *channels,
|
|
|
|
|
ListBase *modifiers,
|
|
|
|
|
NlaEvalStrip *nes,
|
2019-07-31 14:56:17 +02:00
|
|
|
NlaEvalSnapshot *snapshot,
|
T77086 Animation: Passing Dependency Graph to Drivers
Custom driver functions need access to the dependency graph that is
triggering the evaluation of the driver. This patch passes the
dependency graph pointer through all the animation-related calls.
Instead of passing the evaluation time to functions, the code now passes
an `AnimationEvalContext` pointer:
```
typedef struct AnimationEvalContext {
struct Depsgraph *const depsgraph;
const float eval_time;
} AnimationEvalContext;
```
These structs are read-only, meaning that the code cannot change the
evaluation time. Note that the `depsgraph` pointer itself is const, but
it points to a non-const depsgraph.
FCurves and Drivers can be evaluated at a different time than the
current scene time, for example when evaluating NLA strips. This means
that, even though the current time is stored in the dependency graph, we
need an explicit evaluation time.
There are two functions that allow creation of `AnimationEvalContext`
objects:
- `BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float
eval_time)`, which creates a new context object from scratch, and
- `BKE_animsys_eval_context_construct_at(AnimationEvalContext
*anim_eval_context, float eval_time)`, which can be used to create a
`AnimationEvalContext` with the same depsgraph, but at a different
time. This makes it possible to later add fields without changing any
of the code that just want to change the eval time.
This also provides a fix for T75553, although it does require a change
to the custom driver function. The driver should call
`custom_function(depsgraph)`, and the function should use that depsgraph
instead of information from `bpy.context`.
Reviewed By: brecht, sergey
Differential Revision: https://developer.blender.org/D8047
2020-07-17 17:38:09 +02:00
|
|
|
const struct AnimationEvalContext *anim_eval_context,
|
2019-07-31 14:56:17 +02:00
|
|
|
const bool flush_to_original);
|
|
|
|
|
void nladata_flush_channels(PointerRNA *ptr,
|
2018-12-15 16:09:27 +03:00
|
|
|
NlaEvalData *channels,
|
2019-07-31 14:56:17 +02:00
|
|
|
NlaEvalSnapshot *snapshot,
|
|
|
|
|
const bool flush_to_original);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-16 23:58:29 -05:00
|
|
|
void nlasnapshot_enable_all_blend_domain(NlaEvalSnapshot *snapshot);
|
|
|
|
|
|
2021-02-05 16:45:34 -05:00
|
|
|
void nlasnapshot_ensure_channels(NlaEvalData *eval_data, NlaEvalSnapshot *snapshot);
|
|
|
|
|
|
2021-02-03 16:23:18 -05:00
|
|
|
void nlasnapshot_blend(NlaEvalData *eval_data,
|
|
|
|
|
NlaEvalSnapshot *lower_snapshot,
|
|
|
|
|
NlaEvalSnapshot *upper_snapshot,
|
|
|
|
|
const short upper_blendmode,
|
|
|
|
|
const float upper_influence,
|
|
|
|
|
NlaEvalSnapshot *r_blended_snapshot);
|
|
|
|
|
|
2021-05-11 16:04:18 -04:00
|
|
|
void nlasnapshot_blend_get_inverted_upper_snapshot(NlaEvalData *eval_data,
|
|
|
|
|
NlaEvalSnapshot *lower_snapshot,
|
|
|
|
|
NlaEvalSnapshot *blended_snapshot,
|
|
|
|
|
const short upper_blendmode,
|
|
|
|
|
const float upper_influence,
|
|
|
|
|
NlaEvalSnapshot *r_upper_snapshot);
|
|
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|