Blender V5.3
armature.cc File Reference
#include <cctype>
#include <cfloat>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <limits>
#include <optional>
#include <fmt/format.h>
#include "BLI_alloca.hh"
#include "BLI_assert.hh"
#include "BLI_bounds.hh"
#include "BLI_ghash.hh"
#include "BLI_listbase.hh"
#include "BLI_math_geom_c.hh"
#include "BLI_math_matrix.hh"
#include "BLI_math_matrix_c.hh"
#include "BLI_math_rotation_c.hh"
#include "BLI_math_vector_c.hh"
#include "BLI_span.hh"
#include "BLI_string_utf8.hh"
#include "BLI_utildefines.hh"
#include "BLT_translation.hh"
#include "DNA_action_types.h"
#include "DNA_armature_types.h"
#include "DNA_constraint_types.h"
#include "DNA_listBase.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "RNA_prototypes.hh"
#include "BKE_action.hh"
#include "BKE_anim_data.hh"
#include "BKE_anim_visualization.h"
#include "BKE_animsys.hh"
#include "BKE_armature.hh"
#include "BKE_constraint.h"
#include "BKE_curve.hh"
#include "BKE_idprop.hh"
#include "BKE_idtype.hh"
#include "BKE_lib_id.hh"
#include "BKE_lib_query.hh"
#include "BKE_main.hh"
#include "BKE_object.hh"
#include "BKE_pose.hh"
#include "BKE_scene.hh"
#include "ANIM_armature.hh"
#include "ANIM_bone_collections.hh"
#include "DEG_depsgraph_build.hh"
#include "DEG_depsgraph_query.hh"
#include "MEM_guardedalloc.h"
#include "BIK_api.h"
#include "BLO_read_write.hh"
#include "CLG_log.h"

Go to the source code of this file.

Namespaces

namespace  blender
 BMesh Iterators.

Functions

void blender::vec_roll_to_mat3 (const float vec[3], float roll, float r_mat[3][3])
static int blender::visit_bone_and_descendants (const Bone &bone, int bone_index, const ForeachBoneFn callback)
void blender::BKE_armature_foreach_bone (const bArmature &armature, ForeachBoneFn callback)
Prototypes
static void blender::copy_bonechildren (Bone *bone_dst, const Bone *bone_src, const Bone *bone_src_act, Bone **r_bone_dst_act, const int flag)
static void blender::copy_bonechildren_custom_handles (Bone *bone_dst, bArmature *arm_dst)
static void blender::rebuild_bone_array (bArmature &armature)
Armature Data-block
static void blender::armature_init_data (ID *id)
static void blender::copy_bone_collection (bArmature *armature_dst, BoneCollection *&bcoll_dst, const BoneCollection *bcoll_src, const int lib_id_flag)
static void blender::armature_copy_data (Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int flag)
static void blender::armature_free_data (ID *id)
static void blender::armature_foreach_id_bone (Bone *bone, LibraryForeachIDData *data)
static void blender::armature_foreach_id_editbone (EditBone *edit_bone, LibraryForeachIDData *data)
static void blender::armature_foreach_id_bone_collection (BoneCollection *bcoll, LibraryForeachIDData *data)
static void blender::armature_foreach_id (ID *id, LibraryForeachIDData *data)
static void blender::write_bone (BlendWriter *writer, Bone *bone)
static void blender::write_bone_collection (BlendWriter *writer, BoneCollection *bcoll)
static void blender::armature_blend_write (BlendWriter *writer, ID *id, const void *id_address)
static void blender::direct_link_bones (BlendDataReader *reader, Bone *bone, bool *all_bones_are_named)
static void blender::direct_link_bone_collection (BlendDataReader *reader, BoneCollection *bcoll)
static void blender::read_bone_collections (BlendDataReader *reader, bArmature *arm)
static void blender::fix_empty_bone_names (bArmature &armature)
static void blender::armature_blend_read_data (BlendDataReader *reader, ID *id)
static void blender::armature_undo_preserve (BlendLibReader *, ID *id_new, ID *id_old)
Generic Data-Level Functions
bArmature * blender::BKE_armature_add (Main *bmain, const char *name)
bArmature * blender::BKE_armature_from_object (Object *ob)
int blender::BKE_armature_bonelist_count (const ListBaseT< Bone > *lb)
void blender::BKE_armature_bonelist_free (ListBaseT< Bone > *lb, bool do_id_user)
void blender::BKE_armature_editbonelist_free (ListBaseT< EditBone > *lb, bool do_id_user)
Armature Transform Copy
static void blender::copy_bone_transform (Bone *bone_dst, const Bone *bone_src)
void blender::BKE_armature_copy_bone_transforms (bArmature *armature_dst, const bArmature *armature_src)
Armature Transform by 4x4 Matrix
See also
ED_armature_edit_transform for the edit-mode version of this function.
static void blender::armature_transform_recurse (ListBaseT< Bone > *bonebase, const float mat[4][4], const bool do_props, const float mat3[3][3], const float scale, const Bone *bone_parent, const float arm_mat_parent_inv[4][4])
void blender::BKE_armature_transform (bArmature *arm, const float mat[4][4], bool do_props)
Armature Bone Find by Name

