This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/blenkernel/nla_private.h
Sybren A. Stüvel 686ab4c940 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-20 11:51:09 +02:00

195 lines
5.7 KiB
C++

/*
* 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,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
* All rights reserved.
*/
/** \file
* \ingroup bke
*/
#ifndef __NLA_PRIVATE_H__
#define __NLA_PRIVATE_H__
#include "BLI_bitmap.h"
#include "BLI_ghash.h"
#include "RNA_types.h"
#ifdef __cplusplus
extern "C" {
#endif
struct AnimationEvalContext;
/* --------------- NLA Evaluation DataTypes ----------------------- */
/* used for list of strips to accumulate at current time */
typedef struct NlaEvalStrip {
struct NlaEvalStrip *next, *prev;
NlaTrack *track; /* track that this strip belongs to */
NlaStrip *strip; /* strip that's being used */
short track_index; /* the index of the track within the list */
short strip_mode; /* which end of the strip are we looking at */
float strip_time; /* time at which which strip is being evaluated */
} NlaEvalStrip;
/* NlaEvalStrip->strip_mode */
enum eNlaEvalStrip_StripMode {
/* standard evaluation */
NES_TIME_BEFORE = -1,
NES_TIME_WITHIN,
NES_TIME_AFTER,
/* transition-strip evaluations */
NES_TIME_TRANSITION_START,
NES_TIME_TRANSITION_END,
};
struct NlaEvalChannel;
struct NlaEvalData;
/* 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;
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;
/* NlaEvalChannel->mix_mode */
enum eNlaEvalChannel_MixMode {
NEC_MIX_ADD,
NEC_MIX_MULTIPLY,
NEC_MIX_QUATERNION,
NEC_MIX_AXIS_ANGLE,
};
/* Temp channel for accumulating data from NLA for a single property.
* Handles array properties as a unit to allow intelligent blending. */
typedef struct NlaEvalChannel {
struct NlaEvalChannel *next, *prev;
struct NlaEvalData *owner;
/* Original RNA path string and property key. */
const char *rna_path;
NlaEvalChannelKey key;
int index;
bool is_array;
bool in_blend;
char mix_mode;
struct NlaEvalChannel *next_blend;
NlaEvalChannelSnapshot *blend_snapshot;
/* Mask of array items controlled by NLA. */
NlaValidMask valid;
/* Base set of values. */
NlaEvalChannelSnapshot base_snapshot;
/* Memory over-allocated to provide space for base_snapshot.values. */
} NlaEvalChannel;
/* 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;
/* 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;
/* Evaluated NLA stack below the current strip. */
NlaEvalData nla_channels;
} NlaKeyframingContext;
/* --------------- NLA Functions (not to be used as a proper API) ----------------------- */
/* convert from strip time <-> global time */
float nlastrip_get_frame(NlaStrip *strip, float cframe, short mode);
/* --------------- NLA Evaluation (very-private stuff) ----------------------- */
/* these functions are only defined here to avoid problems with the order
* in which they get defined. */
NlaEvalStrip *nlastrips_ctime_get_strip(ListBase *list,
ListBase *strips,
short index,
const struct AnimationEvalContext *anim_eval_context,
const bool flush_to_original);
void nlastrip_evaluate(PointerRNA *ptr,
NlaEvalData *channels,
ListBase *modifiers,
NlaEvalStrip *nes,
NlaEvalSnapshot *snapshot,
const struct AnimationEvalContext *anim_eval_context,
const bool flush_to_original);
void nladata_flush_channels(PointerRNA *ptr,
NlaEvalData *channels,
NlaEvalSnapshot *snapshot,
const bool flush_to_original);
#ifdef __cplusplus
}
#endif
#endif /* __NLA_PRIVATE_H__ */