Blender  V3.3
Classes | Macros
action_mirror.c File Reference
#include <math.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_anim_types.h"
#include "DNA_armature_types.h"
#include "DNA_object_types.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
#include "BKE_action.h"
#include "BKE_armature.h"
#include "BKE_fcurve.h"
#include "DEG_depsgraph.h"

Go to the source code of this file.

Classes

struct  FCurve_KeyCache
 

Macros

#define FCURVE_ASSIGN_VALUE(id, path_test_suffix, index)
 
#define FCURVE_ASSIGN_ARRAY(id, path_test_suffix)
 
#define FCURVE_CHANNEL_LEN   (sizeof(fkc_pchan) / sizeof(struct FCurve_KeyCache))
 
#define READ_VALUE_FLT(id)
 
#define READ_VALUE_INT(id)
 
#define READ_ARRAY_FLT(id)
 
#define WRITE_VALUE_FLT(id)
 
#define WRITE_ARRAY_FLT(id)
 

Functions

Flip the Action (Armature/Pose Objects)

This flips the action using the rest pose (not the evaluated pose).

Details:

  • Key-frames are modified in-place, creating new key-frames is not yet supported. That could be useful if a user for example only has 2x rotation channels set. In practice users typically keyframe all rotation channels or none.
  • F-Curve modifiers are disabled for evaluation, so the values written back to the keyframes don't include modifier offsets.
  • Sub-frame key-frames aren't supported, this could be added if needed without much trouble.
  • F-Curves must have a FCurve.bezt array (sampled curves aren't supported).
static void action_flip_pchan_cache_fcurve_assign_value (struct FCurve_KeyCache *fkc, int index, const char *path, struct FCurvePathCache *fcache)
 
static void action_flip_pchan_cache_fcurve_assign_array (struct FCurve_KeyCache *fkc, int fkc_len, const char *path, struct FCurvePathCache *fcache)
 
static void action_flip_pchan_cache_init (struct FCurve_KeyCache *fkc, const float *keyed_frames, int keyed_frames_len)
 
static void action_flip_pchan (Object *ob_arm, const bPoseChannel *pchan, struct FCurvePathCache *fcache)
 
static void action_flip_pchan_rna_paths (struct bAction *act)
 
void BKE_action_flip_with_pose (struct bAction *act, struct Object *ob_arm)
 

Detailed Description

Mirror/Symmetry functions applying to actions.

Definition in file action_mirror.c.

Macro Definition Documentation

◆ FCURVE_ASSIGN_ARRAY

#define FCURVE_ASSIGN_ARRAY (   id,
  path_test_suffix 
)
Value:
BLI_strncpy(path_xform_suffix, path_test_suffix, path_xform_suffix_len); \
action_flip_pchan_cache_fcurve_assign_array( \
fkc_pchan.id, ARRAY_SIZE(fkc_pchan.id), path_xform, fcache)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
#define ARRAY_SIZE(arr)

◆ FCURVE_ASSIGN_VALUE

#define FCURVE_ASSIGN_VALUE (   id,
  path_test_suffix,
  index 
)
Value:
BLI_strncpy(path_xform_suffix, path_test_suffix, path_xform_suffix_len); \
action_flip_pchan_cache_fcurve_assign_value(&fkc_pchan.id, index, path_xform, fcache)

◆ FCURVE_CHANNEL_LEN

#define FCURVE_CHANNEL_LEN   (sizeof(fkc_pchan) / sizeof(struct FCurve_KeyCache))

◆ READ_ARRAY_FLT

#define READ_ARRAY_FLT (   id)
Value:
for (int i = 0; i < ARRAY_SIZE(pchan_temp.id); i++) { \
READ_VALUE_FLT(id[i]); \
} \
((void)0)
SyclQueue void void size_t num_bytes void

◆ READ_VALUE_FLT

#define READ_VALUE_FLT (   id)
Value:
if (fkc_pchan.id.fcurve_eval != NULL) { \
pchan_temp.id = fkc_pchan.id.fcurve_eval[frame_index]; \
} \
((void)0)

◆ READ_VALUE_INT

#define READ_VALUE_INT (   id)
Value:
if (fkc_pchan.id.fcurve_eval != NULL) { \
pchan_temp.id = floorf(fkc_pchan.id.fcurve_eval[frame_index] + 0.5f); \
} \
((void)0)
#define floorf(x)
Definition: metal/compat.h:224

◆ WRITE_ARRAY_FLT

