22#include "RNA_prototypes.hh"
33 FunctionRef<void(PointerRNA *, bAction *,
slot_handle_t,
const AnimationEvalContext *)>;
35void pose_apply_restore_fcurves(
const Span<FCurve *> fcurves)
37 for (FCurve *fcu : fcurves) {
38 fcu->flag &= ~FCURVE_DISABLED;
43Vector<FCurve *> pose_apply_disable_fcurves_for_unselected_bones(
46 Vector<FCurve *> modified_fcurves;
47 auto disable_unselected_fcurve = [&](FCurve *fcu,
const char *bone_name) {
48 const bool is_bone_selected = selected_bone_names.contains(bone_name);
49 if (!is_bone_selected) {
52 modified_fcurves.append(fcu);
58 return modified_fcurves;
61void pose_apply(Object *ob,
64 const AnimationEvalContext *anim_eval_context,
65 ActionApplier applier)
67 bPose *pose = ob->pose;
68 if (pose ==
nullptr) {
72 if (action->wrap().slot_array_num == 0) {
80 Vector<FCurve *> modified_fcurves = pose_apply_disable_fcurves_for_unselected_bones(
81 action, slot_handle, selected_bone_names);
86 applier(&pose_owner_ptr, action, slot_handle, anim_eval_context);
88 pose_apply_restore_fcurves(modified_fcurves);
113 const float blend_factor)
115 const float fcurve_value =
calculate_fcurve(&anim_rna, &fcu, anim_eval_context);
118 float value_to_write;
124 value_to_write = (1 - blend_factor) * current_value + blend_factor * fcurve_value;
133 value_to_write =
roundf(value_to_write);
139 return value_to_write;
156 float r_quaternion[4])
162 r_quaternion[0] = 1.0f;
163 r_quaternion[1] = 0.0f;
164 r_quaternion[2] = 0.0f;
165 r_quaternion[3] = 0.0f;
168 quat_rna.
prop = prop;
169 for (
FCurve *quat_curve_fcu : quat_fcurves) {
170 const int array_index = quat_curve_fcu->array_index;
172 r_quaternion[array_index] =
calculate_fcurve(&quat_rna, quat_curve_fcu, anim_eval_context);
175 if (quat_fcurves.
size() < 4) {
190 const float blend_factor)
194 float current_quat[4];
197 float target_quat[4];
199 ptr, prop, quaternion_fcurves, anim_eval_context, target_quat);
201 float blended_quat[4];
202 interp_qt_qtqt(blended_quat, current_quat, target_quat, blend_factor);
212 const float blend_factor)
221 anim_rna.
prop = prop;
222 for (
FCurve *fcurve : rotation_fcurves) {
225 *fcurve, anim_rna, anim_eval_context, blend_factor);
240 const float eval_time,
241 const float blend_factor)
245 float4 fcurve_rotation_values(0.0);
248 fcurve_rotation_values[0] = 1.0;
251 for (
FCurve *fcurve : rotation_fcurves) {
252 BLI_assert_msg(fcurve->array_index >= 0 && fcurve->array_index < 4,
253 "Rotation properties have at most 4 components.");
254 fcurve_rotation_values[fcurve->array_index] =
evaluate_fcurve(fcurve, eval_time);
259 switch (fcurve_rotation_mode) {
261 copy_qt_qt(fcurve_quat, fcurve_rotation_values);
271 axis_angle_to_quat(fcurve_quat, &fcurve_rotation_values[1], fcurve_rotation_values[0]);
280 if (ptr.
type == RNA_PoseBone) {
286 else if (ptr.
type == RNA_Object) {
302 const float blend_factor)
307 for (
FCurve *fcurve : fcurves) {
319 rotation_fcurves.
append(fcurve);
322 for (
const auto &[
rna_path, rotation_fcurves] : rotation_fcurve_map.
items()) {
332 ptr_rotation_mode_opt.has_value(),
333 "We have an FCurve on a rotation property, the RNA data should have a rotation order.");
334 const eRotationModes ptr_rotation_mode = ptr_rotation_mode_opt.value();
338 BLI_assert(fcurve_rotation_mode_opt.has_value());
339 const eRotationModes fcurve_rotation_mode = fcurve_rotation_mode_opt.value();
344 if (fcurve_rotation_mode == ptr_rotation_mode ||
355 fcurve_rotation_mode,
362 fcurve_rotation_mode,
368 for (
FCurve *fcu : fcurves) {
384 *fcu, anim_rna, anim_eval_context, blend_factor);
391 const int32_t action_slot_handle,
393 const float blend_factor)
412 const float blend_factor)
414 auto evaluate_and_blend = [blend_factor](
PointerRNA *ptr,
418 blend_in_action(*ptr, act->wrap(), slot_handle, anim_eval_context, blend_factor);
421 pose_apply(ob, action, slot_handle, anim_eval_context, evaluate_and_blend);
428 const float blend_factor)
431 blend_in_action(pose_owner_ptr, action->wrap(), slot_handle, anim_eval_context, blend_factor);
436 for (
const Object *obj : objects) {
452 const float blend_factor)
455 for (
Object *
object : objects) {
463 for (
Object *
object : objects) {
466 object, &pose_action, slot.
handle, anim_eval_context, blend_factor);
474 "Actions without slots have no data. This should have been caught earlier.");
477 if (slot ==
nullptr) {
478 slot = pose_data.
slot(0);
Functions and classes to work with Actions.
Functions to work with animation poses.
Helper functions for animation to interact with the RNA system.
Blender kernel action and pose functionality.
General operations, lookup, etc. for blender objects.
Object is a sort of wrapper for general info.
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
Value & lookup_or_add_default(const Key &key)
bool contains(const Key &key) const
ItemIterator items() const &
constexpr int64_t size() const
void append(const T &value)
const Slot * slot(int64_t index) const
static void blend_rotation(PointerRNA &ptr, PropertyRNA *prop, const Span< FCurve * > rotation_fcurves, const eRotationModes fcurve_rotation_mode, const AnimationEvalContext *anim_eval_context, const float blend_factor)
decltype(blender::ActionSlot::handle) slot_handle_t
std::optional< eRotationModes > get_rotation_mode_from_path(ParsedRNAPathRef rna_path)
void pose_apply_action_all_bones(Object *ob, bAction *action, slot_handle_t slot_handle, const AnimationEvalContext *anim_eval_context)
bool is_rotation_path(ParsedRNAPathRef rna_path)
void pose_apply_action(Span< Object * > objects, Action &pose_action, const AnimationEvalContext *anim_eval_context, float blend_factor)
static bool is_fcurve_evaluatable(const FCurve *fcu)
void pose_apply_action_blend_all_bones(Object *ob, bAction *action, slot_handle_t slot_handle, const AnimationEvalContext *anim_eval_context, float blend_factor)
static void animsys_blend_fcurves_quaternion(PointerRNA &ptr, PropertyRNA *prop, const Span< FCurve * > quaternion_fcurves, const AnimationEvalContext *anim_eval_context, const float blend_factor)
std::optional< eRotationModes > get_rotation_mode_from_rna_pointer(const PointerRNA &ptr)
Span< FCurve * > fcurves_for_action_slot(Action &action, slot_handle_t slot_handle)
static float get_fcurve_blend_value(FCurve &fcu, PathResolvedRNA &anim_rna, const AnimationEvalContext *anim_eval_context, const float blend_factor)
static void animsys_blend_in_fcurves(PointerRNA &ptr, const Span< FCurve * > fcurves, const AnimationEvalContext *anim_eval_context, const float blend_factor)
bool any_bone_selected(Span< const Object * > objects)
Slot & get_best_pose_slot_for_id(const ID &id, Action &pose_data)
static void blend_rotation_with_conversion(PointerRNA &ptr, const Span< FCurve * > rotation_fcurves, const eRotationModes fcurve_rotation_mode, const float eval_time, const float blend_factor)
static void blend_in_action(PointerRNA &ptr, Action &act, const int32_t action_slot_handle, const AnimationEvalContext *anim_eval_context, const float blend_factor)
void pose_apply_action_blend(Object *ob, bAction *action, slot_handle_t slot_handle, const AnimationEvalContext *anim_eval_context, float blend_factor)
static bool rotation_mode_is_euler(const eRotationModes rotation_mode)
Slot * generic_slot_for_autoassign(const ID &animated_id, Action &action, StringRefNull last_slot_identifier)
static void animsys_quaternion_evaluate_fcurves(PointerRNA &ptr, PropertyRNA *prop, const Span< FCurve * > quat_fcurves, const AnimationEvalContext *anim_eval_context, float r_quaternion[4])
Set< std::string > BoneNameSet
void BKE_action_find_fcurves_with_bones(bAction *action, animrig::slot_handle_t slot_handle, FoundFCurveCallback callback)
BoneNameSet BKE_pose_channel_find_selected_names(const Object *object)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
float calculate_fcurve(PathResolvedRNA *anim_rna, FCurve *fcu, const AnimationEvalContext *anim_eval_context)
PointerRNA RNA_id_pointer_create(ID *id)
void animsys_evaluate_action(PointerRNA *ptr, bAction *act, int32_t action_slot_handle, const AnimationEvalContext *anim_eval_context, bool flush_to_original)
float normalize_qt(float q[4])
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
void BKE_pchan_quat_to_rot(bPoseChannel &pchan, const float4 &quat)
Span< rna_path::Item > ParsedRNAPathRef
VecBase< float, 4 > float4
PropertyType RNA_property_type(PropertyRNA *prop)
float4 BKE_object_rot_to_quat(const Object &ob)
void copy_qt_qt(float q[4], const float a[4])
float4 BKE_pchan_rot_to_quat(const bPoseChannel &pchan)
void interp_qt_qtqt(float q[4], const float a[4], const float b[4], float t)
void BKE_object_quat_to_rot(Object &ob, const float4 &quat)
bool BKE_animsys_read_from_rna_path(PathResolvedRNA *anim_rna, float *r_value)
bool BKE_animsys_write_to_rna_path(PathResolvedRNA *anim_rna, float value, bool force_write=false)
void eulO_to_quat(float q[4], const float e[3], short order)
bool BKE_animsys_rna_path_resolve(PointerRNA *ptr, ParsedRNAPathRef rna_path, int array_index, PathResolvedRNA *r_result)
bool BKE_fcurve_is_empty(const FCurve *fcu)
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
float evaluate_fcurve(const FCurve *fcu, float evaltime)