Blender V5.0
BKE_armature.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#include <optional>
12
13#include "BLI_bounds_types.hh"
14#include "BLI_function_ref.hh"
17#include "BLI_set.hh"
18
19#include "DNA_armature_types.h"
20
21struct BMEditMesh;
22struct Bone;
23struct Depsgraph;
24struct IDProperty;
25struct ListBase;
26struct Main;
27struct Mesh;
28struct Object;
29struct PoseTree;
30struct Scene;
31struct bArmature;
32struct bConstraint;
33struct bPose;
34struct bPoseChannel;
35struct MDeformVert;
36
37struct EditBone {
49 char name[/*MAXBONENAME*/ 64];
56 float roll;
57
59 float head[3];
60 float tail[3];
66 int flag;
67 int layer;
68 int drawtype; /* eArmature_Drawtype */
70
71 /* Envelope distance & weight */
72 float dist, weight;
76
77 /* Bendy-Bone parameters */
78 short segments;
79 float roll1, roll2;
82 float ease1, ease2;
83 float scale_in[3], scale_out[3];
84
86 float oldlength;
87
100
101 /* Used for display */
103 float disp_mat[4][4];
105 float disp_tail_mat[4][4];
107 float disp_bbone_mat[/*MAX_BBONE_SUBDIV*/ 32][4][4];
108
111
112 ::BoneColor color; /* MUST be named the same as in bPoseChannel and Bone structs. */
113 ListBase /*BoneCollectionReference*/ bone_collections;
114
115 /* Used to store temporary data */
116 union {
119 void *p;
120 int i;
122};
123
126
127 bConstraint *con; /* the constraint of this target */
128 int tip; /* index of tip pchan in PoseTree */
129};
130
131struct PoseTree {
133
134 int type; /* type of IK that this serves (CONSTRAINT_TYPE_KINEMATIC or ..._SPLINEIK) */
135 int totchannel; /* number of pose channels */
136
137 ListBase targets; /* list of targets of the tree */
138 bPoseChannel **pchan; /* array of pose channels */
139 int *parent; /* and their parents */
140
141 float (*basis_change)[3][3]; /* basis change result from solver */
142 int iterations; /* iterations from the constraint */
143 int stretch; /* disable stretching */
144};
145
146/* Core armature functionality. */
147
148bArmature *BKE_armature_add(Main *bmain, const char *name);
151void BKE_armature_bonelist_free(ListBase *lb, bool do_id_user);
152void BKE_armature_editbonelist_free(ListBase *lb, bool do_id_user);
153
154void BKE_armature_copy_bone_transforms(bArmature *armature_dst, const bArmature *armature_src);
155
156void BKE_armature_transform(bArmature *arm, const float mat[4][4], bool do_props);
157
161std::optional<blender::Bounds<blender::float3>> BKE_armature_min_max(const Object *ob);
162
178void BKE_pchan_minmax(const Object *ob,
179 const bPoseChannel *pchan,
180 const bool use_empty_drawtype,
181 blender::float3 &r_min,
182 blender::float3 &r_max);
195std::optional<blender::Bounds<blender::float3>> BKE_pose_minmax(const Object *ob, bool use_select);
196
205bool bone_autoside_name(char name[64], int strip_number, short axis, float head, float tail);
206
215
218
219bool BKE_armature_bone_flag_test_recursive(const Bone *bone, int flag);
220
224float distfactor_to_bone(const blender::float3 &position,
225 const blender::float3 &head,
226 const blender::float3 &tail,
227 float radius_head,
228 float radius_tail,
229 float falloff_distance);
230
240void BKE_armature_where_is_bone(Bone *bone, const Bone *bone_parent, bool use_recursion);
246void BKE_pose_remap_bone_pointers(bArmature *armature, bPose *pose);
251void BKE_pose_channels_clear_with_null_bone(bPose *pose, bool do_id_user);
259void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, bool do_id_user);
265void BKE_pose_ensure(Main *bmain, Object *ob, bArmature *arm, bool do_id_user);
270void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob);
277void BKE_pose_where_is_bone(Depsgraph *depsgraph,
278 Scene *scene,
279 Object *ob,
280 bPoseChannel *pchan,
281 float ctime,
282 bool do_extra);
287
288void vec_roll_to_mat3(const float vec[3], float roll, float r_mat[3][3]);
289
293void vec_roll_to_mat3_normalized(const float nor[3], float roll, float r_mat[3][3]);
298void mat3_to_vec_roll(const float mat[3][3], float r_vec[3], float *r_roll);
303void mat3_vec_to_roll(const float mat[3][3], const float vec[3], float *r_roll);
304
305/* Common Conversions Between Coordinate Spaces */
306
310void BKE_armature_mat_world_to_pose(Object *ob, const float inmat[4][4], float outmat[4][4]);
316void BKE_armature_loc_world_to_pose(Object *ob, const float inloc[3], float outloc[3]);
323 const float inmat[4][4],
324 float outmat[4][4]);
331 const float inloc[3],
332 float outloc[3]);
337 const float inmat[4][4],
338 float outmat[4][4]);
344void BKE_armature_mat_pose_to_delta(float delta_mat[4][4],
345 float pose_mat[4][4],
346 float arm_mat[4][4]);
347
349 Object *ob,
350 const bPoseChannel *pchan,
351 const float inmat[4][4],
352 float outmat[4][4]);
353
357void BKE_pchan_mat3_to_rot(bPoseChannel *pchan, const float mat[3][3], bool use_compat);
361void BKE_pchan_rot_to_mat3(const bPoseChannel *pchan, float r_mat[3][3]);
366void BKE_pchan_apply_mat4(bPoseChannel *pchan, const float mat[4][4], bool use_compat);
370void BKE_pchan_to_mat4(const bPoseChannel *pchan, float r_chanmat[4][4]);
371
377
382void BKE_bone_offset_matrix_get(const Bone *bone, float offs_bone[4][4]);
383
384/* Transformation inherited from the parent bone. These matrices apply the effects of
385 * HINGE/NO_SCALE/NO_LOCAL_LOCATION options over the pchan loc/rot/scale transformations. */
387 float rotscale_mat[4][4]; /* parent effect on rotation & scale pose channels */
388 float loc_mat[4][4]; /* parent effect on location pose channel */
389 float post_scale[3]; /* additional scale to apply with post-multiply */
390};
391
392/* Matrix-like algebra operations on the transform */
396 const BoneParentTransform *in2,
398
400 const float inmat[4][4],
401 float outmat[4][4]);
402
425 BoneParentTransform *r_bpt);
436 int inherit_scale_mode,
437 const float offs_bone[4][4],
438 const float parent_arm_mat[4][4],
439 const float parent_pose_mat[4][4],
440 BoneParentTransform *r_bpt);
441
450 float quat[4], float eul[3], float axis[3], float *angle, short oldMode, short newMode);
451
452/* B-Bone support */
453#define MAX_BBONE_SUBDIV 32
454
455struct Mat4 {
456 float mat[4][4];
457};
458
461 float length;
462
463 /* Non-uniform scale correction. */
465 float scale[3];
466
467 /* Handle control bone data. */
470
471 float prev_h[3], next_h[3];
472 float prev_mat[4][4], next_mat[4][4];
473
474 /* Control values. */
475 float ease1, ease2;
476 float roll1, roll2;
477 float scale_in[3], scale_out[3];
479};
480
482void BKE_pchan_protected_location_set(bPoseChannel *pchan, const float location[3]);
484void BKE_pchan_protected_scale_set(bPoseChannel *pchan, const float scale[3]);
486void BKE_pchan_protected_rotation_quaternion_set(bPoseChannel *pchan, const float quat[4]);
488void BKE_pchan_protected_rotation_euler_set(bPoseChannel *pchan, const float rotation_euler[3]);
491 const float axis[3],
492 float angle);
493
498 bPoseChannel **r_prev,
499 bPoseChannel **r_next);
504 bool rest,
505 BBoneSplineParameters *param);
506
512 bool rest,
513 bool for_deform,
514 Mat4 *result_array);
515
520 float h1[3],
521 float *r_roll1,
522 float h2[3],
523 float *r_roll2,
524 bool ease,
525 bool offsets);
531 bool for_deform,
532 Mat4 *result_array);
533
542
553 float head_tail,
554 int *r_index,
555 float *r_blend_next);
556
567 const float *co,
568 int *r_index,
569 float *r_blend_next);
570
571/* context.selected_pose_bones */
572#define FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN(_ob, _pchan) \
573 for (bPoseChannel *_pchan = (bPoseChannel *)(_ob)->pose->chanbase.first; _pchan; \
574 _pchan = _pchan->next) \
575 { \
576 if (blender::animrig::bone_is_visible(((bArmature *)(_ob)->data), _pchan) && \
577 ((_pchan)->flag & POSE_SELECTED)) \
578 {
579#define FOREACH_PCHAN_SELECTED_IN_OBJECT_END \
580 } \
581 } \
582 ((void)0)
583/* context.visible_pose_bones */
584#define FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN(_ob, _pchan) \
585 for (bPoseChannel *_pchan = (bPoseChannel *)(_ob)->pose->chanbase.first; _pchan; \
586 _pchan = _pchan->next) \
587 { \
588 if (blender::animrig::bone_is_visible(((bArmature *)(_ob)->data), _pchan)) {
589#define FOREACH_PCHAN_VISIBLE_IN_OBJECT_END \
590 } \
591 } \
592 ((void)0)
593
594/* Evaluation helpers */
596struct bPose;
598
602
603void BKE_pose_splineik_init_tree(Scene *scene, Object *ob, float ctime);
605 Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime);
606
608
609void BKE_pose_eval_init(Depsgraph *depsgraph, Scene *scene, Object *object);
610
611void BKE_pose_eval_init_ik(Depsgraph *depsgraph, Scene *scene, Object *object);
612
613void BKE_pose_eval_bone(Depsgraph *depsgraph, Scene *scene, Object *object, int pchan_index);
614
616 Scene *scene,
617 Object *object,
618 int pchan_index);
619
620void BKE_pose_bone_done(Depsgraph *depsgraph, Object *object, int pchan_index);
621
622void BKE_pose_eval_bbone_segments(Depsgraph *depsgraph, Object *object, int pchan_index);
623
624void BKE_pose_iktree_evaluate(Depsgraph *depsgraph,
625 Scene *scene,
626 Object *object,
627 int rootchan_index);
628
630 Scene *scene,
631 Object *object,
632 int rootchan_index);
633
634void BKE_pose_eval_done(Depsgraph *depsgraph, Object *object);
635
636void BKE_pose_eval_cleanup(Depsgraph *depsgraph, Scene *scene, Object *object);
637
638/* -------------------------------------------------------------------- */
641
642/* Note that we could have a #BKE_armature_deform_coords that doesn't take object data
643 * currently there are no callers for this though. */
644
646 const Object &ob_arm,
647 const Object &ob_target,
648 const ListBase *defbase,
650 std::optional<blender::Span<blender::float3>> vert_coords_prev,
651 std::optional<blender::MutableSpan<blender::float3x3>> vert_deform_mats,
653 int deformflag,
654 blender::StringRefNull defgrp_name);
655
657 const Object &ob_arm,
658 const Object &ob_target,
660 std::optional<blender::Span<blender::float3>> vert_coords_prev,
661 std::optional<blender::MutableSpan<blender::float3x3>> vert_deform_mats,
662 int deformflag,
663 blender::StringRefNull defgrp_name,
664 const Mesh *me_target);
665
667 const Object &ob_arm,
668 const Object &ob_target,
670 std::optional<blender::Span<blender::float3>> vert_coords_prev,
671 std::optional<blender::MutableSpan<blender::float3x3>> vert_deform_mats,
672 int deformflag,
673 blender::StringRefNull defgrp_name,
674 const BMEditMesh &em_target);
675
677
678namespace blender::bke {
679
682 bool no_bones_selected = true;
683};
684
687 SelectedBoneCallback callback);
688
694
696}; // namespace blender::bke
void BKE_pchan_rot_to_mat3(const bPoseChannel *pchan, float r_mat[3][3])
void BKE_armature_deform_coords_with_mesh(const Object &ob_arm, const Object &ob_target, blender::MutableSpan< blender::float3 > vert_coords, std::optional< blender::Span< blender::float3 > > vert_coords_prev, std::optional< blender::MutableSpan< blender::float3x3 > > vert_deform_mats, int deformflag, blender::StringRefNull defgrp_name, const Mesh *me_target)
void BKE_splineik_execute_tree(Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime)
void BKE_pose_eval_init_ik(Depsgraph *depsgraph, Scene *scene, Object *object)
void BKE_pose_splineik_evaluate(Depsgraph *depsgraph, Scene *scene, Object *object, int rootchan_index)
void BKE_pchan_protected_rotation_axisangle_set(bPoseChannel *pchan, const float axis[3], float angle)
void BKE_armature_bone_hash_make(bArmature *arm)
void BKE_pchan_bbone_spline_setup(bPoseChannel *pchan, bool rest, bool for_deform, Mat4 *result_array)
void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, bool do_id_user)
bArmature * BKE_armature_from_object(Object *ob)
bPoseChannel * BKE_armature_ik_solver_find_root(bPoseChannel *pchan, bKinematicConstraint *data)
void BKE_pose_pchan_index_rebuild(bPose *pose)
void BKE_bone_parent_transform_clear(BoneParentTransform *bpt)
void BKE_armature_deform_coords_with_curves(const Object &ob_arm, const Object &ob_target, const ListBase *defbase, blender::MutableSpan< blender::float3 > vert_coords, std::optional< blender::Span< blender::float3 > > vert_coords_prev, std::optional< blender::MutableSpan< blender::float3x3 > > vert_deform_mats, blender::Span< MDeformVert > dverts, int deformflag, blender::StringRefNull defgrp_name)
void BKE_pchan_bbone_deform_segment_index(const bPoseChannel *pchan, const float *co, int *r_index, float *r_blend_next)
void BKE_bone_parent_transform_combine(const BoneParentTransform *in1, const BoneParentTransform *in2, BoneParentTransform *result)
void BKE_pchan_bbone_spline_params_get(bPoseChannel *pchan, bool rest, BBoneSplineParameters *param)
void BKE_pose_where_is_bone(Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan, float ctime, bool do_extra)
int BKE_armature_bonelist_count(const ListBase *lb)
void BKE_pose_splineik_init_tree(Scene *scene, Object *ob, float ctime)
float distfactor_to_bone(const blender::float3 &position, const blender::float3 &head, const blender::float3 &tail, float radius_head, float radius_tail, float falloff_distance)
void BKE_armature_mat_pose_to_bone_ex(Depsgraph *depsgraph, Object *ob, const bPoseChannel *pchan, const float inmat[4][4], float outmat[4][4])
void BKE_bone_parent_transform_invert(BoneParentTransform *bpt)
void mat3_vec_to_roll(const float mat[3][3], const float vec[3], float *r_roll)
void BKE_pchan_protected_location_set(bPoseChannel *pchan, const float location[3])
void BKE_pchan_calc_mat(bPoseChannel *pchan)
void BKE_armature_bonelist_free(ListBase *lb, bool do_id_user)
void BKE_pose_where_is_bone_tail(bPoseChannel *pchan)
void BKE_pchan_apply_mat4(bPoseChannel *pchan, const float mat[4][4], bool use_compat)
void BKE_pose_iktree_evaluate(Depsgraph *depsgraph, Scene *scene, Object *object, int rootchan_index)
void BKE_pose_eval_cleanup(Depsgraph *depsgraph, Scene *scene, Object *object)
void BKE_armature_mat_bone_to_pose(const bPoseChannel *pchan, const float inmat[4][4], float outmat[4][4])
void BKE_pchan_minmax(const Object *ob, const bPoseChannel *pchan, const bool use_empty_drawtype, blender::float3 &r_min, blender::float3 &r_max)
void BKE_pose_eval_init(Depsgraph *depsgraph, Scene *scene, Object *object)
void BKE_armature_where_is_bone(Bone *bone, const Bone *bone_parent, bool use_recursion)
void BKE_armature_loc_pose_to_bone(const bPoseChannel *pchan, const float inloc[3], float outloc[3])
void BKE_pchan_rebuild_bbone_handles(bPose *pose, bPoseChannel *pchan)
void BKE_pose_clear_pointers(bPose *pose)
bool BKE_armature_bone_flag_test_recursive(const Bone *bone, int flag)
void BKE_pchan_to_mat4(const bPoseChannel *pchan, float r_chanmat[4][4])
void BKE_armature_copy_bone_transforms(bArmature *armature_dst, const bArmature *armature_src)
void BKE_rotMode_change_values(float quat[4], float eul[3], float axis[3], float *angle, short oldMode, short newMode)
void BKE_armature_transform(bArmature *arm, const float mat[4][4], bool do_props)
void BKE_bone_parent_transform_apply(const BoneParentTransform *bpt, const float inmat[4][4], float outmat[4][4])
void BKE_pchan_bbone_segments_cache_copy(bPoseChannel *pchan, bPoseChannel *pchan_from)
void BKE_armature_mat_pose_to_delta(float delta_mat[4][4], float pose_mat[4][4], float arm_mat[4][4])
void vec_roll_to_mat3(const float vec[3], float roll, float r_mat[3][3])
void BKE_pose_eval_bbone_segments(Depsgraph *depsgraph, Object *object, int pchan_index)
void BKE_pose_ensure(Main *bmain, Object *ob, bArmature *arm, bool do_id_user)
void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob)
void BKE_armature_deform_coords_with_editmesh(const Object &ob_arm, const Object &ob_target, blender::MutableSpan< blender::float3 > vert_coords, std::optional< blender::Span< blender::float3 > > vert_coords_prev, std::optional< blender::MutableSpan< blender::float3x3 > > vert_deform_mats, int deformflag, blender::StringRefNull defgrp_name, const BMEditMesh &em_target)
void BKE_bone_parent_transform_calc_from_pchan(const bPoseChannel *pchan, BoneParentTransform *r_bpt)
void BKE_armature_editbonelist_free(ListBase *lb, bool do_id_user)
void BKE_pchan_protected_scale_set(bPoseChannel *pchan, const float scale[3])
void BKE_pchan_mat3_to_rot(bPoseChannel *pchan, const float mat[3][3], bool use_compat)
void mat3_to_vec_roll(const float mat[3][3], float r_vec[3], float *r_roll)
void BKE_pchan_bbone_segments_cache_compute(bPoseChannel *pchan)
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_pchan_bbone_handles_get(bPoseChannel *pchan, bPoseChannel **r_prev, bPoseChannel **r_next)
void BKE_armature_mat_pose_to_bone(const bPoseChannel *pchan, const float inmat[4][4], float outmat[4][4])
void BKE_bone_offset_matrix_get(const Bone *bone, float offs_bone[4][4])
std::optional< blender::Bounds< blender::float3 > > BKE_armature_min_max(const Object *ob)
Bone * BKE_armature_find_bone_name(bArmature *arm, const char *name)
void BKE_armature_bone_hash_free(bArmature *arm)
void BKE_armature_where_is(bArmature *arm)
void BKE_pchan_protected_rotation_euler_set(bPoseChannel *pchan, const float rotation_euler[3])
void BKE_pose_bone_done(Depsgraph *depsgraph, Object *object, int pchan_index)
void BKE_pchan_bbone_deform_clamp_segment_index(const bPoseChannel *pchan, float head_tail, int *r_index, float *r_blend_next)
void BKE_pchan_protected_rotation_quaternion_set(bPoseChannel *pchan, const float quat[4])
void BKE_armature_mat_world_to_pose(Object *ob, const float inmat[4][4], float outmat[4][4])
void BKE_pose_constraints_evaluate(Depsgraph *depsgraph, Scene *scene, Object *object, int pchan_index)
void BKE_pose_eval_done(Depsgraph *depsgraph, Object *object)
void vec_roll_to_mat3_normalized(const float nor[3], float roll, float r_mat[3][3])
int BKE_pchan_bbone_spline_compute(BBoneSplineParameters *param, bool for_deform, Mat4 *result_array)
bPoseChannel * BKE_armature_splineik_solver_find_root(bPoseChannel *pchan, bSplineIKConstraint *data)
bool bone_autoside_name(char name[64], int strip_number, short axis, float head, float tail)
void BKE_pose_channels_clear_with_null_bone(bPose *pose, bool do_id_user)
void BKE_pose_remap_bone_pointers(bArmature *armature, bPose *pose)
void BKE_pose_eval_bone(Depsgraph *depsgraph, Scene *scene, Object *object, int pchan_index)
void BKE_armature_loc_world_to_pose(Object *ob, const float inloc[3], float outloc[3])
std::optional< blender::Bounds< blender::float3 > > BKE_pose_minmax(const Object *ob, bool use_select)
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)
bArmature * BKE_armature_add(Main *bmain, const char *name)
eBone_BBoneMappingMode
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:117
BMesh const char void * data
BPy_StructRNA * depsgraph
nullptr float
uint nor
SelectedBonesResult BKE_armature_find_selected_bones(const bArmature *armature, SelectedBoneCallback callback)
blender::FunctionRef< void(Bone *bone)> SelectedBoneCallback
BoneNameSet BKE_armature_find_selected_bone_names(const bArmature *armature)
blender::Set< std::string > BoneNameSet
BoneNameSet BKE_pose_channel_find_selected_names(const Object *object)
VecBase< float, 3 > float3
const char * name
float rotscale_mat[4][4]
float curve_out_z
float scale_in[3]
char name[64]
short bbone_prev_flag
float ease2
float weight
float oldlength
float roll1
::BoneColor color
short segments
float tail[3]
IDProperty * prop
union EditBone::@275371335250266324235150226366250166246037204077 temp
char bbone_prev_type
EditBone * parent
float roll2
ListBase bone_collections
float disp_bbone_mat[32][4][4]
float curve_in_x
float disp_mat[4][4]
float zwidth
short bbone_next_flag
float curve_in_z
float length
Bone * bone
float xwidth
float disp_tail_mat[4][4]
EditBone * next
EditBone * prev
EditBone * bbone_prev
char bbone_next_type
IDProperty * system_properties
float rad_tail
EditBone * bbone_next
EditBone * ebone
EditBone * bbone_child
float ease1
eBone_BBoneMappingMode bbone_mapping_mode
float rad_head
float scale_out[3]
char inherit_scale_mode
float curve_out_x
float head[3]
float mat[4][4]
PoseTarget * next
bConstraint * con
PoseTarget * prev
float(* basis_change)[3][3]
bPoseChannel ** pchan
PoseTree * prev
ListBase targets
PoseTree * next
uint8_t flag
Definition wm_window.cc:145