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