Blender  V3.3
armature.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include <ctype.h>
9 #include <float.h>
10 #include <math.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 
15 #include "MEM_guardedalloc.h"
16 
17 #include "BLI_alloca.h"
18 #include "BLI_ghash.h"
19 #include "BLI_listbase.h"
20 #include "BLI_math.h"
21 #include "BLI_string.h"
22 #include "BLI_utildefines.h"
23 #include "BLT_translation.h"
24 
25 #include "DNA_defaults.h"
26 
27 #include "DNA_armature_types.h"
28 #include "DNA_constraint_types.h"
29 #include "DNA_listBase.h"
30 #include "DNA_object_types.h"
31 #include "DNA_scene_types.h"
32 
33 #include "BKE_action.h"
34 #include "BKE_anim_data.h"
35 #include "BKE_anim_visualization.h"
36 #include "BKE_armature.h"
37 #include "BKE_constraint.h"
38 #include "BKE_curve.h"
39 #include "BKE_idprop.h"
40 #include "BKE_idtype.h"
41 #include "BKE_lib_id.h"
42 #include "BKE_lib_query.h"
43 #include "BKE_main.h"
44 #include "BKE_object.h"
45 #include "BKE_scene.h"
46 
47 #include "DEG_depsgraph_build.h"
48 #include "DEG_depsgraph_query.h"
49 
50 #include "BIK_api.h"
51 
52 #include "BLO_read_write.h"
53 
54 #include "CLG_log.h"
55 
56 /* -------------------------------------------------------------------- */
60 static void copy_bonechildren(Bone *bone_dst,
61  const Bone *bone_src,
62  const Bone *bone_src_act,
63  Bone **r_bone_dst_act,
64  const int flag);
65 
66 static void copy_bonechildren_custom_handles(Bone *bone_dst, bArmature *arm_dst);
67 
70 /* -------------------------------------------------------------------- */
74 static void armature_init_data(ID *id)
75 {
76  bArmature *armature = (bArmature *)id;
78 
80 }
81 
92 static void armature_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag)
93 {
94  bArmature *armature_dst = (bArmature *)id_dst;
95  const bArmature *armature_src = (const bArmature *)id_src;
96 
97  Bone *bone_src, *bone_dst;
98  Bone *bone_dst_act = NULL;
99 
100  /* We never handle usercount here for own data. */
101  const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
102 
103  armature_dst->bonehash = NULL;
104 
105  BLI_duplicatelist(&armature_dst->bonebase, &armature_src->bonebase);
106 
107  /* Duplicate the childrens' lists */
108  bone_dst = armature_dst->bonebase.first;
109  for (bone_src = armature_src->bonebase.first; bone_src; bone_src = bone_src->next) {
110  bone_dst->parent = NULL;
111  copy_bonechildren(bone_dst, bone_src, armature_src->act_bone, &bone_dst_act, flag_subdata);
112  bone_dst = bone_dst->next;
113  }
114 
115  armature_dst->act_bone = bone_dst_act;
116 
117  BKE_armature_bone_hash_make(armature_dst);
118 
119  /* Fix custom handle references. */
120  for (bone_dst = armature_dst->bonebase.first; bone_dst; bone_dst = bone_dst->next) {
121  copy_bonechildren_custom_handles(bone_dst, armature_dst);
122  }
123 
124  armature_dst->edbo = NULL;
125  armature_dst->act_edbone = NULL;
126 }
127 
129 static void armature_free_data(struct ID *id)
130 {
131  bArmature *armature = (bArmature *)id;
132 
133  BKE_armature_bone_hash_free(armature);
134  BKE_armature_bonelist_free(&armature->bonebase, false);
135 
136  /* free editmode data */
137  if (armature->edbo) {
138  BKE_armature_editbonelist_free(armature->edbo, false);
139  MEM_freeN(armature->edbo);
140  armature->edbo = NULL;
141  }
142 }
143 
145 {
147  data,
150 
151  LISTBASE_FOREACH (Bone *, curbone, &bone->childbase) {
153  }
154 }
155 
157 {
159  data,
160  IDP_foreach_property(edit_bone->prop,
163  data));
164 }
165 
167 {
168  bArmature *arm = (bArmature *)id;
169  LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) {
171  }
172 
173  if (arm->edbo != NULL) {
174  LISTBASE_FOREACH (EditBone *, edit_bone, arm->edbo) {
176  }
177  }
178 }
179 
180 static void write_bone(BlendWriter *writer, Bone *bone)
181 {
182  /* PATCH for upward compatibility after 2.37+ armature recode */
183  bone->size[0] = bone->size[1] = bone->size[2] = 1.0f;
184 
185  /* Write this bone */
186  BLO_write_struct(writer, Bone, bone);
187 
188  /* Write ID Properties -- and copy this comment EXACTLY for easy finding
189  * of library blocks that implement this. */
190  if (bone->prop) {
191  IDP_BlendWrite(writer, bone->prop);
192  }
193 
194  /* Write Children */
195  LISTBASE_FOREACH (Bone *, cbone, &bone->childbase) {
196  write_bone(writer, cbone);
197  }
198 }
199 
200 static void armature_blend_write(BlendWriter *writer, ID *id, const void *id_address)
201 {
202  bArmature *arm = (bArmature *)id;
203 
204  /* Clean up, important in undo case to reduce false detection of changed datablocks. */
205  arm->bonehash = NULL;
206  arm->edbo = NULL;
207  /* Must always be cleared (armatures don't have their own edit-data). */
208  arm->needs_flush_to_id = 0;
209  arm->act_edbone = NULL;
210 
211  BLO_write_id_struct(writer, bArmature, id_address, &arm->id);
212  BKE_id_blend_write(writer, &arm->id);
213 
214  if (arm->adt) {
215  BKE_animdata_blend_write(writer, arm->adt);
216  }
217 
218  /* Direct data */
219  LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) {
220  write_bone(writer, bone);
221  }
222 }
223 
224 static void direct_link_bones(BlendDataReader *reader, Bone *bone)
225 {
226  BLO_read_data_address(reader, &bone->parent);
227  BLO_read_data_address(reader, &bone->prop);
228  IDP_BlendDataRead(reader, &bone->prop);
229 
230  BLO_read_data_address(reader, &bone->bbone_next);
231  BLO_read_data_address(reader, &bone->bbone_prev);
232 
234 
235  BLO_read_list(reader, &bone->childbase);
236 
237  LISTBASE_FOREACH (Bone *, child, &bone->childbase) {
238  direct_link_bones(reader, child);
239  }
240 }
241 
242 static void armature_blend_read_data(BlendDataReader *reader, ID *id)
243 {
244  bArmature *arm = (bArmature *)id;
245  BLO_read_list(reader, &arm->bonebase);
246  arm->bonehash = NULL;
247  arm->edbo = NULL;
248  /* Must always be cleared (armatures don't have their own edit-data). */
249  arm->needs_flush_to_id = 0;
250 
251  BLO_read_data_address(reader, &arm->adt);
252  BKE_animdata_blend_read_data(reader, arm->adt);
253 
254  LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) {
255  direct_link_bones(reader, bone);
256  }
257 
258  BLO_read_data_address(reader, &arm->act_bone);
259  arm->act_edbone = NULL;
260 
262 }
263 
264 static void lib_link_bones(BlendLibReader *reader, Library *lib, Bone *bone)
265 {
266  IDP_BlendReadLib(reader, lib, bone->prop);
267 
268  LISTBASE_FOREACH (Bone *, curbone, &bone->childbase) {
269  lib_link_bones(reader, lib, curbone);
270  }
271 }
272 
273 static void armature_blend_read_lib(BlendLibReader *reader, ID *id)
274 {
275  bArmature *arm = (bArmature *)id;
276  LISTBASE_FOREACH (Bone *, curbone, &arm->bonebase) {
277  lib_link_bones(reader, id->lib, curbone);
278  }
279 }
280 
281 static void expand_bones(BlendExpander *expander, Bone *bone)
282 {
283  IDP_BlendReadExpand(expander, bone->prop);
284 
285  LISTBASE_FOREACH (Bone *, curBone, &bone->childbase) {
286  expand_bones(expander, curBone);
287  }
288 }
289 
290 static void armature_blend_read_expand(BlendExpander *expander, ID *id)
291 {
292  bArmature *arm = (bArmature *)id;
293  LISTBASE_FOREACH (Bone *, curBone, &arm->bonebase) {
294  expand_bones(expander, curBone);
295  }
296 }
297 
299  .id_code = ID_AR,
300  .id_filter = FILTER_ID_AR,
301  .main_listbase_index = INDEX_ID_AR,
302  .struct_size = sizeof(bArmature),
303  .name = "Armature",
304  .name_plural = "armatures",
305  .translation_context = BLT_I18NCONTEXT_ID_ARMATURE,
307  .asset_type_info = NULL,
308 
310  .copy_data = armature_copy_data,
311  .free_data = armature_free_data,
312  .make_local = NULL,
313  .foreach_id = armature_foreach_id,
314  .foreach_cache = NULL,
315  .foreach_path = NULL,
316  .owner_get = NULL,
317 
318  .blend_write = armature_blend_write,
319  .blend_read_data = armature_blend_read_data,
320  .blend_read_lib = armature_blend_read_lib,
321  .blend_read_expand = armature_blend_read_expand,
322 
323  .blend_read_undo_preserve = NULL,
324 
325  .lib_override_apply_post = NULL,
326 };
327 
330 /* -------------------------------------------------------------------- */
334 bArmature *BKE_armature_add(Main *bmain, const char *name)
335 {
336  bArmature *arm;
337 
338  arm = BKE_id_new(bmain, ID_AR, name);
339  return arm;
340 }
341 
343 {
344  if (ob->type == OB_ARMATURE) {
345  return (bArmature *)ob->data;
346  }
347  return NULL;
348 }
349 
351 {
352  int i = 0;
353  LISTBASE_FOREACH (Bone *, bone, lb) {
354  i += 1 + BKE_armature_bonelist_count(&bone->childbase);
355  }
356 
357  return i;
358 }
359 
360 void BKE_armature_bonelist_free(ListBase *lb, const bool do_id_user)
361 {
362  Bone *bone;
363 
364  for (bone = lb->first; bone; bone = bone->next) {
365  if (bone->prop) {
366  IDP_FreeProperty_ex(bone->prop, do_id_user);
367  }
368  BKE_armature_bonelist_free(&bone->childbase, do_id_user);
369  }
370 
371  BLI_freelistN(lb);
372 }
373 
374 void BKE_armature_editbonelist_free(ListBase *lb, const bool do_id_user)
375 {
376  LISTBASE_FOREACH_MUTABLE (EditBone *, edit_bone, lb) {
377  if (edit_bone->prop) {
378  IDP_FreeProperty_ex(edit_bone->prop, do_id_user);
379  }
380  BLI_remlink_safe(lb, edit_bone);
381  MEM_freeN(edit_bone);
382  }
383 }
384 
385 static void copy_bonechildren(Bone *bone_dst,
386  const Bone *bone_src,
387  const Bone *bone_src_act,
388  Bone **r_bone_dst_act,
389  const int flag)
390 {
391  Bone *bone_src_child, *bone_dst_child;
392 
393  if (bone_src == bone_src_act) {
394  *r_bone_dst_act = bone_dst;
395  }
396 
397  if (bone_src->prop) {
398  bone_dst->prop = IDP_CopyProperty_ex(bone_src->prop, flag);
399  }
400 
401  /* Copy this bone's list */
402  BLI_duplicatelist(&bone_dst->childbase, &bone_src->childbase);
403 
404  /* For each child in the list, update its children */
405  for (bone_src_child = bone_src->childbase.first, bone_dst_child = bone_dst->childbase.first;
406  bone_src_child;
407  bone_src_child = bone_src_child->next, bone_dst_child = bone_dst_child->next) {
408  bone_dst_child->parent = bone_dst;
409  copy_bonechildren(bone_dst_child, bone_src_child, bone_src_act, r_bone_dst_act, flag);
410  }
411 }
412 
413 static void copy_bonechildren_custom_handles(Bone *bone_dst, bArmature *arm_dst)
414 {
415  Bone *bone_dst_child;
416 
417  if (bone_dst->bbone_prev) {
418  bone_dst->bbone_prev = BKE_armature_find_bone_name(arm_dst, bone_dst->bbone_prev->name);
419  }
420  if (bone_dst->bbone_next) {
421  bone_dst->bbone_next = BKE_armature_find_bone_name(arm_dst, bone_dst->bbone_next->name);
422  }
423 
424  for (bone_dst_child = bone_dst->childbase.first; bone_dst_child;
425  bone_dst_child = bone_dst_child->next) {
426  copy_bonechildren_custom_handles(bone_dst_child, arm_dst);
427  }
428 }
429 
432 /* -------------------------------------------------------------------- */
436 static void copy_bone_transform(Bone *bone_dst, const Bone *bone_src)
437 {
438  bone_dst->roll = bone_src->roll;
439 
440  copy_v3_v3(bone_dst->head, bone_src->head);
441  copy_v3_v3(bone_dst->tail, bone_src->tail);
442 
443  copy_m3_m3(bone_dst->bone_mat, bone_src->bone_mat);
444 
445  copy_v3_v3(bone_dst->arm_head, bone_src->arm_head);
446  copy_v3_v3(bone_dst->arm_tail, bone_src->arm_tail);
447 
448  copy_m4_m4(bone_dst->arm_mat, bone_src->arm_mat);
449 
450  bone_dst->arm_roll = bone_src->arm_roll;
451 }
452 
453 void BKE_armature_copy_bone_transforms(bArmature *armature_dst, const bArmature *armature_src)
454 {
455  Bone *bone_dst = armature_dst->bonebase.first;
456  const Bone *bone_src = armature_src->bonebase.first;
457  while (bone_dst != NULL) {
458  BLI_assert(bone_src != NULL);
459  copy_bone_transform(bone_dst, bone_src);
460  bone_dst = bone_dst->next;
461  bone_src = bone_src->next;
462  }
463 }
464 
467 /* -------------------------------------------------------------------- */
474 static void armature_transform_recurse(ListBase *bonebase,
475  const float mat[4][4],
476  const bool do_props,
477  /* Cached from 'mat'. */
478  const float mat3[3][3],
479  const float scale,
480  /* Child bones. */
481  const Bone *bone_parent,
482  const float arm_mat_parent_inv[4][4])
483 {
484  LISTBASE_FOREACH (Bone *, bone, bonebase) {
485 
486  /* Store the initial bone roll in a matrix, this is needed even for child bones
487  * so any change in head/tail doesn't cause the roll to change.
488  *
489  * Logic here is different to edit-mode because
490  * this is calculated in relative to the parent. */
491  float roll_mat3_pre[3][3];
492  {
493  float delta[3];
494  sub_v3_v3v3(delta, bone->tail, bone->head);
495  vec_roll_to_mat3(delta, bone->roll, roll_mat3_pre);
496  if (bone->parent == NULL) {
497  mul_m3_m3m3(roll_mat3_pre, mat3, roll_mat3_pre);
498  }
499  }
500  /* Optional, use this for predictable results since the roll is re-calculated below anyway. */
501  bone->roll = 0.0f;
502 
503  mul_m4_v3(mat, bone->arm_head);
504  mul_m4_v3(mat, bone->arm_tail);
505 
506  /* Get the new head and tail */
507  if (bone_parent) {
508  sub_v3_v3v3(bone->head, bone->arm_head, bone_parent->arm_tail);
509  sub_v3_v3v3(bone->tail, bone->arm_tail, bone_parent->arm_tail);
510 
511  mul_mat3_m4_v3(arm_mat_parent_inv, bone->head);
512  mul_mat3_m4_v3(arm_mat_parent_inv, bone->tail);
513  }
514  else {
515  copy_v3_v3(bone->head, bone->arm_head);
516  copy_v3_v3(bone->tail, bone->arm_tail);
517  }
518 
519  /* Now the head/tail have been updated, set the roll back, matching 'roll_mat3_pre'. */
520  {
521  float roll_mat3_post[3][3], delta_mat3[3][3];
522  float delta[3];
523  sub_v3_v3v3(delta, bone->tail, bone->head);
524  vec_roll_to_mat3(delta, 0.0f, roll_mat3_post);
525  invert_m3(roll_mat3_post);
526  mul_m3_m3m3(delta_mat3, roll_mat3_post, roll_mat3_pre);
527  bone->roll = atan2f(delta_mat3[2][0], delta_mat3[2][2]);
528  }
529 
530  BKE_armature_where_is_bone(bone, bone_parent, false);
531 
532  {
533  float arm_mat3[3][3];
534  copy_m3_m4(arm_mat3, bone->arm_mat);
535  mat3_to_vec_roll(arm_mat3, NULL, &bone->arm_roll);
536  }
537 
538  if (do_props) {
539  bone->rad_head *= scale;
540  bone->rad_tail *= scale;
541  bone->dist *= scale;
542 
543  /* we could be smarter and scale by the matrix along the x & z axis */
544  bone->xwidth *= scale;
545  bone->zwidth *= scale;
546  }
547 
548  if (!BLI_listbase_is_empty(&bone->childbase)) {
549  float arm_mat_inv[4][4];
550  invert_m4_m4(arm_mat_inv, bone->arm_mat);
551  armature_transform_recurse(&bone->childbase, mat, do_props, mat3, scale, bone, arm_mat_inv);
552  }
553  }
554 }
555 
556 void BKE_armature_transform(bArmature *arm, const float mat[4][4], const bool do_props)
557 {
558  /* Store the scale of the matrix here to use on envelopes. */
559  float scale = mat4_to_scale(mat);
560  float mat3[3][3];
561 
562  copy_m3_m4(mat3, mat);
563  normalize_m3(mat3);
564 
565  armature_transform_recurse(&arm->bonebase, mat, do_props, mat3, scale, NULL, NULL);
566 }
567 
570 /* -------------------------------------------------------------------- */
576 static Bone *get_named_bone_bonechildren(ListBase *lb, const char *name)
577 {
578  Bone *curBone, *rbone;
579 
580  for (curBone = lb->first; curBone; curBone = curBone->next) {
581  if (STREQ(curBone->name, name)) {
582  return curBone;
583  }
584 
585  rbone = get_named_bone_bonechildren(&curBone->childbase, name);
586  if (rbone) {
587  return rbone;
588  }
589  }
590 
591  return NULL;
592 }
593 
595 {
596  if (!arm) {
597  return NULL;
598  }
599 
600  if (arm->bonehash) {
601  return BLI_ghash_lookup(arm->bonehash, name);
602  }
603 
604  return get_named_bone_bonechildren(&arm->bonebase, name);
605 }
606 
608 {
609  LISTBASE_FOREACH (Bone *, bone, lb) {
610  BLI_ghash_insert(bone_hash, bone->name, bone);
611  armature_bone_from_name_insert_recursive(bone_hash, &bone->childbase);
612  }
613 }
614 
622 {
623  const int bones_count = BKE_armature_bonelist_count(&arm->bonebase);
624  GHash *bone_hash = BLI_ghash_str_new_ex(__func__, bones_count);
626  return bone_hash;
627 }
628 
630 {
631  if (!arm->bonehash) {
633  }
634 }
635 
637 {
638  if (arm->bonehash) {
640  arm->bonehash = NULL;
641  }
642 }
643 
646 /* -------------------------------------------------------------------- */
650 bool BKE_armature_bone_flag_test_recursive(const Bone *bone, int flag)
651 {
652  if (bone->flag & flag) {
653  return true;
654  }
655  if (bone->parent) {
656  return BKE_armature_bone_flag_test_recursive(bone->parent, flag);
657  }
658  return false;
659 }
660 
663 /* -------------------------------------------------------------------- */
668 {
669  LISTBASE_FOREACH (Bone *, bone, bones) {
670  arm->layer_used |= bone->layer;
671  armature_refresh_layer_used_recursive(arm, &bone->childbase);
672  }
673 }
674 
676 {
677  if (arm->edbo != NULL) {
678  /* Don't perform this update when the armature is in edit mode. In that case it should be
679  * handled by ED_armature_edit_refresh_layer_used(). */
680  return;
681  }
682 
683  arm->layer_used = 0;
685 
686  if (depsgraph == NULL || DEG_is_active(depsgraph)) {
687  bArmature *arm_orig = (bArmature *)DEG_get_original_id(&arm->id);
688  arm_orig->layer_used = arm->layer_used;
689  }
690 }
691 
694 /* -------------------------------------------------------------------- */
699  char name[MAXBONENAME], int UNUSED(strip_number), short axis, float head, float tail)
700 {
701  unsigned int len;
702  char basename[MAXBONENAME] = "";
703  char extension[5] = "";
704 
705  len = strlen(name);
706  if (len == 0) {
707  return false;
708  }
709  BLI_strncpy(basename, name, sizeof(basename));
710 
711  /* Figure out extension to append:
712  * - The extension to append is based upon the axis that we are working on.
713  * - If head happens to be on 0, then we must consider the tail position as well to decide
714  * which side the bone is on
715  * -> If tail is 0, then its bone is considered to be on axis, so no extension should be added
716  * -> Otherwise, extension is added from perspective of object based on which side tail goes to
717  * - If head is non-zero, extension is added from perspective of object based on side head is on
718  */
719  if (axis == 2) {
720  /* z-axis - vertical (top/bottom) */
721  if (IS_EQF(head, 0.0f)) {
722  if (tail < 0) {
723  strcpy(extension, "Bot");
724  }
725  else if (tail > 0) {
726  strcpy(extension, "Top");
727  }
728  }
729  else {
730  if (head < 0) {
731  strcpy(extension, "Bot");
732  }
733  else {
734  strcpy(extension, "Top");
735  }
736  }
737  }
738  else if (axis == 1) {
739  /* y-axis - depth (front/back) */
740  if (IS_EQF(head, 0.0f)) {
741  if (tail < 0) {
742  strcpy(extension, "Fr");
743  }
744  else if (tail > 0) {
745  strcpy(extension, "Bk");
746  }
747  }
748  else {
749  if (head < 0) {
750  strcpy(extension, "Fr");
751  }
752  else {
753  strcpy(extension, "Bk");
754  }
755  }
756  }
757  else {
758  /* x-axis - horizontal (left/right) */
759  if (IS_EQF(head, 0.0f)) {
760  if (tail < 0) {
761  strcpy(extension, "R");
762  }
763  else if (tail > 0) {
764  strcpy(extension, "L");
765  }
766  }
767  else {
768  if (head < 0) {
769  strcpy(extension, "R");
770  /* XXX Shouldn't this be simple else, as for z and y axes? */
771  }
772  else if (head > 0) {
773  strcpy(extension, "L");
774  }
775  }
776  }
777 
778  /* Simple name truncation
779  * - truncate if there is an extension and it wouldn't be able to fit
780  * - otherwise, just append to end
781  */
782  if (extension[0]) {
783  bool changed = true;
784 
785  while (changed) { /* remove extensions */
786  changed = false;
787  if (len > 2 && basename[len - 2] == '.') {
788  if (ELEM(basename[len - 1], 'L', 'R')) { /* L R */
789  basename[len - 2] = '\0';
790  len -= 2;
791  changed = true;
792  }
793  }
794  else if (len > 3 && basename[len - 3] == '.') {
795  if ((basename[len - 2] == 'F' && basename[len - 1] == 'r') || /* Fr */
796  (basename[len - 2] == 'B' && basename[len - 1] == 'k')) /* Bk */
797  {
798  basename[len - 3] = '\0';
799  len -= 3;
800  changed = true;
801  }
802  }
803  else if (len > 4 && basename[len - 4] == '.') {
804  if ((basename[len - 3] == 'T' && basename[len - 2] == 'o' &&
805  basename[len - 1] == 'p') || /* Top */
806  (basename[len - 3] == 'B' && basename[len - 2] == 'o' &&
807  basename[len - 1] == 't')) /* Bot */
808  {
809  basename[len - 4] = '\0';
810  len -= 4;
811  changed = true;
812  }
813  }
814  }
815 
816  /* Subtract 1 from #MAXBONENAME for the null byte. Add 1 to the extension for the '.' */
817  const int basename_maxlen = (MAXBONENAME - 1) - (1 + strlen(extension));
818  BLI_snprintf(name, MAXBONENAME, "%.*s.%s", basename_maxlen, basename, extension);
819 
820  return true;
821  }
822  return false;
823 }
824 
827 /* -------------------------------------------------------------------- */
831 /* Compute a set of bezier parameter values that produce approximately equally spaced points. */
832 static void equalize_cubic_bezier(const float control[4][3],
833  int temp_segments,
834  int final_segments,
835  const float *segment_scales,
836  float *r_t_points)
837 {
838  float(*coords)[3] = BLI_array_alloca(coords, temp_segments + 1);
839  float *pdist = BLI_array_alloca(pdist, temp_segments + 1);
840 
841  /* Compute the first pass of bezier point coordinates. */
842  for (int i = 0; i < 3; i++) {
843  BKE_curve_forward_diff_bezier(control[0][i],
844  control[1][i],
845  control[2][i],
846  control[3][i],
847  &coords[0][i],
848  temp_segments,
849  sizeof(*coords));
850  }
851 
852  /* Calculate the length of the polyline at each point. */
853  pdist[0] = 0.0f;
854 
855  for (int i = 0; i < temp_segments; i++) {
856  pdist[i + 1] = pdist[i] + len_v3v3(coords[i], coords[i + 1]);
857  }
858 
859  /* Go over distances and calculate new parameter values. */
860  float dist_step = pdist[temp_segments];
861  float dist = 0, sum = 0;
862 
863  for (int i = 0; i < final_segments; i++) {
864  sum += segment_scales[i];
865  }
866 
867  dist_step /= sum;
868 
869  r_t_points[0] = 0.0f;
870 
871  for (int i = 1, nr = 1; i <= final_segments; i++) {
872  dist += segment_scales[i - 1] * dist_step;
873 
874  /* We're looking for location (distance) 'dist' in the array. */
875  while ((nr < temp_segments) && (dist >= pdist[nr])) {
876  nr++;
877  }
878 
879  float fac = (pdist[nr] - dist) / (pdist[nr] - pdist[nr - 1]);
880 
881  r_t_points[i] = (nr - fac) / temp_segments;
882  }
883 
884  r_t_points[final_segments] = 1.0f;
885 }
886 
887 /* Evaluate bezier position and tangent at a specific parameter value
888  * using the De Casteljau algorithm. */
889 static void evaluate_cubic_bezier(const float control[4][3],
890  float t,
891  float r_pos[3],
892  float r_tangent[3])
893 {
894  float layer1[3][3];
895  interp_v3_v3v3(layer1[0], control[0], control[1], t);
896  interp_v3_v3v3(layer1[1], control[1], control[2], t);
897  interp_v3_v3v3(layer1[2], control[2], control[3], t);
898 
899  float layer2[2][3];
900  interp_v3_v3v3(layer2[0], layer1[0], layer1[1], t);
901  interp_v3_v3v3(layer2[1], layer1[1], layer1[2], t);
902 
903  sub_v3_v3v3(r_tangent, layer2[1], layer2[0]);
904  madd_v3_v3v3fl(r_pos, layer2[0], r_tangent, t);
905 }
906 
908 {
909  if (pchan->bone->bbone_prev_type == BBONE_HANDLE_AUTO) {
910  /* Use connected parent. */
911  if (pchan->bone->flag & BONE_CONNECTED) {
912  *r_prev = pchan->parent;
913  }
914  else {
915  *r_prev = NULL;
916  }
917  }
918  else {
919  /* Use the provided bone as prev - leave blank to eliminate this effect altogether. */
920  *r_prev = pchan->bbone_prev;
921  }
922 
923  if (pchan->bone->bbone_next_type == BBONE_HANDLE_AUTO) {
924  /* Use connected child. */
925  *r_next = pchan->child;
926  }
927  else {
928  /* Use the provided bone as next - leave blank to eliminate this effect altogether. */
929  *r_next = pchan->bbone_next;
930  }
931 }
932 
934  const bool rest,
935  struct BBoneSplineParameters *param)
936 {
938  Bone *bone = pchan->bone;
939  float imat[4][4], posemat[4][4], tmpmat[4][4];
940  float delta[3];
941 
942  memset(param, 0, sizeof(*param));
943 
944  param->segments = bone->segments;
945  param->length = bone->length;
946 
947  if (!rest) {
948  float scale[3];
949 
950  /* Check if we need to take non-uniform bone scaling into account. */
951  mat4_to_size(scale, pchan->pose_mat);
952 
953  if (fabsf(scale[0] - scale[1]) > 1e-6f || fabsf(scale[1] - scale[2]) > 1e-6f) {
954  param->do_scale = true;
955  copy_v3_v3(param->scale, scale);
956  }
957  }
958 
960 
961  /* Find the handle points, since this is inside bone space, the
962  * first point = (0, 0, 0)
963  * last point = (0, length, 0) */
964  if (rest) {
965  invert_m4_m4(imat, pchan->bone->arm_mat);
966  }
967  else if (param->do_scale) {
968  copy_m4_m4(posemat, pchan->pose_mat);
969  normalize_m4(posemat);
970  invert_m4_m4(imat, posemat);
971  }
972  else {
973  invert_m4_m4(imat, pchan->pose_mat);
974  }
975 
976  float prev_scale[3], next_scale[3];
977 
978  copy_v3_fl(prev_scale, 1.0f);
979  copy_v3_fl(next_scale, 1.0f);
980 
981  if (prev) {
982  float h1[3];
983  bool done = false;
984 
985  param->use_prev = true;
986 
987  /* Transform previous point inside this bone space. */
988  if (bone->bbone_prev_type == BBONE_HANDLE_RELATIVE) {
989  /* Use delta movement (from restpose), and apply this relative to the current bone's head. */
990  if (rest) {
991  /* In restpose, arm_head == pose_head */
992  zero_v3(param->prev_h);
993  done = true;
994  }
995  else {
996  sub_v3_v3v3(delta, prev->pose_head, prev->bone->arm_head);
997  sub_v3_v3v3(h1, pchan->pose_head, delta);
998  }
999  }
1000  else if (bone->bbone_prev_type == BBONE_HANDLE_TANGENT) {
1001  /* Use bone direction by offsetting so that its tail meets current bone's head */
1002  if (rest) {
1003  sub_v3_v3v3(delta, prev->bone->arm_tail, prev->bone->arm_head);
1004  sub_v3_v3v3(h1, bone->arm_head, delta);
1005  }
1006  else {
1007  sub_v3_v3v3(delta, prev->pose_tail, prev->pose_head);
1008  sub_v3_v3v3(h1, pchan->pose_head, delta);
1009  }
1010  }
1011  else {
1012  /* Apply special handling for smoothly joining B-Bone chains */
1013  param->prev_bbone = (prev->bone->segments > 1);
1014 
1015  /* Use bone head as absolute position. */
1016  copy_v3_v3(h1, rest ? prev->bone->arm_head : prev->pose_head);
1017  }
1018 
1019  if (!done) {
1020  mul_v3_m4v3(param->prev_h, imat, h1);
1021  }
1022 
1023  if (!param->prev_bbone) {
1024  /* Find the previous roll to interpolate. */
1025  mul_m4_m4m4(param->prev_mat, imat, rest ? prev->bone->arm_mat : prev->pose_mat);
1026 
1027  /* Retrieve the local scale of the bone if necessary. */
1028  if ((bone->bbone_prev_flag & BBONE_HANDLE_SCALE_ANY) && !rest) {
1029  BKE_armature_mat_pose_to_bone(prev, prev->pose_mat, tmpmat);
1030  mat4_to_size(prev_scale, tmpmat);
1031  }
1032  }
1033  }
1034 
1035  if (next) {
1036  float h2[3];
1037  bool done = false;
1038 
1039  param->use_next = true;
1040 
1041  /* Transform next point inside this bone space. */
1042  if (bone->bbone_next_type == BBONE_HANDLE_RELATIVE) {
1043  /* Use delta movement (from restpose), and apply this relative to the current bone's tail. */
1044  if (rest) {
1045  /* In restpose, arm_head == pose_head */
1046  copy_v3_fl3(param->next_h, 0.0f, param->length, 0.0);
1047  done = true;
1048  }
1049  else {
1050  sub_v3_v3v3(delta, next->pose_head, next->bone->arm_head);
1051  add_v3_v3v3(h2, pchan->pose_tail, delta);
1052  }
1053  }
1054  else if (bone->bbone_next_type == BBONE_HANDLE_TANGENT) {
1055  /* Use bone direction by offsetting so that its head meets current bone's tail */
1056  if (rest) {
1057  sub_v3_v3v3(delta, next->bone->arm_tail, next->bone->arm_head);
1058  add_v3_v3v3(h2, bone->arm_tail, delta);
1059  }
1060  else {
1061  sub_v3_v3v3(delta, next->pose_tail, next->pose_head);
1062  add_v3_v3v3(h2, pchan->pose_tail, delta);
1063  }
1064  }
1065  else {
1066  /* Apply special handling for smoothly joining B-Bone chains */
1067  param->next_bbone = (next->bone->segments > 1);
1068 
1069  /* Use bone tail as absolute position. */
1070  copy_v3_v3(h2, rest ? next->bone->arm_tail : next->pose_tail);
1071  }
1072 
1073  if (!done) {
1074  mul_v3_m4v3(param->next_h, imat, h2);
1075  }
1076 
1077  /* Find the next roll to interpolate as well. */
1078  mul_m4_m4m4(param->next_mat, imat, rest ? next->bone->arm_mat : next->pose_mat);
1079 
1080  /* Retrieve the local scale of the bone if necessary. */
1081  if ((bone->bbone_next_flag & BBONE_HANDLE_SCALE_ANY) && !rest) {
1082  BKE_armature_mat_pose_to_bone(next, next->pose_mat, tmpmat);
1083  mat4_to_size(next_scale, tmpmat);
1084  }
1085  }
1086 
1087  /* Add effects from bbone properties over the top
1088  * - These properties allow users to hand-animate the
1089  * bone curve/shape, without having to resort to using
1090  * extra bones
1091  * - The "bone" level offsets are for defining the restpose
1092  * shape of the bone (e.g. for curved eyebrows for example).
1093  * -> In the viewport, it's needed to define what the rest pose
1094  * looks like
1095  * -> For "rest == 0", we also still need to have it present
1096  * so that we can "cancel out" this restpose when it comes
1097  * time to deform some geometry, it won't cause double transforms.
1098  * - The "pchan" level offsets are the ones that animators actually
1099  * end up animating
1100  */
1101  {
1102  param->ease1 = bone->ease1 + (!rest ? pchan->ease1 : 0.0f);
1103  param->ease2 = bone->ease2 + (!rest ? pchan->ease2 : 0.0f);
1104 
1105  param->roll1 = bone->roll1 + (!rest ? pchan->roll1 : 0.0f);
1106  param->roll2 = bone->roll2 + (!rest ? pchan->roll2 : 0.0f);
1107 
1108  if (bone->bbone_flag & BBONE_ADD_PARENT_END_ROLL) {
1109  if (prev) {
1110  if (prev->bone) {
1111  param->roll1 += prev->bone->roll2;
1112  }
1113 
1114  if (!rest) {
1115  param->roll1 += prev->roll2;
1116  }
1117  }
1118  }
1119 
1120  copy_v3_v3(param->scale_in, bone->scale_in);
1121  copy_v3_v3(param->scale_out, bone->scale_out);
1122 
1123  if (!rest) {
1124  mul_v3_v3(param->scale_in, pchan->scale_in);
1125  mul_v3_v3(param->scale_out, pchan->scale_out);
1126  }
1127 
1128  /* Extra curve x / z */
1129  param->curve_in_x = bone->curve_in_x + (!rest ? pchan->curve_in_x : 0.0f);
1130  param->curve_in_z = bone->curve_in_z + (!rest ? pchan->curve_in_z : 0.0f);
1131 
1132  param->curve_out_x = bone->curve_out_x + (!rest ? pchan->curve_out_x : 0.0f);
1133  param->curve_out_z = bone->curve_out_z + (!rest ? pchan->curve_out_z : 0.0f);
1134 
1135  if (bone->bbone_flag & BBONE_SCALE_EASING) {
1136  param->ease1 *= param->scale_in[1];
1137  param->curve_in_x *= param->scale_in[1];
1138  param->curve_in_z *= param->scale_in[1];
1139 
1140  param->ease2 *= param->scale_out[1];
1141  param->curve_out_x *= param->scale_out[1];
1142  param->curve_out_z *= param->scale_out[1];
1143  }
1144 
1145  /* Custom handle scale. */
1146  if (bone->bbone_prev_flag & BBONE_HANDLE_SCALE_X) {
1147  param->scale_in[0] *= prev_scale[0];
1148  }
1149  if (bone->bbone_prev_flag & BBONE_HANDLE_SCALE_Y) {
1150  param->scale_in[1] *= prev_scale[1];
1151  }
1152  if (bone->bbone_prev_flag & BBONE_HANDLE_SCALE_Z) {
1153  param->scale_in[2] *= prev_scale[2];
1154  }
1156  param->ease1 *= prev_scale[1];
1157  param->curve_in_x *= prev_scale[1];
1158  param->curve_in_z *= prev_scale[1];
1159  }
1160 
1161  if (bone->bbone_next_flag & BBONE_HANDLE_SCALE_X) {
1162  param->scale_out[0] *= next_scale[0];
1163  }
1164  if (bone->bbone_next_flag & BBONE_HANDLE_SCALE_Y) {
1165  param->scale_out[1] *= next_scale[1];
1166  }
1167  if (bone->bbone_next_flag & BBONE_HANDLE_SCALE_Z) {
1168  param->scale_out[2] *= next_scale[2];
1169  }
1171  param->ease2 *= next_scale[1];
1172  param->curve_out_x *= next_scale[1];
1173  param->curve_out_z *= next_scale[1];
1174  }
1175  }
1176 }
1177 
1179  const bool rest,
1180  const bool for_deform,
1181  Mat4 *result_array)
1182 {
1183  BBoneSplineParameters param;
1184 
1185  BKE_pchan_bbone_spline_params_get(pchan, rest, &param);
1186 
1187  pchan->bone->segments = BKE_pchan_bbone_spline_compute(&param, for_deform, result_array);
1188 }
1189 
1191  float h1[3],
1192  float *r_roll1,
1193  float h2[3],
1194  float *r_roll2,
1195  bool ease,
1196  bool offsets)
1197 {
1198  float mat3[3][3];
1199  float length = param->length;
1200  float epsilon = 1e-5 * length;
1201 
1202  if (param->do_scale) {
1203  length *= param->scale[1];
1204  }
1205 
1206  *r_roll1 = *r_roll2 = 0.0f;
1207 
1208  if (param->use_prev) {
1209  copy_v3_v3(h1, param->prev_h);
1210 
1211  if (param->prev_bbone) {
1212  /* If previous bone is B-bone too, use average handle direction. */
1213  h1[1] -= length;
1214  }
1215 
1216  if (normalize_v3(h1) < epsilon) {
1217  copy_v3_fl3(h1, 0.0f, -1.0f, 0.0f);
1218  }
1219 
1220  negate_v3(h1);
1221 
1222  if (!param->prev_bbone) {
1223  /* Find the previous roll to interpolate. */
1224  copy_m3_m4(mat3, param->prev_mat);
1225  mat3_vec_to_roll(mat3, h1, r_roll1);
1226  }
1227  }
1228  else {
1229  h1[0] = 0.0f;
1230  h1[1] = 1.0;
1231  h1[2] = 0.0f;
1232  }
1233 
1234  if (param->use_next) {
1235  copy_v3_v3(h2, param->next_h);
1236 
1237  /* If next bone is B-bone too, use average handle direction. */
1238  if (param->next_bbone) {
1239  /* pass */
1240  }
1241  else {
1242  h2[1] -= length;
1243  }
1244 
1245  if (normalize_v3(h2) < epsilon) {
1246  copy_v3_fl3(h2, 0.0f, 1.0f, 0.0f);
1247  }
1248 
1249  /* Find the next roll to interpolate as well. */
1250  copy_m3_m4(mat3, param->next_mat);
1251  mat3_vec_to_roll(mat3, h2, r_roll2);
1252  }
1253  else {
1254  h2[0] = 0.0f;
1255  h2[1] = 1.0f;
1256  h2[2] = 0.0f;
1257  }
1258 
1259  if (ease) {
1260  const float circle_factor = length * (cubic_tangent_factor_circle_v3(h1, h2) / 0.75f);
1261 
1262  const float hlength1 = param->ease1 * circle_factor;
1263  const float hlength2 = param->ease2 * circle_factor;
1264 
1265  /* and only now negate h2 */
1266  mul_v3_fl(h1, hlength1);
1267  mul_v3_fl(h2, -hlength2);
1268  }
1269 
1270  /* Add effects from bbone properties over the top
1271  * - These properties allow users to hand-animate the
1272  * bone curve/shape, without having to resort to using
1273  * extra bones
1274  * - The "bone" level offsets are for defining the rest-pose
1275  * shape of the bone (e.g. for curved eyebrows for example).
1276  * -> In the viewport, it's needed to define what the rest pose
1277  * looks like
1278  * -> For "rest == 0", we also still need to have it present
1279  * so that we can "cancel out" this rest-pose when it comes
1280  * time to deform some geometry, it won't cause double transforms.
1281  * - The "pchan" level offsets are the ones that animators actually
1282  * end up animating
1283  */
1284  if (offsets) {
1285  /* Add extra rolls. */
1286  *r_roll1 += param->roll1;
1287  *r_roll2 += param->roll2;
1288 
1289  /* Extra curve x / y */
1290  /* NOTE:
1291  * Scale correction factors here are to compensate for some random floating-point glitches
1292  * when scaling up the bone or its parent by a factor of approximately 8.15/6, which results
1293  * in the bone length getting scaled up too (from 1 to 8), causing the curve to flatten out.
1294  */
1295  const float xscale_correction = (param->do_scale) ? param->scale[0] : 1.0f;
1296  const float zscale_correction = (param->do_scale) ? param->scale[2] : 1.0f;
1297 
1298  h1[0] += param->curve_in_x * xscale_correction;
1299  h1[2] += param->curve_in_z * zscale_correction;
1300 
1301  h2[0] += param->curve_out_x * xscale_correction;
1302  h2[2] += param->curve_out_z * zscale_correction;
1303  }
1304 }
1305 
1307  const float scalemats[2][4][4],
1308  const float pos[3],
1309  const float axis[3],
1310  float roll,
1311  float scalex,
1312  float scalez,
1313  float result[4][4])
1314 {
1315  float mat3[3][3];
1316 
1317  vec_roll_to_mat3(axis, roll, mat3);
1318 
1319  copy_m4_m3(result, mat3);
1320  copy_v3_v3(result[3], pos);
1321 
1322  if (param->do_scale) {
1323  /* Correct for scaling when this matrix is used in scaled space. */
1324  mul_m4_series(result, scalemats[0], result, scalemats[1]);
1325  }
1326 
1327  /* BBone scale... */
1328  mul_v3_fl(result[0], scalex);
1329  mul_v3_fl(result[2], scalez);
1330 }
1331 
1332 /* Fade from first to second derivative when the handle is very short. */
1333 static void ease_handle_axis(const float deriv1[3], const float deriv2[3], float r_axis[3])
1334 {
1335  const float gap = 0.1f;
1336 
1337  copy_v3_v3(r_axis, deriv1);
1338 
1339  const float len2 = len_squared_v3(deriv2);
1340  if (UNLIKELY(len2 == 0.0f)) {
1341  return;
1342  }
1343  const float len1 = len_squared_v3(deriv1);
1344  const float ratio = len1 / len2;
1345  if (ratio < gap * gap) {
1346  madd_v3_v3fl(r_axis, deriv2, gap - sqrtf(ratio));
1347  }
1348 }
1349 
1351  const bool for_deform,
1352  Mat4 *result_array)
1353 {
1354  float scalemats[2][4][4];
1355  float bezt_controls[4][3];
1356  float h1[3], roll1, h2[3], roll2, prev[3], cur[3], axis[3];
1357  float length = param->length;
1358 
1359  if (param->do_scale) {
1360  size_to_mat4(scalemats[1], param->scale);
1361  invert_m4_m4(scalemats[0], scalemats[1]);
1362 
1363  length *= param->scale[1];
1364  }
1365 
1366  BKE_pchan_bbone_handles_compute(param, h1, &roll1, h2, &roll2, true, true);
1367 
1368  /* Make curve. */
1370 
1371  copy_v3_fl3(bezt_controls[3], 0.0f, length, 0.0f);
1372  add_v3_v3v3(bezt_controls[2], bezt_controls[3], h2);
1373  copy_v3_v3(bezt_controls[1], h1);
1374  zero_v3(bezt_controls[0]);
1375 
1376  /* Compute lengthwise segment scale. */
1377  float segment_scales[MAX_BBONE_SUBDIV];
1378 
1379  CLAMP_MIN(param->scale_in[1], 0.0001f);
1380  CLAMP_MIN(param->scale_out[1], 0.0001f);
1381 
1382  const float log_scale_in_len = logf(param->scale_in[1]);
1383  const float log_scale_out_len = logf(param->scale_out[1]);
1384 
1385  for (int i = 0; i < param->segments; i++) {
1386  const float fac = ((float)i) / (param->segments - 1);
1387  segment_scales[i] = expf(interpf(log_scale_out_len, log_scale_in_len, fac));
1388  }
1389 
1390  /* Compute segment vertex offsets along the curve length. */
1391  float bezt_points[MAX_BBONE_SUBDIV + 1];
1392 
1394  bezt_controls, MAX_BBONE_SUBDIV, param->segments, segment_scales, bezt_points);
1395 
1396  /* Deformation uses N+1 matrices computed at points between the segments. */
1397  if (for_deform) {
1398  /* Bezier derivatives. */
1399  float bezt_deriv1[3][3], bezt_deriv2[2][3];
1400 
1401  for (int i = 0; i < 3; i++) {
1402  sub_v3_v3v3(bezt_deriv1[i], bezt_controls[i + 1], bezt_controls[i]);
1403  }
1404  for (int i = 0; i < 2; i++) {
1405  sub_v3_v3v3(bezt_deriv2[i], bezt_deriv1[i + 1], bezt_deriv1[i]);
1406  }
1407 
1408  /* End points require special handling to fix zero length handles. */
1409  ease_handle_axis(bezt_deriv1[0], bezt_deriv2[0], axis);
1411  scalemats,
1412  bezt_controls[0],
1413  axis,
1414  roll1,
1415  param->scale_in[0],
1416  param->scale_in[2],
1417  result_array[0].mat);
1418 
1419  for (int a = 1; a < param->segments; a++) {
1420  evaluate_cubic_bezier(bezt_controls, bezt_points[a], cur, axis);
1421 
1422  float fac = ((float)a) / param->segments;
1423  float roll = interpf(roll2, roll1, fac);
1424  float scalex = interpf(param->scale_out[0], param->scale_in[0], fac);
1425  float scalez = interpf(param->scale_out[2], param->scale_in[2], fac);
1426 
1428  param, scalemats, cur, axis, roll, scalex, scalez, result_array[a].mat);
1429  }
1430 
1431  negate_v3(bezt_deriv2[1]);
1432  ease_handle_axis(bezt_deriv1[2], bezt_deriv2[1], axis);
1434  scalemats,
1435  bezt_controls[3],
1436  axis,
1437  roll2,
1438  param->scale_out[0],
1439  param->scale_out[2],
1440  result_array[param->segments].mat);
1441  }
1442  /* Other code (e.g. display) uses matrices for the segments themselves. */
1443  else {
1444  zero_v3(prev);
1445 
1446  for (int a = 0; a < param->segments; a++) {
1447  evaluate_cubic_bezier(bezt_controls, bezt_points[a + 1], cur, axis);
1448 
1449  sub_v3_v3v3(axis, cur, prev);
1450 
1451  float fac = (a + 0.5f) / param->segments;
1452  float roll = interpf(roll2, roll1, fac);
1453  float scalex = interpf(param->scale_out[0], param->scale_in[0], fac);
1454  float scalez = interpf(param->scale_out[2], param->scale_in[2], fac);
1455 
1457  param, scalemats, prev, axis, roll, scalex, scalez, result_array[a].mat);
1458  copy_v3_v3(prev, cur);
1459  }
1460  }
1461 
1462  return param->segments;
1463 }
1464 
1465 static void allocate_bbone_cache(bPoseChannel *pchan, int segments)
1466 {
1467  bPoseChannel_Runtime *runtime = &pchan->runtime;
1468 
1469  if (runtime->bbone_segments != segments) {
1471 
1472  runtime->bbone_segments = segments;
1474  1 + (uint)segments, sizeof(Mat4), "bPoseChannel_Runtime::bbone_rest_mats");
1476  1 + (uint)segments, sizeof(Mat4), "bPoseChannel_Runtime::bbone_pose_mats");
1478  2 + (uint)segments, sizeof(Mat4), "bPoseChannel_Runtime::bbone_deform_mats");
1480  1 + (uint)segments, sizeof(DualQuat), "bPoseChannel_Runtime::bbone_dual_quats");
1481  }
1482 }
1483 
1485 {
1486  bPoseChannel_Runtime *runtime = &pchan->runtime;
1487  Bone *bone = pchan->bone;
1488  int segments = bone->segments;
1489 
1490  BLI_assert(segments > 1);
1491 
1492  /* Allocate the cache if needed. */
1493  allocate_bbone_cache(pchan, segments);
1494 
1495  /* Compute the shape. */
1496  Mat4 *b_bone = runtime->bbone_pose_mats;
1497  Mat4 *b_bone_rest = runtime->bbone_rest_mats;
1498  Mat4 *b_bone_mats = runtime->bbone_deform_mats;
1499  DualQuat *b_bone_dual_quats = runtime->bbone_dual_quats;
1500  int a;
1501 
1502  BKE_pchan_bbone_spline_setup(pchan, false, true, b_bone);
1503  BKE_pchan_bbone_spline_setup(pchan, true, true, b_bone_rest);
1504 
1505  /* Compute deform matrices. */
1506  /* first matrix is the inverse arm_mat, to bring points in local bone space
1507  * for finding out which segment it belongs to */
1508  invert_m4_m4(b_bone_mats[0].mat, bone->arm_mat);
1509 
1510  /* then we make the b_bone_mats:
1511  * - first transform to local bone space
1512  * - translate over the curve to the bbone mat space
1513  * - transform with b_bone matrix
1514  * - transform back into global space */
1515 
1516  for (a = 0; a <= bone->segments; a++) {
1517  float tmat[4][4];
1518 
1519  invert_m4_m4(tmat, b_bone_rest[a].mat);
1520  mul_m4_series(b_bone_mats[a + 1].mat,
1521  pchan->chan_mat,
1522  bone->arm_mat,
1523  b_bone[a].mat,
1524  tmat,
1525  b_bone_mats[0].mat);
1526 
1527  /* Compute the orthonormal object space rest matrix of the segment. */
1528  mul_m4_m4m4(tmat, bone->arm_mat, b_bone_rest[a].mat);
1529  normalize_m4(tmat);
1530 
1531  mat4_to_dquat(&b_bone_dual_quats[a], tmat, b_bone_mats[a + 1].mat);
1532  }
1533 }
1534 
1536 {
1537  bPoseChannel_Runtime *runtime = &pchan->runtime;
1538  bPoseChannel_Runtime *runtime_from = &pchan_from->runtime;
1539  int segments = runtime_from->bbone_segments;
1540 
1541  if (segments <= 1) {
1543  }
1544  else {
1545  allocate_bbone_cache(pchan, segments);
1546 
1547  memcpy(runtime->bbone_rest_mats, runtime_from->bbone_rest_mats, sizeof(Mat4) * (1 + segments));
1548  memcpy(runtime->bbone_pose_mats, runtime_from->bbone_pose_mats, sizeof(Mat4) * (1 + segments));
1549  memcpy(runtime->bbone_deform_mats,
1550  runtime_from->bbone_deform_mats,
1551  sizeof(Mat4) * (2 + segments));
1552  memcpy(runtime->bbone_dual_quats,
1553  runtime_from->bbone_dual_quats,
1554  sizeof(DualQuat) * (1 + segments));
1555  }
1556 }
1557 
1559  float pos,
1560  int *r_index,
1561  float *r_blend_next)
1562 {
1563  int segments = pchan->bone->segments;
1564 
1565  CLAMP(pos, 0.0f, 1.0f);
1566 
1567  /* Calculate the indices of the 2 affecting b_bone segments.
1568  * Integer part is the first segment's index.
1569  * Integer part plus 1 is the second segment's index.
1570  * Fractional part is the blend factor. */
1571  float pre_blend = pos * (float)segments;
1572 
1573  int index = (int)floorf(pre_blend);
1574  CLAMP(index, 0, segments - 1);
1575 
1576  float blend = pre_blend - index;
1577  CLAMP(blend, 0.0f, 1.0f);
1578 
1579  *r_index = index;
1580  *r_blend_next = blend;
1581 }
1582 
1585 /* -------------------------------------------------------------------- */
1589 void BKE_armature_mat_world_to_pose(Object *ob, const float inmat[4][4], float outmat[4][4])
1590 {
1591  float obmat[4][4];
1592 
1593  /* prevent crashes */
1594  if (ob == NULL) {
1595  return;
1596  }
1597 
1598  /* Get inverse of (armature) object's matrix. */
1599  invert_m4_m4(obmat, ob->obmat);
1600 
1601  /* multiply given matrix by object's-inverse to find pose-space matrix */
1602  mul_m4_m4m4(outmat, inmat, obmat);
1603 }
1604 
1605 void BKE_armature_loc_world_to_pose(Object *ob, const float inloc[3], float outloc[3])
1606 {
1607  float xLocMat[4][4];
1608  float nLocMat[4][4];
1609 
1610  /* build matrix for location */
1611  unit_m4(xLocMat);
1612  copy_v3_v3(xLocMat[3], inloc);
1613 
1614  /* get bone-space cursor matrix and extract location */
1615  BKE_armature_mat_world_to_pose(ob, xLocMat, nLocMat);
1616  copy_v3_v3(outloc, nLocMat[3]);
1617 }
1618 
1621 /* -------------------------------------------------------------------- */
1625 void BKE_bone_offset_matrix_get(const Bone *bone, float offs_bone[4][4])
1626 {
1627  BLI_assert(bone->parent != NULL);
1628 
1629  /* Bone transform itself. */
1630  copy_m4_m3(offs_bone, bone->bone_mat);
1631 
1632  /* The bone's root offset (is in the parent's coordinate system). */
1633  copy_v3_v3(offs_bone[3], bone->head);
1634 
1635  /* Get the length translation of parent (length along y axis). */
1636  offs_bone[3][1] += bone->parent->length;
1637 }
1638 
1640  BoneParentTransform *r_bpt)
1641 {
1642  const Bone *bone, *parbone;
1643  const bPoseChannel *parchan;
1644 
1645  /* set up variables for quicker access below */
1646  bone = pchan->bone;
1647  parbone = bone->parent;
1648  parchan = pchan->parent;
1649 
1650  if (parchan) {
1651  float offs_bone[4][4];
1652  /* yoffs(b-1) + root(b) + bonemat(b). */
1653  BKE_bone_offset_matrix_get(bone, offs_bone);
1654 
1656  bone->inherit_scale_mode,
1657  offs_bone,
1658  parbone->arm_mat,
1659  parchan->pose_mat,
1660  r_bpt);
1661  }
1662  else {
1664  bone->flag, bone->inherit_scale_mode, bone->arm_mat, NULL, NULL, r_bpt);
1665  }
1666 }
1667 
1669  int inherit_scale_mode,
1670  const float offs_bone[4][4],
1671  const float parent_arm_mat[4][4],
1672  const float parent_pose_mat[4][4],
1673  BoneParentTransform *r_bpt)
1674 {
1675  copy_v3_fl(r_bpt->post_scale, 1.0f);
1676 
1677  if (parent_pose_mat) {
1678  const bool use_rotation = (bone_flag & BONE_HINGE) == 0;
1679  const bool full_transform = use_rotation && inherit_scale_mode == BONE_INHERIT_SCALE_FULL;
1680 
1681  /* Compose the rotscale matrix for this bone. */
1682  if (full_transform) {
1683  /* Parent pose rotation and scale. */
1684  mul_m4_m4m4(r_bpt->rotscale_mat, parent_pose_mat, offs_bone);
1685  }
1686  else {
1687  float tmat[4][4], tscale[3];
1688 
1689  /* If using parent pose rotation: */
1690  if (use_rotation) {
1691  copy_m4_m4(tmat, parent_pose_mat);
1692 
1693  /* Normalize the matrix when needed. */
1694  switch (inherit_scale_mode) {
1697  /* Keep scale and shear. */
1698  break;
1699 
1702  /* Remove scale and shear from parent. */
1703  orthogonalize_m4_stable(tmat, 1, true);
1704  break;
1705 
1707  /* Remove shear and extract scale. */
1708  orthogonalize_m4_stable(tmat, 1, false);
1709  normalize_m4_ex(tmat, r_bpt->post_scale);
1710  break;
1711 
1713  /* Remove only scale - bad legacy way. */
1714  normalize_m4(tmat);
1715  break;
1716 
1717  default:
1719  }
1720  }
1721  /* If removing parent pose rotation: */
1722  else {
1723  copy_m4_m4(tmat, parent_arm_mat);
1724 
1725  /* Copy the parent scale when needed. */
1726  switch (inherit_scale_mode) {
1728  /* Ignore effects of shear. */
1729  mat4_to_size(tscale, parent_pose_mat);
1730  rescale_m4(tmat, tscale);
1731  break;
1732 
1734  /* Take the effects of parent shear into account to get exact volume. */
1735  mat4_to_size_fix_shear(tscale, parent_pose_mat);
1736  rescale_m4(tmat, tscale);
1737  break;
1738 
1740  mat4_to_size_fix_shear(r_bpt->post_scale, parent_pose_mat);
1741  break;
1742 
1746  /* Keep unscaled. */
1747  break;
1748 
1749  default:
1751  }
1752  }
1753 
1754  /* Apply the average parent scale when needed. */
1755  if (inherit_scale_mode == BONE_INHERIT_SCALE_AVERAGE) {
1756  mul_mat3_m4_fl(tmat, cbrtf(fabsf(mat4_to_volume_scale(parent_pose_mat))));
1757  }
1758 
1759  mul_m4_m4m4(r_bpt->rotscale_mat, tmat, offs_bone);
1760 
1761  /* Remove remaining shear when needed, preserving volume. */
1762  if (inherit_scale_mode == BONE_INHERIT_SCALE_FIX_SHEAR) {
1763  orthogonalize_m4_stable(r_bpt->rotscale_mat, 1, false);
1764  }
1765  }
1766 
1767  /* Compose the loc matrix for this bone. */
1768  /* NOTE: That version does not modify bone's loc when HINGE/NO_SCALE options are set. */
1769 
1770  /* In this case, use the object's space *orientation*. */
1771  if (bone_flag & BONE_NO_LOCAL_LOCATION) {
1772  /* XXX I'm sure that code can be simplified! */
1773  float bone_loc[4][4], bone_rotscale[3][3], tmat4[4][4], tmat3[3][3];
1774  unit_m4(bone_loc);
1775  unit_m4(r_bpt->loc_mat);
1776  unit_m4(tmat4);
1777 
1778  mul_v3_m4v3(bone_loc[3], parent_pose_mat, offs_bone[3]);
1779 
1780  unit_m3(bone_rotscale);
1781  copy_m3_m4(tmat3, parent_pose_mat);
1782  mul_m3_m3m3(bone_rotscale, tmat3, bone_rotscale);
1783 
1784  copy_m4_m3(tmat4, bone_rotscale);
1785  mul_m4_m4m4(r_bpt->loc_mat, bone_loc, tmat4);
1786  }
1787  /* Those flags do not affect position, use plain parent transform space! */
1788  else if (!full_transform) {
1789  mul_m4_m4m4(r_bpt->loc_mat, parent_pose_mat, offs_bone);
1790  }
1791  /* Else (i.e. default, usual case),
1792  * just use the same matrix for rotation/scaling, and location. */
1793  else {
1794  copy_m4_m4(r_bpt->loc_mat, r_bpt->rotscale_mat);
1795  }
1796  }
1797  /* Root bones. */
1798  else {
1799  /* Rotation/scaling. */
1800  copy_m4_m4(r_bpt->rotscale_mat, offs_bone);
1801  /* Translation. */
1802  if (bone_flag & BONE_NO_LOCAL_LOCATION) {
1803  /* Translation of arm_mat, without the rotation. */
1804  unit_m4(r_bpt->loc_mat);
1805  copy_v3_v3(r_bpt->loc_mat[3], offs_bone[3]);
1806  }
1807  else {
1808  copy_m4_m4(r_bpt->loc_mat, r_bpt->rotscale_mat);
1809  }
1810  }
1811 }
1812 
1814 {
1815  unit_m4(bpt->rotscale_mat);
1816  unit_m4(bpt->loc_mat);
1817  copy_v3_fl(bpt->post_scale, 1.0f);
1818 }
1819 
1821 {
1822  invert_m4(bpt->rotscale_mat);
1823  invert_m4(bpt->loc_mat);
1824  invert_v3_safe(bpt->post_scale);
1825 }
1826 
1828  const struct BoneParentTransform *in2,
1829  struct BoneParentTransform *result)
1830 {
1831  mul_m4_m4m4(result->rotscale_mat, in1->rotscale_mat, in2->rotscale_mat);
1832  mul_m4_m4m4(result->loc_mat, in1->loc_mat, in2->loc_mat);
1833  mul_v3_v3v3(result->post_scale, in1->post_scale, in2->post_scale);
1834 }
1835 
1837  const float inmat[4][4],
1838  float outmat[4][4])
1839 {
1840  /* in case inmat == outmat */
1841  float tmploc[3];
1842  copy_v3_v3(tmploc, inmat[3]);
1843 
1844  mul_m4_m4m4(outmat, bpt->rotscale_mat, inmat);
1845  mul_v3_m4v3(outmat[3], bpt->loc_mat, tmploc);
1846  rescale_m4(outmat, bpt->post_scale);
1847 }
1848 
1850  const float inmat[4][4],
1851  float outmat[4][4])
1852 {
1853  BoneParentTransform bpt;
1854 
1857  BKE_bone_parent_transform_apply(&bpt, inmat, outmat);
1858 }
1859 
1861  const float inmat[4][4],
1862  float outmat[4][4])
1863 {
1864  BoneParentTransform bpt;
1865 
1867  BKE_bone_parent_transform_apply(&bpt, inmat, outmat);
1868 }
1869 
1870 void BKE_armature_loc_pose_to_bone(bPoseChannel *pchan, const float inloc[3], float outloc[3])
1871 {
1872  float xLocMat[4][4];
1873  float nLocMat[4][4];
1874 
1875  /* build matrix for location */
1876  unit_m4(xLocMat);
1877  copy_v3_v3(xLocMat[3], inloc);
1878 
1879  /* get bone-space cursor matrix and extract location */
1880  BKE_armature_mat_pose_to_bone(pchan, xLocMat, nLocMat);
1881  copy_v3_v3(outloc, nLocMat[3]);
1882 }
1883 
1886 /* -------------------------------------------------------------------- */
1893  Object *ob,
1894  bPoseChannel *pchan,
1895  const float inmat[4][4],
1896  float outmat[4][4])
1897 {
1898  bPoseChannel work_pchan = *pchan;
1899 
1900  /* recalculate pose matrix with only parent transformations,
1901  * bone loc/sca/rot is ignored, scene and frame are not used. */
1902  BKE_pose_where_is_bone(depsgraph, NULL, ob, &work_pchan, 0.0f, false);
1903 
1904  /* Find the matrix, need to remove the bone transforms first so this is calculated
1905  * as a matrix to set rather than a difference on top of what's already there. */
1906  unit_m4(outmat);
1907  BKE_pchan_apply_mat4(&work_pchan, outmat, false);
1908 
1909  BKE_armature_mat_pose_to_bone(&work_pchan, inmat, outmat);
1910 }
1911 
1912 void BKE_pchan_mat3_to_rot(bPoseChannel *pchan, const float mat[3][3], bool use_compat)
1913 {
1914  BLI_ASSERT_UNIT_M3(mat);
1915 
1916  switch (pchan->rotmode) {
1917  case ROT_MODE_QUAT:
1918  mat3_normalized_to_quat(pchan->quat, mat);
1919  break;
1920  case ROT_MODE_AXISANGLE:
1921  mat3_normalized_to_axis_angle(pchan->rotAxis, &pchan->rotAngle, mat);
1922  break;
1923  default: /* euler */
1924  if (use_compat) {
1925  mat3_normalized_to_compatible_eulO(pchan->eul, pchan->eul, pchan->rotmode, mat);
1926  }
1927  else {
1928  mat3_normalized_to_eulO(pchan->eul, pchan->rotmode, mat);
1929  }
1930  break;
1931  }
1932 }
1933 
1934 void BKE_pchan_rot_to_mat3(const bPoseChannel *pchan, float r_mat[3][3])
1935 {
1936  /* rotations may either be quats, eulers (with various rotation orders), or axis-angle */
1937  if (pchan->rotmode > 0) {
1938  /* Euler rotations (will cause gimbal lock,
1939  * but this can be alleviated a bit with rotation orders) */
1940  eulO_to_mat3(r_mat, pchan->eul, pchan->rotmode);
1941  }
1942  else if (pchan->rotmode == ROT_MODE_AXISANGLE) {
1943  /* axis-angle - not really that great for 3D-changing orientations */
1944  axis_angle_to_mat3(r_mat, pchan->rotAxis, pchan->rotAngle);
1945  }
1946  else {
1947  /* quats are normalized before use to eliminate scaling issues */
1948  float quat[4];
1949 
1950  /* NOTE: we now don't normalize the stored values anymore,
1951  * since this was kind of evil in some cases but if this proves to be too problematic,
1952  * switch back to the old system of operating directly on the stored copy. */
1953  normalize_qt_qt(quat, pchan->quat);
1954  quat_to_mat3(r_mat, quat);
1955  }
1956 }
1957 
1958 void BKE_pchan_apply_mat4(bPoseChannel *pchan, const float mat[4][4], bool use_compat)
1959 {
1960  float rot[3][3];
1961  mat4_to_loc_rot_size(pchan->loc, rot, pchan->size, mat);
1962  BKE_pchan_mat3_to_rot(pchan, rot, use_compat);
1963 }
1964 
1965 void BKE_armature_mat_pose_to_delta(float delta_mat[4][4],
1966  float pose_mat[4][4],
1967  float arm_mat[4][4])
1968 {
1969  float imat[4][4];
1970 
1971  invert_m4_m4(imat, arm_mat);
1972  mul_m4_m4m4(delta_mat, imat, pose_mat);
1973 }
1974 
1977 /* -------------------------------------------------------------------- */
1984  float quat[4], float eul[3], float axis[3], float *angle, short oldMode, short newMode)
1985 {
1986  /* check if any change - if so, need to convert data */
1987  if (newMode > 0) { /* to euler */
1988  if (oldMode == ROT_MODE_AXISANGLE) {
1989  /* axis-angle to euler */
1990  axis_angle_to_eulO(eul, newMode, axis, *angle);
1991  }
1992  else if (oldMode == ROT_MODE_QUAT) {
1993  /* quat to euler */
1994  normalize_qt(quat);
1995  quat_to_eulO(eul, newMode, quat);
1996  }
1997  /* else { no conversion needed } */
1998  }
1999  else if (newMode == ROT_MODE_QUAT) { /* to quat */
2000  if (oldMode == ROT_MODE_AXISANGLE) {
2001  /* axis angle to quat */
2002  axis_angle_to_quat(quat, axis, *angle);
2003  }
2004  else if (oldMode > 0) {
2005  /* euler to quat */
2006  eulO_to_quat(quat, eul, oldMode);
2007  }
2008  /* else { no conversion needed } */
2009  }
2010  else if (newMode == ROT_MODE_AXISANGLE) { /* to axis-angle */
2011  if (oldMode > 0) {
2012  /* euler to axis angle */
2013  eulO_to_axis_angle(axis, angle, eul, oldMode);
2014  }
2015  else if (oldMode == ROT_MODE_QUAT) {
2016  /* quat to axis angle */
2017  normalize_qt(quat);
2018  quat_to_axis_angle(axis, angle, quat);
2019  }
2020 
2021  /* When converting to axis-angle,
2022  * we need a special exception for the case when there is no axis. */
2023  if (IS_EQF(axis[0], axis[1]) && IS_EQF(axis[1], axis[2])) {
2024  /* for now, rotate around y-axis then (so that it simply becomes the roll) */
2025  axis[1] = 1.0f;
2026  }
2027  }
2028 }
2029 
2032 /* -------------------------------------------------------------------- */
2056 void mat3_to_vec_roll(const float mat[3][3], float r_vec[3], float *r_roll)
2057 {
2058  if (r_vec) {
2059  copy_v3_v3(r_vec, mat[1]);
2060  }
2061 
2062  if (r_roll) {
2063  mat3_vec_to_roll(mat, mat[1], r_roll);
2064  }
2065 }
2066 
2067 void mat3_vec_to_roll(const float mat[3][3], const float vec[3], float *r_roll)
2068 {
2069  float vecmat[3][3], vecmatinv[3][3], rollmat[3][3], q[4];
2070 
2071  /* Compute the orientation relative to the vector with zero roll. */
2072  vec_roll_to_mat3(vec, 0.0f, vecmat);
2073  invert_m3_m3(vecmatinv, vecmat);
2074  mul_m3_m3m3(rollmat, vecmatinv, mat);
2075 
2076  /* Extract the twist angle as the roll value. */
2077  mat3_to_quat(q, rollmat);
2078 
2079  *r_roll = quat_split_swing_and_twist(q, 1, NULL, NULL);
2080 }
2081 
2082 void vec_roll_to_mat3_normalized(const float nor[3], const float roll, float r_mat[3][3])
2083 {
2157  const float SAFE_THRESHOLD = 6.1e-3f; /* Theta above this value has good enough precision. */
2158  const float CRITICAL_THRESHOLD = 2.5e-4f; /* True singularity if XZ distance is below this. */
2159  const float THRESHOLD_SQUARED = CRITICAL_THRESHOLD * CRITICAL_THRESHOLD;
2160 
2161  const float x = nor[0];
2162  const float y = nor[1];
2163  const float z = nor[2];
2164 
2165  float theta = 1.0f + y; /* Remapping Y from [-1,+1] to [0,2]. */
2166  const float theta_alt = x * x + z * z; /* Squared distance from origin in x,z plane. */
2167  float rMatrix[3][3], bMatrix[3][3];
2168 
2170 
2171  /* Determine if the input is far enough from the true singularity of this type of
2172  * transformation at (0,-1,0), where roll becomes 0/0 undefined without a limit.
2173  *
2174  * When theta is close to zero (nor is aligned close to negative Y Axis),
2175  * we have to check we do have non-null X/Z components as well.
2176  * Also, due to float precision errors, nor can be (0.0, -0.99999994, 0.0) which results
2177  * in theta being close to zero. This will cause problems when theta is used as divisor.
2178  */
2179  if (theta > SAFE_THRESHOLD || theta_alt > THRESHOLD_SQUARED) {
2180  /* nor is *not* aligned to negative Y-axis (0,-1,0). */
2181 
2182  bMatrix[0][1] = -x;
2183  bMatrix[1][0] = x;
2184  bMatrix[1][1] = y;
2185  bMatrix[1][2] = z;
2186  bMatrix[2][1] = -z;
2187 
2188  if (theta <= SAFE_THRESHOLD) {
2189  /* When nor is close to negative Y axis (0,-1,0) the theta precision is very bad,
2190  * so recompute it from x and z instead, using the series expansion for sqrt. */
2191  theta = theta_alt * 0.5f + theta_alt * theta_alt * 0.125f;
2192  }
2193 
2194  bMatrix[0][0] = 1 - x * x / theta;
2195  bMatrix[2][2] = 1 - z * z / theta;
2196  bMatrix[2][0] = bMatrix[0][2] = -x * z / theta;
2197  }
2198  else {
2199  /* nor is very close to negative Y axis (0,-1,0): use simple symmetry by Z axis. */
2200  unit_m3(bMatrix);
2201  bMatrix[0][0] = bMatrix[1][1] = -1.0;
2202  }
2203 
2204  /* Make Roll matrix */
2205  axis_angle_normalized_to_mat3(rMatrix, nor, roll);
2206 
2207  /* Combine and output result */
2208  mul_m3_m3m3(r_mat, rMatrix, bMatrix);
2209 }
2210 
2211 void vec_roll_to_mat3(const float vec[3], const float roll, float r_mat[3][3])
2212 {
2213  float nor[3];
2214 
2215  normalize_v3_v3(nor, vec);
2216  vec_roll_to_mat3_normalized(nor, roll, r_mat);
2217 }
2218 
2221 /* -------------------------------------------------------------------- */
2225 void BKE_armature_where_is_bone(Bone *bone, const Bone *bone_parent, const bool use_recursion)
2226 {
2227  float vec[3];
2228 
2229  /* Bone Space */
2230  sub_v3_v3v3(vec, bone->tail, bone->head);
2231  bone->length = len_v3(vec);
2232  vec_roll_to_mat3(vec, bone->roll, bone->bone_mat);
2233 
2234  /* this is called on old file reading too... */
2235  if (bone->xwidth == 0.0f) {
2236  bone->xwidth = 0.1f;
2237  bone->zwidth = 0.1f;
2238  bone->segments = 1;
2239  }
2240 
2241  if (bone_parent) {
2242  float offs_bone[4][4];
2243  /* yoffs(b-1) + root(b) + bonemat(b) */
2244  BKE_bone_offset_matrix_get(bone, offs_bone);
2245 
2246  /* Compose the matrix for this bone. */
2247  mul_m4_m4m4(bone->arm_mat, bone_parent->arm_mat, offs_bone);
2248  }
2249  else {
2250  copy_m4_m3(bone->arm_mat, bone->bone_mat);
2251  copy_v3_v3(bone->arm_mat[3], bone->head);
2252  }
2253 
2254  /* and the kiddies */
2255  if (use_recursion) {
2256  bone_parent = bone;
2257  for (bone = bone->childbase.first; bone; bone = bone->next) {
2258  BKE_armature_where_is_bone(bone, bone_parent, use_recursion);
2259  }
2260  }
2261 }
2262 
2264 {
2265  Bone *bone;
2266 
2267  /* hierarchical from root to children */
2268  for (bone = arm->bonebase.first; bone; bone = bone->next) {
2269  BKE_armature_where_is_bone(bone, NULL, true);
2270  }
2271 }
2272 
2275 /* -------------------------------------------------------------------- */
2283  bPose *pose, Bone *bone, bPoseChannel *parchan, int counter, Bone **r_last_visited_bone_p)
2284 {
2285  bPoseChannel *pchan = BKE_pose_channel_ensure(pose, bone->name); /* verify checks and/or adds */
2286 
2287  pchan->bone = bone;
2288  pchan->parent = parchan;
2289 
2290  /* We ensure the current pchan is immediately after the one we just generated/updated in the
2291  * previous call to `rebuild_pose_bone`.
2292  *
2293  * It may be either the parent, the previous sibling, or the last
2294  * (grand-(grand-(...)))-child (as processed by the recursive, depth-first nature of this
2295  * function) of the previous sibling.
2296  *
2297  * NOTE: In most cases there is nothing to do here, but pose list may get out of order when some
2298  * bones are added, removed or moved in the armature data. */
2299  bPoseChannel *pchan_prev = pchan->prev;
2300  const Bone *last_visited_bone = *r_last_visited_bone_p;
2301  if ((pchan_prev == NULL && last_visited_bone != NULL) ||
2302  (pchan_prev != NULL && pchan_prev->bone != last_visited_bone)) {
2303  pchan_prev = last_visited_bone != NULL ?
2304  BKE_pose_channel_find_name(pose, last_visited_bone->name) :
2305  NULL;
2306  BLI_remlink(&pose->chanbase, pchan);
2307  BLI_insertlinkafter(&pose->chanbase, pchan_prev, pchan);
2308  }
2309 
2310  *r_last_visited_bone_p = pchan->bone;
2311  counter++;
2312 
2313  for (bone = bone->childbase.first; bone; bone = bone->next) {
2314  counter = rebuild_pose_bone(pose, bone, pchan, counter, r_last_visited_bone_p);
2315  /* for quick detecting of next bone in chain, only b-bone uses it now */
2316  if (bone->flag & BONE_CONNECTED) {
2317  pchan->child = BKE_pose_channel_find_name(pose, bone->name);
2318  }
2319  }
2320 
2321  return counter;
2322 }
2323 
2325 {
2326  LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) {
2327  pchan->bone = NULL;
2328  pchan->child = NULL;
2329  }
2330 }
2331 
2333 {
2334  LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) {
2335  pchan->bone = BKE_armature_find_bone_name(armature, pchan->name);
2336  }
2337 }
2338 
2341 {
2342  return (bone != NULL) ? BKE_pose_channel_find_name(pose, bone->name) : NULL;
2343 }
2344 
2346 {
2347  pchan->bbone_prev = pose_channel_find_bone(pose, pchan->bone->bbone_prev);
2348  pchan->bbone_next = pose_channel_find_bone(pose, pchan->bone->bbone_next);
2349 }
2350 
2351 void BKE_pose_channels_clear_with_null_bone(bPose *pose, const bool do_id_user)
2352 {
2353  LISTBASE_FOREACH_MUTABLE (bPoseChannel *, pchan, &pose->chanbase) {
2354  if (pchan->bone == NULL) {
2355  BKE_pose_channel_free_ex(pchan, do_id_user);
2357  BLI_freelinkN(&pose->chanbase, pchan);
2358  }
2359  }
2360 }
2361 
2362 void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_user)
2363 {
2364  Bone *bone;
2365  bPose *pose;
2366  bPoseChannel *pchan;
2367  int counter = 0;
2368 
2369  /* only done here */
2370  if (ob->pose == NULL) {
2371  /* create new pose */
2372  ob->pose = MEM_callocN(sizeof(bPose), "new pose");
2373 
2374  /* set default settings for animviz */
2376  }
2377  pose = ob->pose;
2378 
2379  /* clear */
2381 
2382  /* first step, check if all channels are there */
2383  Bone *prev_bone = NULL;
2384  for (bone = arm->bonebase.first; bone; bone = bone->next) {
2385  counter = rebuild_pose_bone(pose, bone, NULL, counter, &prev_bone);
2386  }
2387 
2388  /* and a check for garbage */
2389  BKE_pose_channels_clear_with_null_bone(pose, do_id_user);
2390 
2392 
2393  for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
2394  /* Find the custom B-Bone handles. */
2395  BKE_pchan_rebuild_bbone_handles(pose, pchan);
2396  /* Re-validate that we are still using a valid pchan form custom transform. */
2397  /* Note that we could store pointers of freed pchan in a GSet to speed this up, however this is
2398  * supposed to be a rarely used feature, so for now assuming that always building that GSet
2399  * would be less optimal. */
2400  if (pchan->custom_tx != NULL && BLI_findindex(&pose->chanbase, pchan->custom_tx) == -1) {
2401  pchan->custom_tx = NULL;
2402  }
2403  }
2404 
2405  // printf("rebuild pose %s, %d bones\n", ob->id.name, counter);
2406 
2407  BKE_pose_update_constraint_flags(pose); /* for IK detection for example */
2408 
2409  pose->flag &= ~POSE_RECALC;
2410  pose->flag |= POSE_WAS_REBUILT;
2411 
2412  /* Rebuilding poses forces us to also rebuild the dependency graph,
2413  * since there is one node per pose/bone. */
2414  if (bmain != NULL) {
2415  DEG_relations_tag_update(bmain);
2416  }
2417 }
2418 
2419 void BKE_pose_ensure(Main *bmain, Object *ob, bArmature *arm, const bool do_id_user)
2420 {
2421  BLI_assert(!ELEM(NULL, arm, ob));
2422  if (ob->type == OB_ARMATURE && ((ob->pose == NULL) || (ob->pose->flag & POSE_RECALC))) {
2423  BLI_assert(GS(arm->id.name) == ID_AR);
2424  BKE_pose_rebuild(bmain, ob, arm, do_id_user);
2425  }
2426 }
2427 
2430 /* -------------------------------------------------------------------- */
2434 void BKE_pchan_to_mat4(const bPoseChannel *pchan, float r_chanmat[4][4])
2435 {
2436  float smat[3][3];
2437  float rmat[3][3];
2438  float tmat[3][3];
2439 
2440  /* get scaling matrix */
2441  size_to_mat3(smat, pchan->size);
2442 
2443  /* get rotation matrix */
2444  BKE_pchan_rot_to_mat3(pchan, rmat);
2445 
2446  /* calculate matrix of bone (as 3x3 matrix, but then copy the 4x4) */
2447  mul_m3_m3m3(tmat, rmat, smat);
2448  copy_m4_m3(r_chanmat, tmat);
2449 
2450  /* prevent action channels breaking chains */
2451  /* need to check for bone here, CONSTRAINT_TYPE_ACTION uses this call */
2452  if ((pchan->bone == NULL) || !(pchan->bone->flag & BONE_CONNECTED)) {
2453  copy_v3_v3(r_chanmat[3], pchan->loc);
2454  }
2455 }
2456 
2458 {
2459  /* this is just a wrapper around the copy of this function which calculates the matrix
2460  * and stores the result in any given channel
2461  */
2462  BKE_pchan_to_mat4(pchan, pchan->chan_mat);
2463 }
2464 
2466 {
2467  float vec[3];
2468 
2469  copy_v3_v3(vec, pchan->pose_mat[1]);
2470  mul_v3_fl(vec, pchan->bone->length);
2471  add_v3_v3v3(pchan->pose_tail, pchan->pose_head, vec);
2472 }
2473 
2475  Scene *scene,
2476  Object *ob,
2477  bPoseChannel *pchan,
2478  float ctime,
2479  bool do_extra)
2480 {
2481  /* This gives a chan_mat with actions (F-Curve) results. */
2482  if (do_extra) {
2483  BKE_pchan_calc_mat(pchan);
2484  }
2485  else {
2486  unit_m4(pchan->chan_mat);
2487  }
2488 
2489  /* Construct the posemat based on PoseChannels, that we do before applying constraints. */
2490  /* pose_mat(b) = pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b) * chan_mat(b) */
2491  BKE_armature_mat_bone_to_pose(pchan, pchan->chan_mat, pchan->pose_mat);
2492 
2493  /* Only rootbones get the cyclic offset (unless user doesn't want that). */
2494  /* XXX That could be a problem for snapping and other "reverse transform" features... */
2495  if (!pchan->parent) {
2496  if ((pchan->bone->flag & BONE_NO_CYCLICOFFSET) == 0) {
2497  add_v3_v3(pchan->pose_mat[3], ob->pose->cyclic_offset);
2498  }
2499  }
2500 
2501  if (do_extra) {
2502  /* Do constraints */
2503  if (pchan->constraints.first) {
2504  bConstraintOb *cob;
2505  float vec[3];
2506 
2507  /* make a copy of location of PoseChannel for later */
2508  copy_v3_v3(vec, pchan->pose_mat[3]);
2509 
2510  /* prepare PoseChannel for Constraint solving
2511  * - makes a copy of matrix, and creates temporary struct to use
2512  */
2514 
2515  /* Solve PoseChannel's Constraints */
2516 
2517  /* ctime doesn't alter objects. */
2518  BKE_constraints_solve(depsgraph, &pchan->constraints, cob, ctime);
2519 
2520  /* cleanup after Constraint Solving
2521  * - applies matrix back to pchan, and frees temporary struct used
2522  */
2524 
2525  /* prevent constraints breaking a chain */
2526  if (pchan->bone->flag & BONE_CONNECTED) {
2527  copy_v3_v3(pchan->pose_mat[3], vec);
2528  }
2529  }
2530  }
2531 
2532  /* calculate head */
2533  copy_v3_v3(pchan->pose_head, pchan->pose_mat[3]);
2534  /* calculate tail */
2536 }
2537 
2539 {
2540  bArmature *arm;
2541  Bone *bone;
2542  bPoseChannel *pchan;
2543  float imat[4][4];
2544  float ctime;
2545 
2546  if (ob->type != OB_ARMATURE) {
2547  return;
2548  }
2549  arm = ob->data;
2550 
2551  if (ELEM(NULL, arm, scene)) {
2552  return;
2553  }
2554  /* WARNING! passing NULL bmain here means we won't tag depsgraph's as dirty -
2555  * hopefully this is OK. */
2556  BKE_pose_ensure(NULL, ob, arm, true);
2557 
2558  ctime = BKE_scene_ctime_get(scene); /* not accurate... */
2559 
2560  /* In edit-mode or rest-position we read the data from the bones. */
2561  if (arm->edbo || (arm->flag & ARM_RESTPOS)) {
2562  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2563  bone = pchan->bone;
2564  if (bone) {
2565  copy_m4_m4(pchan->pose_mat, bone->arm_mat);
2566  copy_v3_v3(pchan->pose_head, bone->arm_head);
2567  copy_v3_v3(pchan->pose_tail, bone->arm_tail);
2568  }
2569  }
2570  }
2571  else {
2572  invert_m4_m4(ob->imat, ob->obmat); /* imat is needed */
2573 
2574  /* 1. clear flags */
2575  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2576  pchan->flag &= ~(POSE_DONE | POSE_CHAIN | POSE_IKTREE | POSE_IKSPLINE);
2577  }
2578 
2579  /* 2a. construct the IK tree (standard IK) */
2580  BIK_init_tree(depsgraph, scene, ob, ctime);
2581 
2582  /* 2b. construct the Spline IK trees
2583  * - this is not integrated as an IK plugin, since it should be able
2584  * to function in conjunction with standard IK
2585  */
2586  BKE_pose_splineik_init_tree(scene, ob, ctime);
2587 
2588  /* 3. the main loop, channels are already hierarchical sorted from root to children */
2589  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2590  /* 4a. if we find an IK root, we handle it separated */
2591  if (pchan->flag & POSE_IKTREE) {
2592  BIK_execute_tree(depsgraph, scene, ob, pchan, ctime);
2593  }
2594  /* 4b. if we find a Spline IK root, we handle it separated too */
2595  else if (pchan->flag & POSE_IKSPLINE) {
2596  BKE_splineik_execute_tree(depsgraph, scene, ob, pchan, ctime);
2597  }
2598  /* 5. otherwise just call the normal solver */
2599  else if (!(pchan->flag & POSE_DONE)) {
2600  BKE_pose_where_is_bone(depsgraph, scene, ob, pchan, ctime, 1);
2601  }
2602  }
2603  /* 6. release the IK tree */
2604  BIK_release_tree(scene, ob, ctime);
2605  }
2606 
2607  /* calculating deform matrices */
2608  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2609  if (pchan->bone) {
2610  invert_m4_m4(imat, pchan->bone->arm_mat);
2611  mul_m4_m4m4(pchan->chan_mat, pchan->pose_mat, imat);
2612  }
2613  }
2614 }
2615 
2618 /* -------------------------------------------------------------------- */
2622 static int minmax_armature(Object *ob, float r_min[3], float r_max[3])
2623 {
2624  bPoseChannel *pchan;
2625 
2626  /* For now, we assume BKE_pose_where_is has already been called
2627  * (hence we have valid data in pachan). */
2628  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2629  minmax_v3v3_v3(r_min, r_max, pchan->pose_head);
2630  minmax_v3v3_v3(r_min, r_max, pchan->pose_tail);
2631  }
2632 
2633  return (BLI_listbase_is_empty(&ob->pose->chanbase) == false);
2634 }
2635 
2636 static void boundbox_armature(Object *ob)
2637 {
2638  BoundBox *bb;
2639  float min[3], max[3];
2640 
2641  if (ob->runtime.bb == NULL) {
2642  ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "Armature boundbox");
2643  }
2644  bb = ob->runtime.bb;
2645 
2646  INIT_MINMAX(min, max);
2647  if (!minmax_armature(ob, min, max)) {
2648  min[0] = min[1] = min[2] = -1.0f;
2649  max[0] = max[1] = max[2] = 1.0f;
2650  }
2651 
2653 
2654  bb->flag &= ~BOUNDBOX_DIRTY;
2655 }
2656 
2658 {
2659  boundbox_armature(ob);
2660 
2661  return ob->runtime.bb;
2662 }
2663 
2664 void BKE_pchan_minmax(const Object *ob,
2665  const bPoseChannel *pchan,
2666  const bool use_empty_drawtype,
2667  float r_min[3],
2668  float r_max[3])
2669 {
2670  const bArmature *arm = ob->data;
2671  Object *ob_custom = (arm->flag & ARM_NO_CUSTOM) ? NULL : pchan->custom;
2672  const bPoseChannel *pchan_tx = (ob_custom && pchan->custom_tx) ? pchan->custom_tx : pchan;
2673  const BoundBox *bb_custom = NULL;
2674  BoundBox bb_custom_buf;
2675 
2676  if (ob_custom) {
2677  float min[3], max[3];
2678  if (use_empty_drawtype && (ob_custom->type == OB_EMPTY) &&
2679  BKE_object_minmax_empty_drawtype(ob_custom, min, max)) {
2680  memset(&bb_custom_buf, 0x0, sizeof(bb_custom_buf));
2681  BKE_boundbox_init_from_minmax(&bb_custom_buf, min, max);
2682  bb_custom = &bb_custom_buf;
2683  }
2684  else {
2685  bb_custom = BKE_object_boundbox_get(ob_custom);
2686  }
2687  }
2688 
2689  if (bb_custom) {
2690  float mat[4][4], smat[4][4], rmat[4][4], tmp[4][4];
2691  scale_m4_fl(smat, PCHAN_CUSTOM_BONE_LENGTH(pchan));
2692  rescale_m4(smat, pchan->custom_scale_xyz);
2694  copy_m4_m4(tmp, pchan_tx->pose_mat);
2695  translate_m4(tmp,
2696  pchan->custom_translation[0],
2697  pchan->custom_translation[1],
2698  pchan->custom_translation[2]);
2699  mul_m4_series(mat, ob->obmat, tmp, rmat, smat);
2700  BKE_boundbox_minmax(bb_custom, mat, r_min, r_max);
2701  }
2702  else {
2703  float vec[3];
2704  mul_v3_m4v3(vec, ob->obmat, pchan_tx->pose_head);
2705  minmax_v3v3_v3(r_min, r_max, vec);
2706  mul_v3_m4v3(vec, ob->obmat, pchan_tx->pose_tail);
2707  minmax_v3v3_v3(r_min, r_max, vec);
2708  }
2709 }
2710 
2711 bool BKE_pose_minmax(Object *ob, float r_min[3], float r_max[3], bool use_hidden, bool use_select)
2712 {
2713  bool changed = false;
2714 
2715  if (ob->pose) {
2716  bArmature *arm = ob->data;
2717  bPoseChannel *pchan;
2718 
2719  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
2720  /* XXX pchan->bone may be NULL for duplicated bones, see duplicateEditBoneObjects() comment
2721  * (editarmature.c:2592)... Skip in this case too! */
2722  if (pchan->bone && (!((use_hidden == false) && (PBONE_VISIBLE(arm, pchan->bone) == false)) &&
2723  !((use_select == true) && ((pchan->bone->flag & BONE_SELECTED) == 0)))) {
2724 
2725  BKE_pchan_minmax(ob, pchan, false, r_min, r_max);
2726  changed = true;
2727  }
2728  }
2729  }
2730 
2731  return changed;
2732 }
2733 
2736 /* -------------------------------------------------------------------- */
2741 {
2742  bPoseChannel *rootchan = pchan;
2743  if (!(data->flag & CONSTRAINT_IK_TIP)) {
2744  /* Exclude tip from chain. */
2745  rootchan = rootchan->parent;
2746  }
2747  if (rootchan != NULL) {
2748  int segcount = 0;
2749  while (rootchan->parent) {
2750  /* Continue up chain, until we reach target number of items. */
2751  segcount++;
2752  if (segcount == data->rootbone) {
2753  break;
2754  }
2755  rootchan = rootchan->parent;
2756  }
2757  }
2758  return rootchan;
2759 }
2760 
2763 {
2764  bPoseChannel *rootchan = pchan;
2765  int segcount = 0;
2766  BLI_assert(rootchan != NULL);
2767  while (rootchan->parent) {
2768  /* Continue up chain, until we reach target number of items. */
2769  segcount++;
2770  if (segcount == data->chainlen) {
2771  break;
2772  }
2773  rootchan = rootchan->parent;
2774  }
2775  return rootchan;
2776 }
2777 
typedef float(TangentPoint)[2]
void BIK_init_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime)
Definition: ikplugin_api.c:66
void BIK_release_tree(struct Scene *scene, struct Object *ob, float ctime)
Definition: ikplugin_api.c:85
void BIK_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime)
Definition: ikplugin_api.c:75
Blender kernel action and pose functionality.
void BKE_pose_channels_hash_free(struct bPose *pose)
Definition: action.c:937
struct bPoseChannel * BKE_pose_channel_find_name(const struct bPose *pose, const char *name)
struct bPoseChannel * BKE_pose_channel_ensure(struct bPose *pose, const char *name)
Definition: action.c:628
void BKE_pose_channel_free_ex(struct bPoseChannel *pchan, bool do_id_user)
Definition: action.c:1024
void BKE_pose_channels_hash_ensure(struct bPose *pose)
Definition: action.c:925
void BKE_pose_update_constraint_flags(struct bPose *pose)
Definition: action.c:1192
void BKE_pose_channel_free_bbone_cache(struct bPoseChannel_Runtime *runtime)
Definition: action.c:1069
void BKE_animdata_blend_read_data(struct BlendDataReader *reader, struct AnimData *adt)
Definition: anim_data.c:1443
void BKE_animdata_blend_write(struct BlendWriter *writer, struct AnimData *adt)
Definition: anim_data.c:1421
void animviz_settings_init(struct bAnimVizSettings *avs)
void BKE_pose_splineik_init_tree(struct Scene *scene, struct Object *ob, float ctime)
#define MAX_BBONE_SUBDIV
Definition: BKE_armature.h:461
void BKE_splineik_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan_root, float ctime)
#define PBONE_VISIBLE(arm, bone)
Definition: BKE_armature.h:549
void BKE_constraints_solve(struct Depsgraph *depsgraph, struct ListBase *conlist, struct bConstraintOb *cob, float ctime)
Definition: constraint.c:6352
struct bConstraintOb * BKE_constraints_make_evalob(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, void *subdata, short datatype)
Definition: constraint.c:119
void BKE_constraints_clear_evalob(struct bConstraintOb *cob)
Definition: constraint.c:196
void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride)
Definition: curve.cc:1717
void IDP_BlendReadExpand(struct BlendExpander *expander, struct IDProperty *prop)
Definition: idprop.c:1471
struct IDProperty * IDP_CopyProperty_ex(const struct IDProperty *prop, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void IDP_BlendWrite(struct BlendWriter *writer, const struct IDProperty *prop)
void IDP_foreach_property(struct IDProperty *id_property_root, int type_filter, IDPForeachPropertyCallback callback, void *user_data)
Definition: idprop.c:1117
#define IDP_BlendDataRead(reader, prop)
Definition: BKE_idprop.h:321
void IDP_FreeProperty_ex(struct IDProperty *prop, bool do_id_user)
Definition: idprop.c:1087
void IDP_BlendReadLib(struct BlendLibReader *reader, struct Library *lib, struct IDProperty *prop)
Definition: idprop.c:1435
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
Definition: BKE_idtype.h:39
@ LIB_ID_CREATE_NO_USER_REFCOUNT
Definition: BKE_lib_id.h:126
void BKE_id_blend_write(struct BlendWriter *writer, struct ID *id)
Definition: lib_id.c:2008
void * BKE_id_new(struct Main *bmain, short type, const char *name)
Definition: lib_id.c:1159
#define BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(_data, _func_call)
void BKE_lib_query_idpropertiesForeachIDLink_callback(struct IDProperty *id_prop, void *user_data)
Definition: lib_query.c:136
General operations, lookup, etc. for blender objects.
void BKE_boundbox_init_from_minmax(struct BoundBox *bb, const float min[3], const float max[3])
Definition: object.cc:3645
bool BKE_object_minmax_empty_drawtype(const struct Object *ob, float r_min[3], float r_max[3])
Definition: object.cc:4011
const struct BoundBox * BKE_object_boundbox_get(struct Object *ob)
Definition: object.cc:3684
void BKE_boundbox_minmax(const struct BoundBox *bb, const float obmat[4][4], float r_min[3], float r_max[3])
float BKE_scene_ctime_get(const struct Scene *scene)
#define BLI_array_alloca(arr, realsize)
Definition: BLI_alloca.h:22
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
#define BLI_assert(a)
Definition: BLI_assert.h:46
GHash * BLI_ghash_str_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:734
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:710
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:863
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:269
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:239
void void void void void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src) ATTR_NONNULL(1
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
Definition: BLI_listbase.h:354
void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition: listbase.c:301
bool BLI_remlink_safe(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:123
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:466
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:100
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define BLI_ASSERT_UNIT_M3(m)
MINLINE float interpf(float a, float b, float t)
#define BLI_ASSERT_UNIT_V3(v)
float cubic_tangent_factor_circle_v3(const float tan_l[3], const float tan_r[3])
Definition: math_geom.c:5895
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:259
void mul_mat3_m4_fl(float R[4][4], float f)
Definition: math_matrix.c:978
void size_to_mat3(float R[3][3], const float size[3])
Definition: math_matrix.c:2098
bool invert_m4(float R[4][4])
Definition: math_matrix.c:1206
void copy_m3_m3(float m1[3][3], const float m2[3][3])
Definition: math_matrix.c:71
void unit_m3(float m[3][3])
Definition: math_matrix.c:40
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:87
void unit_m4(float m[4][4])
Definition: rct.c:1090
void copy_m4_m3(float m1[4][4], const float m2[3][3])
Definition: math_matrix.c:102
void mul_mat3_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:790
void translate_m4(float mat[4][4], float tx, float ty, float tz)
Definition: math_matrix.c:2318
void mat4_to_size_fix_shear(float size[3], const float M[4][4])
Definition: math_matrix.c:2155
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1287
void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], const float wmat[4][4])
Definition: math_matrix.c:2224
void normalize_m3(float R[3][3]) ATTR_NONNULL()
Definition: math_matrix.c:1912
void rescale_m4(float mat[4][4], const float scale[3])
Definition: math_matrix.c:2362
void size_to_mat4(float R[4][4], const float size[3])
Definition: math_matrix.c:2111
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:729
void orthogonalize_m4_stable(float R[4][4], int axis, bool normalize)
Definition: math_matrix.c:1678
#define mul_m4_series(...)
void scale_m4_fl(float R[4][4], float scale)
Definition: math_matrix.c:2297
void normalize_m4_ex(float R[4][4], float r_scale[3]) ATTR_NONNULL()
Definition: math_matrix.c:1935
bool invert_m3_m3(float R[3][3], const float A[3][3])
Definition: math_matrix.c:1180
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:77
float mat4_to_scale(const float M[4][4])
Definition: math_matrix.c:2185
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:739
bool invert_m3(float R[3][3])
Definition: math_matrix.c:1171
void mat4_to_size(float size[3], const float M[4][4])
Definition: math_matrix.c:2138
float mat4_to_volume_scale(const float M[4][4])
Definition: math_matrix.c:2171
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
Definition: math_matrix.c:388
void normalize_m4(float R[4][4]) ATTR_NONNULL()
Definition: math_matrix.c:1945
void mat3_normalized_to_compatible_eulO(float eul[3], const float old[3], short order, const float mat[3][3])
void eulO_to_mat3(float mat[3][3], const float eul[3], short order)
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
void axis_angle_normalized_to_mat3(float R[3][3], const float axis[3], float angle)
void mat3_to_quat(float q[4], const float mat[3][3])
float normalize_qt(float q[4])
void eulO_to_axis_angle(float axis[3], float *angle, const float eul[3], short order)
float normalize_qt_qt(float r[4], const float q[4])
void quat_to_eulO(float eul[3], short order, const float quat[4])
void mat3_normalized_to_axis_angle(float axis[3], float *angle, const float M[3][3])
void quat_to_axis_angle(float axis[3], float *angle, const float q[4])
void eulO_to_quat(float quat[4], const float eul[3], short order)
void mat4_to_dquat(DualQuat *dq, const float basemat[4][4], const float mat[4][4])
void axis_angle_to_eulO(float eul[3], short order, const float axis[3], float angle)
void eulO_to_mat4(float mat[4][4], const float eul[3], short order)
void quat_to_mat3(float mat[3][3], const float q[4])
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
float quat_split_swing_and_twist(const float q[4], int axis, float r_swing[4], float r_twist[4])
void mat3_normalized_to_quat(float q[4], const float mat[3][3])
void mat3_normalized_to_eulO(float eul[3], short order, const float mat[3][3])
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
Definition: math_vector.c:867
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void mul_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE float normalize_v3(float r[3])
MINLINE void mul_v3_v3(float r[3], const float a[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
MINLINE void invert_v3_safe(float r[3])
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
Definition: math_vector.c:29
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void negate_v3(float r[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE void zero_v3(float r[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
unsigned int uint
Definition: BLI_sys_types.h:67
#define CLAMP_MAX(a, c)
#define INIT_MINMAX(min, max)
#define UNUSED(x)
#define UNLIKELY(x)
#define ELEM(...)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define IS_EQF(a, b)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define STREQ(a, b)
#define CLAMP_MIN(a, b)
#define BLO_read_data_address(reader, ptr_p)
#define BLO_write_id_struct(writer, struct_name, id_address, id)
#define BLO_write_struct(writer, struct_name, data_ptr)
void BLO_read_list(BlendDataReader *reader, struct ListBase *list)
Definition: readfile.c:5172
#define BLT_I18NCONTEXT_ID_ARMATURE
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
bool DEG_is_active(const struct Depsgraph *depsgraph)
Definition: depsgraph.cc:312
void DEG_relations_tag_update(struct Main *bmain)
struct ID * DEG_get_original_id(struct ID *id)
@ IDP_TYPE_FILTER_ID
Definition: DNA_ID.h:155
@ INDEX_ID_AR
Definition: DNA_ID.h:1025
#define FILTER_ID_AR
Definition: DNA_ID.h:900
@ ID_AR
Definition: DNA_ID_enums.h:66
#define PCHAN_CUSTOM_BONE_LENGTH(pchan)
@ ROT_MODE_QUAT
@ ROT_MODE_AXISANGLE
@ ROT_MODE_XYZ
@ POSE_DONE
@ POSE_IKTREE
@ POSE_IKSPLINE
@ POSE_CHAIN
@ POSE_WAS_REBUILT
@ POSE_RECALC
#define MAXBONENAME
@ BBONE_HANDLE_AUTO
@ BBONE_HANDLE_TANGENT
@ BBONE_HANDLE_RELATIVE
@ BONE_DRAW_LOCKED_WEIGHT
@ BONE_SELECTED
@ BONE_NO_CYCLICOFFSET
@ BONE_NO_LOCAL_LOCATION
@ BONE_DRAW_ACTIVE
@ BONE_CONNECTED
@ BONE_HINGE
@ ARM_NO_CUSTOM
@ ARM_RESTPOS
struct bArmature bArmature
@ BBONE_ADD_PARENT_END_ROLL
@ BBONE_SCALE_EASING
@ BBONE_HANDLE_SCALE_EASE
@ BBONE_HANDLE_SCALE_Y
@ BBONE_HANDLE_SCALE_X
@ BBONE_HANDLE_SCALE_ANY
@ BBONE_HANDLE_SCALE_Z
@ BONE_INHERIT_SCALE_FULL
@ BONE_INHERIT_SCALE_NONE
@ BONE_INHERIT_SCALE_FIX_SHEAR
@ BONE_INHERIT_SCALE_NONE_LEGACY
@ BONE_INHERIT_SCALE_ALIGNED
@ BONE_INHERIT_SCALE_AVERAGE
@ CONSTRAINT_IK_TIP
@ CONSTRAINT_OBTYPE_BONE
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:29
These structs are the foundation for all linked lists in the library system.
Object is a sort of wrapper for general info.
@ OB_EMPTY
@ OB_ARMATURE
@ BOUNDBOX_DIRTY
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
Read Guarded memory(de)allocation.
static void init_data(ModifierData *md)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
static void armature_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag)
Definition: armature.c:92
void BKE_pchan_rot_to_mat3(const bPoseChannel *pchan, float r_mat[3][3])
Definition: armature.c:1934
void BKE_armature_bone_hash_make(bArmature *arm)
Definition: armature.c:629
void BKE_pose_where_is(struct Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition: armature.c:2538
static void lib_link_bones(BlendLibReader *reader, Library *lib, Bone *bone)
Definition: armature.c:264
static void copy_bone_transform(Bone *bone_dst, const Bone *bone_src)
Definition: armature.c:436
void vec_roll_to_mat3(const float vec[3], const float roll, float r_mat[3][3])
Definition: armature.c:2211
bArmature * BKE_armature_from_object(Object *ob)
Definition: armature.c:342
static void ease_handle_axis(const float deriv1[3], const float deriv2[3], float r_axis[3])
Definition: armature.c:1333
IDTypeInfo IDType_ID_AR
Definition: armature.c:298
static void allocate_bbone_cache(bPoseChannel *pchan, int segments)
Definition: armature.c:1465
void BKE_pchan_bbone_deform_segment_index(const bPoseChannel *pchan, float pos, int *r_index, float *r_blend_next)
Definition: armature.c:1558
bool bone_autoside_name(char name[MAXBONENAME], int UNUSED(strip_number), short axis, float head, float tail)
Definition: armature.c:698
static int minmax_armature(Object *ob, float r_min[3], float r_max[3])
Definition: armature.c:2622
static bPoseChannel * pose_channel_find_bone(bPose *pose, Bone *bone)
Definition: armature.c:2340
int BKE_armature_bonelist_count(const ListBase *lb)
Definition: armature.c:350
void BKE_armature_refresh_layer_used(struct Depsgraph *depsgraph, struct bArmature *arm)
Definition: armature.c:675
void BKE_armature_loc_pose_to_bone(bPoseChannel *pchan, const float inloc[3], float outloc[3])
Definition: armature.c:1870
void BKE_armature_bonelist_free(ListBase *lb, const bool do_id_user)
Definition: armature.c:360
void BKE_pose_channels_clear_with_null_bone(bPose *pose, const bool do_id_user)
Definition: armature.c:2351
void BKE_pose_ensure(Main *bmain, Object *ob, bArmature *arm, const bool do_id_user)
Definition: armature.c:2419
void BKE_armature_where_is_bone(Bone *bone, const Bone *bone_parent, const bool use_recursion)
Definition: armature.c:2225
void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_user)
Definition: armature.c:2362
void mat3_vec_to_roll(const float mat[3][3], const float vec[3], float *r_roll)
Definition: armature.c:2067
static void write_bone(BlendWriter *writer, Bone *bone)
Definition: armature.c:180
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])
Definition: armature.c:474
void BKE_armature_mat_bone_to_pose(bPoseChannel *pchan, const float inmat[4][4], float outmat[4][4])
Definition: armature.c:1860
bArmature * BKE_armature_add(Main *bmain, const char *name)
Definition: armature.c:334
void BKE_pchan_calc_mat(bPoseChannel *pchan)
Definition: armature.c:2457
void BKE_pose_where_is_bone_tail(bPoseChannel *pchan)
Definition: armature.c:2465
static void expand_bones(BlendExpander *expander, Bone *bone)
Definition: armature.c:281
void BKE_pchan_apply_mat4(bPoseChannel *pchan, const float mat[4][4], bool use_compat)
Definition: armature.c:1958
void BKE_pchan_minmax(const Object *ob, const bPoseChannel *pchan, const bool use_empty_drawtype, float r_min[3], float r_max[3])
Definition: armature.c:2664
void BKE_armature_mat_pose_to_bone_ex(struct Depsgraph *depsgraph, Object *ob, bPoseChannel *pchan, const float inmat[4][4], float outmat[4][4])
Definition: armature.c:1892
void BKE_armature_mat_pose_to_bone(bPoseChannel *pchan, const float inmat[4][4], float outmat[4][4])
Definition: armature.c:1849
void BKE_bone_parent_transform_combine(const struct BoneParentTransform *in1, const struct BoneParentTransform *in2, struct BoneParentTransform *result)
Definition: armature.c:1827
static void armature_foreach_id_bone(Bone *bone, LibraryForeachIDData *data)
Definition: armature.c:144
static void equalize_cubic_bezier(const float control[4][3], int temp_segments, int final_segments, const float *segment_scales, float *r_t_points)
Definition: armature.c:832
Bone * BKE_armature_find_bone_name(bArmature *arm, const char *name)
Definition: armature.c:594
void BKE_pchan_rebuild_bbone_handles(bPose *pose, bPoseChannel *pchan)
Definition: armature.c:2345
static void boundbox_armature(Object *ob)
Definition: armature.c:2636
void BKE_bone_parent_transform_invert(struct BoneParentTransform *bpt)
Definition: armature.c:1820
void BKE_pose_clear_pointers(bPose *pose)
Definition: armature.c:2324
bool BKE_armature_bone_flag_test_recursive(const Bone *bone, int flag)
Definition: armature.c:650
void BKE_pchan_to_mat4(const bPoseChannel *pchan, float r_chanmat[4][4])
Definition: armature.c:2434
bool BKE_pose_minmax(Object *ob, float r_min[3], float r_max[3], bool use_hidden, bool use_select)
Definition: armature.c:2711
static void copy_bonechildren(Bone *bone_dst, const Bone *bone_src, const Bone *bone_src_act, Bone **r_bone_dst_act, const int flag)
Definition: armature.c:385
void BKE_armature_copy_bone_transforms(bArmature *armature_dst, const bArmature *armature_src)
Definition: armature.c:453
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 scalez, float result[4][4])
Definition: armature.c:1306
static void armature_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition: armature.c:200
bPoseChannel * BKE_armature_splineik_solver_find_root(bPoseChannel *pchan, bSplineIKConstraint *data)
Definition: armature.c:2761
static void armature_foreach_id_editbone(EditBone *edit_bone, LibraryForeachIDData *data)
Definition: armature.c:156
static int rebuild_pose_bone(bPose *pose, Bone *bone, bPoseChannel *parchan, int counter, Bone **r_last_visited_bone_p)
Definition: armature.c:2282
void BKE_rotMode_change_values(float quat[4], float eul[3], float axis[3], float *angle, short oldMode, short newMode)
Definition: armature.c:1983
static void copy_bonechildren_custom_handles(Bone *bone_dst, bArmature *arm_dst)
Definition: armature.c:413
void BKE_bone_parent_transform_clear(struct BoneParentTransform *bpt)
Definition: armature.c:1813
void BKE_pchan_bbone_segments_cache_copy(bPoseChannel *pchan, bPoseChannel *pchan_from)
Definition: armature.c:1535
void BKE_armature_mat_pose_to_delta(float delta_mat[4][4], float pose_mat[4][4], float arm_mat[4][4])
Definition: armature.c:1965
BoundBox * BKE_armature_boundbox_get(Object *ob)
Definition: armature.c:2657
void BKE_bone_parent_transform_calc_from_pchan(const bPoseChannel *pchan, BoneParentTransform *r_bpt)
Definition: armature.c:1639
static void armature_refresh_layer_used_recursive(bArmature *arm, ListBase *bones)
Definition: armature.c:667
int BKE_pchan_bbone_spline_compute(BBoneSplineParameters *param, const bool for_deform, Mat4 *result_array)
Definition: armature.c:1350
void BKE_pchan_mat3_to_rot(bPoseChannel *pchan, const float mat[3][3], bool use_compat)
Definition: armature.c:1912
void mat3_to_vec_roll(const float mat[3][3], float r_vec[3], float *r_roll)
Definition: armature.c:2056
static void armature_blend_read_lib(BlendLibReader *reader, ID *id)
Definition: armature.c:273
static void armature_bone_from_name_insert_recursive(GHash *bone_hash, ListBase *lb)
Definition: armature.c:607
static void armature_free_data(struct ID *id)
Definition: armature.c:129
void BKE_armature_transform(bArmature *arm, const float mat[4][4], const bool do_props)
Definition: armature.c:556
void BKE_pchan_bbone_segments_cache_compute(bPoseChannel *pchan)
Definition: armature.c:1484
void BKE_armature_editbonelist_free(ListBase *lb, const bool do_id_user)
Definition: armature.c:374
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)
Definition: armature.c:1668
void BKE_pchan_bbone_handles_get(bPoseChannel *pchan, bPoseChannel **r_prev, bPoseChannel **r_next)
Definition: armature.c:907
static void armature_foreach_id(ID *id, LibraryForeachIDData *data)
Definition: armature.c:166
void BKE_bone_offset_matrix_get(const Bone *bone, float offs_bone[4][4])
Definition: armature.c:1625
static void armature_init_data(ID *id)
Definition: armature.c:74
void BKE_armature_bone_hash_free(bArmature *arm)
Definition: armature.c:636
void BKE_armature_where_is(bArmature *arm)
Definition: armature.c:2263
static void direct_link_bones(BlendDataReader *reader, Bone *bone)
Definition: armature.c:224
static Bone * get_named_bone_bonechildren(ListBase *lb, const char *name)
Definition: armature.c:576
void BKE_armature_mat_world_to_pose(Object *ob, const float inmat[4][4], float outmat[4][4])
Definition: armature.c:1589
void BKE_pchan_bbone_spline_setup(bPoseChannel *pchan, const bool rest, const bool for_deform, Mat4 *result_array)
Definition: armature.c:1178
void BKE_bone_parent_transform_apply(const struct BoneParentTransform *bpt, const float inmat[4][4], float outmat[4][4])
Definition: armature.c:1836
static GHash * armature_bone_from_name_map(bArmature *arm)
Definition: armature.c:621
static void armature_blend_read_data(BlendDataReader *reader, ID *id)
Definition: armature.c:242
bPoseChannel * BKE_armature_ik_solver_find_root(bPoseChannel *pchan, bKinematicConstraint *data)
Definition: armature.c:2740
static void evaluate_cubic_bezier(const float control[4][3], float t, float r_pos[3], float r_tangent[3])
Definition: armature.c:889
void BKE_pose_remap_bone_pointers(bArmature *armature, bPose *pose)
Definition: armature.c:2332
void BKE_armature_loc_world_to_pose(Object *ob, const float inloc[3], float outloc[3])
Definition: armature.c:1605
static void armature_blend_read_expand(BlendExpander *expander, ID *id)
Definition: armature.c:290
void BKE_pose_where_is_bone(struct Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan, float ctime, bool do_extra)
Definition: armature.c:2474
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)
Definition: armature.c:1190
void BKE_pchan_bbone_spline_params_get(struct bPoseChannel *pchan, const bool rest, struct BBoneSplineParameters *param)
Definition: armature.c:933
void vec_roll_to_mat3_normalized(const float nor[3], const float roll, float r_mat[3][3])
Definition: armature.c:2082
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static T sum(const btAlignedObjectArray< T > &items)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
#define logf(x)
Definition: cuda/compat.h:105
#define expf(x)
Definition: cuda/compat.h:106
static char * basename(char *string)
Definition: datatoc.c:17
Scene scene
const Depsgraph * depsgraph
int len
Definition: draw_manager.c:108
DRWShaderLibrary * lib
#define rot(x, k)
uint pos
uint nor
#define GS(x)
Definition: iris.c:225
ccl_gpu_kernel_postfix ccl_global int * counter
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:34
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
static ulong * next
#define atan2f(x, y)
Definition: metal/compat.h:227
#define floorf(x)
Definition: metal/compat.h:224
#define fabsf(x)
Definition: metal/compat.h:219
#define sqrtf(x)
Definition: metal/compat.h:243
static unsigned a[3]
Definition: RandGen.cpp:78
T length(const vec_base< T, Size > &a)
SymEdge< T > * prev(const SymEdge< T > *se)
Definition: delaunay_2d.cc:105
static double epsilon
#define min(a, b)
Definition: sort.c:35
float loc_mat[4][4]
Definition: BKE_armature.h:396
float rotscale_mat[4][4]
Definition: BKE_armature.h:395
float curve_in_z
float ease1
int bbone_flag
short bbone_next_flag
float roll
float zwidth
short bbone_prev_flag
struct Bone * parent
struct Bone * bbone_prev
float roll1
float arm_head[3]
float roll2
char name[64]
float xwidth
float tail[3]
float arm_tail[3]
struct Bone * bbone_next
char inherit_scale_mode
char bbone_prev_type
short segments
float curve_in_x
float scale_out[3]
float size[3]
IDProperty * prop
float curve_out_z
float length
float ease2
float arm_mat[4][4]
float bone_mat[3][3]
float scale_in[3]
float head[3]
char bbone_next_type
struct Bone * next
float curve_out_x
ListBase childbase
float arm_roll
struct IDProperty * prop
Definition: BKE_armature.h:35
short id_code
Definition: BKE_idtype.h:114
Definition: DNA_ID.h:368
struct Library * lib
Definition: DNA_ID.h:372
char name[66]
Definition: DNA_ID.h:378
void * first
Definition: DNA_listBase.h:31
Definition: BKE_main.h:121
float mat[4][4]
Definition: BKE_armature.h:464
struct BoundBox * bb
struct bPose * pose
float imat[4][4]
Object_Runtime runtime
float obmat[4][4]
void * data
struct AnimData * adt
unsigned int layer_used
ListBase bonebase
struct GHash * bonehash
struct EditBone * act_edbone
ListBase * edbo
struct Mat4 * bbone_deform_mats
struct DualQuat * bbone_dual_quats
struct Mat4 * bbone_pose_mats
struct Mat4 * bbone_rest_mats
ListBase constraints
float custom_scale_xyz[3]
float scale_out[3]
float custom_rotation_euler[3]
struct Bone * bone
struct bPoseChannel * parent
struct bPoseChannel * custom_tx
float pose_head[3]
float chan_mat[4][4]
struct bPoseChannel * bbone_next
float pose_tail[3]
struct Object * custom
struct bPoseChannel * prev
struct bPoseChannel * next
float custom_translation[3]
struct bPoseChannel_Runtime runtime
struct bPoseChannel * bbone_prev
float pose_mat[4][4]
struct bPoseChannel * child
ListBase chanbase
short flag
bAnimVizSettings avs
float cyclic_offset[3]
static int blend(const Tex *tex, const float texvec[3], TexResult *texres)
float max