Blender  V2.93
Variables
armature.c File Reference
#include <ctype.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_alloca.h"
#include "BLI_ghash.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
#include "DNA_defaults.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 "BKE_action.h"
#include "BKE_anim_data.h"
#include "BKE_anim_visualization.h"
#include "BKE_armature.h"
#include "BKE_constraint.h"
#include "BKE_curve.h"
#include "BKE_idprop.h"
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_scene.h"
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_query.h"
#include "BIK_api.h"
#include "BLO_read_write.h"
#include "CLG_log.h"

Go to the source code of this file.

Functions

Prototypes
static void copy_bonechildren (Bone *bone_dst, const Bone *bone_src, const Bone *bone_src_act, Bone **r_bone_dst_act, const int flag)
 
static void copy_bonechildren_custom_handles (Bone *bone_dst, bArmature *arm_dst)
 
Generic Data-Level Functions
bArmatureBKE_armature_add (Main *bmain, const char *name)
 
bArmatureBKE_armature_from_object (Object *ob)
 
int BKE_armature_bonelist_count (ListBase *lb)
 
void BKE_armature_bonelist_free (ListBase *lb, const bool do_id_user)
 
void BKE_armature_editbonelist_free (ListBase *lb, const bool do_id_user)
 
Armature Transform Copy
static void copy_bone_transform (Bone *bone_dst, const Bone *bone_src)
 
void 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 armature_transform_recurse (ListBase *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 BKE_armature_transform (bArmature *arm, const float mat[4][4], const bool do_props)
 
Armature Bone Find by Name

Using fast GHash lookups when available.

static Boneget_named_bone_bonechildren (ListBase *lb, const char *name)
 
BoneBKE_armature_find_bone_name (bArmature *arm, const char *name)
 
static void armature_bone_from_name_insert_recursive (GHash *bone_hash, ListBase *lb)
 
static GHasharmature_bone_from_name_map (bArmature *arm)
 
void BKE_armature_bone_hash_make (bArmature *arm)
 
void BKE_armature_bone_hash_free (bArmature *arm)
 
Armature Bone Flags
bool BKE_armature_bone_flag_test_recursive (const Bone *bone, int flag)
 
Armature Layer Refresh Used
static void armature_refresh_layer_used_recursive (bArmature *arm, ListBase *bones)
 
void BKE_armature_refresh_layer_used (struct Depsgraph *depsgraph, struct bArmature *arm)
 
bool bone_autoside_name (char name[MAXBONENAME], int UNUSED(strip_number), short axis, float head, float tail)
 
Armature B-Bone Support
static void equalize_cubic_bezier (const float control[4][3], int temp_segments, int final_segments, float *r_t_points)
 
static void evaluate_cubic_bezier (const float control[4][3], float t, float r_pos[3], float r_tangent[3])
 
void BKE_pchan_bbone_handles_get (bPoseChannel *pchan, bPoseChannel **r_prev, bPoseChannel **r_next)
 
void BKE_pchan_bbone_spline_params_get (struct bPoseChannel *pchan, const bool rest, struct BBoneSplineParameters *param)
 
void BKE_pchan_bbone_spline_setup (bPoseChannel *pchan, const bool rest, const bool for_deform, Mat4 *result_array)
 
void 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 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 scaley, float result[4][4])
 
static void ease_handle_axis (const float deriv1[3], const float deriv2[3], float r_axis[3])
 
int BKE_pchan_bbone_spline_compute (BBoneSplineParameters *param, const bool for_deform, Mat4 *result_array)
 
static void allocate_bbone_cache (bPoseChannel *pchan, int segments)
 
void BKE_pchan_bbone_segments_cache_compute (bPoseChannel *pchan)
 
void BKE_pchan_bbone_segments_cache_copy (bPoseChannel *pchan, bPoseChannel *pchan_from)
 
void BKE_pchan_bbone_deform_segment_index (const bPoseChannel *pchan, float pos, int *r_index, float *r_blend_next)
 
Bone Space to Space Conversion API
void BKE_armature_mat_world_to_pose (Object *ob, const float inmat[4][4], float outmat[4][4])
 
void BKE_armature_loc_world_to_pose (Object *ob, const float inloc[3], float outloc[3])
 
Bone Matrix Calculation API
void BKE_bone_offset_matrix_get (const Bone *bone, float offs_bone[4][4])
 
void BKE_bone_parent_transform_calc_from_pchan (const bPoseChannel *pchan, BoneParentTransform *r_bpt)
 
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 BKE_bone_parent_transform_clear (struct BoneParentTransform *bpt)
 
void BKE_bone_parent_transform_invert (struct BoneParentTransform *bpt)
 
void BKE_bone_parent_transform_combine (const struct BoneParentTransform *in1, const struct BoneParentTransform *in2, struct BoneParentTransform *result)
 
