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