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