void BKE_bone_parent_transform_apply (const struct BoneParentTransform *bpt, const float inmat[4][4], float outmat[4][4])
 
void BKE_armature_mat_pose_to_bone (bPoseChannel *pchan, const float inmat[4][4], float outmat[4][4])
 
void BKE_armature_mat_bone_to_pose (bPoseChannel *pchan, const float inmat[4][4], float outmat[4][4])
 
void BKE_armature_loc_pose_to_bone (bPoseChannel *pchan, const float inloc[3], float outloc[3])
 
Bone Matrix Read/Write API

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

void BKE_armature_mat_pose_to_bone_ex (struct Depsgraph *depsgraph, Object *ob, bPoseChannel *pchan, const float inmat[4][4], float outmat[4][4])
 
void BKE_pchan_mat3_to_rot (bPoseChannel *pchan, const float mat[3][3], bool use_compat)
 
void BKE_pchan_rot_to_mat3 (const bPoseChannel *pchan, float r_mat[3][3])
 
void BKE_pchan_apply_mat4 (bPoseChannel *pchan, const float mat[4][4], bool use_compat)
 
void 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 BKE_rotMode_change_values (float quat[4], float eul[3], float axis[3], float *angle, short oldMode, short newMode)
 
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 mat3_to_vec_roll (const float mat[3][3], float r_vec[3], float *r_roll)
 
void mat3_vec_to_roll (const float mat[3][3], const float vec[3], float *r_roll)
 
void vec_roll_to_mat3_normalized (const float nor[3], const float roll, float r_mat[3][3])
 
void vec_roll_to_mat3 (const float vec[3], const float roll, float r_mat[3][3])
 
Armature Bone Matrix Calculation (Recursive)
void BKE_armature_where_is_bone (Bone *bone, const Bone *bone_parent, const bool use_recursion)
 
void BKE_armature_where_is (bArmature *arm)
 
Pose Rebuild
static void pose_proxy_sync (Object *ob, Object *from, int layer_protected)
 
static int rebuild_pose_bone (bPose *pose, Bone *bone, bPoseChannel *parchan, int counter, Bone **r_last_visited_bone_p)
 
void BKE_pose_clear_pointers (bPose *pose)
 
void BKE_pose_remap_bone_pointers (bArmature *armature, bPose *pose)
 
static bPoseChannelpose_channel_find_bone (bPose *pose, Bone *bone)
 
void BKE_pchan_rebuild_bbone_handles (bPose *pose, bPoseChannel *pchan)
 
void BKE_pose_channels_clear_with_null_bone (bPose *pose, const bool do_id_user)
 
void BKE_pose_rebuild (Main *bmain, Object *ob, bArmature *arm, const bool do_id_user)
 
void BKE_pose_ensure (Main *bmain, Object *ob, bArmature *arm, const bool do_id_user)
 
Pose Solver
void BKE_pchan_to_mat4 (const bPoseChannel *pchan, float r_chanmat[4][4])
 
void BKE_pchan_calc_mat (bPoseChannel *pchan)
 
void BKE_pose_where_is_bone_tail (bPoseChannel *pchan)
 
void BKE_pose_where_is_bone (struct Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan, float ctime, bool do_extra)
 
void BKE_pose_where_is (struct Depsgraph *depsgraph, Scene *scene, Object *ob)
 
Calculate Bounding Box (Armature & Pose)
static int minmax_armature (Object *ob, float r_min[3], float r_max[3])
 
static void boundbox_armature (Object *ob)
 
BoundBoxBKE_armature_boundbox_get (Object *ob)
 
bool BKE_pose_minmax (Object *ob, float r_min[3], float r_max[3], bool use_hidden, bool use_select)
 
Graph Evaluation
bPoseChannelBKE_armature_ik_solver_find_root (bPoseChannel *pchan, bKinematicConstraint *data)
 
bPoseChannelBKE_armature_splineik_solver_find_root (bPoseChannel *pchan, bSplineIKConstraint *data)
 

Variables

static CLG_LogRef LOG = {"bke.armature"}
 

Armature Data-block

IDTypeInfo IDType_ID_AR
 
static void armature_init_data (ID *id)
 
static void armature_copy_data (Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag)
 
static void armature_free_data (struct ID *id)
 
static void armature_foreach_id_bone (Bone *bone, LibraryForeachIDData *data)
 
static void armature_foreach_id_editbone (EditBone *edit_bone, LibraryForeachIDData *data)
 
static void armature_foreach_id (ID *id, LibraryForeachIDData *data)
 
static void write_bone (BlendWriter *writer, Bone *bone)
 
static void armature_blend_write (BlendWriter *writer, ID *id, const void *id_address)
 
static void direct_link_bones (BlendDataReader *reader, Bone *bone)
 
static void armature_blend_read_data (BlendDataReader *reader, ID *id)
 
