Blender V2.61 - r43446

ArmatureImporter.h

Go to the documentation of this file.
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  * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory.
00019  *
00020  * ***** END GPL LICENSE BLOCK *****
00021  */
00022 
00027 #ifndef __BC_ARMATUREIMPORTER_H__
00028 #define __BC_ARMATUREIMPORTER_H__
00029 
00030 #include "COLLADAFWNode.h"
00031 #include "COLLADAFWUniqueId.h"
00032 
00033 extern "C" {
00034 #include "BKE_context.h"
00035 
00036 #include "DNA_armature_types.h"
00037 #include "DNA_object_types.h"
00038 #include "DNA_scene_types.h"
00039 
00040 #include "ED_armature.h"
00041 }
00042 
00043 #include "AnimationImporter.h"
00044 #include "MeshImporter.h"
00045 #include "SkinInfo.h"
00046 #include "TransformReader.h"
00047 #include "ExtraTags.h"
00048 
00049 #include <map>
00050 #include <vector>
00051 
00052 #include "collada_internal.h"
00053 #include "collada_utils.h"
00054 
00055 class ArmatureImporter : private TransformReader
00056 {
00057 private:
00058     Scene *scene;
00059     UnitConverter *unit_converter;
00060 
00061     // std::map<int, JointData> joint_index_to_joint_info_map;
00062     // std::map<COLLADAFW::UniqueId, int> joint_id_to_joint_index_map;
00063 
00064     struct LeafBone {
00065         // COLLADAFW::Node *node;
00066         EditBone *bone;
00067         char name[32];
00068         float mat[4][4]; // bone matrix, derived from inv_bind_mat
00069     };
00070     std::vector<LeafBone> leaf_bones;
00071     // int bone_direction_row; // XXX not used
00072     float leaf_bone_length;
00073     int totbone;
00074     // XXX not used
00075     // float min_angle; // minimum angle between bone head-tail and a row of bone matrix
00076 
00077 #if 0
00078     struct ArmatureJoints {
00079         Object *ob_arm;
00080         std::vector<COLLADAFW::Node*> root_joints;
00081     };
00082     std::vector<ArmatureJoints> armature_joints;
00083 #endif
00084 
00085     Object *empty; // empty for leaf bones
00086 
00087     std::map<COLLADAFW::UniqueId, COLLADAFW::UniqueId> geom_uid_by_controller_uid;
00088     std::map<COLLADAFW::UniqueId, COLLADAFW::Node*> joint_by_uid; // contains all joints
00089     std::vector<COLLADAFW::Node*> root_joints;
00090     std::vector<COLLADAFW::Node*> finished_joints;
00091     std::map<COLLADAFW::UniqueId, Object*> joint_parent_map;
00092     std::map<COLLADAFW::UniqueId, Object*> unskinned_armature_map;
00093 
00094     MeshImporterBase *mesh_importer;
00095     AnimationImporterBase *anim_importer;
00096 
00097     // This is used to store data passed in write_controller_data.
00098     // Arrays from COLLADAFW::SkinControllerData lose ownership, so do this class members
00099     // so that arrays don't get freed until we free them explicitly.
00100 
00101     std::map<COLLADAFW::UniqueId, SkinInfo> skin_by_data_uid; // data UID = skin controller data UID
00102 #if 0
00103     JointData *get_joint_data(COLLADAFW::Node *node);
00104 #endif
00105 
00106     void create_bone(SkinInfo& skin, COLLADAFW::Node *node, EditBone *parent, int totchild,
00107                      float parent_mat[][4], bArmature *arm);
00108 
00109     void create_unskinned_bone(COLLADAFW::Node *node, EditBone *parent, int totchild,
00110                                float parent_mat[][4], Object * ob_arm);
00111 
00112     void add_leaf_bone(float mat[][4], EditBone *bone, COLLADAFW::Node * node);
00113 
00114     void fix_leaf_bones();
00115     
00116     void set_pose ( Object * ob_arm ,  COLLADAFW::Node * root_node , const char *parentname, float parent_mat[][4]);
00117 
00118 
00119 #if 0
00120     void set_leaf_bone_shapes(Object *ob_arm);
00121     void set_euler_rotmode();
00122 #endif
00123 
00124     Object *get_empty_for_leaves();
00125 
00126 #if 0
00127     Object *find_armature(COLLADAFW::Node *node);
00128 
00129     ArmatureJoints& get_armature_joints(Object *ob_arm);
00130 #endif
00131 
00132     void create_armature_bones(SkinInfo& skin);
00133     void create_armature_bones( );
00134 
00136     typedef std::map<std::string, ExtraTags*> TagsMap;
00137     TagsMap uid_tags_map;
00138 public:
00139 
00140     ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, AnimationImporterBase *anim, Scene *sce);
00141     ~ArmatureImporter();
00142 
00143     // root - if this joint is the top joint in hierarchy, if a joint
00144     // is a child of a node (not joint), root should be true since
00145     // this is where we build armature bones from
00146     void add_joint(COLLADAFW::Node *node, bool root, Object *parent, Scene *sce);
00147 
00148 #if 0
00149     void add_root_joint(COLLADAFW::Node *node);
00150 #endif
00151 
00152     // here we add bones to armatures, having armatures previously created in write_controller
00153     void make_armatures(bContext *C);
00154 
00155 #if 0
00156     // link with meshes, create vertex groups, assign weights
00157     void link_armature(Object *ob_arm, const COLLADAFW::UniqueId& geom_id, const COLLADAFW::UniqueId& controller_data_id);
00158 #endif
00159 
00160     bool write_skin_controller_data(const COLLADAFW::SkinControllerData* data);
00161 
00162     bool write_controller(const COLLADAFW::Controller* controller);
00163 
00164     COLLADAFW::UniqueId *get_geometry_uid(const COLLADAFW::UniqueId& controller_uid);
00165     
00166     Object *get_armature_for_joint(COLLADAFW::Node *node);
00167 
00168     void get_rna_path_for_joint(COLLADAFW::Node *node, char *joint_path, size_t count);
00169     
00170     // gives a world-space mat
00171     bool get_joint_bind_mat(float m[][4], COLLADAFW::Node *joint);
00172 
00173     void set_tags_map( TagsMap& tags_map);
00174     
00175 };
00176 
00177 #endif