|
Blender
V2.59
|
00001 /* 00002 * $Id: ArmatureImporter.h 35020 2011-02-21 08:38:53Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory. 00021 * 00022 * ***** END GPL LICENSE BLOCK ***** 00023 */ 00024 00029 #ifndef __BC_ARMATUREIMPORTER_H__ 00030 #define __BC_ARMATUREIMPORTER_H__ 00031 00032 #include "COLLADAFWNode.h" 00033 #include "COLLADAFWUniqueId.h" 00034 00035 extern "C" { 00036 #include "BKE_context.h" 00037 00038 #include "DNA_armature_types.h" 00039 #include "DNA_object_types.h" 00040 #include "DNA_scene_types.h" 00041 00042 #include "ED_armature.h" 00043 } 00044 00045 #include "AnimationImporter.h" 00046 #include "MeshImporter.h" 00047 #include "SkinInfo.h" 00048 #include "TransformReader.h" 00049 00050 #include <map> 00051 #include <vector> 00052 00053 #include "collada_internal.h" 00054 #include "collada_utils.h" 00055 00056 class ArmatureImporter : private TransformReader 00057 { 00058 private: 00059 Scene *scene; 00060 UnitConverter *unit_converter; 00061 00062 // std::map<int, JointData> joint_index_to_joint_info_map; 00063 // std::map<COLLADAFW::UniqueId, int> joint_id_to_joint_index_map; 00064 00065 struct LeafBone { 00066 // COLLADAFW::Node *node; 00067 EditBone *bone; 00068 char name[32]; 00069 float mat[4][4]; // bone matrix, derived from inv_bind_mat 00070 }; 00071 std::vector<LeafBone> leaf_bones; 00072 // int bone_direction_row; // XXX not used 00073 float leaf_bone_length; 00074 int totbone; 00075 // XXX not used 00076 // float min_angle; // minimum angle between bone head-tail and a row of bone matrix 00077 00078 #if 0 00079 struct ArmatureJoints { 00080 Object *ob_arm; 00081 std::vector<COLLADAFW::Node*> root_joints; 00082 }; 00083 std::vector<ArmatureJoints> armature_joints; 00084 #endif 00085 00086 Object *empty; // empty for leaf bones 00087 00088 std::map<COLLADAFW::UniqueId, COLLADAFW::UniqueId> geom_uid_by_controller_uid; 00089 std::map<COLLADAFW::UniqueId, COLLADAFW::Node*> joint_by_uid; // contains all joints 00090 std::vector<COLLADAFW::Node*> root_joints; 00091 std::map<COLLADAFW::UniqueId, Object*> joint_parent_map; 00092 00093 MeshImporterBase *mesh_importer; 00094 AnimationImporterBase *anim_importer; 00095 00096 // This is used to store data passed in write_controller_data. 00097 // Arrays from COLLADAFW::SkinControllerData lose ownership, so do this class members 00098 // so that arrays don't get freed until we free them explicitly. 00099 00100 std::map<COLLADAFW::UniqueId, SkinInfo> skin_by_data_uid; // data UID = skin controller data UID 00101 #if 0 00102 JointData *get_joint_data(COLLADAFW::Node *node); 00103 #endif 00104 00105 void create_bone(SkinInfo& skin, COLLADAFW::Node *node, EditBone *parent, int totchild, 00106 float parent_mat[][4], bArmature *arm); 00107 00108 void add_leaf_bone(float mat[][4], EditBone *bone); 00109 00110 void fix_leaf_bones(); 00111 00112 #if 0 00113 void set_leaf_bone_shapes(Object *ob_arm); 00114 void set_euler_rotmode(); 00115 #endif 00116 00117 Object *get_empty_for_leaves(); 00118 00119 #if 0 00120 Object *find_armature(COLLADAFW::Node *node); 00121 00122 ArmatureJoints& get_armature_joints(Object *ob_arm); 00123 #endif 00124 00125 void create_armature_bones(SkinInfo& skin); 00126 00127 public: 00128 00129 ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, AnimationImporterBase *anim, Scene *sce); 00130 ~ArmatureImporter(); 00131 00132 // root - if this joint is the top joint in hierarchy, if a joint 00133 // is a child of a node (not joint), root should be true since 00134 // this is where we build armature bones from 00135 void add_joint(COLLADAFW::Node *node, bool root, Object *parent); 00136 00137 #if 0 00138 void add_root_joint(COLLADAFW::Node *node); 00139 #endif 00140 00141 // here we add bones to armatures, having armatures previously created in write_controller 00142 void make_armatures(bContext *C); 00143 00144 #if 0 00145 // link with meshes, create vertex groups, assign weights 00146 void link_armature(Object *ob_arm, const COLLADAFW::UniqueId& geom_id, const COLLADAFW::UniqueId& controller_data_id); 00147 #endif 00148 00149 bool write_skin_controller_data(const COLLADAFW::SkinControllerData* data); 00150 00151 bool write_controller(const COLLADAFW::Controller* controller); 00152 00153 COLLADAFW::UniqueId *get_geometry_uid(const COLLADAFW::UniqueId& controller_uid); 00154 00155 Object *get_armature_for_joint(COLLADAFW::Node *node); 00156 00157 void get_rna_path_for_joint(COLLADAFW::Node *node, char *joint_path, size_t count); 00158 00159 // gives a world-space mat 00160 bool get_joint_bind_mat(float m[][4], COLLADAFW::Node *joint); 00161 }; 00162 00163 #endif