cmake option to build without iksolver
[blender.git] / source / blender / ikplugin / intern / ikplugin_api.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Original author: Benoit Bolsee
24  * Contributor(s): 
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file blender/ikplugin/intern/ikplugin_api.c
30  *  \ingroup ikplugin
31  */
32
33
34
35 #include "BIK_api.h"
36 #include "BLI_blenlib.h"
37 #include "BLI_math.h"
38
39 #include "BKE_armature.h"
40
41 #include "DNA_object_types.h"
42 #include "DNA_action_types.h"
43 #include "DNA_scene_types.h"
44 #include "DNA_constraint_types.h"
45 #include "DNA_armature_types.h"
46
47 #include "ikplugin_api.h"
48
49 #ifdef WITH_IK_SOLVER
50 #  include "iksolver_plugin.h"
51 #endif
52
53 #ifdef WITH_IK_ITASC
54 #  include "itasc_plugin.h"
55 #endif
56
57 static IKPlugin ikplugin_tab[] = {
58 #ifdef WITH_IK_SOLVER
59         /* Legacy IK solver */
60         {
61                 iksolver_initialize_tree,
62                 iksolver_execute_tree,
63                 NULL,
64                 NULL,
65                 NULL,
66                 NULL,
67                 NULL,
68         },
69 #endif
70
71 #ifdef WITH_IK_ITASC
72         /* iTaSC IK solver */
73         {
74                 itasc_initialize_tree,
75                 itasc_execute_tree,
76                 itasc_release_tree,
77                 itasc_clear_data,
78                 itasc_clear_cache,
79                 itasc_update_param,
80                 itasc_test_constraint,
81         },
82         #endif
83 };
84
85 static IKPlugin *get_plugin(bPose *pose)
86 {
87         if (!pose || pose->iksolver < 0 || pose->iksolver >= (sizeof(ikplugin_tab) / sizeof(IKPlugin)))
88                 return NULL;
89
90         return &ikplugin_tab[pose->iksolver];
91 }
92
93 /*----------------------------------------*/
94 /* Plugin API                                                     */
95
96 void BIK_initialize_tree(Scene *scene, Object *ob, float ctime) 
97 {
98         IKPlugin *plugin = get_plugin(ob->pose);
99
100         if (plugin && plugin->initialize_tree_func)
101                 plugin->initialize_tree_func(scene, ob, ctime);
102 }
103
104 void BIK_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan, float ctime) 
105 {
106         IKPlugin *plugin = get_plugin(ob->pose);
107
108         if (plugin && plugin->execute_tree_func)
109                 plugin->execute_tree_func(scene, ob, pchan, ctime);
110 }
111
112 void BIK_release_tree(struct Scene *scene, Object *ob, float ctime) 
113 {
114         IKPlugin *plugin = get_plugin(ob->pose);
115
116         if (plugin && plugin->release_tree_func)
117                 plugin->release_tree_func(scene, ob, ctime);
118 }
119
120 void BIK_clear_data(struct bPose *pose)
121 {
122         IKPlugin *plugin = get_plugin(pose);
123
124         if (plugin && plugin->remove_armature_func)
125                 plugin->remove_armature_func(pose);
126 }
127
128 void BIK_clear_cache(struct bPose *pose)
129 {
130         IKPlugin *plugin = get_plugin(pose);
131
132         if (plugin && plugin->clear_cache)
133                 plugin->clear_cache(pose);
134 }
135
136 void BIK_update_param(struct bPose *pose)
137 {
138         IKPlugin *plugin = get_plugin(pose);
139
140         if (plugin && plugin->update_param)
141                 plugin->update_param(pose);
142 }
143
144 void BIK_test_constraint(struct Object *ob, struct bConstraint *cons)
145 {
146         IKPlugin *plugin = get_plugin(ob->pose);
147
148         if (plugin && plugin->test_constraint)
149                 plugin->test_constraint(ob, cons);
150 }
151