Refactor: combine insert_keyframe() and insert_key_rna() into a single function #122053
@ -17,6 +17,7 @@
|
||||
#include "BLI_bit_span.hh"
|
||||
#include "BLI_vector.hh"
|
||||
#include "DNA_anim_types.h"
|
||||
#include "RNA_path.hh"
|
||||
#include "RNA_types.hh"
|
||||
|
||||
struct ID;
|
||||
@ -194,7 +195,7 @@ bool autokeyframe_cfra_can_key(const Scene *scene, ID *id);
|
||||
*
|
||||
* \param rna_paths: Only inserts keys on those RNA paths.
|
||||
*/
|
||||
void autokeyframe_object(bContext *C, Scene *scene, Object *ob, Span<std::string> rna_paths);
|
||||
void autokeyframe_object(bContext *C, Scene *scene, Object *ob, Span<RNAPath> rna_paths);
|
||||
/**
|
||||
* Auto-keyframing feature - for objects
|
||||
*
|
||||
@ -216,7 +217,7 @@ void autokeyframe_pose_channel(bContext *C,
|
||||
Scene *scene,
|
||||
Object *ob,
|
||||
bPoseChannel *pose_channel,
|
||||
Span<std::string> rna_paths,
|
||||
Span<RNAPath> rna_paths,
|
||||
short targetless_ik);
|
||||
/**
|
||||
* Use for auto-key-framing.
|
||||
@ -261,7 +262,7 @@ CombinedKeyingResult insert_key_action(Main *bmain,
|
||||
* \returns How often keyframe insertion was successful and how often it failed / for which reason.
|
||||
*/
|
||||
CombinedKeyingResult insert_key_rna(PointerRNA *rna_pointer,
|
||||
const blender::Span<std::string> rna_paths,
|
||||
const blender::Span<RNAPath> rna_paths,
|
||||
float scene_frame,
|
||||
eInsertKeyFlags insert_key_flags,
|
||||
eBezTriple_KeyframeType key_type,
|
||||
|
@ -960,7 +960,7 @@ CombinedKeyingResult insert_key_action(Main *bmain,
|
||||
}
|
||||
|
||||
CombinedKeyingResult insert_key_rna(PointerRNA *rna_pointer,
|
||||
const blender::Span<std::string> rna_paths,
|
||||
const blender::Span<RNAPath> rna_paths,
|
||||
const float scene_frame,
|
||||
const eInsertKeyFlags insert_key_flags,
|
||||
const eBezTriple_KeyframeType key_type,
|
||||
@ -990,11 +990,11 @@ CombinedKeyingResult insert_key_rna(PointerRNA *rna_pointer,
|
||||
const float nla_frame = BKE_nla_tweakedit_remap(adt, scene_frame, NLATIME_CONVERT_UNMAP);
|
||||
const bool visual_keyframing = insert_key_flags & INSERTKEY_MATRIX;
|
||||
|
||||
for (const std::string &rna_path : rna_paths) {
|
||||
for (const RNAPath &rna_path : rna_paths) {
|
||||
PointerRNA ptr;
|
||||
PropertyRNA *prop = nullptr;
|
||||
const bool path_resolved = RNA_path_resolve_property(
|
||||
rna_pointer, rna_path.c_str(), &ptr, &prop);
|
||||
rna_pointer, rna_path.path.c_str(), &ptr, &prop);
|
||||
if (!path_resolved) {
|
||||
continue;
|
||||
}
|
||||
@ -1007,7 +1007,7 @@ CombinedKeyingResult insert_key_rna(PointerRNA *rna_pointer,
|
||||
rna_pointer,
|
||||
prop,
|
||||
rna_values.as_mutable_span(),
|
||||
-1,
|
||||
rna_path.index.value_or(-1),
|
||||
&anim_eval_context,
|
||||
nullptr,
|
||||
nathanvegdahl marked this conversation as resolved
Outdated
|
||||
successful_remaps);
|
||||
|
@ -103,7 +103,7 @@ bool autokeyframe_cfra_can_key(const Scene *scene, ID *id)
|
||||
return true;
|
||||
}
|
||||
|
||||
void autokeyframe_object(bContext *C, Scene *scene, Object *ob, Span<std::string> rna_paths)
|
||||
void autokeyframe_object(bContext *C, Scene *scene, Object *ob, Span<RNAPath> rna_paths)
|
||||
{
|
||||
BLI_assert(ob != nullptr);
|
||||
BLI_assert(scene != nullptr);
|
||||
@ -198,7 +198,7 @@ void autokeyframe_pose_channel(bContext *C,
|
||||
Scene *scene,
|
||||
Object *ob,
|
||||
bPoseChannel *pose_channel,
|
||||
Span<std::string> rna_paths,
|
||||
Span<RNAPath> rna_paths,
|
||||
short targetless_ik)
|
||||
{
|
||||
BLI_assert(C != nullptr);
|
||||
|
@ -256,11 +256,11 @@ static bool is_idproperty_keyable(IDProperty *id_prop, PointerRNA *ptr, Property
|
||||
return false;
|
||||
}
|
||||
|
||||
static blender::Vector<std::string> construct_rna_paths(PointerRNA *ptr)
|
||||
static blender::Vector<RNAPath> construct_rna_paths(PointerRNA *ptr)
|
||||
{
|
||||
eRotationModes rotation_mode;
|
||||
IDProperty *properties;
|
||||
blender::Vector<std::string> paths;
|
||||
blender::Vector<RNAPath> paths;
|
||||
|
||||
if (ptr->type == &RNA_PoseBone) {
|
||||
bPoseChannel *pchan = static_cast<bPoseChannel *>(ptr->data);
|
||||
@ -279,15 +279,15 @@ static blender::Vector<std::string> construct_rna_paths(PointerRNA *ptr)
|
||||
|
||||
eKeyInsertChannels insert_channel_flags = eKeyInsertChannels(U.key_insert_channels);
|
||||
if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_LOCATION) {
|
||||
paths.append("location");
|
||||
paths.append({"location"});
|
||||
}
|
||||
if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_ROTATION) {
|
||||
switch (rotation_mode) {
|
||||
case ROT_MODE_QUAT:
|
||||
paths.append("rotation_quaternion");
|
||||
paths.append({"rotation_quaternion"});
|
||||
break;
|
||||
case ROT_MODE_AXISANGLE:
|
||||
paths.append("rotation_axis_angle");
|
||||
paths.append({"rotation_axis_angle"});
|
||||
break;
|
||||
case ROT_MODE_XYZ:
|
||||
case ROT_MODE_XZY:
|
||||
@ -295,16 +295,16 @@ static blender::Vector<std::string> construct_rna_paths(PointerRNA *ptr)
|
||||
case ROT_MODE_YZX:
|
||||
case ROT_MODE_ZXY:
|
||||
case ROT_MODE_ZYX:
|
||||
paths.append("rotation_euler");
|
||||
paths.append({"rotation_euler"});
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_SCALE) {
|
||||
paths.append("scale");
|
||||
paths.append({"scale"});
|
||||
}
|
||||
if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_ROTATION_MODE) {
|
||||
paths.append("rotation_mode");
|
||||
paths.append({"rotation_mode"});
|
||||
}
|
||||
if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_CUSTOM_PROPERTIES) {
|
||||
if (properties) {
|
||||
@ -329,7 +329,7 @@ static blender::Vector<std::string> construct_rna_paths(PointerRNA *ptr)
|
||||
continue;
|
||||
}
|
||||
if (is_idproperty_keyable(id_prop, &resolved_ptr, resolved_prop)) {
|
||||
paths.append(path);
|
||||
paths.append({path});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -400,7 +400,7 @@ static int insert_key(bContext *C, wmOperator *op)
|
||||
BKE_reportf(op->reports, RPT_ERROR, "'%s' is not editable", selected_id->name + 2);
|
||||
continue;
|
||||
}
|
||||
Vector<std::string> rna_paths = construct_rna_paths(&id_ptr);
|
||||
Vector<RNAPath> rna_paths = construct_rna_paths(&id_ptr);
|
||||
|
||||
combined_result.merge(animrig::insert_key_rna(&id_ptr,
|
||||
rna_paths.as_span(),
|
||||
|
@ -1267,41 +1267,41 @@ static void restoreMirrorPoseBones(TransDataContainer *tc)
|
||||
|
||||
/* Given the transform mode `tmode` return a Vector of RNA paths that were possibly modified during
|
||||
* that transformation. */
|
||||
static blender::Vector<std::string> get_affected_rna_paths_from_transform_mode(
|
||||
static blender::Vector<RNAPath> get_affected_rna_paths_from_transform_mode(
|
||||
const eTfmMode tmode,
|
||||
ToolSettings *toolsettings,
|
||||
const blender::StringRef rotation_path,
|
||||
const bool targetless_ik)
|
||||
{
|
||||
blender::Vector<std::string> rna_paths;
|
||||
blender::Vector<RNAPath> rna_paths;
|
||||
switch (tmode) {
|
||||
case TFM_TRANSLATION:
|
||||
if (targetless_ik) {
|
||||
rna_paths.append(rotation_path);
|
||||
rna_paths.append({rotation_path});
|
||||
}
|
||||
else {
|
||||
rna_paths.append("location");
|
||||
rna_paths.append({"location"});
|
||||
}
|
||||
break;
|
||||
|
||||
case TFM_ROTATION:
|
||||
case TFM_TRACKBALL:
|
||||
if (ELEM(toolsettings->transform_pivot_point, V3D_AROUND_CURSOR, V3D_AROUND_ACTIVE)) {
|
||||
rna_paths.append("location");
|
||||
rna_paths.append({"location"});
|
||||
}
|
||||
|
||||
if ((toolsettings->transform_flag & SCE_XFORM_AXIS_ALIGN) == 0) {
|
||||
rna_paths.append(rotation_path);
|
||||
rna_paths.append({rotation_path});
|
||||
}
|
||||
break;
|
||||
|
||||
case TFM_RESIZE:
|
||||
if (ELEM(toolsettings->transform_pivot_point, V3D_AROUND_CURSOR, V3D_AROUND_ACTIVE)) {
|
||||
rna_paths.append("location");
|
||||
rna_paths.append({"location"});
|
||||
}
|
||||
|
||||
if ((toolsettings->transform_flag & SCE_XFORM_AXIS_ALIGN) == 0) {
|
||||
rna_paths.append("scale");
|
||||
rna_paths.append({"scale"});
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1323,7 +1323,7 @@ static void autokeyframe_pose(
|
||||
continue;
|
||||
}
|
||||
|
||||
blender::Vector<std::string> rna_paths;
|
||||
blender::Vector<RNAPath> rna_paths;
|
||||
const blender::StringRef rotation_path = blender::animrig::get_rotation_mode_path(
|
||||
eRotationModes(pchan->rotmode));
|
||||
|
||||
@ -1332,7 +1332,7 @@ static void autokeyframe_pose(
|
||||
tmode, scene->toolsettings, rotation_path, targetless_ik);
|
||||
}
|
||||
else {
|
||||
rna_paths = {"location", rotation_path, "scale"};
|
||||
rna_paths = {{"location"}, {rotation_path}, {"scale"}};
|
||||
}
|
||||
|
||||
blender::animrig::autokeyframe_pose_channel(
|
||||
|
@ -759,17 +759,17 @@ static bool motionpath_need_update_object(Scene *scene, Object *ob)
|
||||
|
||||
/* Given the transform mode `tmode` return a Vector of RNA paths that were possibly modified during
|
||||
* that transformation. */
|
||||
static blender::Vector<std::string> get_affected_rna_paths_from_transform_mode(
|
||||
static blender::Vector<RNAPath> get_affected_rna_paths_from_transform_mode(
|
||||
const eTfmMode tmode,
|
||||
Scene *scene,
|
||||
ViewLayer *view_layer,
|
||||
Object *ob,
|
||||
const blender::StringRef rotation_path)
|
||||
{
|
||||
blender::Vector<std::string> rna_paths;
|
||||
blender::Vector<RNAPath> rna_paths;
|
||||
switch (tmode) {
|
||||
case TFM_TRANSLATION:
|
||||
rna_paths.append("location");
|
||||
rna_paths.append({"location"});
|
||||
break;
|
||||
|
||||
case TFM_ROTATION:
|
||||
@ -777,15 +777,15 @@ static blender::Vector<std::string> get_affected_rna_paths_from_transform_mode(
|
||||
if (scene->toolsettings->transform_pivot_point == V3D_AROUND_ACTIVE) {
|
||||
BKE_view_layer_synced_ensure(scene, view_layer);
|
||||
if (ob != BKE_view_layer_active_object_get(view_layer)) {
|
||||
rna_paths.append("location");
|
||||
rna_paths.append({"location"});
|
||||
}
|
||||
}
|
||||
else if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CURSOR) {
|
||||
rna_paths.append("location");
|
||||
rna_paths.append({"location"});
|
||||
}
|
||||
|
||||
if ((scene->toolsettings->transform_flag & SCE_XFORM_AXIS_ALIGN) == 0) {
|
||||
rna_paths.append(rotation_path);
|
||||
rna_paths.append({rotation_path});
|
||||
}
|
||||
break;
|
||||
|
||||
@ -793,22 +793,22 @@ static blender::Vector<std::string> get_affected_rna_paths_from_transform_mode(
|
||||
if (scene->toolsettings->transform_pivot_point == V3D_AROUND_ACTIVE) {
|
||||
BKE_view_layer_synced_ensure(scene, view_layer);
|
||||
if (ob != BKE_view_layer_active_object_get(view_layer)) {
|
||||
rna_paths.append("location");
|
||||
rna_paths.append({"location"});
|
||||
}
|
||||
}
|
||||
else if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CURSOR) {
|
||||
rna_paths.append("location");
|
||||
rna_paths.append({"location"});
|
||||
}
|
||||
|
||||
if ((scene->toolsettings->transform_flag & SCE_XFORM_AXIS_ALIGN) == 0) {
|
||||
rna_paths.append("scale");
|
||||
rna_paths.append({"scale"});
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
rna_paths.append("location");
|
||||
rna_paths.append(rotation_path);
|
||||
rna_paths.append("scale");
|
||||
rna_paths.append({"location"});
|
||||
rna_paths.append({rotation_path});
|
||||
rna_paths.append({"scale"});
|
||||
}
|
||||
|
||||
return rna_paths;
|
||||
@ -816,7 +816,7 @@ static blender::Vector<std::string> get_affected_rna_paths_from_transform_mode(
|
||||
|
||||
static void autokeyframe_object(bContext *C, Scene *scene, Object *ob, const eTfmMode tmode)
|
||||
{
|
||||
blender::Vector<std::string> rna_paths;
|
||||
blender::Vector<RNAPath> rna_paths;
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
const blender::StringRef rotation_path = blender::animrig::get_rotation_mode_path(
|
||||
eRotationModes(ob->rotmode));
|
||||
@ -826,7 +826,7 @@ static void autokeyframe_object(bContext *C, Scene *scene, Object *ob, const eTf
|
||||
tmode, scene, view_layer, ob, rotation_path);
|
||||
}
|
||||
else {
|
||||
rna_paths = {"location", rotation_path, "scale"};
|
||||
rna_paths = {{"location"}, {rotation_path}, {"scale"}};
|
||||
}
|
||||
blender::animrig::autokeyframe_object(C, scene, ob, rna_paths.as_span());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user
The functionality of
BKE_animsys_nla_remap_keyframe_values()
should be documented at the declaration of that function, not here. The note that this is an "interesting" function with various potentially-unexpected effects is very welcome though.Good call. I've made a separate PR that can be landed either before or after this one that (hopefully) improves the documentation of
BKE_animsys_nla_remap_keyframe_values()
in the ways needed to understand this call site's usage of it: #123081I've now removed the output parameter descriptions, leaving that to #123081. I also renamed the
elements_to_key
variable torna_values_mask
, to make its relationship torna_values
more obvious.