Blender  V2.93
transform_convert_armature.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include "DNA_armature_types.h"
25 #include "DNA_constraint_types.h"
26 
27 #include "MEM_guardedalloc.h"
28 
29 #include "BLI_ghash.h"
30 #include "BLI_listbase.h"
31 #include "BLI_math.h"
32 #include "BLI_string.h"
33 
34 #include "BKE_action.h"
35 #include "BKE_animsys.h"
36 #include "BKE_armature.h"
37 #include "BKE_constraint.h"
38 #include "BKE_context.h"
39 #include "BKE_main.h"
40 #include "BKE_report.h"
41 
42 #include "BIK_api.h"
43 
44 #include "ED_armature.h"
45 #include "ED_keyframing.h"
46 
47 #include "DEG_depsgraph.h"
48 #include "DEG_depsgraph_query.h"
49 
50 #include "RNA_access.h"
51 
52 #include "transform.h"
53 #include "transform_snap.h"
54 
55 /* Own include. */
56 #include "transform_convert.h"
57 
58 typedef struct BoneInitData {
59  struct EditBone *bone;
60  float tail[3];
61  float rad_head;
62  float rad_tail;
63  float roll;
64  float head[3];
65  float dist;
66  float xwidth;
67  float zwidth;
69 
70 /* Return if we need to update motion paths, only if they already exist,
71  * and we will insert a keyframe at the end of transform. */
73 {
74  if (autokeyframe_cfra_can_key(scene, &ob->id)) {
75  return (ob->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) != 0;
76  }
77 
78  return false;
79 }
80 
91 static void autokeyframe_pose(
92  bContext *C, Scene *scene, Object *ob, int tmode, short targetless_ik)
93 {
94  Main *bmain = CTX_data_main(C);
95  ID *id = &ob->id;
96  AnimData *adt = ob->adt;
97  bAction *act = (adt) ? adt->action : NULL;
98  bPose *pose = ob->pose;
99  bPoseChannel *pchan;
100  FCurve *fcu;
101 
103  return;
104  }
105 
106  ReportList *reports = CTX_wm_reports(C);
109  ListBase nla_cache = {NULL, NULL};
112  (float)CFRA);
113  eInsertKeyFlags flag = 0;
114 
115  /* flag is initialized from UserPref keyframing settings
116  * - special exception for targetless IK - INSERTKEY_MATRIX keyframes should get
117  * visual keyframes even if flag not set, as it's not that useful otherwise
118  * (for quick animation recording)
119  */
121 
122  if (targetless_ik) {
124  }
125 
126  for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
127  if ((pchan->bone->flag & BONE_TRANSFORM) == 0 &&
128  !((pose->flag & POSE_MIRROR_EDIT) && (pchan->bone->flag & BONE_TRANSFORM_MIRROR))) {
129  continue;
130  }
131 
132  ListBase dsources = {NULL, NULL};
133 
134  /* add datasource override for the camera object */
135  ANIM_relative_keyingset_add_source(&dsources, id, &RNA_PoseBone, pchan);
136 
137  /* only insert into active keyingset? */
138  if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (active_ks)) {
139  /* run the active Keying Set on the current datasource */
141  C, &dsources, NULL, active_ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time);
142  }
143  /* only insert into available channels? */
144  else if (IS_AUTOKEY_FLAG(scene, INSERTAVAIL)) {
145  if (act) {
146  for (fcu = act->curves.first; fcu; fcu = fcu->next) {
147  /* only insert keyframes for this F-Curve if it affects the current bone */
148  if (strstr(fcu->rna_path, "bones") == NULL) {
149  continue;
150  }
151  char *pchanName = BLI_str_quoted_substrN(fcu->rna_path, "bones[");
152 
153  /* only if bone name matches too...
154  * NOTE: this will do constraints too, but those are ok to do here too?
155  */
156  if (pchanName) {
157  if (STREQ(pchanName, pchan->name)) {
158  insert_keyframe(bmain,
159  reports,
160  id,
161  act,
162  ((fcu->grp) ? (fcu->grp->name) : (NULL)),
163  fcu->rna_path,
164  fcu->array_index,
165  &anim_eval_context,
166  ts->keyframe_type,
167  &nla_cache,
168  flag);
169  }
170 
171  MEM_freeN(pchanName);
172  }
173  }
174  }
175  }
176  /* only insert keyframe if needed? */
177  else if (IS_AUTOKEY_FLAG(scene, INSERTNEEDED)) {
178  bool do_loc = false, do_rot = false, do_scale = false;
179 
180  /* Filter the conditions when this happens
181  * (assume that 'curarea->spacetype == SPACE_VIEW3D'). */
182  if (tmode == TFM_TRANSLATION) {
183  if (targetless_ik) {
184  do_rot = true;
185  }
186  else {
187  do_loc = true;
188  }
189  }
190  else if (ELEM(tmode, TFM_ROTATION, TFM_TRACKBALL)) {
194  do_loc = true;
195  }
196 
198  do_rot = true;
199  }
200  }
201  else if (tmode == TFM_RESIZE) {
205  do_loc = true;
206  }
207 
209  do_scale = true;
210  }
211  }
212 
213  if (do_loc) {
216  C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time);
217  }
218  if (do_rot) {
221  C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time);
222  }
223  if (do_scale) {
226  C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time);
227  }
228  }
229  /* insert keyframe in all (transform) channels */
230  else {
233  C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time);
234  }
235 
236  /* free temp info */
237  BLI_freelistN(&dsources);
238  }
239 
241 }
242 
244  bKinematicConstraint *targetless_con)
245 {
247  NULL, pchan, "TempConstraint", CONSTRAINT_TYPE_KINEMATIC);
248 
249  /* for draw, but also for detecting while pose solving */
251 
252  bKinematicConstraint *temp_con_data = con->data;
253 
254  if (targetless_con) {
255  /* if exists, use values from last targetless (but disabled) IK-constraint as base */
256  *temp_con_data = *targetless_con;
257  }
258  else {
259  temp_con_data->flag = CONSTRAINT_IK_TIP;
260  }
261 
263 
264  return con;
265 }
266 
267 static void update_deg_with_temporary_ik(Main *bmain, Object *ob)
268 {
269  BIK_clear_data(ob->pose);
270  /* TODO(sergey): Consider doing partial update only. */
272 }
273 
274 /* -------------------------------------------------------------------- */
279 {
280  bConstraint *con = pchan->constraints.first;
281 
282  for (; con; con = con->next) {
283  if (con->type == CONSTRAINT_TYPE_KINEMATIC && (con->flag & CONSTRAINT_OFF) == 0 &&
284  (con->enforce != 0.0f)) {
286 
287  if (data->tar == NULL) {
288  return data;
289  }
290  if (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0) {
291  return data;
292  }
293  }
294  }
295  return NULL;
296 }
297 
298 /* adds the IK to pchan - returns if added */
300 {
301  bKinematicConstraint *targetless = NULL;
303  bConstraint *con;
304 
305  /* Sanity check */
306  if (pchan == NULL) {
307  return 0;
308  }
309 
310  /* Rule: not if there's already an IK on this channel */
311  for (con = pchan->constraints.first; con; con = con->next) {
312  if (con->type == CONSTRAINT_TYPE_KINEMATIC && (con->flag & CONSTRAINT_OFF) == 0) {
313  data = con->data;
314 
315  if (data->tar == NULL || (data->tar->type == OB_ARMATURE && data->subtarget[0] == '\0')) {
316  /* make reference to constraint to base things off later
317  * (if it's the last targetless constraint encountered) */
318  targetless = (bKinematicConstraint *)con->data;
319 
320  /* but, if this is a targetless IK, we make it auto anyway (for the children loop) */
321  if (con->enforce != 0.0f) {
322  data->flag |= CONSTRAINT_IK_AUTO;
323 
324  /* if no chain length has been specified,
325  * just make things obey standard rotation locks too */
326  if (data->rootbone == 0) {
327  for (bPoseChannel *pchan_iter = pchan; pchan_iter; pchan_iter = pchan_iter->parent) {
328  /* here, we set ik-settings for bone from pchan->protectflag */
329  /* XXX: careful with quats/axis-angle rotations where we're locking 4d components. */
330  if (pchan_iter->protectflag & OB_LOCK_ROTX) {
331  pchan_iter->ikflag |= BONE_IK_NO_XDOF_TEMP;
332  }
333  if (pchan_iter->protectflag & OB_LOCK_ROTY) {
334  pchan_iter->ikflag |= BONE_IK_NO_YDOF_TEMP;
335  }
336  if (pchan_iter->protectflag & OB_LOCK_ROTZ) {
337  pchan_iter->ikflag |= BONE_IK_NO_ZDOF_TEMP;
338  }
339  }
340  }
341 
342  /* Return early (as in: don't actually create a temporary constraint here), since adding
343  * will take place later in add_pose_transdata() for targetless constraints. */
344  return 0;
345  }
346  }
347 
348  if ((con->flag & CONSTRAINT_DISABLE) == 0 && (con->enforce != 0.0f)) {
349  return 0;
350  }
351  }
352  }
353 
354  data = add_temporary_ik_constraint(pchan, targetless)->data;
355 
356  copy_v3_v3(data->grabtarget, pchan->pose_tail);
357 
358  /* watch-it! has to be 0 here, since we're still on the
359  * same bone for the first time through the loop T25885. */
360  data->rootbone = 0;
361 
362  /* we only include bones that are part of a continual connected chain */
363  do {
364  /* here, we set ik-settings for bone from pchan->protectflag */
365  /* XXX: careful with quats/axis-angle rotations where we're locking 4d components. */
366  if (pchan->protectflag & OB_LOCK_ROTX) {
367  pchan->ikflag |= BONE_IK_NO_XDOF_TEMP;
368  }
369  if (pchan->protectflag & OB_LOCK_ROTY) {
370  pchan->ikflag |= BONE_IK_NO_YDOF_TEMP;
371  }
372  if (pchan->protectflag & OB_LOCK_ROTZ) {
373  pchan->ikflag |= BONE_IK_NO_ZDOF_TEMP;
374  }
375 
376  /* now we count this pchan as being included */
377  data->rootbone++;
378 
379  /* continue to parent, but only if we're connected to it */
380  if (pchan->bone->flag & BONE_CONNECTED) {
381  pchan = pchan->parent;
382  }
383  else {
384  pchan = NULL;
385  }
386  } while (pchan);
387 
388  /* make a copy of maximum chain-length */
389  data->max_rootbone = data->rootbone;
390 
391  return 1;
392 }
393 
394 /* bone is a candidate to get IK, but we don't do it if it has children connected */
396 {
397  Bone *bonec;
398  short wentdeeper = 0, added = 0;
399 
400  /* go deeper if children & children are connected */
401  for (bonec = bone->childbase.first; bonec; bonec = bonec->next) {
402  if (bonec->flag & BONE_CONNECTED) {
403  wentdeeper = 1;
404  added += pose_grab_with_ik_children(pose, bonec);
405  }
406  }
407  if (wentdeeper == 0) {
409  if (pchan) {
410  added += pose_grab_with_ik_add(pchan);
411  }
412  }
413 
414  return added;
415 }
416 
417 /* main call which adds temporal IK chains */
418 static short pose_grab_with_ik(Main *bmain, Object *ob)
419 {
420  bArmature *arm;
421  bPoseChannel *pchan, *parent;
422  Bone *bonec;
423  short tot_ik = 0;
424 
425  if ((ob == NULL) || (ob->pose == NULL) || (ob->mode & OB_MODE_POSE) == 0) {
426  return 0;
427  }
428 
429  arm = ob->data;
430 
431  /* Rule: allow multiple Bones
432  * (but they must be selected, and only one ik-solver per chain should get added) */
433  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
434  if (pchan->bone->layer & arm->layer) {
435  if (pchan->bone->flag & (BONE_SELECTED | BONE_TRANSFORM_MIRROR)) {
436  /* Rule: no IK for solitary (unconnected) bones. */
437  for (bonec = pchan->bone->childbase.first; bonec; bonec = bonec->next) {
438  if (bonec->flag & BONE_CONNECTED) {
439  break;
440  }
441  }
442  if ((pchan->bone->flag & BONE_CONNECTED) == 0 && (bonec == NULL)) {
443  continue;
444  }
445 
446  /* rule: if selected Bone is not a root bone, it gets a temporal IK */
447  if (pchan->parent) {
448  /* only adds if there's no IK yet (and no parent bone was selected) */
449  for (parent = pchan->parent; parent; parent = parent->parent) {
451  break;
452  }
453  }
454  if (parent == NULL) {
455  tot_ik += pose_grab_with_ik_add(pchan);
456  }
457  }
458  else {
459  /* rule: go over the children and add IK to the tips */
460  tot_ik += pose_grab_with_ik_children(ob->pose, pchan->bone);
461  }
462  }
463  }
464  }
465 
466  /* iTaSC needs clear for new IK constraints */
467  if (tot_ik) {
468  update_deg_with_temporary_ik(bmain, ob);
469  }
470 
471  return (tot_ik) ? 1 : 0;
472 }
473 
476 /* -------------------------------------------------------------------- */
480 typedef struct PoseInitData_Mirror {
484  struct {
485  float loc[3];
486  float size[3];
487  union {
488  float eul[3];
489  float quat[4];
490  float axis_angle[4];
491  };
492  float curve_in_x;
493  float curve_out_x;
494  float roll1;
495  float roll2;
496  } orig;
501  float offset_mtx[4][4];
503 
505  bPoseChannel *pchan,
506  bPoseChannel *pchan_orig,
507  bool is_mirror_relative)
508 {
509  pid->pchan = pchan;
510  copy_v3_v3(pid->orig.loc, pchan->loc);
511  copy_v3_v3(pid->orig.size, pchan->size);
512  pid->orig.curve_in_x = pchan->curve_in_x;
513  pid->orig.curve_out_x = pchan->curve_out_x;
514  pid->orig.roll1 = pchan->roll1;
515  pid->orig.roll2 = pchan->roll2;
516 
517  if (pchan->rotmode > 0) {
518  copy_v3_v3(pid->orig.eul, pchan->eul);
519  }
520  else if (pchan->rotmode == ROT_MODE_AXISANGLE) {
521  copy_v3_v3(pid->orig.axis_angle, pchan->rotAxis);
522  pid->orig.axis_angle[3] = pchan->rotAngle;
523  }
524  else {
525  copy_qt_qt(pid->orig.quat, pchan->quat);
526  }
527 
528  if (is_mirror_relative) {
529  float pchan_mtx[4][4];
530  float pchan_mtx_mirror[4][4];
531 
532  float flip_mtx[4][4];
533  unit_m4(flip_mtx);
534  flip_mtx[0][0] = -1;
535 
536  BKE_pchan_to_mat4(pchan_orig, pchan_mtx_mirror);
537  BKE_pchan_to_mat4(pchan, pchan_mtx);
538 
539  mul_m4_m4m4(pchan_mtx_mirror, pchan_mtx_mirror, flip_mtx);
540  mul_m4_m4m4(pchan_mtx_mirror, flip_mtx, pchan_mtx_mirror);
541 
542  invert_m4(pchan_mtx_mirror);
543  mul_m4_m4m4(pid->offset_mtx, pchan_mtx, pchan_mtx_mirror);
544  }
545  else {
546  unit_m4(pid->offset_mtx);
547  }
548 }
549 
552 /* -------------------------------------------------------------------- */
557 {
558  Bone *bone = pchan->bone;
559  float pmat[3][3], omat[3][3];
560  float cmat[3][3], tmat[3][3];
561  float vec[3];
562 
563  copy_v3_v3(vec, pchan->pose_mat[3]);
564  copy_v3_v3(td->center, vec);
565 
566  td->ob = ob;
567  td->flag = TD_SELECTED;
568  if (bone->flag & BONE_HINGE_CHILD_TRANSFORM) {
569  td->flag |= TD_NOCENTER;
570  }
571 
572  if (bone->flag & BONE_TRANSFORM_CHILD) {
573  td->flag |= TD_NOCENTER;
574  td->flag |= TD_NO_LOC;
575  }
576 
577  td->extra = pchan;
578  td->protectflag = pchan->protectflag;
579 
580  td->loc = pchan->loc;
581  copy_v3_v3(td->iloc, pchan->loc);
582 
583  td->ext->size = pchan->size;
584  copy_v3_v3(td->ext->isize, pchan->size);
585 
586  if (pchan->rotmode > 0) {
587  td->ext->rot = pchan->eul;
588  td->ext->rotAxis = NULL;
589  td->ext->rotAngle = NULL;
590  td->ext->quat = NULL;
591 
592  copy_v3_v3(td->ext->irot, pchan->eul);
593  }
594  else if (pchan->rotmode == ROT_MODE_AXISANGLE) {
595  td->ext->rot = NULL;
596  td->ext->rotAxis = pchan->rotAxis;
597  td->ext->rotAngle = &pchan->rotAngle;
598  td->ext->quat = NULL;
599 
600  td->ext->irotAngle = pchan->rotAngle;
601  copy_v3_v3(td->ext->irotAxis, pchan->rotAxis);
602  }
603  else {
604  td->ext->rot = NULL;
605  td->ext->rotAxis = NULL;
606  td->ext->rotAngle = NULL;
607  td->ext->quat = pchan->quat;
608 
609  copy_qt_qt(td->ext->iquat, pchan->quat);
610  }
611  td->ext->rotOrder = pchan->rotmode;
612 
613  /* proper way to get parent transform + own transform + constraints transform */
614  copy_m3_m4(omat, ob->obmat);
615 
616  /* New code, using "generic" BKE_bone_parent_transform_calc_from_pchan(). */
617  {
619  float rpmat[3][3];
620 
622  if (t->mode == TFM_TRANSLATION) {
623  copy_m3_m4(pmat, bpt.loc_mat);
624  }
625  else {
626  copy_m3_m4(pmat, bpt.rotscale_mat);
627  }
628 
629  /* Grrr! Exceptional case: When translating pose bones that are either Hinge or NoLocal,
630  * and want align snapping, we just need both loc_mat and rotscale_mat.
631  * So simply always store rotscale mat in td->ext, and always use it to apply rotations...
632  * Ugly to need such hacks! :/ */
633  copy_m3_m4(rpmat, bpt.rotscale_mat);
634 
635  if (constraints_list_needinv(t, &pchan->constraints)) {
636  copy_m3_m4(tmat, pchan->constinv);
637  invert_m3_m3(cmat, tmat);
638  mul_m3_series(td->mtx, cmat, omat, pmat);
639  mul_m3_series(td->ext->r_mtx, cmat, omat, rpmat);
640  }
641  else {
642  mul_m3_series(td->mtx, omat, pmat);
643  mul_m3_series(td->ext->r_mtx, omat, rpmat);
644  }
645  invert_m3_m3(td->ext->r_smtx, td->ext->r_mtx);
646  }
647 
649 
650  /* exceptional case: rotate the pose bone which also applies transformation
651  * when a parentless bone has BONE_NO_LOCAL_LOCATION [] */
652  if (!ELEM(t->mode, TFM_TRANSLATION, TFM_RESIZE) &&
653  (pchan->bone->flag & BONE_NO_LOCAL_LOCATION)) {
654  if (pchan->parent) {
655  /* same as td->smtx but without pchan->bone->bone_mat */
656  td->flag |= TD_PBONE_LOCAL_MTX_C;
657  mul_m3_m3m3(td->ext->l_smtx, pchan->bone->bone_mat, td->smtx);
658  }
659  else {
660  td->flag |= TD_PBONE_LOCAL_MTX_P;
661  }
662  }
663 
664  /* For `axismtx` we use bone's own transform. */
665  copy_m3_m4(pmat, pchan->pose_mat);
666  mul_m3_m3m3(td->axismtx, omat, pmat);
667  normalize_m3(td->axismtx);
668 
669  if (t->mode == TFM_BONE_ENVELOPE_DIST) {
670  td->loc = NULL;
671  td->val = &bone->dist;
672  td->ival = bone->dist;
673  }
674  else if (t->mode == TFM_BONESIZE) {
675  /* Abusive storage of scale in the loc pointer :) */
676  td->loc = &bone->xwidth;
677  copy_v3_v3(td->iloc, td->loc);
678  td->val = NULL;
679  }
680 
681  /* in this case we can do target-less IK grabbing */
682  if (t->mode == TFM_TRANSLATION) {
684  if (data) {
685  if (data->flag & CONSTRAINT_IK_TIP) {
686  copy_v3_v3(data->grabtarget, pchan->pose_tail);
687  }
688  else {
689  copy_v3_v3(data->grabtarget, pchan->pose_head);
690  }
691  td->loc = data->grabtarget;
692  copy_v3_v3(td->iloc, td->loc);
693 
694  data->flag |= CONSTRAINT_IK_AUTO;
695 
696  /* Add a temporary auto IK constraint here, as we will only temporarily active this
697  * targetless bone during transform. (Targetless IK constraints are treated as if they are
698  * disabled unless they are transformed).
699  * Only do this for targetless IK though, AutoIK already added a constraint in
700  * pose_grab_with_ik_add() beforehand. */
701  if ((data->flag & CONSTRAINT_IK_TEMP) == 0) {
703  Main *bmain = CTX_data_main(t->context);
704  update_deg_with_temporary_ik(bmain, ob);
705  }
706 
707  /* only object matrix correction */
708  copy_m3_m3(td->mtx, omat);
710  }
711  }
712 
713  /* store reference to first constraint */
714  td->con = pchan->constraints.first;
715 }
716 
721 {
722  Main *bmain = CTX_data_main(t->context);
723 
724  t->data_len_all = 0;
725 
726  bool has_translate_rotate_buf[2] = {false, false};
727  bool *has_translate_rotate = (t->mode == TFM_TRANSLATION) ? has_translate_rotate_buf : NULL;
728 
730  Object *ob = tc->poseobj;
731  bPose *pose = ob->pose;
732 
733  bArmature *arm;
734 
735  /* check validity of state */
736  arm = BKE_armature_from_object(tc->poseobj);
737  if ((arm == NULL) || (pose == NULL)) {
738  continue;
739  }
740 
741  const bool mirror = ((pose->flag & POSE_MIRROR_EDIT) != 0);
742 
743  /* set flags and count total */
745  ob, t->mode, t->around, has_translate_rotate);
746 
747  if (tc->data_len == 0) {
748  continue;
749  }
750 
751  if (arm->flag & ARM_RESTPOS) {
752  if (ELEM(t->mode, TFM_DUMMY, TFM_BONESIZE) == 0) {
753  BKE_report(t->reports, RPT_ERROR, "Cannot change Pose when 'Rest Position' is enabled");
754  tc->data_len = 0;
755  continue;
756  }
757  }
758 
759  if (mirror) {
760  int total_mirrored = 0;
761  LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) {
762  /* Clear the MIRROR flag from previous runs. */
763  pchan->bone->flag &= ~BONE_TRANSFORM_MIRROR;
764 
765  if ((pchan->bone->flag & BONE_TRANSFORM) &&
766  BKE_pose_channel_get_mirrored(ob->pose, pchan->name)) {
767  total_mirrored++;
768  }
769  }
770 
771  PoseInitData_Mirror *pid = MEM_mallocN((total_mirrored + 1) * sizeof(PoseInitData_Mirror),
772  "PoseInitData_Mirror");
773 
774  /* Trick to terminate iteration. */
775  pid[total_mirrored].pchan = NULL;
776 
777  tc->custom.type.data = pid;
778  tc->custom.type.use_free = true;
779  }
780  }
781 
783  if (tc->data_len == 0) {
784  continue;
785  }
786  Object *ob = tc->poseobj;
787  TransData *td;
788  TransDataExtension *tdx;
789  int i;
790 
791  PoseInitData_Mirror *pid = tc->custom.type.data;
792  int pid_index = 0;
793  bPose *pose = ob->pose;
794 
795  if (pose == NULL) {
796  continue;
797  }
798 
799  const bool mirror = ((pose->flag & POSE_MIRROR_EDIT) != 0);
800  const bool is_mirror_relative = ((pose->flag & POSE_MIRROR_RELATIVE) != 0);
801 
802  tc->poseobj = ob; /* we also allow non-active objects to be transformed, in weightpaint */
803 
804  /* init trans data */
805  td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransPoseBone");
806  tdx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension),
807  "TransPoseBoneExt");
808  for (i = 0; i < tc->data_len; i++, td++, tdx++) {
809  td->ext = tdx;
810  td->val = NULL;
811  }
812 
813  if (mirror) {
814  LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) {
815  if (pchan->bone->flag & BONE_TRANSFORM) {
816  bPoseChannel *pchan_mirror = BKE_pose_channel_get_mirrored(ob->pose, pchan->name);
817  if (pchan_mirror) {
818  pchan_mirror->bone->flag |= BONE_TRANSFORM_MIRROR;
819  pose_mirror_info_init(&pid[pid_index], pchan_mirror, pchan, is_mirror_relative);
820  pid_index++;
821  }
822  }
823  }
824  }
825 
826  /* do we need to add temporal IK chains? */
827  if ((pose->flag & POSE_AUTO_IK) && t->mode == TFM_TRANSLATION) {
828  if (pose_grab_with_ik(bmain, ob)) {
829  t->flag |= T_AUTOIK;
830  has_translate_rotate[0] = true;
831  }
832  }
833 
834  /* use pose channels to fill trans data */
835  td = tc->data;
836  LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) {
837  if (pchan->bone->flag & BONE_TRANSFORM) {
838  add_pose_transdata(t, pchan, ob, td);
839  td++;
840  }
841  }
842 
843  if (td != (tc->data + tc->data_len)) {
844  BKE_report(t->reports, RPT_DEBUG, "Bone selection count error");
845  }
846  }
847 
848  /* initialize initial auto=ik chainlen's? */
849  if (t->flag & T_AUTOIK) {
851  }
852 
853  /* if there are no translatable bones, do rotation */
854  if ((t->mode == TFM_TRANSLATION) && !has_translate_rotate[0]) {
855  if (has_translate_rotate[1]) {
856  t->mode = TFM_ROTATION;
857  }
858  else {
859  t->mode = TFM_RESIZE;
860  }
861  }
862 }
863 
865 {
866  t->data_len_all = 0;
867 
869  EditBone *ebo, *eboflip;
870  bArmature *arm = tc->obedit->data;
871  ListBase *edbo = arm->edbo;
872  bool mirror = ((arm->flag & ARM_MIRROR_EDIT) != 0);
873  int total_mirrored = 0;
874 
875  tc->data_len = 0;
876  for (ebo = edbo->first; ebo; ebo = ebo->next) {
877  const int data_len_prev = tc->data_len;
878 
879  if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) {
880  if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) {
881  if (ebo->flag & BONE_SELECTED) {
882  tc->data_len++;
883  }
884  }
885  else if (t->mode == TFM_BONE_ROLL) {
886  if (ebo->flag & BONE_SELECTED) {
887  tc->data_len++;
888  }
889  }
890  else {
891  if (ebo->flag & BONE_TIPSEL) {
892  tc->data_len++;
893  }
894  if (ebo->flag & BONE_ROOTSEL) {
895  tc->data_len++;
896  }
897  }
898  }
899 
900  if (mirror && (data_len_prev < tc->data_len)) {
901  eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo);
902  if (eboflip) {
903  total_mirrored++;
904  }
905  }
906  }
907  if (!tc->data_len) {
908  continue;
909  }
910 
911  if (mirror) {
912  BoneInitData *bid = MEM_mallocN((total_mirrored + 1) * sizeof(BoneInitData), "BoneInitData");
913 
914  /* trick to terminate iteration */
915  bid[total_mirrored].bone = NULL;
916 
917  tc->custom.type.data = bid;
918  tc->custom.type.use_free = true;
919  }
920  t->data_len_all += tc->data_len;
921  }
922 
924  t->data_len_all = -1;
925 
927  if (!tc->data_len) {
928  continue;
929  }
930 
931  EditBone *ebo, *eboflip;
932  bArmature *arm = tc->obedit->data;
933  ListBase *edbo = arm->edbo;
934  TransData *td, *td_old;
935  float mtx[3][3], smtx[3][3], bonemat[3][3];
936  bool mirror = ((arm->flag & ARM_MIRROR_EDIT) != 0);
937  BoneInitData *bid = tc->custom.type.data;
938 
939  copy_m3_m4(mtx, tc->obedit->obmat);
941 
942  td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransEditBone");
943  int i = 0;
944 
945  for (ebo = edbo->first; ebo; ebo = ebo->next) {
946  td_old = td;
947 
948  /* (length == 0.0) on extrude, used for scaling radius of bone points. */
949  ebo->oldlength = ebo->length;
950 
951  if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) {
952  if (t->mode == TFM_BONE_ENVELOPE) {
953  if (ebo->flag & BONE_ROOTSEL) {
954  td->val = &ebo->rad_head;
955  td->ival = *td->val;
956 
957  copy_v3_v3(td->center, ebo->head);
958  td->flag = TD_SELECTED;
959 
960  copy_m3_m3(td->smtx, smtx);
961  copy_m3_m3(td->mtx, mtx);
962 
963  td->loc = NULL;
964  td->ext = NULL;
965  td->ob = tc->obedit;
966 
967  td++;
968  }
969  if (ebo->flag & BONE_TIPSEL) {
970  td->val = &ebo->rad_tail;
971  td->ival = *td->val;
972  copy_v3_v3(td->center, ebo->tail);
973  td->flag = TD_SELECTED;
974 
975  copy_m3_m3(td->smtx, smtx);
976  copy_m3_m3(td->mtx, mtx);
977 
978  td->loc = NULL;
979  td->ext = NULL;
980  td->ob = tc->obedit;
981 
982  td++;
983  }
984  }
985  else if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) {
986  if (ebo->flag & BONE_SELECTED) {
987  if (t->mode == TFM_BONE_ENVELOPE_DIST) {
988  td->loc = NULL;
989  td->val = &ebo->dist;
990  td->ival = ebo->dist;
991  }
992  else {
993  /* Abusive storage of scale in the loc pointer :). */
994  td->loc = &ebo->xwidth;
995  copy_v3_v3(td->iloc, td->loc);
996  td->val = NULL;
997  }
998  copy_v3_v3(td->center, ebo->head);
999  td->flag = TD_SELECTED;
1000 
1001  /* use local bone matrix */
1002  ED_armature_ebone_to_mat3(ebo, bonemat);
1003  mul_m3_m3m3(td->mtx, mtx, bonemat);
1004  invert_m3_m3(td->smtx, td->mtx);
1005 
1006  copy_m3_m3(td->axismtx, td->mtx);
1007  normalize_m3(td->axismtx);
1008 
1009  td->ext = NULL;
1010  td->ob = tc->obedit;
1011 
1012  td++;
1013  }
1014  }
1015  else if (t->mode == TFM_BONE_ROLL) {
1016  if (ebo->flag & BONE_SELECTED) {
1017  td->loc = NULL;
1018  td->val = &(ebo->roll);
1019  td->ival = ebo->roll;
1020 
1021  copy_v3_v3(td->center, ebo->head);
1022  td->flag = TD_SELECTED;
1023 
1024  td->ext = NULL;
1025  td->ob = tc->obedit;
1026 
1027  td++;
1028  }
1029  }
1030  else {
1031  if (ebo->flag & BONE_TIPSEL) {
1032  copy_v3_v3(td->iloc, ebo->tail);
1033 
1034  /* Don't allow single selected tips to have a modified center,
1035  * causes problem with snapping (see T45974).
1036  * However, in rotation mode, we want to keep that 'rotate bone around root with
1037  * only its tip selected' behavior (see T46325). */
1038  if ((t->around == V3D_AROUND_LOCAL_ORIGINS) &&
1039  ((t->mode == TFM_ROTATION) || (ebo->flag & BONE_ROOTSEL))) {
1040  copy_v3_v3(td->center, ebo->head);
1041  }
1042  else {
1043  copy_v3_v3(td->center, td->iloc);
1044  }
1045 
1046  td->loc = ebo->tail;
1047  td->flag = TD_SELECTED;
1048  if (ebo->flag & BONE_EDITMODE_LOCKED) {
1050  }
1051 
1052  copy_m3_m3(td->smtx, smtx);
1053  copy_m3_m3(td->mtx, mtx);
1054 
1056 
1057  if ((ebo->flag & BONE_ROOTSEL) == 0) {
1058  td->extra = ebo;
1059  td->ival = ebo->roll;
1060  }
1061 
1062  td->ext = NULL;
1063  td->val = NULL;
1064  td->ob = tc->obedit;
1065 
1066  td++;
1067  }
1068  if (ebo->flag & BONE_ROOTSEL) {
1069  copy_v3_v3(td->iloc, ebo->head);
1070  copy_v3_v3(td->center, td->iloc);
1071  td->loc = ebo->head;
1072  td->flag = TD_SELECTED;
1073  if (ebo->flag & BONE_EDITMODE_LOCKED) {
1075  }
1076 
1077  copy_m3_m3(td->smtx, smtx);
1078  copy_m3_m3(td->mtx, mtx);
1079 
1081 
1082  td->extra = ebo; /* to fix roll */
1083  td->ival = ebo->roll;
1084 
1085  td->ext = NULL;
1086  td->val = NULL;
1087  td->ob = tc->obedit;
1088 
1089  td++;
1090  }
1091  }
1092  }
1093 
1094  if (mirror && (td_old != td)) {
1095  eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo);
1096  if (eboflip) {
1097  bid[i].bone = eboflip;
1098  bid[i].dist = eboflip->dist;
1099  bid[i].rad_head = eboflip->rad_head;
1100  bid[i].rad_tail = eboflip->rad_tail;
1101  bid[i].roll = eboflip->roll;
1102  bid[i].xwidth = eboflip->xwidth;
1103  bid[i].zwidth = eboflip->zwidth;
1104  copy_v3_v3(bid[i].head, eboflip->head);
1105  copy_v3_v3(bid[i].tail, eboflip->tail);
1106  i++;
1107  }
1108  }
1109  }
1110 
1111  if (mirror) {
1112  /* trick to terminate iteration */
1113  BLI_assert(i + 1 == (MEM_allocN_len(bid) / sizeof(*bid)));
1114  bid[i].bone = NULL;
1115  }
1116  }
1117 }
1118 
1121 /* -------------------------------------------------------------------- */
1126 {
1127  bArmature *arm;
1128  BoneInitData *bid = tc->custom.type.data;
1129  EditBone *ebo;
1130 
1131  if (tc->obedit) {
1132  arm = tc->obedit->data;
1133  }
1134  else {
1135  BLI_assert(tc->poseobj != NULL);
1136  arm = tc->poseobj->data;
1137  }
1138 
1139  while (bid->bone) {
1140  ebo = bid->bone;
1141 
1142  ebo->dist = bid->dist;
1143  ebo->rad_head = bid->rad_head;
1144  ebo->rad_tail = bid->rad_tail;
1145  ebo->roll = bid->roll;
1146  ebo->xwidth = bid->xwidth;
1147  ebo->zwidth = bid->zwidth;
1148  copy_v3_v3(ebo->head, bid->head);
1149  copy_v3_v3(ebo->tail, bid->tail);
1150 
1151  if (arm->flag & ARM_MIRROR_EDIT) {
1152  EditBone *ebo_child;
1153 
1154  /* Also move connected ebo_child, in case ebo_child's name aren't mirrored properly */
1155  for (ebo_child = arm->edbo->first; ebo_child; ebo_child = ebo_child->next) {
1156  if ((ebo_child->flag & BONE_CONNECTED) && (ebo_child->parent == ebo)) {
1157  copy_v3_v3(ebo_child->head, ebo->tail);
1158  ebo_child->rad_head = ebo->rad_tail;
1159  }
1160  }
1161 
1162  /* Also move connected parent, in case parent's name isn't mirrored properly */
1163  if ((ebo->flag & BONE_CONNECTED) && ebo->parent) {
1164  EditBone *parent = ebo->parent;
1165  copy_v3_v3(parent->tail, ebo->head);
1166  parent->rad_tail = ebo->rad_head;
1167  }
1168  }
1169 
1170  bid++;
1171  }
1172 }
1173 
1175 {
1176  if (t->state != TRANS_CANCEL) {
1177  applyProject(t);
1178  }
1179 
1181  bArmature *arm = tc->obedit->data;
1182  ListBase *edbo = arm->edbo;
1183  EditBone *ebo, *ebo_parent;
1184  TransData *td = tc->data;
1185  int i;
1186 
1187  /* Ensure all bones are correctly adjusted */
1188  for (ebo = edbo->first; ebo; ebo = ebo->next) {
1189  ebo_parent = (ebo->flag & BONE_CONNECTED) ? ebo->parent : NULL;
1190 
1191  if (ebo_parent) {
1192  /* If this bone has a parent tip that has been moved */
1193  if (ebo_parent->flag & BONE_TIPSEL) {
1194  copy_v3_v3(ebo->head, ebo_parent->tail);
1195  if (t->mode == TFM_BONE_ENVELOPE) {
1196  ebo->rad_head = ebo_parent->rad_tail;
1197  }
1198  }
1199  /* If this bone has a parent tip that has NOT been moved */
1200  else {
1201  copy_v3_v3(ebo_parent->tail, ebo->head);
1202  if (t->mode == TFM_BONE_ENVELOPE) {
1203  ebo_parent->rad_tail = ebo->rad_head;
1204  }
1205  }
1206  }
1207 
1208  /* on extrude bones, oldlength==0.0f, so we scale radius of points */
1209  ebo->length = len_v3v3(ebo->head, ebo->tail);
1210  if (ebo->oldlength == 0.0f) {
1211  ebo->rad_head = 0.25f * ebo->length;
1212  ebo->rad_tail = 0.10f * ebo->length;
1213  ebo->dist = 0.25f * ebo->length;
1214  if (ebo->parent) {
1215  if (ebo->rad_head > ebo->parent->rad_tail) {
1216  ebo->rad_head = ebo->parent->rad_tail;
1217  }
1218  }
1219  }
1220  else if (t->mode != TFM_BONE_ENVELOPE) {
1221  /* if bones change length, lets do that for the deform distance as well */
1222  ebo->dist *= ebo->length / ebo->oldlength;
1223  ebo->rad_head *= ebo->length / ebo->oldlength;
1224  ebo->rad_tail *= ebo->length / ebo->oldlength;
1225  ebo->oldlength = ebo->length;
1226 
1227  if (ebo_parent) {
1228  ebo_parent->rad_tail = ebo->rad_head;
1229  }
1230  }
1231  }
1232 
1234  /* fix roll */
1235  for (i = 0; i < tc->data_len; i++, td++) {
1236  if (td->extra) {
1237  float vec[3], up_axis[3];
1238  float qrot[4];
1239  float roll;
1240 
1241  ebo = td->extra;
1242 
1243  if (t->state == TRANS_CANCEL) {
1244  /* restore roll */
1245  ebo->roll = td->ival;
1246  }
1247  else {
1248  copy_v3_v3(up_axis, td->axismtx[2]);
1249 
1250  sub_v3_v3v3(vec, ebo->tail, ebo->head);
1251  normalize_v3(vec);
1252  rotation_between_vecs_to_quat(qrot, td->axismtx[1], vec);
1253  mul_qt_v3(qrot, up_axis);
1254 
1255  /* roll has a tendency to flip in certain orientations - T34283, T33974. */
1256  roll = ED_armature_ebone_roll_to_vector(ebo, up_axis, false);
1257  ebo->roll = angle_compat_rad(roll, td->ival);
1258  }
1259  }
1260  }
1261  }
1262 
1263  if (arm->flag & ARM_MIRROR_EDIT) {
1264  if (t->state != TRANS_CANCEL) {
1266  }
1267  else {
1268  restoreBones(tc);
1269  }
1270  }
1271 
1272  /* Tag for redraw/invalidate overlay cache. */
1274  }
1275 }
1276 
1279 /* -------------------------------------------------------------------- */
1288 {
1289  float flip_mtx[4][4];
1290  unit_m4(flip_mtx);
1291  flip_mtx[0][0] = -1;
1292 
1293  LISTBASE_FOREACH (bPoseChannel *, pchan_orig, &ob->pose->chanbase) {
1294  /* Clear the MIRROR flag from previous runs. */
1295  pchan_orig->bone->flag &= ~BONE_TRANSFORM_MIRROR;
1296  }
1297 
1298  bPose *pose = ob->pose;
1299  PoseInitData_Mirror *pid = NULL;
1300  if ((t->mode != TFM_BONESIZE) && (pose->flag & POSE_MIRROR_RELATIVE)) {
1301  pid = tc->custom.type.data;
1302  }
1303 
1304  TransData *td = tc->data;
1305  for (int i = tc->data_len; i--; td++) {
1306  bPoseChannel *pchan_orig = td->extra;
1307  BLI_assert(pchan_orig->bone->flag & BONE_TRANSFORM);
1308  /* No layer check, correct mirror is more important. */
1309  bPoseChannel *pchan = BKE_pose_channel_get_mirrored(pose, pchan_orig->name);
1310  if (pchan == NULL) {
1311  continue;
1312  }
1313 
1314  /* Also do bbone scaling. */
1315  pchan->bone->xwidth = pchan_orig->bone->xwidth;
1316  pchan->bone->zwidth = pchan_orig->bone->zwidth;
1317 
1318  /* We assume X-axis flipping for now. */
1319  pchan->curve_in_x = pchan_orig->curve_in_x * -1;
1320  pchan->curve_out_x = pchan_orig->curve_out_x * -1;
1321  pchan->roll1 = pchan_orig->roll1 * -1; /* XXX? */
1322  pchan->roll2 = pchan_orig->roll2 * -1; /* XXX? */
1323 
1324  float pchan_mtx_final[4][4];
1325  BKE_pchan_to_mat4(pchan_orig, pchan_mtx_final);
1326  mul_m4_m4m4(pchan_mtx_final, pchan_mtx_final, flip_mtx);
1327  mul_m4_m4m4(pchan_mtx_final, flip_mtx, pchan_mtx_final);
1328  if (pid) {
1329  mul_m4_m4m4(pchan_mtx_final, pid->offset_mtx, pchan_mtx_final);
1330  }
1331  BKE_pchan_apply_mat4(pchan, pchan_mtx_final, false);
1332 
1333  /* Set flag to let auto key-frame know to key-frame the mirrored bone. */
1334  pchan->bone->flag |= BONE_TRANSFORM_MIRROR;
1335 
1336  /* In this case we can do target-less IK grabbing. */
1337  if (t->mode == TFM_TRANSLATION) {
1339  if (data == NULL) {
1340  continue;
1341  }
1342  mul_v3_m4v3(data->grabtarget, flip_mtx, td->loc);
1343  if (pid) {
1344  /* TODO(germano): Relative Mirror support. */
1345  }
1346  data->flag |= CONSTRAINT_IK_AUTO;
1347  /* Add a temporary auto IK constraint here, as we will only temporarily active this
1348  * target-less bone during transform. (Target-less IK constraints are treated as if they are
1349  * disabled unless they are transformed).
1350  * Only do this for targetless IK though, AutoIK already added a constraint in
1351  * pose_grab_with_ik_add() beforehand. */
1352  if ((data->flag & CONSTRAINT_IK_TEMP) == 0) {
1354  Main *bmain = CTX_data_main(t->context);
1355  update_deg_with_temporary_ik(bmain, ob);
1356  }
1357  }
1358 
1359  if (pid) {
1360  pid++;
1361  }
1362  }
1363 }
1364 
1366 {
1367  bPoseChannel *pchan = pid->pchan;
1368  copy_v3_v3(pchan->loc, pid->orig.loc);
1369  copy_v3_v3(pchan->size, pid->orig.size);
1370  pchan->curve_in_x = pid->orig.curve_in_x;
1371  pchan->curve_out_x = pid->orig.curve_out_x;
1372  pchan->roll1 = pid->orig.roll1;
1373  pchan->roll2 = pid->orig.roll2;
1374 
1375  if (pchan->rotmode > 0) {
1376  copy_v3_v3(pchan->eul, pid->orig.eul);
1377  }
1378  else if (pchan->rotmode == ROT_MODE_AXISANGLE) {
1379  copy_v3_v3(pchan->rotAxis, pid->orig.axis_angle);
1380  pchan->rotAngle = pid->orig.axis_angle[3];
1381  }
1382  else {
1383  copy_qt_qt(pchan->quat, pid->orig.quat);
1384  }
1385 }
1386 
1388 {
1389  bPose *pose = tc->poseobj->pose;
1390 
1391  if (!(pose->flag & POSE_MIRROR_EDIT)) {
1392  return;
1393  }
1394 
1395  for (PoseInitData_Mirror *pid = tc->custom.type.data; pid->pchan; pid++) {
1397  }
1398 }
1399 
1401 {
1402  if (t->mode == TFM_BONESIZE) {
1403  /* Handle the exception where for TFM_BONESIZE in edit mode we pretend to be
1404  * in pose mode (to use bone orientation matrix),
1405  * in that case we have to do mirroring as well. */
1407  Object *ob = tc->poseobj;
1408  bArmature *arm = ob->data;
1409  if (ob->mode == OB_MODE_EDIT) {
1410  if (arm->flag & ARM_MIRROR_EDIT) {
1411  if (t->state != TRANS_CANCEL) {
1413  }
1414  else {
1415  restoreBones(tc);
1416  }
1417  }
1418  }
1419  else if (ob->mode == OB_MODE_POSE) {
1420  /* actually support TFM_BONESIZE in posemode as well */
1422  bPose *pose = ob->pose;
1423  if (arm->flag & ARM_MIRROR_EDIT || pose->flag & POSE_MIRROR_EDIT) {
1425  }
1426  }
1427  }
1428  }
1429  else {
1430  GSet *motionpath_updates = BLI_gset_ptr_new("motionpath updates");
1431 
1433  Object *ob = tc->poseobj;
1434  bPose *pose = ob->pose;
1435 
1436  if (pose->flag & POSE_MIRROR_EDIT) {
1437  if (t->state != TRANS_CANCEL) {
1439  }
1440  else {
1442  }
1443  }
1444 
1445  /* if animtimer is running, and the object already has animation data,
1446  * check if the auto-record feature means that we should record 'samples'
1447  * (i.e. un-editable animation values)
1448  *
1449  * context is needed for keying set poll() functions.
1450  */
1451 
1452  /* TODO: autokeyframe calls need some setting to specify to add samples
1453  * (FPoints) instead of keyframes? */
1454  if ((t->animtimer) && (t->context) && IS_AUTOKEY_ON(t->scene)) {
1455  int targetless_ik =
1456  (t->flag &
1457  T_AUTOIK); /* XXX this currently doesn't work, since flags aren't set yet! */
1458 
1460  autokeyframe_pose(t->context, t->scene, ob, t->mode, targetless_ik);
1461  }
1462 
1463  if (motionpath_need_update_pose(t->scene, ob)) {
1464  BLI_gset_insert(motionpath_updates, ob);
1465  }
1466 
1468  }
1469 
1470  /* Update motion paths once for all transformed bones in an object. */
1471  GSetIterator gs_iter;
1472  GSET_ITER (gs_iter, motionpath_updates) {
1473  Object *ob = BLI_gsetIterator_getKey(&gs_iter);
1475  }
1476  BLI_gset_free(motionpath_updates, NULL);
1477  }
1478 }
1479 
1482 /* -------------------------------------------------------------------- */
1486 static void bone_children_clear_transflag(int mode, short around, ListBase *lb)
1487 {
1488  Bone *bone = lb->first;
1489 
1490  for (; bone; bone = bone->next) {
1491  if ((bone->flag & BONE_HINGE) && (bone->flag & BONE_CONNECTED)) {
1493  }
1494  else if ((bone->flag & BONE_TRANSFORM) && (ELEM(mode, TFM_ROTATION, TFM_TRACKBALL)) &&
1495  (around == V3D_AROUND_LOCAL_ORIGINS)) {
1496  bone->flag |= BONE_TRANSFORM_CHILD;
1497  }
1498  else {
1499  bone->flag &= ~BONE_TRANSFORM;
1500  }
1501 
1502  bone_children_clear_transflag(mode, around, &bone->childbase);
1503  }
1504 }
1505 
1506 /* Sets transform flags in the bones.
1507  * Returns total number of bones with `BONE_TRANSFORM`. */
1509  const int mode,
1510  const short around,
1511  bool has_translate_rotate[2])
1512 {
1513  bArmature *arm = ob->data;
1514  bPoseChannel *pchan;
1515  Bone *bone;
1516  int total = 0;
1517 
1518  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1519  bone = pchan->bone;
1520  if (PBONE_VISIBLE(arm, bone)) {
1521  if ((bone->flag & BONE_SELECTED)) {
1522  bone->flag |= BONE_TRANSFORM;
1523  }
1524  else {
1525  bone->flag &= ~BONE_TRANSFORM;
1526  }
1527 
1528  bone->flag &= ~BONE_HINGE_CHILD_TRANSFORM;
1529  bone->flag &= ~BONE_TRANSFORM_CHILD;
1530  }
1531  else {
1532  bone->flag &= ~BONE_TRANSFORM;
1533  }
1534  }
1535 
1536  /* make sure no bone can be transformed when a parent is transformed */
1537  /* since pchans are depsgraph sorted, the parents are in beginning of list */
1538  if (!ELEM(mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) {
1539  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1540  bone = pchan->bone;
1541  if (bone->flag & BONE_TRANSFORM) {
1542  bone_children_clear_transflag(mode, around, &bone->childbase);
1543  }
1544  }
1545  }
1546  /* now count, and check if we have autoIK or have to switch from translate to rotate */
1547  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1548  bone = pchan->bone;
1549  if (bone->flag & BONE_TRANSFORM) {
1550  total++;
1551 
1552  if (has_translate_rotate != NULL) {
1553  if (has_targetless_ik(pchan) == NULL) {
1554  if (pchan->parent && (pchan->bone->flag & BONE_CONNECTED)) {
1555  if (pchan->bone->flag & BONE_HINGE_CHILD_TRANSFORM) {
1556  has_translate_rotate[0] = true;
1557  }
1558  }
1559  else {
1560  if ((pchan->protectflag & OB_LOCK_LOC) != OB_LOCK_LOC) {
1561  has_translate_rotate[0] = true;
1562  }
1563  }
1564  if ((pchan->protectflag & OB_LOCK_ROT) != OB_LOCK_ROT) {
1565  has_translate_rotate[1] = true;
1566  }
1567  }
1568  else {
1569  has_translate_rotate[0] = true;
1570  }
1571  }
1572  }
1573  }
1574 
1575  return total;
1576 }
1577 
1578 static short apply_targetless_ik(Object *ob)
1579 {
1580  bPoseChannel *pchan, *parchan, *chanlist[256];
1582  int segcount, apply = 0;
1583 
1584  /* now we got a difficult situation... we have to find the
1585  * target-less IK pchans, and apply transformation to the all
1586  * pchans that were in the chain */
1587 
1588  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1589  data = has_targetless_ik(pchan);
1590  if (data && (data->flag & CONSTRAINT_IK_AUTO)) {
1591 
1592  /* fill the array with the bones of the chain (armature.c does same, keep it synced) */
1593  segcount = 0;
1594 
1595  /* exclude tip from chain? */
1596  if (!(data->flag & CONSTRAINT_IK_TIP)) {
1597  parchan = pchan->parent;
1598  }
1599  else {
1600  parchan = pchan;
1601  }
1602 
1603  /* Find the chain's root & count the segments needed */
1604  for (; parchan; parchan = parchan->parent) {
1605  chanlist[segcount] = parchan;
1606  segcount++;
1607 
1608  if (segcount == data->rootbone || segcount > 255) {
1609  break; /* 255 is weak */
1610  }
1611  }
1612  for (; segcount; segcount--) {
1613  Bone *bone;
1614  float mat[4][4];
1615 
1616  /* pose_mat(b) = pose_mat(b-1) * offs_bone * channel * constraint * IK */
1617  /* we put in channel the entire result of mat = (channel * constraint * IK) */
1618  /* pose_mat(b) = pose_mat(b-1) * offs_bone * mat */
1619  /* mat = pose_mat(b) * inv(pose_mat(b-1) * offs_bone ) */
1620 
1621  parchan = chanlist[segcount - 1];
1622  bone = parchan->bone;
1623  bone->flag |= BONE_TRANSFORM; /* ensures it gets an auto key inserted */
1624 
1625  BKE_armature_mat_pose_to_bone(parchan, parchan->pose_mat, mat);
1626  /* apply and decompose, doesn't work for constraints or non-uniform scale well */
1627  {
1628  float rmat3[3][3], qrmat[3][3], imat3[3][3], smat[3][3];
1629 
1630  copy_m3_m4(rmat3, mat);
1631  /* Make sure that our rotation matrix only contains rotation and not scale. */
1632  normalize_m3(rmat3);
1633 
1634  /* rotation */
1635  /* T22409 is partially caused by this, as slight numeric error introduced during
1636  * the solving process leads to locked-axis values changing. However, we cannot modify
1637  * the values here, or else there are huge discrepancies between IK-solver (interactive)
1638  * and applied poses. */
1639  BKE_pchan_mat3_to_rot(parchan, rmat3, false);
1640 
1641  /* for size, remove rotation */
1642  /* causes problems with some constraints (so apply only if needed) */
1643  if (data->flag & CONSTRAINT_IK_STRETCH) {
1644  BKE_pchan_rot_to_mat3(parchan, qrmat);
1645  invert_m3_m3(imat3, qrmat);
1646  mul_m3_m3m3(smat, rmat3, imat3);
1647  mat3_to_size(parchan->size, smat);
1648  }
1649 
1650  /* causes problems with some constraints (e.g. childof), so disable this */
1651  /* as it is IK shouldn't affect location directly */
1652  /* copy_v3_v3(parchan->loc, mat[3]); */
1653  }
1654  }
1655 
1656  apply = 1;
1657  data->flag &= ~CONSTRAINT_IK_AUTO;
1658  }
1659  }
1660 
1661  return apply;
1662 }
1663 
1664 /* frees temporal IKs */
1665 static void pose_grab_with_ik_clear(Main *bmain, Object *ob)
1666 {
1668  bPoseChannel *pchan;
1669  bConstraint *con, *next;
1670  bool relations_changed = false;
1671 
1672  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1673  /* clear all temporary lock flags */
1675 
1676  pchan->constflag &= ~(PCHAN_HAS_IK | PCHAN_HAS_TARGET);
1677 
1678  /* remove all temporary IK-constraints added */
1679  for (con = pchan->constraints.first; con; con = next) {
1680  next = con->next;
1681  if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
1682  data = con->data;
1683  if (data->flag & CONSTRAINT_IK_TEMP) {
1684  relations_changed = true;
1685 
1686  /* iTaSC needs clear for removed constraints */
1687  BIK_clear_data(ob->pose);
1688 
1689  BLI_remlink(&pchan->constraints, con);
1690  MEM_freeN(con->data);
1691  MEM_freeN(con);
1692  continue;
1693  }
1694  pchan->constflag |= PCHAN_HAS_IK;
1695  if (data->tar == NULL || (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0)) {
1696  pchan->constflag |= PCHAN_HAS_TARGET;
1697  }
1698  }
1699  }
1700  }
1701 
1702  if (relations_changed) {
1703  /* TODO(sergey): Consider doing partial update only. */
1704  DEG_relations_tag_update(bmain);
1705  }
1706 }
1707 
1709 {
1710  Object *ob;
1711 
1712  if (t->mode == TFM_BONESIZE) {
1713  /* Handle the exception where for TFM_BONESIZE in edit mode we pretend to be
1714  * in pose mode (to use bone orientation matrix),
1715  * in that case we don't do operations like auto-keyframing. */
1717  ob = tc->poseobj;
1719  }
1720  }
1721  else {
1722  const bool canceled = (t->state == TRANS_CANCEL);
1723  GSet *motionpath_updates = BLI_gset_ptr_new("motionpath updates");
1724 
1726 
1727  bPoseChannel *pchan;
1728  short targetless_ik = 0;
1729 
1730  ob = tc->poseobj;
1731 
1732  if ((t->flag & T_AUTOIK) && (t->options & CTX_AUTOCONFIRM)) {
1733  /* when running transform non-interactively (operator exec),
1734  * we need to update the pose otherwise no updates get called during
1735  * transform and the auto-ik is not applied. see T26164. */
1736  struct Object *pose_ob = tc->poseobj;
1737  BKE_pose_where_is(t->depsgraph, t->scene, pose_ob);
1738  }
1739 
1740  /* set BONE_TRANSFORM flags for autokey, gizmo draw might have changed them */
1741  if (!canceled && (t->mode != TFM_DUMMY)) {
1742  transform_convert_pose_transflags_update(ob, t->mode, t->around, NULL);
1743  }
1744 
1745  /* if target-less IK grabbing, we calculate the pchan transforms and clear flag */
1746  if (!canceled && t->mode == TFM_TRANSLATION) {
1747  targetless_ik = apply_targetless_ik(ob);
1748  }
1749  else {
1750  /* not forget to clear the auto flag */
1751  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1753  if (data) {
1754  data->flag &= ~CONSTRAINT_IK_AUTO;
1755  }
1756  }
1757  }
1758 
1759  if (t->mode == TFM_TRANSLATION) {
1760  struct Main *bmain = CTX_data_main(t->context);
1761  pose_grab_with_ik_clear(bmain, ob);
1762  }
1763 
1764  /* automatic inserting of keys and unkeyed tagging -
1765  * only if transform wasn't canceled (or TFM_DUMMY) */
1766  if (!canceled && (t->mode != TFM_DUMMY)) {
1767  autokeyframe_pose(C, t->scene, ob, t->mode, targetless_ik);
1769  }
1770  else {
1772  }
1773 
1774  if (t->mode != TFM_DUMMY && motionpath_need_update_pose(t->scene, ob)) {
1775  BLI_gset_insert(motionpath_updates, ob);
1776  }
1777  }
1778 
1779  /* Update motion paths once for all transformed bones in an object. */
1780  GSetIterator gs_iter;
1781  GSET_ITER (gs_iter, motionpath_updates) {
1782  const ePosePathCalcRange range = canceled ? POSE_PATH_CALC_RANGE_CURRENT_FRAME :
1784  ob = BLI_gsetIterator_getKey(&gs_iter);
1785  ED_pose_recalculate_paths(C, t->scene, ob, range);
1786  }
1787  BLI_gset_free(motionpath_updates, NULL);
1788  }
1789 }
1790 
void BIK_clear_data(struct bPose *pose)
Definition: ikplugin_api.c:111
Blender kernel action and pose functionality.
struct bPoseChannel * BKE_pose_channel_find_name(const struct bPose *pose, const char *name)
struct bPoseChannel * BKE_pose_channel_get_mirrored(const struct bPose *pose, const char *name)
void BKE_animsys_free_nla_keyframing_context_cache(struct ListBase *cache)
Definition: anim_sys.c:2756
AnimationEvalContext BKE_animsys_eval_context_construct(struct Depsgraph *depsgraph, float eval_time)
Definition: anim_sys.c:637
void BKE_bone_parent_transform_calc_from_pchan(const struct bPoseChannel *pchan, struct BoneParentTransform *r_bpt)
void BKE_pchan_to_mat4(const struct bPoseChannel *pchan, float r_chanmat[4][4])
struct bArmature * BKE_armature_from_object(struct Object *ob)
Definition: armature.c:353
void BKE_pchan_apply_mat4(struct bPoseChannel *pchan, const float mat[4][4], bool use_compat)
Definition: armature.c:1951
void BKE_pchan_mat3_to_rot(struct bPoseChannel *pchan, const float mat[3][3], bool use_compat)
Definition: armature.c:1898
void BKE_armature_mat_pose_to_bone(struct bPoseChannel *pchan, const float inmat[4][4], float outmat[4][4])
Definition: armature.c:1828
#define PBONE_VISIBLE(arm, bone)
Definition: BKE_armature.h:338
void BKE_pose_where_is(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
Definition: armature.c:2739
void BKE_pchan_rot_to_mat3(const struct bPoseChannel *pchan, float r_mat[3][3])
struct bConstraint * BKE_constraint_add_for_pose(struct Object *ob, struct bPoseChannel *pchan, const char *name, short type)
Definition: constraint.c:5659
struct ReportList * CTX_wm_reports(const bContext *C)
Definition: context.c:751
struct Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
Definition: context.c:1401
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
#define BLI_assert(a)
Definition: BLI_assert.h:58
struct GSet GSet
Definition: BLI_ghash.h:189
GSet * BLI_gset_ptr_new(const char *info)
void BLI_gset_insert(GSet *gs, void *key)
Definition: BLI_ghash.c:1147
#define GSET_ITER(gs_iter_, gset_)
Definition: BLI_ghash.h:268
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
Definition: BLI_ghash.c:1253
BLI_INLINE void * BLI_gsetIterator_getKey(GSetIterator *gsi)
Definition: BLI_ghash.h:255
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:547
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:133
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:262
bool invert_m4(float R[4][4])
Definition: math_matrix.c:1187
void copy_m3_m3(float m1[3][3], const float m2[3][3])
Definition: math_matrix.c:89
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:105
#define PSEUDOINVERSE_EPSILON
void unit_m4(float m[4][4])
Definition: rct.c:1140
void normalize_m3(float R[3][3]) ATTR_NONNULL()
Definition: math_matrix.c:1919
bool invert_m3_m3(float R[3][3], const float A[3][3])
Definition: math_matrix.c:1161
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:742
#define mul_m3_series(...)
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
Definition: math_matrix.c:391
void mat3_to_size(float size[3], const float M[3][3])
Definition: math_matrix.c:2138
void pseudoinverse_m3_m3(float Ainv[3][3], const float A[3][3], float epsilon)
Definition: math_matrix.c:3228
float angle_compat_rad(float angle, float angle_compat)
void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3])
void mul_qt_v3(const float q[4], float r[3])
Definition: math_rotation.c:97
void copy_qt_qt(float q[4], const float a[4])
Definition: math_rotation.c:52
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float normalize_v3(float r[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
char * BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict prefix) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:432
#define ELEM(...)
#define STREQ(a, b)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
@ ID_RECALC_SELECT
Definition: DNA_ID.h:638
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
@ MOTIONPATH_BAKE_HAS_PATHS
@ ROT_MODE_AXISANGLE
@ BONE_IK_NO_YDOF_TEMP
@ BONE_IK_NO_XDOF_TEMP
@ BONE_IK_NO_ZDOF_TEMP
@ PCHAN_HAS_IK
@ PCHAN_HAS_TARGET
@ POSE_AUTO_IK
@ POSE_MIRROR_EDIT
@ POSE_MIRROR_RELATIVE
eInsertKeyFlags
@ INSERTKEY_MATRIX
@ BONE_ROOTSEL
@ BONE_SELECTED
@ BONE_TRANSFORM
@ BONE_EDITMODE_LOCKED
@ BONE_TRANSFORM_MIRROR
@ BONE_NO_LOCAL_LOCATION
@ BONE_TRANSFORM_CHILD
@ BONE_TIPSEL
@ BONE_CONNECTED
@ BONE_HINGE
@ BONE_HINGE_CHILD_TRANSFORM
@ ARM_MIRROR_EDIT
@ ARM_RESTPOS
@ CONSTRAINT_OFF
@ CONSTRAINT_DISABLE
@ CONSTRAINT_IK_TEMP
@ CONSTRAINT_IK_POS
@ CONSTRAINT_IK_AUTO
@ CONSTRAINT_IK_STRETCH
@ CONSTRAINT_IK_TIP
@ CONSTRAINT_TYPE_KINEMATIC
@ OB_MODE_EDIT
@ OB_MODE_POSE
@ OB_LOCK_ROTZ
@ OB_LOCK_ROT
@ OB_LOCK_ROTX
@ OB_LOCK_ROTY
@ OB_LOCK_LOC
@ OB_LOCK_SCALE
@ OB_ARMATURE
#define CFRA
@ SCE_XFORM_AXIS_ALIGN
@ V3D_AROUND_ACTIVE
@ V3D_AROUND_CURSOR
@ V3D_AROUND_LOCAL_ORIGINS
ePosePathCalcRange
Definition: ED_armature.h:200
@ POSE_PATH_CALC_RANGE_CURRENT_FRAME
Definition: ED_armature.h:201
@ POSE_PATH_CALC_RANGE_CHANGED
Definition: ED_armature.h:202
#define EBONE_VISIBLE(arm, ebone)
Definition: ED_armature.h:56
#define ANIM_KS_LOC_ROT_SCALE_ID
#define IS_AUTOKEY_FLAG(scene, flag)
@ MODIFYKEY_MODE_INSERT
#define ANIM_KS_LOCATION_ID
#define ANIM_KS_SCALING_ID
#define IS_AUTOKEY_ON(scene)
#define ANIM_KS_ROTATION_ID
@ TFM_RESIZE
Definition: ED_transform.h:48
@ TFM_BONESIZE
Definition: ED_transform.h:59
@ TFM_ROTATION
Definition: ED_transform.h:47
@ TFM_BONE_ENVELOPE
Definition: ED_transform.h:60
@ TFM_BONE_ROLL
Definition: ED_transform.h:64
@ TFM_TRANSLATION
Definition: ED_transform.h:46
@ TFM_BONE_ENVELOPE_DIST
Definition: ED_transform.h:77
@ TFM_DUMMY
Definition: ED_transform.h:45
@ TFM_TRACKBALL
Definition: ED_transform.h:55
_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.
StructRNA RNA_PoseBone
#define C
Definition: RandGen.cpp:39
float ED_armature_ebone_roll_to_vector(const EditBone *bone, const float align_axis[3], const bool axis_only)
void ED_armature_edit_transform_mirror_update(Object *obedit)
void ED_armature_ebone_to_mat3(EditBone *ebone, float r_mat[3][3])
EditBone * ED_armature_ebone_get_mirrored(const ListBase *edbo, EditBone *ebo)
Scene scene
const Depsgraph * depsgraph
bool autokeyframe_cfra_can_key(const Scene *scene, ID *id)
Definition: keyframing.c:2779
eInsertKeyFlags ANIM_get_keyframing_flags(Scene *scene, const bool use_autokey_mode)
Definition: keyframing.c:92
int insert_keyframe(Main *bmain, ReportList *reports, ID *id, bAction *act, const char group[], const char rna_path[], int array_index, const AnimationEvalContext *anim_eval_context, eBezTriple_KeyframeType keytype, ListBase *nla_cache, eInsertKeyFlags flag)
Definition: keyframing.c:1413
int ANIM_apply_keyingset(bContext *C, ListBase *dsources, bAction *act, KeyingSet *ks, short mode, float cfra)
Definition: keyingsets.c:1028
KeyingSet * ANIM_scene_get_active_keyingset(const Scene *scene)
Definition: keyingsets.c:674
KeyingSet * ANIM_builtin_keyingset_get_named(KeyingSet *prevKS, const char name[])
Definition: keyingsets.c:550
void ANIM_relative_keyingset_add_source(ListBase *dsources, ID *id, StructRNA *srna, void *data)
Definition: keyingsets.c:898
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
size_t(* MEM_allocN_len)(const void *vmemh)
Definition: mallocn.c:40
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
static ulong * next
void ED_pose_recalculate_paths(bContext *C, Scene *scene, Object *ob, ePosePathCalcRange range)
Definition: pose_edit.c:203
bAction * action
struct EditBone * bone
float loc_mat[4][4]
Definition: BKE_armature.h:247
float rotscale_mat[4][4]
Definition: BKE_armature.h:246
float zwidth
char name[64]
float xwidth
float bone_mat[3][3]
float dist
struct Bone * next
ListBase childbase
float oldlength
Definition: BKE_armature.h:90
struct EditBone * next
Definition: BKE_armature.h:49
float tail[3]
Definition: BKE_armature.h:66
float roll
Definition: BKE_armature.h:62
struct Bone * bone
Definition: BKE_armature.h:113
float zwidth
Definition: BKE_armature.h:77
float length
Definition: BKE_armature.h:77
float xwidth
Definition: BKE_armature.h:77
float dist
Definition: BKE_armature.h:75
struct EditBone * parent
Definition: BKE_armature.h:55
float rad_tail
Definition: BKE_armature.h:78
float rad_head
Definition: BKE_armature.h:78
float head[3]
Definition: BKE_armature.h:65
Definition: DNA_ID.h:273
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
struct bPose * pose
float obmat[4][4]
struct AnimData * adt
void * data
struct bPoseChannel * pchan
struct PoseInitData_Mirror::@572 orig
struct ToolSettings * toolsettings
char transform_pivot_point
TransCustomData type
Definition: transform.h:428
TransCustomDataContainer custom
Definition: transform.h:501
struct Object * obedit
Definition: transform.h:461
TransData * data
Definition: transform.h:448
struct Object * poseobj
Definition: transform.h:473
float r_smtx[3][3]
float l_smtx[3][3]
float smtx[3][3]
short protectflag
struct bConstraint * con
float axismtx[3][3]
float mtx[3][3]
TransDataExtension * ext
float * val
struct Object * ob
ListBase curves
unsigned int layer
ListBase * edbo
struct bConstraint * next
ListBase constraints
struct Bone * bone
struct bPoseChannel * parent
float pose_head[3]
float pose_tail[3]
struct bPoseChannel * next
float constinv[4][4]
float pose_mat[4][4]
ListBase chanbase
short flag
bAnimVizSettings avs
@ CTX_AUTOCONFIRM
Definition: transform.h:92
@ T_AUTOIK
Definition: transform.h:122
@ TRANS_CANCEL
Definition: transform.h:193
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition: transform.h:813
void transform_autoik_update(TransInfo *t, short mode)
void animrecord_check_state(TransInfo *t, struct Object *ob)
void transform_around_single_fallback(TransInfo *t)
bool constraints_list_needinv(TransInfo *t, ListBase *list)
conversion and adaptation of different datablocks to a common struct.
static bool motionpath_need_update_pose(Scene *scene, Object *ob)
void special_aftertrans_update__pose(bContext *C, TransInfo *t)
void recalcData_pose(TransInfo *t)
static void restoreMirrorPoseBones(TransDataContainer *tc)
static void pose_mirror_info_init(PoseInitData_Mirror *pid, bPoseChannel *pchan, bPoseChannel *pchan_orig, bool is_mirror_relative)
int transform_convert_pose_transflags_update(Object *ob, const int mode, const short around, bool has_translate_rotate[2])
static void pose_mirror_info_restore(const PoseInitData_Mirror *pid)
static void pose_transform_mirror_update(TransInfo *t, TransDataContainer *tc, Object *ob)
struct BoneInitData BoneInitData
static void update_deg_with_temporary_ik(Main *bmain, Object *ob)
static bKinematicConstraint * has_targetless_ik(bPoseChannel *pchan)
static void bone_children_clear_transflag(int mode, short around, ListBase *lb)
static bConstraint * add_temporary_ik_constraint(bPoseChannel *pchan, bKinematicConstraint *targetless_con)
static short pose_grab_with_ik(Main *bmain, Object *ob)
static short pose_grab_with_ik_add(bPoseChannel *pchan)
void createTransPose(TransInfo *t)
static short apply_targetless_ik(Object *ob)
static void restoreBones(TransDataContainer *tc)
static void autokeyframe_pose(bContext *C, Scene *scene, Object *ob, int tmode, short targetless_ik)
void recalcData_edit_armature(TransInfo *t)
struct PoseInitData_Mirror PoseInitData_Mirror
static short pose_grab_with_ik_children(bPose *pose, Bone *bone)
void createTransArmatureVerts(TransInfo *t)
static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, TransData *td)
static void pose_grab_with_ik_clear(Main *bmain, Object *ob)
@ TD_PBONE_LOCAL_MTX_P
@ TD_PBONE_LOCAL_MTX_C
@ TD_SELECTED
@ TD_NO_LOC
@ TD_NOCENTER
void applyProject(TransInfo *t)