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