Using fast GHash lookups when available.

static Bone * blender::get_named_bone_bonechildren (ListBaseT< Bone > *lb, const char *name)
Bone * blender::BKE_armature_find_bone_name (bArmature *arm, const char *name)
static void blender::armature_bone_from_name_insert_recursive (GHash *bone_hash, ListBaseT< Bone > *lb)
static GHash * blender::armature_bone_from_name_map (bArmature *arm)
void blender::BKE_armature_bone_hash_make (bArmature *arm)
void blender::BKE_armature_bone_hash_free (bArmature *arm)
Armature Bone Flags
bool blender::BKE_armature_bone_flag_test_recursive (const Bone *bone, int flag)
Bone auto-side name support
bool blender::bone_autoside_name (char name[MAXBONENAME], int, short axis, float head, float tail)
Armature B-Bone Support
static void blender::equalize_cubic_bezier (const float control[4][3], int temp_segments, int final_segments, const float *segment_scales, float *r_t_points)
static void blender::evaluate_cubic_bezier (const float control[4][3], float t, float r_pos[3], float r_tangent[3])
void blender::BKE_pchan_bbone_handles_get (bke::PChanBoneConst pchanbone, bPoseChannel **r_prev, bPoseChannel **r_next)
void blender::BKE_pchan_bbone_spline_params_get (bke::PChanBoneConst pchanbone, const bArmature &armature, bool rest, BBoneSplineParameters *param)
void blender::BKE_pchan_bbone_spline_setup (bke::PChanBone pchanbone, const bArmature &armature, bool rest, bool for_deform, Mat4 *result_array)
void blender::BKE_pchan_bbone_handles_compute (const BBoneSplineParameters *param, float h1[3], float *r_roll1, float h2[3], float *r_roll2, bool ease, bool offsets)
static void blender::make_bbone_spline_matrix (BBoneSplineParameters *param, const float scalemats[2][4][4], const float pos[3], const float axis[3], float roll, float scalex, float scalez, float result[4][4])
static void blender::ease_handle_axis (const float deriv1[3], const float deriv2[3], float r_axis[3])
int blender::BKE_pchan_bbone_spline_compute (BBoneSplineParameters *param, bool for_deform, Mat4 *result_array)
static void blender::allocate_bbone_cache (bPoseChannel *pchan, const int segments, const bool use_boundaries)
static void blender::compute_bbone_segment_boundaries (bke::PChanBone pchanbone)
void blender::BKE_pchan_bbone_segments_cache_compute (bke::PChanBone pchanbone, const bArmature &armature)
void blender::BKE_pchan_bbone_segments_cache_copy (bPoseChannel *pchan, bPoseChannel *pchan_from)
void blender::BKE_pchan_bbone_deform_clamp_segment_index (const Bone &bone, float head_tail, int *r_index, float *r_blend_next)
static void blender::find_bbone_segment_index_straight (const bke::PChanBoneConst pchanbone, const float *co, int *r_index, float *r_blend_next)
float blender::bbone_segment_bsp_signed_distance (const bPoseChannel_BBoneSegmentBoundary &boundary, const float *co)
static void blender::find_bbone_segment_index_curved (const bke::PChanBoneConst pchanbone, const float *co, int *r_index, float *r_blend_next)
void blender::BKE_pchan_bbone_deform_segment_index (bke::PChanBoneConst pchanbone, const float *co, int *r_index, float *r_blend_next)
Bone Space to Space Conversion API
void blender::BKE_armature_mat_world_to_pose (Object *ob, const float inmat[4][4], float outmat[4][4])
void blender::BKE_armature_loc_world_to_pose (Object *ob, const float inloc[3], float outloc[3])
Bone Matrix Calculation API
void blender::BKE_bone_offset_matrix_get (const Bone *bone, float offs_bone[4][4])
void blender::BKE_bone_parent_transform_calc_from_pchan (bke::PChanBoneConst pchanbone, BoneParentTransform *r_bpt)
void blender::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 blender::BKE_bone_parent_transform_clear (BoneParentTransform *bpt)
void blender::BKE_bone_parent_transform_invert (BoneParentTransform *bpt)
void blender::BKE_bone_parent_transform_combine (const BoneParentTransform *in1, const BoneParentTransform *in2, BoneParentTransform *result)
void blender::BKE_bone_parent_transform_apply (const BoneParentTransform *bpt, const float inmat[4][4], float outmat[4][4])
void blender::BKE_armature_mat_pose_to_bone (bke::PChanBoneConst pchanbone, const float inmat[4][4], float outmat[4][4])
void blender::BKE_armature_mat_bone_to_pose (bke::PChanBoneConst pchanbone, const float inmat[4][4], float outmat[4][4])
void blender::BKE_armature_loc_pose_to_bone (bke::PChanBoneConst pchanbone, const float inloc[3], float outloc[3])
Bone Matrix Read/Write API

High level functions for transforming bones and reading the transform values.