static void lib_link_bones (BlendLibReader *reader, Bone *bone)
 
static void armature_blend_read_lib (BlendLibReader *reader, ID *id)
 
static void expand_bones (BlendExpander *expander, Bone *bone)
 
static void armature_blend_read_expand (BlendExpander *expander, ID *id)
 

Function Documentation

◆ allocate_bbone_cache()

static void allocate_bbone_cache ( bPoseChannel pchan,
int  segments 
)
static

◆ armature_blend_read_data()

static void armature_blend_read_data ( BlendDataReader reader,
ID id 
)
static

◆ armature_blend_read_expand()

static void armature_blend_read_expand ( BlendExpander expander,
ID id 
)
static

Definition at line 303 of file armature.c.

References bArmature::bonebase, expand_bones(), and LISTBASE_FOREACH.

◆ armature_blend_read_lib()

static void armature_blend_read_lib ( BlendLibReader reader,
ID id 
)
static

Definition at line 286 of file armature.c.

References bArmature::bonebase, lib_link_bones(), and LISTBASE_FOREACH.

◆ armature_blend_write()

static void armature_blend_write ( BlendWriter writer,
ID id,
const void *  id_address 
)
static

◆ armature_bone_from_name_insert_recursive()

static void armature_bone_from_name_insert_recursive ( GHash bone_hash,
ListBase lb 
)
static

Definition at line 622 of file armature.c.

References BLI_ghash_insert(), and LISTBASE_FOREACH.

Referenced by armature_bone_from_name_map().

◆ armature_bone_from_name_map()

static GHash* armature_bone_from_name_map ( bArmature arm)
static

Create a (name -> bone) map.

Note
typically bPose.chanhash us used via BKE_pose_channel_find_name this is for the cases we can't use pose channels.

Definition at line 636 of file armature.c.

References armature_bone_from_name_insert_recursive(), BKE_armature_bonelist_count(), BLI_ghash_str_new_ex(), and bArmature::bonebase.

Referenced by BKE_armature_bone_hash_make().

◆ armature_copy_data()

static void armature_copy_data ( Main UNUSEDbmain,
ID id_dst,
const ID id_src,
const int  flag 
)
static

Only copy internal data of Armature ID from source to already allocated/initialized destination. You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs.

WARNING! This function will not handle ID user count!

Parameters
flagCopying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more).

Definition at line 110 of file armature.c.

References bArmature::act_bone, bArmature::act_edbone, BKE_armature_bone_hash_make(), BLI_duplicatelist(), bArmature::bonebase, bArmature::bonehash, copy_bonechildren(), copy_bonechildren_custom_handles(), bArmature::edbo, ListBase::first, LIB_ID_CREATE_NO_USER_REFCOUNT, Bone::next, NULL, and Bone::parent.

◆ armature_foreach_id()

static void armature_foreach_id ( ID id,
LibraryForeachIDData data 
)
static

◆ armature_foreach_id_bone()

static void armature_foreach_id_bone ( Bone bone,
LibraryForeachIDData data 
)
static

◆ armature_foreach_id_editbone()

static void armature_foreach_id_editbone ( EditBone edit_bone,
LibraryForeachIDData data 
)
static

◆ armature_free_data()

static void armature_free_data ( struct ID id)
static

Free (or release) any data used by this armature (does not free the armature itself).

Definition at line 147 of file armature.c.

References BKE_armature_bone_hash_free(), BKE_armature_bonelist_free(), BKE_armature_editbonelist_free(), bArmature::bonebase, bArmature::edbo, MEM_freeN, and NULL.

◆ armature_init_data()

static void armature_init_data ( ID id)
static

◆ armature_refresh_layer_used_recursive()

static void armature_refresh_layer_used_recursive ( bArmature arm,
ListBase bones 
)
static

Definition at line 682 of file armature.c.

References bArmature::layer_used, and LISTBASE_FOREACH.

Referenced by BKE_armature_refresh_layer_used().

◆ armature_transform_recurse()

static void armature_transform_recurse ( ListBase 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] 
)
static

◆ BKE_armature_add()

bArmature* BKE_armature_add ( Main bmain,
const char *  name 
)

Definition at line 345 of file armature.c.

References BKE_id_new(), and ID_AR.

Referenced by BKE_object_obdata_add_from_type().

◆ BKE_armature_bone_flag_test_recursive()

bool BKE_armature_bone_flag_test_recursive ( const Bone bone,
int  flag 
)

Definition at line 665 of file armature.c.

References Bone::flag, and Bone::parent.

◆ BKE_armature_bone_hash_free()

void BKE_armature_bone_hash_free ( bArmature arm)

Definition at line 651 of file armature.c.

References BLI_ghash_free(), bArmature::bonehash, and NULL.

Referenced by armature_free_data(), and ED_armature_from_edit().

◆ BKE_armature_bone_hash_make()

