Refactor: anim, move pose backup code from editors into blenkernel
Move `pose_backup.cc` from `editors/armature` to `blenkernel`. This is in preparation of an upcoming change where the pose backup is going to be owned by the `Object`. This will need to be automatically cleared when the object is freed, which means that `blenkernel` needs the corresponding logic. Technically only the freeing code could be moved, but I felt it made more sense to keep the related code together. No functional changes.
This commit is contained in:
36
source/blender/blenkernel/BKE_pose_backup.h
Normal file
36
source/blender/blenkernel/BKE_pose_backup.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup bke
|
||||
*
|
||||
* Pose Backups can be created from the current pose, and later restored. The
|
||||
* backup is restricted to those bones animated by a given Action, so that
|
||||
* operations are as fast as possible.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "BLI_listbase.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct PoseBackup;
|
||||
|
||||
/**
|
||||
* Create a backup of those bones that are animated in the given action.
|
||||
*/
|
||||
struct PoseBackup *BKE_pose_backup_create_selected_bones(
|
||||
const struct Object *ob, const struct bAction *action) ATTR_WARN_UNUSED_RESULT;
|
||||
struct PoseBackup *BKE_pose_backup_create_all_bones(
|
||||
const struct Object *ob, const struct bAction *action) ATTR_WARN_UNUSED_RESULT;
|
||||
bool BKE_pose_backup_is_selection_relevant(const struct PoseBackup *pose_backup);
|
||||
void BKE_pose_backup_restore(const struct PoseBackup *pbd);
|
||||
void BKE_pose_backup_free(struct PoseBackup *pbd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -254,6 +254,7 @@ set(SRC
|
||||
intern/pbvh_uv_islands.cc
|
||||
intern/pointcache.c
|
||||
intern/pointcloud.cc
|
||||
intern/pose_backup.cc
|
||||
intern/preferences.c
|
||||
intern/report.c
|
||||
intern/rigidbody.c
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup edarmature
|
||||
* \ingroup bke
|
||||
*/
|
||||
|
||||
#include "ED_armature.h"
|
||||
#include "BKE_pose_backup.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@@ -86,24 +86,24 @@ static PoseBackup *pose_backup_create(const Object *ob,
|
||||
return pose_backup;
|
||||
}
|
||||
|
||||
PoseBackup *ED_pose_backup_create_all_bones(const Object *ob, const bAction *action)
|
||||
PoseBackup *BKE_pose_backup_create_all_bones(const Object *ob, const bAction *action)
|
||||
{
|
||||
return pose_backup_create(ob, action, BoneNameSet());
|
||||
}
|
||||
|
||||
PoseBackup *ED_pose_backup_create_selected_bones(const Object *ob, const bAction *action)
|
||||
PoseBackup *BKE_pose_backup_create_selected_bones(const Object *ob, const bAction *action)
|
||||
{
|
||||
const bArmature *armature = static_cast<const bArmature *>(ob->data);
|
||||
const BoneNameSet selected_bone_names = BKE_armature_find_selected_bone_names(armature);
|
||||
return pose_backup_create(ob, action, selected_bone_names);
|
||||
}
|
||||
|
||||
bool ED_pose_backup_is_selection_relevant(const struct PoseBackup *pose_backup)
|
||||
bool BKE_pose_backup_is_selection_relevant(const struct PoseBackup *pose_backup)
|
||||
{
|
||||
return pose_backup->is_bone_selection_relevant;
|
||||
}
|
||||
|
||||
void ED_pose_backup_restore(const PoseBackup *pbd)
|
||||
void BKE_pose_backup_restore(const PoseBackup *pbd)
|
||||
{
|
||||
LISTBASE_FOREACH (PoseChannelBackup *, chan_bak, &pbd->backups) {
|
||||
memcpy(chan_bak->pchan, &chan_bak->olddata, sizeof(chan_bak->olddata));
|
||||
@@ -117,7 +117,7 @@ void ED_pose_backup_restore(const PoseBackup *pbd)
|
||||
}
|
||||
}
|
||||
|
||||
void ED_pose_backup_free(PoseBackup *pbd)
|
||||
void BKE_pose_backup_free(PoseBackup *pbd)
|
||||
{
|
||||
LISTBASE_FOREACH_MUTABLE (PoseChannelBackup *, chan_bak, &pbd->backups) {
|
||||
if (chan_bak->oldprops) {
|
||||
@@ -30,7 +30,6 @@ set(SRC
|
||||
armature_utils.c
|
||||
editarmature_undo.c
|
||||
meshlaplacian.c
|
||||
pose_backup.cc
|
||||
pose_edit.c
|
||||
pose_group.c
|
||||
pose_lib_2.c
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_lib_id.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_pose_backup.h"
|
||||
#include "BKE_report.h"
|
||||
|
||||
#include "DEG_depsgraph.h"
|
||||
@@ -37,7 +38,6 @@
|
||||
|
||||
#include "UI_interface.h"
|
||||
|
||||
#include "ED_armature.h"
|
||||
#include "ED_asset.h"
|
||||
#include "ED_keyframing.h"
|
||||
#include "ED_screen.h"
|
||||
@@ -86,7 +86,7 @@ typedef struct PoseBlendData {
|
||||
/* Makes a copy of the current pose for restoration purposes - doesn't do constraints currently */
|
||||
static void poselib_backup_posecopy(PoseBlendData *pbd)
|
||||
{
|
||||
pbd->pose_backup = ED_pose_backup_create_selected_bones(pbd->ob, pbd->act);
|
||||
pbd->pose_backup = BKE_pose_backup_create_selected_bones(pbd->ob, pbd->act);
|
||||
|
||||
if (pbd->state == POSE_BLEND_INIT) {
|
||||
/* Ready for blending now. */
|
||||
@@ -125,7 +125,7 @@ static void poselib_keytag_pose(bContext *C, Scene *scene, PoseBlendData *pbd)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ED_pose_backup_is_selection_relevant(pbd->pose_backup) &&
|
||||
if (BKE_pose_backup_is_selection_relevant(pbd->pose_backup) &&
|
||||
!PBONE_SELECTED(armature, pchan->bone)) {
|
||||
continue;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ static void poselib_blend_apply(bContext *C, wmOperator *op)
|
||||
}
|
||||
pbd->needs_redraw = false;
|
||||
|
||||
ED_pose_backup_restore(pbd->pose_backup);
|
||||
BKE_pose_backup_restore(pbd->pose_backup);
|
||||
|
||||
/* The pose needs updating, whether it's for restoring the original pose or for showing the
|
||||
* result of the blend. */
|
||||
@@ -381,7 +381,7 @@ static void poselib_blend_cleanup(bContext *C, wmOperator *op)
|
||||
BKE_report(op->reports, RPT_ERROR, "Internal pose library error, canceling operator");
|
||||
ATTR_FALLTHROUGH;
|
||||
case POSE_BLEND_CANCEL:
|
||||
ED_pose_backup_restore(pbd->pose_backup);
|
||||
BKE_pose_backup_restore(pbd->pose_backup);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ static void poselib_blend_free(wmOperator *op)
|
||||
poselib_tempload_exit(pbd);
|
||||
|
||||
/* Free temp data for operator */
|
||||
ED_pose_backup_free(pbd->pose_backup);
|
||||
BKE_pose_backup_free(pbd->pose_backup);
|
||||
pbd->pose_backup = NULL;
|
||||
|
||||
MEM_SAFE_FREE(op->customdata);
|
||||
|
||||
@@ -369,19 +369,6 @@ void ED_mesh_deform_bind_callback(struct Object *object,
|
||||
int verts_num,
|
||||
float cagemat[4][4]);
|
||||
|
||||
/* Pose backups, pose_backup.c */
|
||||
struct PoseBackup;
|
||||
/**
|
||||
* Create a backup of those bones that are animated in the given action.
|
||||
*/
|
||||
struct PoseBackup *ED_pose_backup_create_selected_bones(
|
||||
const struct Object *ob, const struct bAction *action) ATTR_WARN_UNUSED_RESULT;
|
||||
struct PoseBackup *ED_pose_backup_create_all_bones(
|
||||
const struct Object *ob, const struct bAction *action) ATTR_WARN_UNUSED_RESULT;
|
||||
bool ED_pose_backup_is_selection_relevant(const struct PoseBackup *pose_backup);
|
||||
void ED_pose_backup_restore(const struct PoseBackup *pbd);
|
||||
void ED_pose_backup_free(struct PoseBackup *pbd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_node.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_pose_backup.h"
|
||||
#include "BKE_scene.h"
|
||||
#include "BKE_screen.h"
|
||||
#include "BKE_texture.h"
|
||||
@@ -81,7 +82,6 @@
|
||||
#include "WM_api.h"
|
||||
#include "WM_types.h"
|
||||
|
||||
#include "ED_armature.h"
|
||||
#include "ED_datafiles.h"
|
||||
#include "ED_render.h"
|
||||
#include "ED_screen.h"
|
||||
@@ -955,7 +955,7 @@ static struct PoseBackup *action_preview_render_prepare(IconPreview *preview)
|
||||
|
||||
/* Create a backup of the current pose. */
|
||||
struct bAction *action = (struct bAction *)preview->id;
|
||||
struct PoseBackup *pose_backup = ED_pose_backup_create_all_bones(object, action);
|
||||
struct PoseBackup *pose_backup = BKE_pose_backup_create_all_bones(object, action);
|
||||
|
||||
/* Apply the Action as pose, so that it can be rendered. This assumes the Action represents a
|
||||
* single pose, and that thus the evaluation time doesn't matter. */
|
||||
@@ -974,8 +974,8 @@ static void action_preview_render_cleanup(IconPreview *preview, struct PoseBacku
|
||||
if (pose_backup == nullptr) {
|
||||
return;
|
||||
}
|
||||
ED_pose_backup_restore(pose_backup);
|
||||
ED_pose_backup_free(pose_backup);
|
||||
BKE_pose_backup_restore(pose_backup);
|
||||
BKE_pose_backup_free(pose_backup);
|
||||
|
||||
DEG_id_tag_update(&preview->active_object->id, ID_RECALC_GEOMETRY);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user