68 float totlength = 0.0f;
95 Bone *pchan_bone = pchan_tip->bone_get(*ob);
98 for (pchan = pchan_tip; pchan && (segcount < ik_data->
chainlen);
99 pchan = pchan->
parent, pchan_bone = pchan_bone->
parent, segcount++)
102 pchan_chain[segcount] = pchan;
105 bone_lengths[segcount] = pchan_bone->
length;
106 totlength += bone_lengths[segcount];
113 pchan_root = pchan_chain[segcount - 1];
117 float segmentLen = (1.0f /
float(segcount));
121 MEM_delete(ik_data->
points);
125 "Spline IK Binding");
128 ik_data->
points[0] = 1.0f;
133 for (
int i = 0; i < segcount; i++) {
139 ik_data->
points[i + 1] = ik_data->
points[i] - segmentLen;
145 ik_data->
points[i + 1] = ik_data->
points[i] - (bone_lengths[i] / totlength);
168 tree->
chain = std::move(pchan_chain);
174 tree->
root = pchan_root;
217 if (ik_data->
tar ==
nullptr) {
228 state->curve_position = 0.0f;
229 state->curve_scale = 1.0f;
232 state->prev_tail_radius = 1.0f;
233 state->prev_tail_seg_idx = 0;
258 mul_m4_v3(ik_data->
tar->object_to_world().ptr(), r_vec);
262 mul_m4_v3(ob->world_to_object().ptr(), r_vec);
265 *r_radius = (radius + *r_radius) / 2;
269 const float sphere_radius,
270 const float point[3])
274 return sphere_radius -
len_v3(vec);
281 const float head_pos[3],
282 const float sphere_radius,
285 float *r_new_curve_pos,
302 const float guessed_len = *r_new_curve_pos * spline_len;
305 int cur_seg_idx = prev_seg_idx;
306 while (cur_seg_idx < max_seg_idx && guessed_len > seg_accum_len[cur_seg_idx]) {
313 int bp_idx = cur_seg_idx + 1;
316 bool is_cyclic = bl->
poly >= 0;
323 while (
len_v3v3(head_pos, bp->
vec) < sphere_radius) {
324 if (bp_idx > max_seg_idx) {
329 if (is_cyclic && bp_idx == max_seg_idx) {
342 float x0 = 0.0f, x1 = 1.0f;
343 float x0_point[3], x1_point[3], start_p[3];
346 if (prev_seg_idx == bp_idx - 1) {
357 for (
int i = 0; i < 10; i++) {
364 if (
fabsf(f_x1) <= epsilon || f_x0 == f_x1) {
368 const float x2 = x1 - f_x1 * (x1 - x0) / (f_x1 - f_x0);
379 prev_seg_idx = bp_idx - 2;
380 float prev_seg_len = 0;
382 if (prev_seg_idx < 0) {
387 prev_seg_len = seg_accum_len[prev_seg_idx];
391 const float isect_seg_len =
len_v3v3(prev_bp->
vec, r_tail_pos);
393 *r_new_curve_pos = (prev_seg_len + isect_seg_len) / spline_len;
395 if (*r_new_curve_pos > 1.0f) {
411 Bone *pchan_bone = pchan->bone_get(*ob);
415 float bone_pos[4], rad;
417 ik_data->
tar,
state->curve_position, bone_pos,
nullptr,
nullptr, &rad,
nullptr);
428 float orig_head[3], orig_tail[3], pose_head[3], pose_tail[3];
429 float base_pose_mat[3][3], pose_mat[3][3];
430 float spline_vec[3], scale_fac, radius = 1.0f;
431 float tail_blend_fac = 0.0f;
440 float bone_len =
len_v3v3(pose_head, pose_tail);
441 float point_start =
state->curve_position;
442 float pose_scale = bone_len / pchan_bone->
length;
443 float base_scale = 1.0f;
447 base_scale = pose_scale;
450 float point_end = point_start + curveLen * base_scale *
state->curve_scale;
452 state->curve_position = point_end;
455 if (point_start < 1.0f) {
460 if (point_start == 0.0f) {
466 rad =
state->prev_tail_radius;
478 sphere_radius = bone_len;
482 sphere_radius = pchan_bone->
length;
487 ik_data, vec, sphere_radius,
state->prev_tail_seg_idx, pose_tail, &point_end, &rad);
489 state->prev_tail_radius = rad;
493 state->curve_position = point_end;
498 state->prev_tail_radius = rad;
510 if (point_end >= 1.0f) {
512 tail_blend_fac = (1.0f - point_start) / (point_end - point_start);
515 tail_blend_fac = 1.0f;
532 float dmat[3][3], rmat[3][3];
533 float raxis[3], rangle;
558 int order[3] = {0, 1, 2};
565 tmp_axis[order[1]] = 1.0f;
569 rangle =
dot_v3v3(rmat[1], spline_vec);
570 CLAMP(rangle, -1.0f, 1.0f);
571 rangle =
acosf(rangle);
576 rangle *= tree->
con->
enforce * tail_blend_fac;
618 scale_fac /= pose_scale;
633 if (
fabsf(scale_fac) != 0.0f) {
654 if (
fabsf(scale_fac) != 0.0f) {
661 float hard =
min_ff(bulge, bulge_max);
663 float range = bulge_max - 1.0f;
664 float scale = (range > 0.0f) ? 1.0f / range : 0.0f;
672 float bulge_min = std::clamp(ik_data->
bulge_min, 0.0f, 1.0f);
673 float hard =
max_ff(bulge, bulge_min);
675 float range = 1.0f - bulge_min;
676 float scale = (range > 0.0f) ? 1.0f / range : 0.0f;
684 final_scale =
sqrtf(bulge);
723 if (index < tree->chainlen - 1) {
755 while ((tree = pchan_root->
siktree.first()) !=
nullptr) {
758 for (
int i = tree->
chainlen - 1; i >= 0; i--) {
770 for (
int i = tree->
chainlen - 1; i >= 0; i--) {
799 const int num_channels =
pose->chanbase.count();
800 pose->runtime->chan_array.reinitialize(num_channels);
802 for (
bPoseChannel *pchan =
pose->chanbase.first(); pchan !=
nullptr; pchan = pchan->next) {
803 pose->runtime->chan_array[pchan_index++] = pchan;
813 BLI_assert(pchan_index < pose->runtime->chan_array.size());
814 return pose->runtime->chan_array[pchan_index];
834 for (
bPoseChannel *pchan =
pose->chanbase.first(); pchan !=
nullptr; pchan = pchan->next) {
838 const Bone *bone = pchan->bone_get(*
object);
839 if (bone ==
nullptr || bone->
segments <= 1) {
867 if (armature->
edbo !=
nullptr) {
872 depsgraph, __func__,
object->id.name,
object,
"pchan", pchan->
name, pchan);
875 Bone *bone = pchan->bone_get(*
object);
906 if (armature->
edbo !=
nullptr) {
911 depsgraph, __func__,
object->id.name,
object,
"pchan", pchan->
name, pchan);
934 if (armature->
edbo !=
nullptr) {
953 if (armature->
edbo !=
nullptr) {
959 depsgraph, __func__,
object->id.name,
object,
"pchan", pchan->
name, pchan);
960 const Bone *bone = pchan->bone_get(*armature);
971 if (bone ==
nullptr || bone->
segments <= 1) {
980 if (armature->
edbo !=
nullptr) {
985 depsgraph, __func__,
object->id.name,
object,
"pchan", pchan->
name, pchan);
986 Bone *bone = pchan->bone_get(*
object);
987 if (bone !=
nullptr && bone->
segments > 1) {
1001 if (armature->
edbo !=
nullptr) {
1006 depsgraph, __func__,
object->id.name,
object,
"rootchan", rootchan->
name, rootchan);
1022 if (armature->
edbo !=
nullptr) {
1027 depsgraph, __func__,
object->id.name,
object,
"rootchan", rootchan->
name, rootchan);
Blender kernel action and pose functionality.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define UNUSED_VARS_NDEBUG(...)
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Array(Allocator allocator={}) noexcept
CCL_NAMESPACE_BEGIN ccl_device_inline float frac(const float x, ccl_private int *ix)
float3x3 scale(float3x3 mat, float2 scale)
MINLINE float min_ff(float a, float b)
void BIK_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_pose_eval_bbone_segments(Depsgraph *depsgraph, Object *object, int pchan_index)
static void apply_curve_transform(bSplineIKConstraint *ik_data, Object *ob, float radius, float r_vec[3], float *r_radius)
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
void BKE_pose_eval_cleanup(Depsgraph *depsgraph, Scene *scene, Object *object)
void BKE_pose_channel_free_bbone_cache(bPoseChannel_Runtime *runtime) ATTR_NONNULL(1)
bool DEG_is_active(const Depsgraph *depsgraph)
void BKE_pose_eval_init_ik(Depsgraph *depsgraph, Scene *scene, Object *object)
@ CONSTRAINT_TYPE_SPLINEIK
static int position_tail_on_spline(bSplineIKConstraint *ik_data, const float head_pos[3], const float sphere_radius, int prev_seg_idx, float r_tail_pos[3], float *r_new_curve_pos, float *r_radius)
static void pose_eval_cleanup_common(Object *object)
void copy_m4_m3(float m1[4][4], const float m2[3][3])
bool BKE_where_on_path(const struct Object *ob, float ctime, float r_vec[4], float r_dir[3], float r_quat[4], float *r_radius, float *r_weight)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void normalize_m3(float R[3][3]) ATTR_NONNULL()
static void splineik_execute_tree(Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void BKE_pose_where_is_bone(Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan, float ctime, bool do_extra)
void BKE_pose_eval_init(Depsgraph *depsgraph, Scene *scene, Object *object)
void DEG_debug_print_eval(Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address)
static void splineik_init_tree_from_pchan(Scene *, Object *ob, bPoseChannel *pchan_tip)
@ CONSTRAINT_SPLINEIK_EVENSPLITS
@ CONSTRAINT_SPLINEIK_NO_CURVERAD
@ CONSTRAINT_SPLINEIK_USE_BULGE_MAX
@ CONSTRAINT_SPLINEIK_BOUND
@ CONSTRAINT_SPLINEIK_USE_BULGE_MIN
@ CONSTRAINT_SPLINEIK_USE_ORIGINAL_SCALE
@ CONSTRAINT_SPLINEIK_NO_ROOT
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
void BKE_splineik_execute_tree(Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime)
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])
BLI_INLINE bPoseChannel * pose_pchan_get_indexed(Object *ob, int pchan_index)
void BKE_pose_iktree_evaluate(Depsgraph *depsgraph, Scene *scene, Object *object, int rootchan_index)
void mul_m3_m4m4(float R[3][3], const float A[4][4], const float B[4][4])
static void splineik_evaluate_bone(tSplineIK_Tree *tree, Object *ob, bPoseChannel *pchan, int index, tSplineIk_EvalState *state)
MINLINE void mul_v3_fl(float r[3], float f)
void BKE_pchan_bbone_segments_cache_copy(bPoseChannel *pchan, bPoseChannel *pchan_from)
void mul_m4_v3(const float M[4][4], float r[3])
@ CONSTRAINT_SPLINEIK_XZS_ORIGINAL
@ CONSTRAINT_SPLINEIK_XZS_NONE
@ CONSTRAINT_SPLINEIK_XZS_INVERSE
@ CONSTRAINT_SPLINEIK_XZS_VOLUMETRIC
void BKE_pose_pchan_index_rebuild(bPose *pose)
void BKE_pose_constraints_evaluate(Depsgraph *depsgraph, Scene *scene, Object *object, int pchan_index)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
bool BKE_constraint_has_influence(const struct bConstraint *con)
@ CONSTRAINT_SPLINEIK_YS_FIT_CURVE
@ CONSTRAINT_SPLINEIK_YS_ORIGINAL
void BIK_init_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void unit_m4(float m[4][4])
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
int BKE_anim_path_get_array_size(const struct CurveCache *curve_cache)
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v3(float r[3])
void BKE_pose_splineik_evaluate(Depsgraph *depsgraph, Scene *scene, Object *object, int rootchan_index)
void normalize_m3_m3(float R[3][3], const float M[3][3]) ATTR_NONNULL()
void mat4_to_dquat(DualQuat *dq, const float basemat[4][4], const float mat[4][4])
void DEG_debug_print_eval_subdata(Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address, const char *subdata_comment, const char *subdata_name, const void *subdata_address)
MINLINE float normalize_v3(float n[3])
void BKE_pose_eval_bone(Depsgraph *depsgraph, Scene *scene, Object *object, int pchan_index)
void BKE_pose_eval_done(Depsgraph *depsgraph, Object *object)
void BKE_pose_where_is_bone_tail(bke::PChanBone pchanbone)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
float BKE_scene_ctime_get(const Scene *scene)
MINLINE float max_ff(float a, float b)
void BKE_pchan_bbone_segments_cache_compute(bke::PChanBone pchanbone, const bArmature &armature)
void axis_sort_v3(const float axis_values[3], int r_axis_order[3])
void BKE_pose_splineik_init_tree(Scene *scene, Object *ob, float ctime)
MINLINE float interpf(float target, float origin, float t)
void madd_m3_m3m3fl(float R[3][3], const float A[3][3], const float B[3][3], float f)
static void pose_channel_flush_to_orig_if_needed(Depsgraph *depsgraph, Object *object, bPoseChannel *pchan)
float BKE_anim_path_get_length(const struct CurveCache *curve_cache)
static float dist_to_sphere_shell(const float sphere_origin[3], const float sphere_radius, const float point[3])
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
static bool splineik_evaluate_init(tSplineIK_Tree *tree, tSplineIk_EvalState *state)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void sub_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void BKE_pose_bone_done(Depsgraph *depsgraph, Object *object, int pchan_index)
void mul_m4_m3m4(float R[4][4], const float A[3][3], const float B[4][4])
static void splineik_init_tree(Scene *scene, Object *ob, float)
void BIK_release_tree(struct Scene *scene, struct Object *ob, float ctime)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
const float * anim_path_accum_length
bke::ObjectRuntime * runtime
ListBaseT< EditBone > * edbo
struct bConstraint * next
struct DualQuat deform_dual_quat
struct bPoseChannel_Runtime runtime
struct bPoseChannel * parent
ListBaseT< struct bConstraint > constraints
ePchan_ConstFlag constflag
ListBaseT< struct tSplineIK_Tree > siktree
struct bPoseChannel * orig_pchan
ListBaseT< bPoseChannel > chanbase
eSplineIK_YScaleModes yScaleMode
eSplineIK_XZScaleModes xzScaleMode
Array< bPoseChannel * > chain
bSplineIKConstraint * ik_data
float locrot_offset[4][4]