void BKE_armature_bone_hash_make ( bArmature arm)

◆ BKE_armature_bonelist_count()

int BKE_armature_bonelist_count ( ListBase lb)

◆ BKE_armature_bonelist_free()

void BKE_armature_bonelist_free ( ListBase lb,
const bool  do_id_user 
)

◆ BKE_armature_boundbox_get()

BoundBox* BKE_armature_boundbox_get ( Object ob)

Definition at line 2858 of file armature.c.

References Object_Runtime::bb, boundbox_armature(), and Object::runtime.

Referenced by BKE_object_boundbox_get(), and snapArmature().

◆ BKE_armature_copy_bone_transforms()

void BKE_armature_copy_bone_transforms ( bArmature armature_dst,
const bArmature armature_src 
)

◆ BKE_armature_editbonelist_free()

void BKE_armature_editbonelist_free ( ListBase lb,
const bool  do_id_user 
)

Definition at line 385 of file armature.c.

References BLI_remlink_safe(), IDP_FreeProperty_ex(), LISTBASE_FOREACH_MUTABLE, and MEM_freeN.

Referenced by armature_free_data().

◆ BKE_armature_find_bone_name()

Bone* BKE_armature_find_bone_name ( bArmature arm,
const char *  name 
)

◆ BKE_armature_from_object()

bArmature* BKE_armature_from_object ( Object ob)

◆ BKE_armature_ik_solver_find_root()

bPoseChannel* BKE_armature_ik_solver_find_root ( bPoseChannel pchan,
bKinematicConstraint data 
)

◆ BKE_armature_loc_pose_to_bone()

void BKE_armature_loc_pose_to_bone ( bPoseChannel pchan,
const float  inloc[3],
float  outloc[3] 
)

◆ BKE_armature_loc_world_to_pose()

void BKE_armature_loc_world_to_pose ( Object ob,
const float  inloc[3],
float  outloc[3] 
)

Definition at line 1555 of file armature.c.

References BKE_armature_mat_world_to_pose(), copy_v3_v3(), and unit_m4().

◆ BKE_armature_mat_bone_to_pose()

void BKE_armature_mat_bone_to_pose ( bPoseChannel pchan,
const float  inmat[4][4],
float  outmat[4][4] 
)

◆ BKE_armature_mat_pose_to_bone()

void BKE_armature_mat_pose_to_bone ( bPoseChannel pchan,
const float  inmat[4][4],
float  outmat[4][4] 
)

◆ BKE_armature_mat_pose_to_bone_ex()

void BKE_armature_mat_pose_to_bone_ex ( struct Depsgraph depsgraph,
Object ob,
bPoseChannel pchan,
const float  inmat[4][4],
float  outmat[4][4] 
)

◆ BKE_armature_mat_pose_to_delta()

void BKE_armature_mat_pose_to_delta ( float  delta_mat[4][4],
float  pose_mat[4][4],
float  arm_mat[4][4] 
)

Remove rest-position effects from pose-transform for obtaining 'visual' transformation of pose-channel. (used by the Visual-Keyframing stuff).

Definition at line 1963 of file armature.c.

References invert_m4_m4(), and mul_m4_m4m4().

◆ BKE_armature_mat_world_to_pose()

void BKE_armature_mat_world_to_pose ( Object ob,
const float  inmat[4][4],
float  outmat[4][4] 
)

Definition at line 1536 of file armature.c.

References invert_m4_m4(), mul_m4_m4m4(), NULL, and Object::obmat.

Referenced by BKE_armature_loc_world_to_pose().

◆ BKE_armature_refresh_layer_used()

void BKE_armature_refresh_layer_used ( struct Depsgraph depsgraph,
struct bArmature arm 
)

◆ BKE_armature_splineik_solver_find_root()

bPoseChannel* BKE_armature_splineik_solver_find_root ( bPoseChannel pchan,
bSplineIKConstraint data 
)

◆ BKE_armature_transform()

void BKE_armature_transform ( bArmature arm,
const float  mat[4][4],
const bool  do_props 
)

◆ BKE_armature_where_is()

void BKE_armature_where_is ( bArmature arm)

◆ BKE_armature_where_is_bone()

void BKE_armature_where_is_bone ( Bone bone,
const Bone bone_parent,
const bool  use_recursion 
)

Recursive part, calculates rest-position of entire tree of children.

Note
Used when exiting edit-mode too.

Definition at line 2230 of file armature.c.

References Bone::arm_mat, BKE_bone_offset_matrix_get(), Bone::bone_mat, Bone::childbase, copy_m4_m3(), copy_v3_v3(), ListBase::first, Bone::head, len_v3(), Bone::length, mul_m4_m4m4(), Bone::next, Bone::roll, Bone::segments, sub_v3_v3v3(), Bone::tail, vec_roll_to_mat3(), Bone::xwidth, and Bone::zwidth.

