Blender  V2.93
ikplugin_api.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 "BIK_api.h"
26 
27 #include "DNA_action_types.h"
28 #include "DNA_object_types.h"
29 #include "DNA_scene_types.h"
30 
31 #include "ikplugin_api.h"
32 
33 #ifdef WITH_IK_SOLVER
34 # include "iksolver_plugin.h"
35 #endif
36 
37 #ifdef WITH_IK_ITASC
38 # include "itasc_plugin.h"
39 #endif
40 
41 static IKPlugin ikplugin_tab[] = {
42 #ifdef WITH_IK_SOLVER
43  /* Legacy IK solver */
44  {
49  NULL,
50  NULL,
51  NULL,
52  },
53 #endif
54 
55 #ifdef WITH_IK_ITASC
56  /* iTaSC IK solver */
57  {
65  },
66 #endif
67 
68  {NULL}};
69 
70 static IKPlugin *get_plugin(bPose *pose)
71 {
72  if (!pose || pose->iksolver < 0 ||
73  pose->iksolver >= ((sizeof(ikplugin_tab) / sizeof(IKPlugin)) - 1)) {
74  return NULL;
75  }
76 
77  return &ikplugin_tab[pose->iksolver];
78 }
79 
80 /*----------------------------------------*/
81 /* Plugin API */
82 
83 void BIK_init_tree(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime)
84 {
85  IKPlugin *plugin = get_plugin(ob->pose);
86 
87  if (plugin && plugin->initialize_tree_func) {
88  plugin->initialize_tree_func(depsgraph, scene, ob, ctime);
89  }
90 }
91 
93  struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, bPoseChannel *pchan, float ctime)
94 {
95  IKPlugin *plugin = get_plugin(ob->pose);
96 
97  if (plugin && plugin->execute_tree_func) {
98  plugin->execute_tree_func(depsgraph, scene, ob, pchan, ctime);
99  }
100 }
101 
102 void BIK_release_tree(struct Scene *scene, Object *ob, float ctime)
103 {
104  IKPlugin *plugin = get_plugin(ob->pose);
105 
106  if (plugin && plugin->release_tree_func) {
107  plugin->release_tree_func(scene, ob, ctime);
108  }
109 }
110 
111 void BIK_clear_data(struct bPose *pose)
112 {
113  IKPlugin *plugin = get_plugin(pose);
114 
115  if (plugin && plugin->remove_armature_func) {
116  plugin->remove_armature_func(pose);
117  }
118 }
119 
120 void BIK_clear_cache(struct bPose *pose)
121 {
122  IKPlugin *plugin = get_plugin(pose);
123 
124  if (plugin && plugin->clear_cache) {
125  plugin->clear_cache(pose);
126  }
127 }
128 
129 void BIK_update_param(struct bPose *pose)
130 {
131  IKPlugin *plugin = get_plugin(pose);
132 
133  if (plugin && plugin->update_param) {
134  plugin->update_param(pose);
135  }
136 }
137 
138 void BIK_test_constraint(struct Object *ob, struct bConstraint *cons)
139 {
140  IKPlugin *plugin = get_plugin(ob->pose);
141 
142  if (plugin && plugin->test_constraint) {
143  plugin->test_constraint(ob, cons);
144  }
145 }
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
Object is a sort of wrapper for general info.
Scene scene
const Depsgraph * depsgraph
void BIK_clear_cache(struct bPose *pose)
Definition: ikplugin_api.c:120
void BIK_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, bPoseChannel *pchan, float ctime)
Definition: ikplugin_api.c:92
void BIK_test_constraint(struct Object *ob, struct bConstraint *cons)
Definition: ikplugin_api.c:138
void BIK_release_tree(struct Scene *scene, Object *ob, float ctime)
Definition: ikplugin_api.c:102
void BIK_init_tree(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime)
Definition: ikplugin_api.c:83
void BIK_update_param(struct bPose *pose)
Definition: ikplugin_api.c:129
static IKPlugin ikplugin_tab[]
Definition: ikplugin_api.c:41
void BIK_clear_data(struct bPose *pose)
Definition: ikplugin_api.c:111
static IKPlugin * get_plugin(bPose *pose)
Definition: ikplugin_api.c:70
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))
void iksolver_clear_data(bPose *pose)
void iksolver_release_tree(struct Scene *UNUSED(scene), struct Object *ob, float UNUSED(ctime))
void itasc_clear_cache(struct bPose *pose)
void itasc_clear_data(struct bPose *pose)
void itasc_update_param(struct bPose *pose)
void itasc_release_tree(struct Scene *scene, struct Object *ob, float ctime)
void itasc_initialize_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, float ctime)
void itasc_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime)
void itasc_test_constraint(struct Object *ob, struct bConstraint *cons)
void(* clear_cache)(struct bPose *pose)
Definition: ikplugin_api.h:48
void(* remove_armature_func)(struct bPose *pose)
Definition: ikplugin_api.h:47
void(* initialize_tree_func)(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime)
Definition: ikplugin_api.h:37
void(* release_tree_func)(struct Scene *scene, struct Object *ob, float ctime)
Definition: ikplugin_api.h:46
void(* update_param)(struct bPose *pose)
Definition: ikplugin_api.h:49
void(* execute_tree_func)(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime)
Definition: ikplugin_api.h:41
void(* test_constraint)(struct Object *ob, struct bConstraint *cons)
Definition: ikplugin_api.h:50
struct bPose * pose