93 if (fcu && fcu->
bezt) {
106 for (
int i = 0; i < fkc_len; i++) {
111 if (fcu && fcu->
bezt) {
130 const int keyed_frames_len = keyed_frames.
size();
132 for (
int frame_index = 0; frame_index < keyed_frames_len; frame_index++) {
133 const float evaltime = keyed_frames[frame_index];
144 while (frame_index < keyed_frames_len) {
145 const float evaltime = keyed_frames[frame_index];
146 const float bezt_time =
roundf(bezt->
vec[1][0]);
147 if (bezt_time > evaltime) {
151 if (bezt_time == evaltime) {
155 if (bezt == bezt_end) {
161 while (frame_index < keyed_frames_len) {
176 char path_xform[256];
177 char pchan_name_esc[
sizeof(pchan->
name) * 2];
180 path_xform,
"pose.bones[\"%s\"]", pchan_name_esc);
181 char *path_xform_suffix = path_xform + path_xform_prefix_len;
182 const int path_xform_suffix_maxncpy =
sizeof(path_xform) - path_xform_prefix_len;
201 } fkc_pchan = {{{
nullptr}}};
203#define FCURVE_ASSIGN_VALUE(id, path_test_suffix, index) \
204 BLI_strncpy(path_xform_suffix, path_test_suffix, path_xform_suffix_maxncpy); \
205 action_flip_pchan_cache_fcurve_assign_value(&fkc_pchan.id, index, path_xform, fcurve_cache)
207#define FCURVE_ASSIGN_ARRAY(id, path_test_suffix) \
208 BLI_strncpy(path_xform_suffix, path_test_suffix, path_xform_suffix_maxncpy); \
209 action_flip_pchan_cache_fcurve_assign_array( \
210 fkc_pchan.id, ARRAY_SIZE(fkc_pchan.id), path_xform, fcurve_cache)
220#undef FCURVE_ASSIGN_VALUE
221#undef FCURVE_ASSIGN_ARRAY
224#define FCURVE_CHANNEL_LEN (sizeof(fkc_pchan) / sizeof(FCurve_KeyCache))
229 if (fkc->
fcurve !=
nullptr) {
245 if (fkc->
fcurve ==
nullptr) {
252 float flip_mtx[4][4];
259 if (!
STREQ(pchan_name_flip, pchan->
name)) {
263 const Bone *pchan_bone = pchan->bone_get(*ob_arm);
264 const Bone *pchan_flip_bone = pchan_flip ? pchan_flip->bone_get(*ob_arm) :
nullptr;
266 float arm_mat_inv[4][4];
271 for (
int frame_index = 0; frame_index < keyed_frames.
size(); frame_index++) {
278#define READ_VALUE_FLT(id) \
279 if (fkc_pchan.id.fcurve_eval != nullptr) { \
280 pchan_temp.id = fkc_pchan.id.fcurve_eval[frame_index]; \
284#define READ_VALUE_INT(id) \
285 if (fkc_pchan.id.fcurve_eval != nullptr) { \
286 pchan_temp.id = decltype(pchan_temp.id)( \
287 int(floorf(fkc_pchan.id.fcurve_eval[frame_index] + 0.5f))); \
291#define READ_ARRAY_FLT(id) \
292 for (int i = 0; i < ARRAY_SIZE(pchan_temp.id); i++) { \
293 READ_VALUE_FLT(id[i]); \
309 float chan_mat[4][4];
327 const float unit_x[3] = {1.0f, 0.0f, 0.0f};
328 const bool is_x_axis_orthogonal = (pchan_flip ==
nullptr) &&
330 if (is_x_axis_orthogonal) {
332 float extra_mat[4][4] = {
333 {-1.0f, 0.0f, 0.0f, 0.0f},
334 {0.0f, 1.0f, 0.0f, 0.0f},
335 {0.0f, 0.0f, -1.0f, 0.0f},
336 {0.0f, 0.0f, 0.0f, 1.0f},
344#define WRITE_VALUE_FLT(id) \
345 if (fkc_pchan.id.fcurve_eval != nullptr) { \
346 BezTriple *bezt = fkc_pchan.id.bezt_array[frame_index]; \
347 if (bezt != nullptr) { \
348 const float delta = pchan_temp.id - bezt->vec[1][1]; \
349 bezt->vec[0][1] += delta; \
350 bezt->vec[1][1] += delta; \
351 bezt->vec[2][1] += delta; \
356#define WRITE_ARRAY_FLT(id) \
357 for (int i = 0; i < ARRAY_SIZE(pchan_temp.id); i++) { \
358 WRITE_VALUE_FLT(id[i]); \
371#undef WRITE_ARRAY_FLT
372#undef WRITE_VALUE_FLT
376 for (
FCurve *fcurve : fcurve_array) {
396 const char *path_pose_prefix =
"pose.bones[\"";
397 const int path_pose_prefix_len = strlen(path_pose_prefix);
405 if (!fcu->rna_path().startswith(path_pose_prefix)) {
409 const char *name_esc = fcu->rna_path().c_str() + path_pose_prefix_len;
413 if (name_esc_end ==
nullptr) [[unlikely]] {
418 const size_t name_esc_len = size_t(name_esc_end - name_esc);
424 if (!is_complete) [[unlikely]] {
431 if (!
STREQ(name_flip, name)) {
434 fcu->rna_path_set_move(
BLI_sprintfN(
"pose.bones[\"%s%s", name_flip_esc, name_esc_end));
436 if (fcu->grp !=
nullptr) {
450 if (!
STREQ(name_flip, agrp->name)) {
464 for (
Object *
object : objects) {
467 slot = action.
slot(0);
469 if (!flipped_slots.
add(slot)) {
474 for (
FCurve *fcu : fcurves) {
475 fcu_cache.
add({fcu->rna_path(), std::nullopt, fcu->array_index}, fcu);
Functions for backward compatibility with the legacy Action API.
Blender kernel action and pose functionality.
#define SNPRINTF_UTF8(dst, format,...)
#define STRNCPY_UTF8(dst, src)
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define READ_VALUE_FLT(id)
#define WRITE_ARRAY_FLT(id)
#define READ_VALUE_INT(id)
#define FCURVE_ASSIGN_ARRAY(id, path_test_suffix)
#define FCURVE_CHANNEL_LEN
#define WRITE_VALUE_FLT(id)
#define READ_ARRAY_FLT(id)
#define FCURVE_ASSIGN_VALUE(id, path_test_suffix, index)
bool add(const Key &key, const Value &value)
Value lookup_default(const Key &key, const Value &default_value) const
constexpr int64_t size() const
void append(const T &value)
const Slot * slot(int64_t index) const
float3x3 scale(float3x3 mat, float2 scale)
Vector< const FCurve * > fcurves_all(const bAction *action)
Vector< bActionGroup * > channel_groups_all(bAction *action)
Span< FCurve * > fcurves_for_action_slot(Action &action, slot_handle_t slot_handle)
Slot * generic_slot_for_autoassign(const ID &animated_id, Action &action, StringRefNull last_slot_identifier)
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void action_flip_pchan_cache_init(FCurve_KeyCache *fkc, const Span< float > keyed_frames)
static void action_flip_pchan_rna_paths(bAction *act)
static void action_flip_pchan(Object *ob_arm, const bPoseChannel *pchan, Map< RNAPath, FCurve * > &fcurve_cache)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
static void action_flip_pchan_cache_fcurve_assign_array(FCurve_KeyCache *fkc, int fkc_len, const char *path, Map< RNAPath, FCurve * > &fcurve_cache)
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
void BKE_fcurve_handles_recalc_ex(FCurve &fcu, eBezTriple_Flag handle_sel_flag)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void BKE_pchan_to_mat4(bke::PChanBoneConst pchanbone, float r_chanmat[4][4])
static void action_flip_pchan_cache_fcurve_assign_value(FCurve_KeyCache *fkc, int index, const char *path, Map< RNAPath, FCurve * > &fcurve_cache)
void void void void void BKE_action_flip_with_pose(bAction *act, Span< Object * > objects) ATTR_NONNULL(1)
size_t size_t const char * BLI_str_escape_find_quote(const char *str) ATTR_NONNULL(1)
void DEG_id_tag_update(ID *id, unsigned int flags)
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
void BKE_pchan_apply_mat4(bPoseChannel *pchan, const float mat[4][4], bool use_compat)
void unit_m4(float m[4][4])
size_t BLI_str_unescape_ex(char *__restrict dst, const char *__restrict src, size_t src_len, size_t dst_maxncpy, bool *r_is_complete) ATTR_NONNULL(1
float evaluate_fcurve_only_curve(const FCurve *fcu, float evaltime)
Array< float > BKE_fcurves_calc_keyed_frames(Span< FCurve * > fcurve_array)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
size_t BLI_string_flip_side_name(char *name_dst, const char *name_src, bool strip_number, size_t name_dst_maxncpy) ATTR_NONNULL(1