Referenced by armature_transform_recurse(), and BKE_armature_where_is().

◆ BKE_bone_offset_matrix_get()

void BKE_bone_offset_matrix_get ( const Bone bone,
float  offs_bone[4][4] 
)

◆ BKE_bone_parent_transform_apply()

void BKE_bone_parent_transform_apply ( const struct BoneParentTransform bpt,
const float  inmat[4][4],
float  outmat[4][4] 
)

◆ BKE_bone_parent_transform_calc_from_matrices()

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 
)

◆ BKE_bone_parent_transform_calc_from_pchan()

void BKE_bone_parent_transform_calc_from_pchan ( const bPoseChannel pchan,
BoneParentTransform r_bpt 
)

◆ BKE_bone_parent_transform_clear()

void BKE_bone_parent_transform_clear ( struct BoneParentTransform bpt)

◆ BKE_bone_parent_transform_combine()

void BKE_bone_parent_transform_combine ( const struct BoneParentTransform in1,
const struct BoneParentTransform in2,
struct BoneParentTransform result 
)

◆ BKE_bone_parent_transform_invert()

void BKE_bone_parent_transform_invert ( struct BoneParentTransform bpt)

◆ BKE_pchan_apply_mat4()

void BKE_pchan_apply_mat4 ( bPoseChannel pchan,
const float  mat[4][4],
bool  use_compat 
)

◆ BKE_pchan_bbone_deform_segment_index()

void BKE_pchan_bbone_deform_segment_index ( const bPoseChannel pchan,
float  pos,
int *  r_index,
float r_blend_next 
)

Calculate index and blend factor for the two B-Bone segment nodes affecting the point at 0 <= pos <= 1.

Definition at line 1504 of file armature.c.

References blend(), bPoseChannel::bone, CLAMP, float(), floorf, pos, and Bone::segments.

◆ BKE_pchan_bbone_handles_compute()

void BKE_pchan_bbone_handles_compute ( const BBoneSplineParameters param,
float  h1[3],
float r_roll1,
float  h2[3],
float r_roll2,
bool  ease,
bool  offsets 
)

◆ BKE_pchan_bbone_handles_get()

void BKE_pchan_bbone_handles_get ( bPoseChannel pchan,
bPoseChannel **  r_prev,
bPoseChannel **  r_next 
)

◆ BKE_pchan_bbone_segments_cache_compute()

void BKE_pchan_bbone_segments_cache_compute ( bPoseChannel pchan)

◆ BKE_pchan_bbone_segments_cache_copy()

void BKE_pchan_bbone_segments_cache_copy ( bPoseChannel pchan,
bPoseChannel pchan_from 
)

◆ BKE_pchan_bbone_spline_compute()

int BKE_pchan_bbone_spline_compute ( BBoneSplineParameters param,
const bool  for_deform,
Mat4 result_array 
)

◆ BKE_pchan_bbone_spline_params_get()

void BKE_pchan_bbone_spline_params_get ( struct bPoseChannel pchan,
const bool  rest,
struct BBoneSplineParameters param 
)

Definition at line 948 of file armature.c.

References add_v3_v3v3(), Bone::arm_head, Bone::arm_mat, Bone::arm_tail, BBONE_HANDLE_RELATIVE, BBONE_HANDLE_TANGENT, Bone::bbone_next_type, Bone::bbone_prev_type, BKE_pchan_bbone_handles_get(), bPoseChannel::bone, BONE_ADD_PARENT_END_ROLL, copy_m4_m4(), copy_v3_fl3(), copy_v3_v3(), BBoneSplineParameters::curve_in_x, bPoseChannel::curve_in_x, Bone::curve_in_x, BBoneSplineParameters::curve_in_y, bPoseChannel::curve_in_y, Bone::curve_in_y, BBoneSplineParameters::curve_out_x, bPoseChannel::curve_out_x, Bone::curve_out_x, BBoneSplineParameters::curve_out_y, bPoseChannel::curve_out_y, Bone::curve_out_y, BBoneSplineParameters::do_scale, BBoneSplineParameters::ease1, bPoseChannel::ease1, Bone::ease1, BBoneSplineParameters::ease2, bPoseChannel::ease2, Bone::ease2, fabsf, Bone::flag, invert_m4_m4(), BBoneSplineParameters::length, Bone::length, mat4_to_size(), mul_m4_m4m4(), mul_v3_m4v3(), next, BBoneSplineParameters::next_bbone, BBoneSplineParameters::next_h, BBoneSplineParameters::next_mat, normalize_m4(), bPoseChannel::pose_head, bPoseChannel::pose_mat, bPoseChannel::pose_tail, BBoneSplineParameters::prev_bbone, BBoneSplineParameters::prev_h, BBoneSplineParameters::prev_mat, BBoneSplineParameters::roll1, bPoseChannel::roll1, Bone::roll1, BBoneSplineParameters::roll2, bPoseChannel::roll2, Bone::roll2, BBoneSplineParameters::scale, BBoneSplineParameters::scale_in_x, bPoseChannel::scale_in_x, Bone::scale_in_x, BBoneSplineParameters::scale_in_y, bPoseChannel::scale_in_y, Bone::scale_in_y, BBoneSplineParameters::scale_out_x, bPoseChannel::scale_out_x, Bone::scale_out_x, BBoneSplineParameters::scale_out_y, bPoseChannel::scale_out_y, Bone::scale_out_y, BBoneSplineParameters::segments, Bone::segments, sub_v3_v3v3(), BBoneSplineParameters::use_next, BBoneSplineParameters::use_prev, and zero_v3().

