46#include "RNA_prototypes.hh"
106 if ((ob->parent == armob) && (ob->partype ==
PARBONE)) {
119 const float pose_mat[4][4],
120 const float new_tail[3],
121 float r_new_arm_mat[4][4])
132 float premat[3][3], pmat[3][3];
156 const Bone *pchan_bone = pchanbone.
bone;
196 const float delta_mat[4][4],
197 float r_new_arm_mat[4][4])
200 float delta[3], new_tail[3], premat[3][3], new_pose[4][4];
235 if (!pchan || !pchan_eval) {
240 new_pstate.
bone = bone;
242 if (std::find_if(selected.
begin(),
244 [&](
const PointerRNA &ptr) { return ptr.data == pchan; }) != selected.
end())
259 float offs_bone[4][4];
296 pstate = &new_pstate;
309 float offs_bone[4][4], delta[4][4], old_chan_loc[3];
335 float inv_parent_arm[4][4];
352 pstate = &new_pstate;
366 switch (constraint->
type) {
428 "Actions on this armature will be destroyed by this new rest pose as the "
429 "transforms stored are relative to the old rest pose");
451 arm,
pose, ob_eval->
pose, &bone, selected_bones,
nullptr);
498 ot->
name =
"Apply Pose as Rest Pose";
499 ot->
idname =
"POSE_OT_armature_apply";
500 ot->
description =
"Apply the current pose as the new rest pose";
514 "Only apply the selected bones (with propagation to children)");
536 const bArmature *arm = id_cast<const bArmature *>(ob->data);
538 int chanbase_len = ob->pose->chanbase.count();
546 bool changed =
false;
548 for (
const auto [i, pchan] : ob->pose->chanbase.enumerate()) {
551 pchan_xform_array[i].is_set =
false;
565 pchan_xform_array[i].is_set =
true;
571 for (
const auto [i, pchan] : ob->pose->chanbase.enumerate()) {
572 if (!pchan_xform_array[i].
is_set) {
584 MEM_delete(pchan_xform_array);
594 ot->
name =
"Apply Visual Transform to Pose";
595 ot->
idname =
"POSE_OT_visual_transform_apply";
596 ot->
description =
"Apply final constrained position of pose bones to their transform";
621 const float flip_factor = do_flip ? -1 : 1;
622 const float curve_in_x = copy_bone.
curve_in_x * flip_factor;
623 const float curve_out_x = copy_bone.
curve_out_x * flip_factor;
624 const float roll1 = copy_bone.
roll1 * flip_factor;
625 const float roll2 = copy_bone.
roll2 * flip_factor;
672 if (prop.
len != target.
len) {
680 for (
int i = 0; i < prop.
len; i++) {
688 for (
int i = 0; i < prop.
len; i++) {
689 prop_val[i] =
interpf(target_val[i], prop_val[i], factor);
696 for (
int i = 0; i < prop.
len; i++) {
697 prop_val[i] =
interpd(target_val[i], prop_val[i], factor);
723 if (!paste_prop || copy_prop->
type != paste_prop->
type ||
745 const bool selected_only,
748 bool *r_is_found =
nullptr)
763 *r_is_found = paste_bone !=
nullptr;
765 if (paste_bone ==
nullptr) {
797 if (copy_bone->
prop) {
798 if (paste_bone->
prop) {
846 BLI_assert_msg(armature,
"If an armature object has a pose, it should have armature data");
859 (PartialWriteContext::IDAddOperations::MAKE_LOCAL |
860 PartialWriteContext::IDAddOperations::SET_FAKE_USER |
861 PartialWriteContext::IDAddOperations::SET_CLIPBOARD_MARK)},
865 if (*(cb_data->id_pointer) == ob->data) {
866 return (PartialWriteContext::IDAddOperations::MAKE_LOCAL |
867 PartialWriteContext::IDAddOperations::ADD_DEPENDENCIES);
874 copybuffer.write_as_copypaste_buffer(filepath, *op->reports);
884 ot->
name =
"Copy Pose";
885 ot->
idname =
"POSE_OT_copy";
886 ot->
description =
"Copy the current pose of the selected bones to the internal clipboard";
929 Object *object_from =
nullptr;
934 if (object_from !=
nullptr) {
949 if (pose_from ==
nullptr) {
960 selected_only =
false;
966 int num_pasted_bones = 0;
967 int num_skipped_bones = 0;
968 int num_copied_bones = 0;
981 *ob, {*object_from, pchan_from}, selected_only, flip, factor, &is_found);
992 "Copied pose has bone '%s', but that bone cannot be found now.\n",
1002 if (num_pasted_bones == 0) {
1003 const char *msg = selected_only ?
"None of the %d copied bones are selected now" :
1004 "None of the %d copied bones could be pasted";
1011 if (num_pasted_bones + num_skipped_bones == num_copied_bones) {
1013 if (num_skipped_bones) {
1016 "Pasted %d bones, and skipped %d unselected bones",
1026 if (num_skipped_bones) {
1029 "Pasted only %d of the %d copied bones, and skipped %d unselected bones",
1037 "Pasted only %d of the %d copied bones",
1061 ot->
name =
"Paste Pose";
1062 ot->
idname =
"POSE_OT_paste";
1063 ot->
description =
"Paste the stored pose on to the current pose";
1076 "Flipped on X-Axis",
1077 "Paste the stored pose flipped on to current pose");
1084 "Only paste the stored pose on to selected bones in the current pose");
1093 "Blends the current pose to the pose to paste. At 1, the pasted pose completely "
1094 "overwrites the current pose",
1109 pchan->
scale[0] = 1.0f;
1112 pchan->
scale[1] = 1.0f;
1115 pchan->
scale[2] = 1.0f;
1118 pchan->
ease1 = 0.0f;
1119 pchan->
ease2 = 0.0f;
1130 if (pchan_mirror !=
nullptr) {
1141 pchan->
loc[0] = 0.0f;
1144 pchan->
loc[1] = 0.0f;
1147 pchan->
loc[2] = 0.0f;
1156 if (pchan_mirror !=
nullptr) {
1194 pchan->
quat[0] = 1.0f;
1197 pchan->
quat[1] = 0.0f;
1200 pchan->
quat[2] = 0.0f;
1203 pchan->
quat[3] = 0.0f;
1209 pchan->
eul[0] = 0.0f;
1212 pchan->
eul[1] = 0.0f;
1215 pchan->
eul[2] = 0.0f;
1221 float eul[3], oldeul[3], quat1[4] = {0};
1235 eul[0] = eul[1] = eul[2] = 0.0f;
1254 if ((quat1[0] < 0.0f && pchan->
quat[0] > 0.0f) ||
1255 (quat1[0] > 0.0f && pchan->
quat[0] < 0.0f))
1283 pchan->
roll1 = 0.0f;
1284 pchan->
roll2 = 0.0f;
1297 if (pchan_mirror !=
nullptr) {
1317 void (*clear_func)(
const bPose *,
1319 const char default_ksName[])
1324 bool changed_multi =
false;
1327 if (
ELEM(
nullptr, clear_func, default_ksName)) {
1330 "Programming error: missing clear transform function or keying set name");
1342 bool changed =
false;
1346 clear_func(ob_iter->pose, pchan);
1356 clear_func(ob_iter->pose, pchan_eval);
1363 changed_multi =
true;
1406 ot->
name =
"Clear Pose Scale";
1407 ot->
idname =
"POSE_OT_scale_clear";
1408 ot->
description =
"Reset scaling of selected bones to their default values";
1433 ot->
name =
"Clear Pose Rotation";
1434 ot->
idname =
"POSE_OT_rot_clear";
1435 ot->
description =
"Reset rotations of selected bones to their default values";
1460 ot->
name =
"Clear Pose Location";
1461 ot->
idname =
"POSE_OT_loc_clear";
1462 ot->
description =
"Reset locations of selected bones to their default values";
1487 ot->
name =
"Clear Pose Transforms";
1488 ot->
idname =
"POSE_OT_transforms_clear";
1490 "Reset location, rotation, and scaling of selected bones to their default values";
1508 const bool selected_only)
1511 if (paste_bone ==
nullptr) {
1528 if (copy_bone.
prop && paste_bone->
prop) {
1548 depsgraph,
float(scene->
r.
cfra));
1552 if ((ob->adt) && (ob->adt->action)) {
1555 bPose *dummyPose =
nullptr;
1563 workob.
data = ob->data;
1564 workob.
adt = ob->adt;
1565 workob.
pose = dummyPose;
1585 dummyPose->
chanbase.free_no_destruct();
1586 MEM_delete(dummyPose->
runtime);
1587 MEM_delete(dummyPose);
1605 ot->
name =
"Clear User Transforms";
1606 ot->
idname =
"POSE_OT_user_transforms_clear";
1607 ot->
description =
"Reset pose bone transforms to keyframed state";
1617 RNA_def_boolean(ot->
srna,
"only_selected",
true,
"Only Selected",
"Only visible/selected bones");
Functions to deal with Armatures.
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
Functions to insert, delete or modify keyframes.
Functionality to interact with keying sets.
Blender kernel action and pose functionality.
#define FOREACH_PCHAN_SELECTED_IN_OBJECT_END
#define FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN(_ob, _pchan)
#define CTX_DATA_COUNT(C, member)
#define IDP_float_get(prop)
#define IDP_int_get(prop)
#define IDP_array_double_get(prop)
#define IDP_int_set(prop, value)
#define IDP_double_get(prop)
#define IDP_array_int_get(prop)
#define IDP_float_set(prop, value)
#define IDP_double_set(prop, value)
#define IDP_array_float_get(prop)
#define FOREACH_OBJECT_IN_MODE_BEGIN(_bmain, _scene, _view_layer, _v3d, _object_type, _object_mode, _instance)
#define FOREACH_OBJECT_IN_MODE_END
General operations, lookup, etc. for blender objects.
#define BLI_path_join(...)
#define STRNCPY_UTF8(dst, src)
#define CLOG_INFO(clg_ref,...)
#define ID_IS_PACKED(_id)
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define BLI_assert_msg(a, msg)
constexpr const T * end() const
constexpr const T * begin() const
ID * id_add(const ID *id, IDAddOptions options, FunctionRef< IDAddOperations(LibraryIDLinkCallbackData *cb_data, IDAddOptions options)> dependencies_filter_cb=nullptr)
constexpr const char * c_str() const
void relative_keyingset_add_source(Vector< PointerRNA > &sources, ID *id, StructRNA *srna, void *data)
void bone_deselect(bPoseChannel *pchan)
bool autokeyframe_cfra_can_key(const Scene *scene, ID *id)
bool bone_is_visible(const bArmature *armature, const Bone *bone)
bool bone_is_selected(const bArmature *armature, const Bone *bone)
KeyingSet * get_keyingset_for_autokeying(const Scene *scene, const char *transformKSName)
bool autokeyframe_pchan(bContext *C, Scene *scene, Object *ob, bPoseChannel *pchan, KeyingSet *ks)
int apply_keyingset(bContext *C, Vector< PointerRNA > *sources, KeyingSet *keyingset, ModifyKeyMode mode, float cfra)
PChanBoneT< bPoseChannel, Bone > PChanBone
Array< float, 4 > TransformFloats
void mat3_vec_to_roll(const float mat[3][3], const float vec[3], float *r_roll)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_bone_parent_transform_combine(const BoneParentTransform *in1, const BoneParentTransform *in2, BoneParentTransform *result)
bArmature * BKE_armature_from_object(Object *ob)
static bPoseChannel * pose_bone_blend_to(Object &paste_ob, const ed::AnimTransformable ©_transformable, const bool selected_only, const bool flip, const float factor, bool *r_is_found=nullptr)
static void pchan_clear_loc_with_mirrored(const bPose *pose, bPoseChannel *pchan)
static wmOperatorStatus pose_clear_loc_exec(bContext *C, wmOperator *op)
static void applyarmature_transfer_properties(EditBone *curbone, bke::PChanBone pchanbone, const bPoseChannel *pchan_eval)
void vec_roll_to_mat3(const float vec[3], float roll, float r_mat[3][3])
Main * BKE_copybuffer_read(Main &reference_bmain, const char *libname, ReportList *reports, uint64_t id_types_mask)
void axis_angle_to_eulO(float eul[3], short order, const float axis[3], float angle)
static void pchan_clear_scale_with_mirrored(const bPose *pose, bPoseChannel *pchan)
static wmOperatorStatus pose_clear_transforms_exec(bContext *C, wmOperator *op)
static wmOperatorStatus pose_clear_scale_exec(bContext *C, wmOperator *op)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void pose_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
void ED_armature_to_edit(bArmature *arm)
void ED_armature_from_edit(Main *bmain, bArmature *arm)
static void blend_id_property(IDProperty &prop, const IDProperty &target, const float factor)
static void applyarmature_reset_bone_constraints(const bPoseChannel *pchan)
void copy_m3_m4(float m1[3][3], const float m2[4][4])
static void apply_armature_pose2bones_ui(bContext *C, wmOperator *op)
void POSE_OT_armature_apply(wmOperatorType *ot)
MINLINE int round_fl_to_int(float a)
@ CONSTRAINT_TYPE_STRETCHTO
void copy_m4_m3(float m1[4][4], const float m2[3][3])
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool ED_operator_posemode(bContext *C)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
MINLINE double interpd(double target, double origin, double t)
static void pchan_clear_transforms(const bPose *pose, bPoseChannel *pchan)
void IDP_foreach_property(IDProperty *id_property_root, int type_filter, FunctionRef< void(IDProperty *id_property)> callback)
static constexpr const char * ANIM_KS_SCALING_ID
void quat_to_eul(float eul[3], const float quat[4])
void mul_v3_mat3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
bool invert_m4(float mat[4][4])
static void applyarmature_process_selected_recursive(bArmature *arm, bPose *pose, bPose *pose_eval, Bone *bone, Span< PointerRNA > selected, ApplyArmature_ParentState *pstate)
void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob)
static constexpr const char * ANIM_KS_LOCATION_ID
static void blend_bbone_values(const bPoseChannel ©_bone, bPoseChannel &paste_bone, const float factor, const bool do_flip)
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_object_apply_mat4(Object *ob, const float mat[4][4], bool use_compat, bool use_parent)
AnimationEvalContext BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float eval_time) ATTR_WARN_UNUSED_RESULT
void BKE_bone_parent_transform_apply(const BoneParentTransform *bpt, const float inmat[4][4], float outmat[4][4])
void IDP_CopyPropertyContent(IDProperty *dst, const IDProperty *src) ATTR_NONNULL()
void BKE_bone_parent_transform_clear(BoneParentTransform *bpt)
void unit_axis_angle(float axis[3], float *angle)
PropertyRNA * RNA_def_float_factor(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void mul_m4_v3(const float M[4][4], float r[3])
static wmOperatorStatus pose_clear_rot_exec(bContext *C, wmOperator *op)
void POSE_OT_copy(wmOperatorType *ot)
static wmOperatorStatus pose_paste_exec(bContext *C, wmOperator *op)
MINLINE void mul_v3_v3(float r[3], const float a[3])
bPoseChannel * BKE_pose_channel_get_mirrored(const bPose *pose, const char *name) ATTR_WARN_UNUSED_RESULT
void BKE_bone_parent_transform_calc_from_matrices(int bone_flag, int inherit_scale_mode, const float offs_bone[4][4], const float parent_arm_mat[4][4], const float parent_pose_mat[4][4], BoneParentTransform *r_bpt)
void eulO_to_axis_angle(float axis[3], float *angle, const float eul[3], short order)
void BKE_armature_mat_pose_to_bone(bke::PChanBoneConst pchanbone, const float inmat[4][4], float outmat[4][4])
static wmOperatorStatus pose_visual_transform_apply_exec(bContext *C, wmOperator *)
void mul_m4_m4m3(float R[4][4], const float A[4][4], const float B[3][3])
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Object * BKE_object_pose_armature_get(Object *ob)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
wmWindowManager * CTX_wm_manager(const bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
static wmOperatorStatus pose_clear_transform_generic_exec(bContext *C, wmOperator *op, void(*clear_func)(const bPose *, bPoseChannel *), const char default_ksName[])
static wmOperatorStatus pose_copy_exec(bContext *C, wmOperator *op)
void BKE_pchan_apply_mat4(bPoseChannel *pchan, const float mat[4][4], bool use_compat)
void eul_to_quat(float quat[4], const float eul[3])
void POSE_OT_rot_clear(wmOperatorType *ot)
void BKE_bone_parent_transform_invert(BoneParentTransform *bpt)
static void pchan_clear_rot(bPoseChannel *pchan)
static wmOperatorStatus pose_clear_user_transforms_exec(bContext *C, wmOperator *op)
void unit_m4(float m[4][4])
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
static void pchan_clear_loc(bPoseChannel *pchan)
void ED_armature_edit_free(bArmature *arm)
static void pchan_clear_rot_with_mirrored(const bPose *pose, bPoseChannel *pchan)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
const char * BKE_tempdir_base() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
bool CTX_data_selected_pose_bones(const bContext *C, Vector< PointerRNA > *list)
MINLINE void zero_v3(float r[3])
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void POSE_OT_paste(wmOperatorType *ot)
void IDP_SyncGroupValues(IDProperty *dest, const IDProperty *src) ATTR_NONNULL()
static void applyarmature_fix_boneparents(const bContext *C, Scene *scene, Object *armob)
void BKE_main_free(Main *bmain)
void BKE_pose_copy_data(bPose **dst, const bPose *src, bool copy_constraints)
void BKE_animsys_evaluate_animdata(ID *id, AnimData *adt, const AnimationEvalContext *anim_eval_context, eAnimData_Recalc recalc, bool flush_to_original)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void POSE_OT_transforms_clear(wmOperatorType *ot)
void POSE_OT_scale_clear(wmOperatorType *ot)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
static void pose_bone_copy_transform_values(Object &paste_ob, const bPoseChannel ©_bone, const bool selected_only)
static constexpr const char * ANIM_KS_ROTATION_ID
float4x4 BKE_object_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *ob)
Main * CTX_data_main(const bContext *C)
MINLINE void copy_v3_fl(float r[3], float f)
void BKE_bone_offset_matrix_get(const Bone *bone, float offs_bone[4][4])
void IDP_FreeProperty(IDProperty *prop)
static void blend_properties(IDProperty *copy_props, IDProperty *paste_props, const float factor)
MINLINE float interpf(float target, float origin, float t)
Scene * CTX_data_scene(const bContext *C)
MINLINE void copy_v4_v4(float r[4], const float a[4])
void POSE_OT_loc_clear(wmOperatorType *ot)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
static constexpr const char * ANIM_KS_LOC_ROT_SCALE_ID
@ MOTIONPATH_BAKE_HAS_PATHS
void BKE_pose_rest(Object &pose_ob, bool selected_bones_only)
Object * CTX_data_active_object(const bContext *C)
static void applyarmature_set_edit_position(EditBone *curbone, const float pose_mat[4][4], const float new_tail[3], float r_new_arm_mat[4][4])
static void applyarmature_reset_constraints(bPose *pose, const bool use_selected)
void POSE_OT_user_transforms_clear(wmOperatorType *ot)
float RNA_float_get(PointerRNA *ptr, const char *name)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
void mul_qt_fl(float q[4], float f)
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
static wmOperatorStatus apply_armature_pose2bones_exec(bContext *C, wmOperator *op)
void POSE_OT_visual_transform_apply(wmOperatorType *ot)
void ED_pose_recalculate_paths(bContext *C, Scene *scene, Object *ob)
View3D * CTX_wm_view3d(const bContext *C)
static constexpr const char * ANIM_KS_WHOLE_CHARACTER_ID
static void applyarmature_reset_bone_constraint(const bConstraint *constraint)
static void applyarmature_adjust_edit_position(bArmature *arm, bPoseChannel *pchan, const float delta_mat[4][4], float r_new_arm_mat[4][4])
EditBone * ED_armature_ebone_find_name(const ListBaseT< EditBone > *edbo, const char *name)
bool BKE_object_obdata_is_libdata(const Object *ob)
static void pchan_clear_scale(bPoseChannel *pchan)
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
float normalize_qt_qt(float r[4], const float q[4])
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< Bone > childbase
eBone_InheritScaleMode inherit_scale_mode
ListBaseT< Object > objects
eMotionPath_BakeFlag path_bakeflag
ListBaseT< EditBone > * edbo
ListBaseT< Bone > bonebase
struct bPoseChannel * parent
ListBaseT< struct bConstraint > constraints
IDProperty * system_properties
bke::bPoseRuntime * runtime
ListBaseT< bPoseChannel > chanbase
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
void(*) ui(bContext *C, wmOperator *op)
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
struct wmOperatorType * type