void blender::BKE_armature_mat_pose_to_bone_ex (Depsgraph *depsgraph, Object *ob, const bPoseChannel *pchan, const float inmat[4][4], float outmat[4][4])
void blender::BKE_pchan_mat3_to_rot (bPoseChannel *pchan, const float mat[3][3], bool use_compat)
void blender::BKE_pchan_rot_to_mat3 (const bPoseChannel *pchan, float r_mat[3][3])
float4 blender::BKE_pchan_rot_to_quat (const bPoseChannel &pchan)
void blender::BKE_pchan_quat_to_rot (bPoseChannel &pchan, const float4 &quat)
void blender::BKE_pchan_apply_mat4 (bPoseChannel *pchan, const float mat[4][4], bool use_compat)
void blender::BKE_armature_mat_pose_to_delta (float delta_mat[4][4], float pose_mat[4][4], float arm_mat[4][4])
Rotation Mode Conversions

Used for Objects and Pose Channels, since both can have multiple rotation representations.

void blender::BKE_rotMode_change_values (float quat[4], float eul[3], float axis[3], float *angle, eRotationModes oldMode, eRotationModes newMode)
Protected Transform Channel Assignment
void blender::BKE_pchan_protected_location_set (bPoseChannel *pchan, const float location[3])
void blender::BKE_pchan_protected_rotation_set (bPoseChannel *pchan, const float mat[3][3])
void blender::BKE_pchan_protected_scale_set (bPoseChannel *pchan, const float scale[3])
void blender::BKE_pchan_protected_rotation_quaternion_set (bPoseChannel *pchan, const float quat[4])
void blender::BKE_pchan_protected_rotation_euler_set (bPoseChannel *pchan, const float rotation_euler[3])
void blender::BKE_pchan_protected_rotation_axisangle_set (bPoseChannel *pchan, const float axis[3], float angle)
Bone Vector, Roll Conversion

Used for Objects and Pose Channels, since both can have multiple rotation representations.

How it Works

This is the bone transformation trick; they're hierarchical so each bone(b) is in the coord system of bone(b-1):

arm_mat(b)= arm_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b)

-> yoffs is just the y axis translation in parent's coord system -> d_root is the translation of the bone root, also in parent's coord system

pose_mat(b)= pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b) * chan_mat(b)

we then - in init deform - store the deform in chan_mat, such that:

pose_mat(b)= arm_mat(b) * chan_mat(b)

void blender::mat3_to_vec_roll (const float mat[3][3], float r_vec[3], float *r_roll)
void blender::mat3_vec_to_roll (const float mat[3][3], const float vec[3], float *r_roll)
void blender::vec_roll_to_mat3_normalized (const float nor[3], float roll, float r_mat[3][3])
Armature Bone Matrix Calculation (Recursive)
void blender::BKE_armature_where_is_bone (Bone *bone, const Bone *bone_parent, bool use_recursion)
void blender::BKE_armature_where_is (bArmature *arm)
Pose Rebuild
static void blender::rebuild_pose_from_armature (Object &pose_ob, const bArmature &armature)
void blender::BKE_pose_clear_pointers (bPose *pose)
static bPoseChannel * blender::pose_channel_find_bone (bPose *pose, Bone *bone)
void blender::BKE_pchan_rebuild_bbone_handles (bPose *pose, bke::PChanBone pchanbone)
void blender::BKE_pose_channels_clear_with_null_bone (Object *armature_ob, bool do_id_user)
void blender::BKE_pose_rebuild (Main *bmain, Object *ob, bArmature *arm, bool do_id_user)
void blender::BKE_pose_ensure (Main *bmain, Object *ob, bArmature *arm, bool do_id_user)
static void blender::rebuild_pose_bone_indices (const Object &pose_ob)
void blender::BKE_pose_ensure_bone_indices (const Object &pose_object)
Pose Solver
void blender::BKE_pchan_to_mat4 (bke::PChanBoneConst pchanbone, float r_chanmat[4][4])
void blender::BKE_pchan_calc_mat (bke::PChanBone pchanbone)
void blender::BKE_pose_where_is_bone_tail (bke::PChanBone pchanbone)
void blender::BKE_pose_where_is_bone (Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan, float ctime, bool do_extra)
void blender::BKE_pose_where_is (Depsgraph *depsgraph, Scene *scene, Object *ob)
Calculate Bounding Box (Armature & Pose)
std::optional< Bounds< float3 > > blender::BKE_armature_min_max (const Object *ob)
void blender::BKE_pchan_minmax (const Object *ob, bke::PChanBoneConst pchanbone, bool use_empty_drawtype, float3 &r_min, float3 &r_max)
std::optional< Bounds< float3 > > blender::BKE_pose_minmax (const Object *ob, bool use_select)
Graph Evaluation
bPoseChannel * blender::BKE_armature_ik_solver_find_root (bPoseChannel *pchan, bKinematicConstraint *data)
bPoseChannel * blender::BKE_armature_splineik_solver_find_root (bPoseChannel *pchan, bSplineIKConstraint *data)

Variables

static CLG_LogRef blender::LOG = {"bke.armature"}