Referenced by BKE_pchan_bbone_spline_setup().

◆ BKE_pchan_bbone_spline_setup()

void BKE_pchan_bbone_spline_setup ( bPoseChannel pchan,
const bool  rest,
const bool  for_deform,
Mat4 result_array 
)

◆ BKE_pchan_calc_mat()

void BKE_pchan_calc_mat ( bPoseChannel pchan)

Definition at line 2651 of file armature.c.

References BKE_pchan_to_mat4(), and bPoseChannel::chan_mat.

Referenced by actcon_get_tarmat(), and BKE_pose_where_is_bone().

◆ BKE_pchan_mat3_to_rot()

void BKE_pchan_mat3_to_rot ( bPoseChannel pchan,
const float  mat[3][3],
bool  use_compat 
)

◆ BKE_pchan_rebuild_bbone_handles()

void BKE_pchan_rebuild_bbone_handles ( bPose pose,
bPoseChannel pchan 
)

Update the links for the B-Bone handles from Bone data.

Definition at line 2512 of file armature.c.

References bPoseChannel::bbone_next, Bone::bbone_next, bPoseChannel::bbone_prev, Bone::bbone_prev, bPoseChannel::bone, and pose_channel_find_bone().

Referenced by BKE_pose_rebuild().

◆ BKE_pchan_rot_to_mat3()

void BKE_pchan_rot_to_mat3 ( const bPoseChannel pchan,
float  r_mat[3][3] 
)

◆ BKE_pchan_to_mat4()

void BKE_pchan_to_mat4 ( const bPoseChannel pchan,
float  r_chanmat[4][4] 
)

◆ BKE_pose_channels_clear_with_null_bone()

void BKE_pose_channels_clear_with_null_bone ( bPose pose,
const bool  do_id_user 
)

◆ BKE_pose_clear_pointers()

void BKE_pose_clear_pointers ( bPose pose)

Clear pointers of object's pose (needed in remap case, since we cannot always wait for a complete pose rebuild).

Definition at line 2490 of file armature.c.

References bPose::chanbase, LISTBASE_FOREACH, and NULL.

Referenced by BKE_lib_override_library_update(), BKE_pose_rebuild(), and libblock_remap_data_preprocess().

◆ BKE_pose_ensure()

void BKE_pose_ensure ( Main bmain,
Object ob,
bArmature arm,
const bool  do_id_user 
)

◆ BKE_pose_minmax()

bool BKE_pose_minmax ( Object ob,
float  r_min[3],
float  r_max[3],
bool  use_hidden,
bool  use_select 
)

◆ BKE_pose_rebuild()

void BKE_pose_rebuild ( Main bmain,
Object ob,
bArmature arm,
const bool  do_id_user 
)

◆ BKE_pose_remap_bone_pointers()

void BKE_pose_remap_bone_pointers ( bArmature armature,
bPose pose 
)

Definition at line 2498 of file armature.c.

References BKE_armature_find_bone_name(), bPose::chanbase, and LISTBASE_FOREACH.

◆ BKE_pose_where_is()

void BKE_pose_where_is ( struct Depsgraph depsgraph,
Scene scene,
Object ob 
)

◆ BKE_pose_where_is_bone()

void BKE_pose_where_is_bone ( struct Depsgraph depsgraph,
Scene scene,
Object ob,
bPoseChannel pchan,
float  ctime,
bool  do_extra 
)

◆ BKE_pose_where_is_bone_tail()

void BKE_pose_where_is_bone_tail ( bPoseChannel pchan)

◆ BKE_rotMode_change_values()

void BKE_rotMode_change_values ( float  quat[4],
float  eul[3],
float  axis[3],
float angle,
short  oldMode,
short  newMode 
)

◆ bone_autoside_name()

bool bone_autoside_name ( char  name[MAXBONENAME],
int   UNUSEDstrip_number,
short  axis,
float  head,
float  tail 
)

Definition at line 717 of file armature.c.

References basename(), BLI_snprintf(), BLI_strncpy(), ELEM, IS_EQF, len, and MAXBONENAME.

