147c2b50e3158de047b422e3f99466ada1cd92c2
[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 #include "iksolver_plugin.h"
49
50 #ifdef WITH_IK_ITASC
51 #include "itasc_plugin.h"
52 #endif
53
54 static IKPlugin ikplugin_tab[] = {
55         /* Legacy IK solver */
56         {
57                 iksolver_initialize_tree,
58                 iksolver_execute_tree,
59                 NULL,
60                 NULL,
61                 NULL,
62                 NULL,
63                 NULL,
64 #ifdef WITH_IK_ITASC
65         },
66         /* iTaSC IK solver */
67         {
68                 itasc_initialize_tree,
69                 itasc_execute_tree,
70                 itasc_release_tree,
71                 itasc_clear_data,
72                 itasc_clear_cache,
73                 itasc_update_param,
74                 itasc_test_constraint,
75 #endif
76         }
77 };
78
79 static IKPlugin *get_plugin(bPose *pose)
80 {
81         if (!pose || pose->iksolver < 0 || pose->iksolver >= (sizeof(ikplugin_tab) / sizeof(IKPlugin)))
82                 return NULL;
83
84         return &ikplugin_tab[pose->iksolver];
85 }
86
87 /*----------------------------------------*/
88 /* Plugin API                                                     */
89
90 void BIK_initialize_tree(Scene *scene, Object *ob, float ctime) 
91 {
92         IKPlugin *plugin = get_plugin(ob->pose);
93
94         if (plugin && plugin->initialize_tree_func)
95                 plugin->initialize_tree_func(scene, ob, ctime);
96 }
97
98 void BIK_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan, float ctime) 
99 {
100         IKPlugin *plugin = get_plugin(ob->pose);
101
102         if (plugin && plugin->execute_tree_func)
103                 plugin->execute_tree_func(scene, ob, pchan, ctime);
104 }
105
106 void BIK_release_tree(struct Scene *scene, Object *ob, float ctime) 
107 {
108         IKPlugin *plugin = get_plugin(ob->pose);
109
110         if (plugin && plugin->release_tree_func)
111                 plugin->release_tree_func(scene, ob, ctime);
112 }
113
114 void BIK_clear_data(struct bPose *pose)
115 {
116         IKPlugin *plugin = get_plugin(pose);
117
118         if (plugin && plugin->remove_armature_func)
119                 plugin->remove_armature_func(pose);
120 }
121
122 void BIK_clear_cache(struct bPose *pose)
123 {
124         IKPlugin *plugin = get_plugin(pose);
125
126         if (plugin && plugin->clear_cache)
127                 plugin->clear_cache(pose);
128 }
129
130 void BIK_update_param(struct bPose *pose)
131 {
132         IKPlugin *plugin = get_plugin(pose);
133
134         if (plugin && plugin->update_param)
135                 plugin->update_param(pose);
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