Blender  V2.59
ikplugin_api.c
Go to the documentation of this file.
00001 /*
00002  * $Id: ikplugin_api.c 35240 2011-02-27 20:24:49Z jesterking $
00003  * ***** BEGIN GPL LICENSE BLOCK *****
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020  * All rights reserved.
00021  *
00022  * The Original Code is: all of this file.
00023  *
00024  * Original author: Benoit Bolsee
00025  * Contributor(s): 
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00036 #include "BIK_api.h"
00037 #include "BLI_blenlib.h"
00038 #include "BLI_math.h"
00039 
00040 #include "BKE_armature.h"
00041 
00042 #include "DNA_object_types.h"
00043 #include "DNA_action_types.h"
00044 #include "DNA_scene_types.h"
00045 #include "DNA_constraint_types.h"
00046 #include "DNA_armature_types.h"
00047 
00048 #include "ikplugin_api.h"
00049 #include "iksolver_plugin.h"
00050 
00051 #ifdef WITH_IK_ITASC
00052 #include "itasc_plugin.h"
00053 #endif
00054 
00055 static IKPlugin ikplugin_tab[] = {
00056         /* Legacy IK solver */
00057         {
00058                 iksolver_initialize_tree,
00059                 iksolver_execute_tree,
00060                 NULL,
00061                 NULL,
00062                 NULL,
00063                 NULL,
00064                 NULL,
00065 #ifdef WITH_IK_ITASC
00066         },
00067         /* iTaSC IK solver */
00068         {
00069                 itasc_initialize_tree,
00070                 itasc_execute_tree,
00071                 itasc_release_tree,
00072                 itasc_clear_data,
00073                 itasc_clear_cache,
00074                 itasc_update_param,
00075                 itasc_test_constraint,
00076 #endif
00077         }
00078 };
00079 
00080 static IKPlugin *get_plugin(bPose *pose)
00081 {
00082         if (!pose || pose->iksolver < 0 || pose->iksolver >= (sizeof(ikplugin_tab) / sizeof(IKPlugin)))
00083                 return NULL;
00084 
00085         return &ikplugin_tab[pose->iksolver];
00086 }
00087 
00088 /*----------------------------------------*/
00089 /* Plugin API                                                     */
00090 
00091 void BIK_initialize_tree(Scene *scene, Object *ob, float ctime) 
00092 {
00093         IKPlugin *plugin = get_plugin(ob->pose);
00094 
00095         if (plugin && plugin->initialize_tree_func)
00096                 plugin->initialize_tree_func(scene, ob, ctime);
00097 }
00098 
00099 void BIK_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan, float ctime) 
00100 {
00101         IKPlugin *plugin = get_plugin(ob->pose);
00102 
00103         if (plugin && plugin->execute_tree_func)
00104                 plugin->execute_tree_func(scene, ob, pchan, ctime);
00105 }
00106 
00107 void BIK_release_tree(struct Scene *scene, Object *ob, float ctime) 
00108 {
00109         IKPlugin *plugin = get_plugin(ob->pose);
00110 
00111         if (plugin && plugin->release_tree_func)
00112                 plugin->release_tree_func(scene, ob, ctime);
00113 }
00114 
00115 void BIK_clear_data(struct bPose *pose)
00116 {
00117         IKPlugin *plugin = get_plugin(pose);
00118 
00119         if (plugin && plugin->remove_armature_func)
00120                 plugin->remove_armature_func(pose);
00121 }
00122 
00123 void BIK_clear_cache(struct bPose *pose)
00124 {
00125         IKPlugin *plugin = get_plugin(pose);
00126 
00127         if (plugin && plugin->clear_cache)
00128                 plugin->clear_cache(pose);
00129 }
00130 
00131 void BIK_update_param(struct bPose *pose)
00132 {
00133         IKPlugin *plugin = get_plugin(pose);
00134 
00135         if (plugin && plugin->update_param)
00136                 plugin->update_param(pose);
00137 }
00138 
00139 void BIK_test_constraint(struct Object *ob, struct bConstraint *cons)
00140 {
00141         IKPlugin *plugin = get_plugin(ob->pose);
00142 
00143         if (plugin && plugin->test_constraint)
00144                 plugin->test_constraint(ob, cons);
00145 }
00146