◆ boundbox_armature()

static void boundbox_armature ( Object ob)
static

◆ copy_bone_transform()

static void copy_bone_transform ( Bone bone_dst,
const Bone bone_src 
)
static

◆ copy_bonechildren()

static void copy_bonechildren ( Bone bone_dst,
const Bone bone_src,
const Bone bone_src_act,
Bone **  r_bone_dst_act,
const int  flag 
)
static

◆ copy_bonechildren_custom_handles()

static void copy_bonechildren_custom_handles ( Bone bone_dst,
bArmature arm_dst 
)
static

◆ direct_link_bones()

static void direct_link_bones ( BlendDataReader reader,
Bone bone 
)
static

◆ ease_handle_axis()

static void ease_handle_axis ( const float  deriv1[3],
const float  deriv2[3],
float  r_axis[3] 
)
static

Definition at line 1290 of file armature.c.

References copy_v3_v3(), len_squared_v3(), madd_v3_v3fl(), and sqrtf.

Referenced by BKE_pchan_bbone_spline_compute().

◆ equalize_cubic_bezier()

static void equalize_cubic_bezier ( const float  control[4][3],
int  temp_segments,
int  final_segments,
float r_t_points 
)
static

◆ evaluate_cubic_bezier()

static void evaluate_cubic_bezier ( const float  control[4][3],
float  t,
float  r_pos[3],
float  r_tangent[3] 
)
static

Definition at line 902 of file armature.c.

References interp_v3_v3v3(), madd_v3_v3v3fl(), sub_v3_v3v3(), and t.

Referenced by BKE_pchan_bbone_spline_compute().

◆ expand_bones()

static void expand_bones ( BlendExpander expander,
Bone bone 
)
static

Definition at line 294 of file armature.c.

References Bone::childbase, IDP_BlendReadExpand(), LISTBASE_FOREACH, and Bone::prop.

Referenced by armature_blend_read_expand().

◆ get_named_bone_bonechildren()

static Bone* get_named_bone_bonechildren ( ListBase lb,
const char *  name 
)
static

Definition at line 587 of file armature.c.

References Bone::childbase, ListBase::first, Bone::name, Bone::next, NULL, and STREQ.

Referenced by BKE_armature_find_bone_name().

◆ lib_link_bones()

static void lib_link_bones ( BlendLibReader reader,
Bone bone 
)
static

Definition at line 277 of file armature.c.

References Bone::childbase, IDP_BlendReadLib(), LISTBASE_FOREACH, and Bone::prop.

Referenced by armature_blend_read_lib().

◆ make_bbone_spline_matrix()

static void 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  scaley,
float  result[4][4] 
)
static

◆ mat3_to_vec_roll()

void mat3_to_vec_roll ( const float  mat[3][3],
float  r_vec[3],
float r_roll 
)

◆ mat3_vec_to_roll()

void mat3_vec_to_roll ( const float  mat[3][3],
const float  vec[3],
float r_roll 
)

◆ minmax_armature()

static int minmax_armature ( Object ob,
float  r_min[3],
float  r_max[3] 
)
static

◆ pose_channel_find_bone()

static bPoseChannel* pose_channel_find_bone ( bPose pose,
Bone bone 
)
static

Find the matching pose channel using the bone name, if not NULL.

Definition at line 2506 of file armature.c.

References BKE_pose_channel_find_name(), Bone::name, and NULL.

Referenced by BKE_pchan_rebuild_bbone_handles().

◆ pose_proxy_sync()

static void pose_proxy_sync ( Object ob,
Object from,
int  layer_protected 
)
static

◆ rebuild_pose_bone()

static int rebuild_pose_bone ( bPose pose,
Bone bone,
bPoseChannel parchan,
int  counter,
Bone **  r_last_visited_bone_p 
)
static

◆ vec_roll_to_mat3()

void vec_roll_to_mat3 ( const float  vec[3],
const float  roll,
float  r_mat[3][3] 
)

◆ vec_roll_to_mat3_normalized()

void vec_roll_to_mat3_normalized ( const float  nor[3],
const float  roll,
float  r_mat[3][3] 
)

Given v = (v.x, v.y, v.z) our (normalized) bone vector, we want the rotation matrix M from the Y axis (so that M * (0, 1, 0) = v).

  • The rotation axis a lays on XZ plane, and it is orthonormal to v, hence to the projection of v onto XZ plane.
  • a = (v.z, 0, -v.x)

We know a is eigenvector of M (so M * a = a). Finally, we have w, such that M * w = (0, 1, 0) (i.e. the vector that will be aligned with Y axis once transformed). We know w is symmetric to v by the Y axis.

  • w = (-v.x, v.y, -v.z)

Solving this, we get (x, y and z being the components of v):

    ┌ (x^2 * y + z^2) / (x^2 + z^2),   x,   x * z * (y - 1) / (x^2 + z^2) ┐
