Blender  V2.93
iksolver_plugin.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  * Original author: Benoit Bolsee
19  */
20 
25 #include "MEM_guardedalloc.h"
26 
27 #include "BIK_api.h"
28 #include "BLI_blenlib.h"
29 #include "BLI_math.h"
30 #include "BLI_utildefines.h"
31 
32 #include "BKE_armature.h"
33 #include "BKE_constraint.h"
34 
35 #include "DNA_action_types.h"
36 #include "DNA_armature_types.h"
37 #include "DNA_constraint_types.h"
38 #include "DNA_object_types.h"
39 
40 #include "IK_solver.h"
41 #include "iksolver_plugin.h"
42 
43 #include <string.h> /* memcpy */
44 
45 #define USE_NONUNIFORM_SCALE
46 
47 /* ********************** THE IK SOLVER ******************* */
48 
49 /* allocates PoseTree, and links that to root bone/channel */
50 /* Note: detecting the IK chain is duplicate code...
51  * in drawarmature.c and in transform_conversions.c */
52 static void initialize_posetree(struct Object *UNUSED(ob), bPoseChannel *pchan_tip)
53 {
54  bPoseChannel *curchan, *pchan_root = NULL, *chanlist[256], **oldchan;
55  PoseTree *tree;
56  PoseTarget *target;
57  bConstraint *con;
59  int a, t, segcount = 0, size, newsize, *oldparent, parent;
60 
61  /* find IK constraint, and validate it */
62  for (con = pchan_tip->constraints.first; con; con = con->next) {
63  if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
64  data = (bKinematicConstraint *)con->data;
65  if (data->flag & CONSTRAINT_IK_AUTO) {
66  break;
67  }
68  if (data->tar == NULL) {
69  continue;
70  }
71  if (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0) {
72  continue;
73  }
74  if ((con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) == 0 && (con->enforce != 0.0f)) {
75  break;
76  }
77  }
78  }
79  if (con == NULL) {
80  return;
81  }
82 
83  /* exclude tip from chain? */
84  if (!(data->flag & CONSTRAINT_IK_TIP)) {
85  pchan_tip = pchan_tip->parent;
86  }
87 
88  /* Find the chain's root & count the segments needed */
89  for (curchan = pchan_tip; curchan; curchan = curchan->parent) {
90  pchan_root = curchan;
91 
92  curchan->flag |= POSE_CHAIN; /* don't forget to clear this */
93  chanlist[segcount] = curchan;
94  segcount++;
95 
96  if (segcount == data->rootbone || segcount > 255) {
97  break; /* 255 is weak */
98  }
99  }
100  if (!segcount) {
101  return;
102  }
103 
104  /* setup the chain data */
105 
106  /* we make tree-IK, unless all existing targets are in this chain */
107  for (tree = pchan_root->iktree.first; tree; tree = tree->next) {
108  for (target = tree->targets.first; target; target = target->next) {
109  curchan = tree->pchan[target->tip];
110  if (curchan->flag & POSE_CHAIN) {
111  curchan->flag &= ~POSE_CHAIN;
112  }
113  else {
114  break;
115  }
116  }
117  if (target) {
118  break;
119  }
120  }
121 
122  /* create a target */
123  target = MEM_callocN(sizeof(PoseTarget), "posetarget");
124  target->con = con;
125  pchan_tip->flag &= ~POSE_CHAIN;
126 
127  if (tree == NULL) {
128  /* make new tree */
129  tree = MEM_callocN(sizeof(PoseTree), "posetree");
130 
132 
133  tree->iterations = data->iterations;
134  tree->totchannel = segcount;
135  tree->stretch = (data->flag & CONSTRAINT_IK_STRETCH);
136 
137  tree->pchan = MEM_callocN(segcount * sizeof(void *), "ik tree pchan");
138  tree->parent = MEM_callocN(segcount * sizeof(int), "ik tree parent");
139  for (a = 0; a < segcount; a++) {
140  tree->pchan[a] = chanlist[segcount - a - 1];
141  tree->parent[a] = a - 1;
142  }
143  target->tip = segcount - 1;
144 
145  /* AND! link the tree to the root */
146  BLI_addtail(&pchan_root->iktree, tree);
147  }
148  else {
149  tree->iterations = MAX2(data->iterations, tree->iterations);
150  tree->stretch = tree->stretch && !(data->flag & CONSTRAINT_IK_STRETCH);
151 
152  /* skip common pose channels and add remaining*/
153  size = MIN2(segcount, tree->totchannel);
154  a = t = 0;
155  while (a < size && t < tree->totchannel) {
156  /* locate first matching channel */
157  for (; t < tree->totchannel && tree->pchan[t] != chanlist[segcount - a - 1]; t++) {
158  /* pass */
159  }
160  if (t >= tree->totchannel) {
161  break;
162  }
163  for (; a < size && t < tree->totchannel && tree->pchan[t] == chanlist[segcount - a - 1];
164  a++, t++) {
165  /* pass */
166  }
167  }
168 
169  segcount = segcount - a;
170  target->tip = tree->totchannel + segcount - 1;
171 
172  if (segcount > 0) {
173  for (parent = a - 1; parent < tree->totchannel; parent++) {
174  if (tree->pchan[parent] == chanlist[segcount - 1]->parent) {
175  break;
176  }
177  }
178 
179  /* shouldn't happen, but could with dependency cycles */
180  if (parent == tree->totchannel) {
181  parent = a - 1;
182  }
183 
184  /* resize array */
185  newsize = tree->totchannel + segcount;
186  oldchan = tree->pchan;
187  oldparent = tree->parent;
188 
189  tree->pchan = MEM_callocN(newsize * sizeof(void *), "ik tree pchan");
190  tree->parent = MEM_callocN(newsize * sizeof(int), "ik tree parent");
191  memcpy(tree->pchan, oldchan, sizeof(void *) * tree->totchannel);
192  memcpy(tree->parent, oldparent, sizeof(int) * tree->totchannel);
193  MEM_freeN(oldchan);
194  MEM_freeN(oldparent);
195 
196  /* add new pose channels at the end, in reverse order */
197  for (a = 0; a < segcount; a++) {
198  tree->pchan[tree->totchannel + a] = chanlist[segcount - a - 1];
199  tree->parent[tree->totchannel + a] = tree->totchannel + a - 1;
200  }
201  tree->parent[tree->totchannel] = parent;
202 
203  tree->totchannel = newsize;
204  }
205 
206  /* move tree to end of list, for correct evaluation order */
207  BLI_remlink(&pchan_root->iktree, tree);
208  BLI_addtail(&pchan_root->iktree, tree);
209  }
210 
211  /* add target to the tree */
212  BLI_addtail(&tree->targets, target);
213  /* mark root channel having an IK tree */
214  pchan_root->flag |= POSE_IKTREE;
215 }
216 
217 /* transform from bone(b) to bone(b+1), store in chan_mat */
218 static void make_dmats(bPoseChannel *pchan)
219 {
220  if (pchan->parent) {
221  float iR_parmat[4][4];
222  invert_m4_m4(iR_parmat, pchan->parent->pose_mat);
223  mul_m4_m4m4(pchan->chan_mat, iR_parmat, pchan->pose_mat); /* delta mat */
224  }
225  else {
226  copy_m4_m4(pchan->chan_mat, pchan->pose_mat);
227  }
228 }
229 
230 /* applies IK matrix to pchan, IK is done separated */
231 /* formula: pose_mat(b) = pose_mat(b-1) * diffmat(b-1, b) * ik_mat(b) */
232 /* to make this work, the diffmats have to be precalculated! Stored in chan_mat */
233 static void where_is_ik_bone(bPoseChannel *pchan,
234  float ik_mat[3][3]) /* nr = to detect if this is first bone */
235 {
236  float vec[3], ikmat[4][4];
237 
238  copy_m4_m3(ikmat, ik_mat);
239 
240  if (pchan->parent) {
241  mul_m4_m4m4(pchan->pose_mat, pchan->parent->pose_mat, pchan->chan_mat);
242  }
243  else {
244  copy_m4_m4(pchan->pose_mat, pchan->chan_mat);
245  }
246 
247 #ifdef USE_NONUNIFORM_SCALE
248  /* apply IK mat, but as if the bones have uniform scale since the IK solver
249  * is not aware of non-uniform scale */
250  float scale[3];
251  mat4_to_size(scale, pchan->pose_mat);
252  normalize_v3_length(pchan->pose_mat[0], scale[1]);
253  normalize_v3_length(pchan->pose_mat[2], scale[1]);
254 #endif
255 
256  mul_m4_m4m4(pchan->pose_mat, pchan->pose_mat, ikmat);
257 
258 #ifdef USE_NONUNIFORM_SCALE
259  float ik_scale[3];
260  mat3_to_size(ik_scale, ik_mat);
261  normalize_v3_length(pchan->pose_mat[0], scale[0] * ik_scale[0]);
262  normalize_v3_length(pchan->pose_mat[2], scale[2] * ik_scale[2]);
263 #endif
264 
265  /* calculate head */
266  copy_v3_v3(pchan->pose_head, pchan->pose_mat[3]);
267  /* calculate tail */
268  copy_v3_v3(vec, pchan->pose_mat[1]);
269  mul_v3_fl(vec, pchan->bone->length);
270  add_v3_v3v3(pchan->pose_tail, pchan->pose_head, vec);
271 
272  pchan->flag |= POSE_DONE;
273 }
274 
275 /* called from within the core BKE_pose_where_is loop, all animsystems and constraints
276  * were executed & assigned. Now as last we do an IK pass */
278  struct Scene *scene,
279  Object *ob,
280  PoseTree *tree)
281 {
282  float R_parmat[3][3], identity[3][3];
283  float iR_parmat[3][3];
284  float R_bonemat[3][3];
285  float goalrot[3][3], goalpos[3];
286  float rootmat[4][4], imat[4][4];
287  float goal[4][4], goalinv[4][4];
288  float irest_basis[3][3], full_basis[3][3];
289  float end_pose[4][4], world_pose[4][4];
290  float basis[3][3], rest_basis[3][3], start[3], *ikstretch = NULL;
291  float resultinf = 0.0f;
292  int a, flag, hasstretch = 0, resultblend = 0;
293  bPoseChannel *pchan;
294  IK_Segment *seg, *parent, **iktree, *iktarget;
295  IK_Solver *solver;
296  PoseTarget *target;
297  bKinematicConstraint *data, *poleangledata = NULL;
298  Bone *bone;
299 
300  if (tree->totchannel == 0) {
301  return;
302  }
303 
304  iktree = MEM_mallocN(sizeof(void *) * tree->totchannel, "ik tree");
305 
306  for (a = 0; a < tree->totchannel; a++) {
307  float length;
308  pchan = tree->pchan[a];
309  bone = pchan->bone;
310 
311  /* set DoF flag */
312  flag = 0;
313  if (!(pchan->ikflag & BONE_IK_NO_XDOF) && !(pchan->ikflag & BONE_IK_NO_XDOF_TEMP)) {
314  flag |= IK_XDOF;
315  }
316  if (!(pchan->ikflag & BONE_IK_NO_YDOF) && !(pchan->ikflag & BONE_IK_NO_YDOF_TEMP)) {
317  flag |= IK_YDOF;
318  }
319  if (!(pchan->ikflag & BONE_IK_NO_ZDOF) && !(pchan->ikflag & BONE_IK_NO_ZDOF_TEMP)) {
320  flag |= IK_ZDOF;
321  }
322 
323  if (tree->stretch && (pchan->ikstretch > 0.0f)) {
324  flag |= IK_TRANS_YDOF;
325  hasstretch = 1;
326  }
327 
328  seg = iktree[a] = IK_CreateSegment(flag);
329 
330  /* find parent */
331  if (a == 0) {
332  parent = NULL;
333  }
334  else {
335  parent = iktree[tree->parent[a]];
336  }
337 
338  IK_SetParent(seg, parent);
339 
340  /* get the matrix that transforms from prevbone into this bone */
341  copy_m3_m4(R_bonemat, pchan->pose_mat);
342 
343  /* gather transformations for this IK segment */
344 
345  if (pchan->parent) {
346  copy_m3_m4(R_parmat, pchan->parent->pose_mat);
347  }
348  else {
349  unit_m3(R_parmat);
350  }
351 
352  /* bone offset */
353  if (pchan->parent && (a > 0)) {
354  sub_v3_v3v3(start, pchan->pose_head, pchan->parent->pose_tail);
355  }
356  else {
357  /* only root bone (a = 0) has no parent */
358  start[0] = start[1] = start[2] = 0.0f;
359  }
360 
361  /* change length based on bone size */
362  length = bone->length * len_v3(R_bonemat[1]);
363 
364  /* basis must be pure rotation */
365  normalize_m3(R_bonemat);
366  normalize_m3(R_parmat);
367 
368  /* compute rest basis and its inverse */
369  copy_m3_m3(rest_basis, bone->bone_mat);
370  transpose_m3_m3(irest_basis, bone->bone_mat);
371 
372  /* compute basis with rest_basis removed */
373  invert_m3_m3(iR_parmat, R_parmat);
374  mul_m3_m3m3(full_basis, iR_parmat, R_bonemat);
375  mul_m3_m3m3(basis, irest_basis, full_basis);
376 
377  /* transform offset into local bone space */
378  mul_m3_v3(iR_parmat, start);
379 
380  IK_SetTransform(seg, start, rest_basis, basis, length);
381 
382  if (pchan->ikflag & BONE_IK_XLIMIT) {
383  IK_SetLimit(seg, IK_X, pchan->limitmin[0], pchan->limitmax[0]);
384  }
385  if (pchan->ikflag & BONE_IK_YLIMIT) {
386  IK_SetLimit(seg, IK_Y, pchan->limitmin[1], pchan->limitmax[1]);
387  }
388  if (pchan->ikflag & BONE_IK_ZLIMIT) {
389  IK_SetLimit(seg, IK_Z, pchan->limitmin[2], pchan->limitmax[2]);
390  }
391 
392  IK_SetStiffness(seg, IK_X, pchan->stiffness[0]);
393  IK_SetStiffness(seg, IK_Y, pchan->stiffness[1]);
394  IK_SetStiffness(seg, IK_Z, pchan->stiffness[2]);
395 
396  if (tree->stretch && (pchan->ikstretch > 0.0f)) {
397  const float ikstretch_sq = square_f(pchan->ikstretch);
398  /* this function does its own clamping */
399  IK_SetStiffness(seg, IK_TRANS_Y, 1.0f - ikstretch_sq);
401  }
402  }
403 
404  solver = IK_CreateSolver(iktree[0]);
405 
406  /* set solver goals */
407 
408  /* first set the goal inverse transform, assuming the root of tree was done ok! */
409  pchan = tree->pchan[0];
410  if (pchan->parent) {
411  /* transform goal by parent mat, so this rotation is not part of the
412  * segment's basis. otherwise rotation limits do not work on the
413  * local transform of the segment itself. */
414  copy_m4_m4(rootmat, pchan->parent->pose_mat);
415  /* However, we do not want to get (i.e. reverse) parent's scale,
416  * as it generates T31008 kind of nasty bugs. */
417  normalize_m4(rootmat);
418  }
419  else {
420  unit_m4(rootmat);
421  }
422  copy_v3_v3(rootmat[3], pchan->pose_head);
423 
424  mul_m4_m4m4(imat, ob->obmat, rootmat);
425  invert_m4_m4(goalinv, imat);
426 
427  for (target = tree->targets.first; target; target = target->next) {
428  float polepos[3];
429  int poleconstrain = 0;
430 
431  data = (bKinematicConstraint *)target->con->data;
432 
433  /* 1.0=ctime, we pass on object for auto-ik (owner-type here is object, even though
434  * strictly speaking, it is a posechannel)
435  */
437  depsgraph, scene, target->con, 0, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0);
438 
439  /* and set and transform goal */
440  mul_m4_m4m4(goal, goalinv, rootmat);
441 
442  copy_v3_v3(goalpos, goal[3]);
443  copy_m3_m4(goalrot, goal);
444  normalize_m3(goalrot);
445 
446  /* same for pole vector target */
447  if (data->poletar) {
449  depsgraph, scene, target->con, 1, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0);
450 
451  if (data->flag & CONSTRAINT_IK_SETANGLE) {
452  /* don't solve IK when we are setting the pole angle */
453  break;
454  }
455 
456  mul_m4_m4m4(goal, goalinv, rootmat);
457  copy_v3_v3(polepos, goal[3]);
458  poleconstrain = 1;
459 
460  /* for pole targets, we blend the result of the ik solver
461  * instead of the target position, otherwise we can't get
462  * a smooth transition */
463  resultblend = 1;
464  resultinf = target->con->enforce;
465 
466  if (data->flag & CONSTRAINT_IK_GETANGLE) {
467  poleangledata = data;
468  data->flag &= ~CONSTRAINT_IK_GETANGLE;
469  }
470  }
471 
472  /* do we need blending? */
473  if (!resultblend && target->con->enforce != 1.0f) {
474  float q1[4], q2[4], q[4];
475  float fac = target->con->enforce;
476  float mfac = 1.0f - fac;
477 
478  pchan = tree->pchan[target->tip];
479 
480  /* end effector in world space */
481  copy_m4_m4(end_pose, pchan->pose_mat);
482  copy_v3_v3(end_pose[3], pchan->pose_tail);
483  mul_m4_series(world_pose, goalinv, ob->obmat, end_pose);
484 
485  /* blend position */
486  goalpos[0] = fac * goalpos[0] + mfac * world_pose[3][0];
487  goalpos[1] = fac * goalpos[1] + mfac * world_pose[3][1];
488  goalpos[2] = fac * goalpos[2] + mfac * world_pose[3][2];
489 
490  /* blend rotation */
491  mat3_to_quat(q1, goalrot);
492  mat4_to_quat(q2, world_pose);
493  interp_qt_qtqt(q, q1, q2, mfac);
494  quat_to_mat3(goalrot, q);
495  }
496 
497  iktarget = iktree[target->tip];
498 
499  if ((data->flag & CONSTRAINT_IK_POS) && data->weight != 0.0f) {
500  if (poleconstrain) {
502  solver, iktarget, goalpos, polepos, data->poleangle, (poleangledata == data));
503  }
504  IK_SolverAddGoal(solver, iktarget, goalpos, data->weight);
505  }
506  if ((data->flag & CONSTRAINT_IK_ROT) && (data->orientweight != 0.0f)) {
507  if ((data->flag & CONSTRAINT_IK_AUTO) == 0) {
508  IK_SolverAddGoalOrientation(solver, iktarget, goalrot, data->orientweight);
509  }
510  }
511  }
512 
513  /* solve */
514  IK_Solve(solver, 0.0f, tree->iterations);
515 
516  if (poleangledata) {
517  poleangledata->poleangle = IK_SolverGetPoleAngle(solver);
518  }
519 
520  IK_FreeSolver(solver);
521 
522  /* gather basis changes */
523  tree->basis_change = MEM_mallocN(sizeof(float[3][3]) * tree->totchannel, "ik basis change");
524  if (hasstretch) {
525  ikstretch = MEM_mallocN(sizeof(float) * tree->totchannel, "ik stretch");
526  }
527 
528  for (a = 0; a < tree->totchannel; a++) {
529  IK_GetBasisChange(iktree[a], tree->basis_change[a]);
530 
531  if (hasstretch) {
532  /* have to compensate for scaling received from parent */
533  float parentstretch, stretch;
534 
535  pchan = tree->pchan[a];
536  parentstretch = (tree->parent[a] >= 0) ? ikstretch[tree->parent[a]] : 1.0f;
537 
538  if (tree->stretch && (pchan->ikstretch > 0.0f)) {
539  float trans[3], length;
540 
541  IK_GetTranslationChange(iktree[a], trans);
542  length = pchan->bone->length * len_v3(pchan->pose_mat[1]);
543 
544  ikstretch[a] = (length == 0.0f) ? 1.0f : (trans[1] + length) / length;
545  }
546  else {
547  ikstretch[a] = 1.0;
548  }
549 
550  stretch = (parentstretch == 0.0f) ? 1.0f : ikstretch[a] / parentstretch;
551 
552  mul_v3_fl(tree->basis_change[a][0], stretch);
553  mul_v3_fl(tree->basis_change[a][1], stretch);
554  mul_v3_fl(tree->basis_change[a][2], stretch);
555  }
556 
557  if (resultblend && resultinf != 1.0f) {
558  unit_m3(identity);
559  blend_m3_m3m3(tree->basis_change[a], identity, tree->basis_change[a], resultinf);
560  }
561 
562  IK_FreeSegment(iktree[a]);
563  }
564 
565  MEM_freeN(iktree);
566  if (ikstretch) {
567  MEM_freeN(ikstretch);
568  }
569 }
570 
572 {
573  BLI_freelistN(&tree->targets);
574  if (tree->pchan) {
575  MEM_freeN(tree->pchan);
576  }
577  if (tree->parent) {
578  MEM_freeN(tree->parent);
579  }
580  if (tree->basis_change) {
581  MEM_freeN(tree->basis_change);
582  }
583  MEM_freeN(tree);
584 }
585 
586 /* ------------------------------
587  * Plugin API for legacy iksolver */
588 
590  struct Scene *UNUSED(scene),
591  struct Object *ob,
592  float UNUSED(ctime))
593 {
594  bPoseChannel *pchan;
595 
596  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
597  if (pchan->constflag & PCHAN_HAS_IK) { /* flag is set on editing constraints */
598  initialize_posetree(ob, pchan); /* will attach it to root! */
599  }
600  }
601  ob->pose->flag &= ~POSE_WAS_REBUILT;
602 }
603 
605  struct Scene *scene,
606  Object *ob,
607  bPoseChannel *pchan_root,
608  float ctime)
609 {
610  while (pchan_root->iktree.first) {
611  PoseTree *tree = pchan_root->iktree.first;
612  int a;
613 
614  /* stop on the first tree that isn't a standard IK chain */
615  if (tree->type != CONSTRAINT_TYPE_KINEMATIC) {
616  return;
617  }
618 
619  /* 4. walk over the tree for regular solving */
620  for (a = 0; a < tree->totchannel; a++) {
621  if (!(tree->pchan[a]->flag & POSE_DONE)) { /* successive trees can set the flag */
622  BKE_pose_where_is_bone(depsgraph, scene, ob, tree->pchan[a], ctime, 1);
623  }
624  /* Tell blender that this channel was controlled by IK,
625  * it's cleared on each BKE_pose_where_is(). */
626  tree->pchan[a]->flag |= POSE_CHAIN;
627  }
628 
629  /* 5. execute the IK solver */
631 
632  /* 6. apply the differences to the channels,
633  * we need to calculate the original differences first */
634  for (a = 0; a < tree->totchannel; a++) {
635  make_dmats(tree->pchan[a]);
636  }
637 
638  for (a = 0; a < tree->totchannel; a++) {
639  /* sets POSE_DONE */
640  where_is_ik_bone(tree->pchan[a], tree->basis_change[a]);
641  }
642 
643  /* 7. and free */
644  BLI_remlink(&pchan_root->iktree, tree);
646  }
647 }
648 
649 void iksolver_release_tree(struct Scene *UNUSED(scene), struct Object *ob, float UNUSED(ctime))
650 {
652 }
653 
655 {
656  LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) {
657  if ((pchan->flag & POSE_IKTREE) == 0) {
658  continue;
659  }
660 
661  while (pchan->iktree.first) {
662  PoseTree *tree = pchan->iktree.first;
663 
664  /* stop on the first tree that isn't a standard IK chain */
665  if (tree->type != CONSTRAINT_TYPE_KINEMATIC) {
666  break;
667  }
668 
669  BLI_remlink(&pchan->iktree, tree);
671  }
672  }
673 }
void BKE_pose_where_is_bone(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime, bool do_extra)
Definition: armature.c:2673
void BKE_constraint_target_matrix_get(struct Depsgraph *depsgraph, struct Scene *scene, struct bConstraint *con, int index, short ownertype, void *ownerdata, float mat[4][4], float ctime)
Definition: constraint.c:6025
#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_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:133
MINLINE float square_f(float a)
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:930
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:262
void copy_m3_m3(float m1[3][3], const float m2[3][3])
Definition: math_matrix.c:89
void unit_m3(float m[3][3])
Definition: math_matrix.c:58
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:105
void unit_m4(float m[4][4])
Definition: rct.c:1140
void copy_m4_m3(float m1[4][4], const float m2[3][3])
Definition: math_matrix.c:120
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1278
void normalize_m3(float R[3][3]) ATTR_NONNULL()
Definition: math_matrix.c:1919
#define mul_m4_series(...)
bool invert_m3_m3(float R[3][3], const float A[3][3])
Definition: math_matrix.c:1161
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:95
void blend_m3_m3m3(float out[3][3], const float dst[3][3], const float src[3][3], const float srcweight)
Definition: math_matrix.c:2439
void mat4_to_size(float size[3], const float M[4][4])
Definition: math_matrix.c:2145
void transpose_m3_m3(float R[3][3], const float M[3][3])
Definition: math_matrix.c:1327
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 normalize_m4(float R[4][4]) ATTR_NONNULL()
Definition: math_matrix.c:1952
void mat3_to_quat(float q[4], const float mat[3][3])
void mat4_to_quat(float q[4], const float mat[4][4])
void interp_qt_qtqt(float q[4], const float a[4], const float b[4], const float t)
void quat_to_mat3(float mat[3][3], const float q[4])
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 add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE float normalize_v3_length(float r[3], const float unit_scale)
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
#define UNUSED(x)
#define MAX2(a, b)
#define MIN2(a, b)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
@ BONE_IK_ZLIMIT
@ BONE_IK_NO_YDOF_TEMP
@ BONE_IK_XLIMIT
@ BONE_IK_NO_XDOF_TEMP
@ BONE_IK_NO_ZDOF
@ BONE_IK_NO_ZDOF_TEMP
@ BONE_IK_YLIMIT
@ BONE_IK_NO_YDOF
@ BONE_IK_NO_XDOF
@ PCHAN_HAS_IK
@ POSE_DONE
@ POSE_IKTREE
@ POSE_CHAIN
@ POSE_WAS_REBUILT
@ CONSTRAINT_OFF
@ CONSTRAINT_DISABLE
@ CONSTRAINT_IK_ROT
@ CONSTRAINT_IK_GETANGLE
@ CONSTRAINT_IK_SETANGLE
@ CONSTRAINT_IK_POS
@ CONSTRAINT_IK_AUTO
@ CONSTRAINT_IK_STRETCH
@ CONSTRAINT_IK_TIP
@ CONSTRAINT_TYPE_KINEMATIC
@ CONSTRAINT_OBTYPE_OBJECT
Object is a sort of wrapper for general info.
@ OB_ARMATURE
_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
IK_Solver * IK_CreateSolver(IK_Segment *root)
Definition: IK_Solver.cpp:275
float IK_SolverGetPoleAngle(IK_Solver *solver)
Definition: IK_Solver.cpp:371
#define IK_STRETCH_STIFF_MAX
Definition: IK_solver.h:163
IK_Segment * IK_CreateSegment(int flag)
Definition: IK_Solver.cpp:103
void IK_SolverSetPoleVectorConstraint(IK_Solver *solver, IK_Segment *tip, float goal[3], float polegoal[3], float poleangle, int getangle)
Definition: IK_Solver.cpp:348
void IK_Segment
Definition: IK_solver.h:96
void IK_SetParent(IK_Segment *seg, IK_Segment *parent)
Definition: IK_Solver.cpp:137
void IK_FreeSolver(IK_Solver *solver)
Definition: IK_Solver.cpp:286
#define IK_STRETCH_STIFF_MIN
Definition: IK_solver.h:162
void IK_FreeSegment(IK_Segment *seg)
Definition: IK_Solver.cpp:128
@ IK_TRANS_YDOF
Definition: IK_solver.h:103
void IK_SolverAddGoalOrientation(IK_Solver *solver, IK_Segment *tip, float goal[][3], float weight)
Definition: IK_Solver.cpp:320
void IK_SetLimit(IK_Segment *seg, IK_SegmentAxis axis, float lmin, float lmax)
Definition: IK_Solver.cpp:187
void IK_SolverAddGoal(IK_Solver *solver, IK_Segment *tip, float goal[3], float weight)
Definition: IK_Solver.cpp:301
int IK_Solve(IK_Solver *solver, float tolerance, int max_iterations)
Definition: IK_Solver.cpp:402
void IK_SetTransform(IK_Segment *seg, float start[3], float rest_basis[][3], float basis[][3], float length)
Definition: IK_Solver.cpp:148
void IK_GetBasisChange(IK_Segment *seg, float basis_change[][3])
Definition: IK_Solver.cpp:240
void IK_SetStiffness(IK_Segment *seg, IK_SegmentAxis axis, float stiffness)
Definition: IK_Solver.cpp:210
void IK_GetTranslationChange(IK_Segment *seg, float *translation_change)
Definition: IK_Solver.cpp:261
void IK_Solver
Definition: IK_solver.h:141
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
Definition: btQuaternion.h:895
Scene scene
const Depsgraph * depsgraph
void * tree
void iksolver_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime)
void iksolver_initialize_tree(struct Depsgraph *UNUSED(depsgraph), struct Scene *UNUSED(scene), struct Object *ob, float UNUSED(ctime))
static void free_posetree(PoseTree *tree)
static void where_is_ik_bone(bPoseChannel *pchan, float ik_mat[3][3])
void iksolver_clear_data(bPose *pose)
static void make_dmats(bPoseChannel *pchan)
static void initialize_posetree(struct Object *UNUSED(ob), bPoseChannel *pchan_tip)
static void execute_posetree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, PoseTree *tree)
void iksolver_release_tree(struct Scene *UNUSED(scene), struct Object *ob, float UNUSED(ctime))
@ IK_ZDOF
@ IK_XDOF
@ IK_YDOF
@ IK_X
@ IK_Y
@ IK_TRANS_Y
@ IK_Z
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
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 unsigned a[3]
Definition: RandGen.cpp:92
float length
float bone_mat[3][3]
void * first
Definition: DNA_listBase.h:47
struct bPose * pose
float obmat[4][4]
struct PoseTarget * next
Definition: BKE_armature.h:120
struct bConstraint * con
Definition: BKE_armature.h:122
struct bConstraint * next
ListBase constraints
struct Bone * bone
struct bPoseChannel * parent
float stiffness[3]
struct ListBase iktree
float pose_head[3]
float chan_mat[4][4]
float pose_tail[3]
struct bPoseChannel * next
float pose_mat[4][4]
ListBase chanbase
short flag