#define WRITE_ARRAY_FLT (   id)
Value:
for (int i = 0; i < ARRAY_SIZE(pchan_temp.id); i++) { \
WRITE_VALUE_FLT(id[i]); \
} \
((void)0)

◆ WRITE_VALUE_FLT

#define WRITE_VALUE_FLT (   id)
Value:
if (fkc_pchan.id.fcurve_eval != NULL) { \
BezTriple *bezt = fkc_pchan.id.bezt_array[frame_index]; \
if (bezt != NULL) { \
const float delta = pchan_temp.id - bezt->vec[1][1]; \
bezt->vec[0][1] += delta; \
bezt->vec[1][1] += delta; \
bezt->vec[2][1] += delta; \
} \
} \
((void)0)

Function Documentation

◆ action_flip_pchan()

static void action_flip_pchan ( Object ob_arm,
const bPoseChannel pchan,
struct FCurvePathCache fcache 
)
static

Structure to store transformation F-Curves corresponding to a pose bones transformation. Match struct member names from bPoseChannel so macros avoid repetition.

Note
There is no need to read values unless they influence the 4x4 transform matrix, and no need to write values back unless they would be changed by a modified matrix. So rotmode needs to be read, but doesn't need to be written back to.

Most bendy-bone settings don't need to be included either, flipping their RNA paths is enough. Although the X/Y settings could make sense to transform, in practice it would only work well if the rotation happened to swap X/Y alignment, leave this for now.

Definition at line 160 of file action_mirror.c.

References action_flip_pchan_cache_init(), Bone::arm_mat, FCurve_KeyCache::bezt_array, BKE_fcurve_handles_recalc_ex(), BKE_fcurves_calc_keyed_frames(), BKE_pchan_apply_mat4(), BKE_pchan_to_mat4(), BKE_pose_channel_find_name(), BLI_str_escape(), BLI_string_flip_side_name(), bPoseChannel::bone, dot_v3v3(), fabsf, FCurve_KeyCache::fcurve, FCURVE_ASSIGN_ARRAY, FCURVE_ASSIGN_VALUE, FCURVE_CHANNEL_LEN, FCurve_KeyCache::fcurve_eval, invert_m4_m4(), MAXBONENAME, MEM_freeN, mul_m4_m4m4(), bPoseChannel::name, NULL, Object::pose, READ_ARRAY_FLT, READ_VALUE_FLT, READ_VALUE_INT, size(), SNPRINTF, STREQ, unit_m4(), WRITE_ARRAY_FLT, and WRITE_VALUE_FLT.

Referenced by BKE_action_flip_with_pose().

◆ action_flip_pchan_cache_fcurve_assign_array()

static void action_flip_pchan_cache_fcurve_assign_array ( struct FCurve_KeyCache fkc,
int  fkc_len,
const char *  path,
struct FCurvePathCache fcache 
)
static

Assign FCurve_KeyCache.fcurve path, using a path lookup for an array.

Definition at line 92 of file action_mirror.c.

References BKE_fcurve_pathcache_find_array(), and FCurve_KeyCache::fcurve.

◆ action_flip_pchan_cache_fcurve_assign_value()

static void action_flip_pchan_cache_fcurve_assign_value ( struct FCurve_KeyCache fkc,
int  index,
const char *  path,
struct FCurvePathCache fcache 
)
static

Assign fkc path, using a path lookup for a single value.

Definition at line 78 of file action_mirror.c.

References FCurve::bezt, BKE_fcurve_pathcache_find(), and FCurve_KeyCache::fcurve.

◆ action_flip_pchan_cache_init()

static void action_flip_pchan_cache_init ( struct FCurve_KeyCache fkc,
const float keyed_frames,
int  keyed_frames_len 
)
static

Fill in pose channel cache for each frame in keyed_frames.

Parameters
keyed_framesAn array of keyed_frames to evaluate, note that each frame is rounded to the nearest int.
keyed_frames_lenThe length of the keyed_frames array.

Definition at line 114 of file action_mirror.c.

References FCurve::bezt, FCurve_KeyCache::bezt_array, BLI_assert, evaltime, evaluate_fcurve_only_curve(), FCurve_KeyCache::fcurve, FCurve_KeyCache::fcurve_eval, FCURVE_MOD_OFF, FCurve::flag, MEM_mallocN, NULL, FCurve::totvert, and BezTriple::vec.

Referenced by action_flip_pchan().

◆ action_flip_pchan_rna_paths()

static void action_flip_pchan_rna_paths ( struct bAction act)
static

◆ BKE_action_flip_with_pose()

void BKE_action_flip_with_pose ( struct bAction act,
struct Object ob_arm 
)