M = │  x * (y^2 - 1)  / (x^2 + z^2),   y,    z * (y^2 - 1)  / (x^2 + z^2) │
    └ x * z * (y - 1) / (x^2 + z^2),   z,   (x^2 + z^2 * y) / (x^2 + z^2) ┘

This is stable as long as v (the bone) is not too much aligned with +/-Y (i.e. x and z components are not too close to 0).

Since v is normalized, we have x^2 + y^2 + z^2 = 1, hence x^2 + z^2 = 1 - y^2 = (1 - y)(1 + y).

This allows to simplifies M like this:

    ┌ 1 - x^2 / (1 + y),   x,     -x * z / (1 + y) ┐
M = │                -x,   y,                   -z │
    └  -x * z / (1 + y),   z,    1 - z^2 / (1 + y) ┘

Written this way, we see the case v = +Y is no more a singularity. The only one remaining is the bone being aligned with -Y.

Let's handle the asymptotic behavior when bone vector is reaching the limit of y = -1. Each of the four corner elements can vary from -1 to 1, depending on the axis a chosen for doing the rotation. And the "rotation" here is in fact established by mirroring XZ plane by that given axis, then inversing the Y-axis. For sufficiently small x and z, and with y approaching -1, all elements but the four corner ones of M will degenerate. So let's now focus on these corner elements.

We rewrite M so that it only contains its four corner elements, and combine the 1 / (1 + y) factor:

                   ┌ 1 + y - x^2,        -x * z ┐
M* = 1 / (1 + y) * │                            │
                   └      -x * z,   1 + y - z^2 ┘

When y is close to -1, computing 1 / (1 + y) will cause severe numerical instability, so we ignore it and normalize M instead. We know y^2 = 1 - (x^2 + z^2), and y < 0, hence y = -sqrt(1 - (x^2 + z^2)).

Since x and z are both close to 0, we apply the binomial expansion to the first order: y = -sqrt(1 - (x^2 + z^2)) = -1 + (x^2 + z^2) / 2. Which gives:

                       ┌  z^2 - x^2,  -2 * x * z ┐
M* = 1 / (x^2 + z^2) * │                         │
                       └ -2 * x * z,   x^2 - z^2 ┘

Definition at line 2155 of file armature.c.

References axis_angle_normalized_to_mat3(), BLI_ASSERT_UNIT_V3, mul_m3_m3m3(), nor, unit_m3(), x, y, and z.

Referenced by ED_armature_ebone_roll_to_vector(), ED_armature_ebone_to_mat3(), blender::bke::tests::TEST(), and vec_roll_to_mat3().

◆ write_bone()

static void write_bone ( BlendWriter writer,
Bone bone 
)
static

Variable Documentation

◆ IDType_ID_AR

IDTypeInfo IDType_ID_AR
Initial value:
= {
.id_code = ID_AR,
.id_filter = FILTER_ID_AR,
.main_listbase_index = INDEX_ID_AR,
.struct_size = sizeof(bArmature),
.name = "Armature",
.name_plural = "armatures",
.translation_context = BLT_I18NCONTEXT_ID_ARMATURE,
.flags = 0,
.copy_data = armature_copy_data,
.free_data = armature_free_data,
.make_local = NULL,
.foreach_id = armature_foreach_id,
.foreach_cache = NULL,
.owner_get = NULL,
.blend_write = armature_blend_write,
.blend_read_data = armature_blend_read_data,
.blend_read_lib = armature_blend_read_lib,
.blend_read_expand = armature_blend_read_expand,
.blend_read_undo_preserve = NULL,
.lib_override_apply_post = NULL,
}
#define BLT_I18NCONTEXT_ID_ARMATURE
#define FILTER_ID_AR
Definition: DNA_ID.h:706
@ INDEX_ID_AR
Definition: DNA_ID.h:826
@ ID_AR
Definition: DNA_ID_enums.h:78
struct bArmature bArmature
static void init_data(ModifierData *md)
static void armature_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag)
Definition: armature.c:110
static void armature_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition: armature.c:212
static void armature_blend_read_lib(BlendLibReader *reader, ID *id)
Definition: armature.c:286
static void armature_free_data(struct ID *id)
Definition: armature.c:147
static void armature_foreach_id(ID *id, LibraryForeachIDData *data)
Definition: armature.c:178
static void armature_init_data(ID *id)
Definition: armature.c:92
static void armature_blend_read_data(BlendDataReader *reader, ID *id)
Definition: armature.c:255
static void armature_blend_read_expand(BlendExpander *expander, ID *id)
Definition: armature.c:303

Definition at line 311 of file armature.c.

◆ LOG

CLG_LogRef LOG = {"bke.armature"}
static

Definition at line 72 of file armature.c.

Referenced by pose_proxy_sync().