Blender V2.61 - r43446

SkinInfo.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_SKININFO_H__
00028 #define __BC_SKININFO_H__
00029 
00030 #include <map>
00031 #include <vector>
00032 
00033 #include "COLLADAFWUniqueId.h"
00034 #include "COLLADAFWTypes.h"
00035 #include "COLLADAFWNode.h"
00036 #include "COLLADAFWSkinController.h"
00037 #include "COLLADAFWSkinControllerData.h"
00038 
00039 #include "DNA_object_types.h"
00040 #include "BKE_context.h"
00041 
00042 #include "TransformReader.h"
00043 #include "collada_internal.h"
00044 
00045 // This is used to store data passed in write_controller_data.
00046 // Arrays from COLLADAFW::SkinControllerData lose ownership, so do this class members
00047 // so that arrays don't get freed until we free them explicitly.
00048 class SkinInfo
00049 {
00050 private:
00051     // to build armature bones from inverse bind matrices
00052     struct JointData {
00053         float inv_bind_mat[4][4]; // joint inverse bind matrix
00054         COLLADAFW::UniqueId joint_uid; // joint node UID
00055         // Object *ob_arm;            // armature object
00056     };
00057 
00058     float bind_shape_matrix[4][4];
00059 
00060     // data from COLLADAFW::SkinControllerData, each array should be freed
00061     COLLADAFW::UIntValuesArray joints_per_vertex;
00062     COLLADAFW::UIntValuesArray weight_indices;
00063     COLLADAFW::IntValuesArray joint_indices;
00064     // COLLADAFW::FloatOrDoubleArray weights;
00065     std::vector<float> weights;
00066 
00067     std::vector<JointData> joint_data; // index to this vector is joint index
00068 
00069     UnitConverter *unit_converter;
00070 
00071     Object *ob_arm;
00072     COLLADAFW::UniqueId controller_uid;
00073     Object *parent;
00074 
00075 public:
00076 
00077     SkinInfo();
00078     SkinInfo(const SkinInfo& skin);
00079     SkinInfo(UnitConverter *conv);
00080 
00081     // nobody owns the data after this, so it should be freed manually with releaseMemory
00082     template <typename T>
00083     void transfer_array_data(T& src, T& dest);
00084 
00085     // when src is const we cannot src.yieldOwnerShip, this is used by copy constructor
00086     void transfer_int_array_data_const(const COLLADAFW::IntValuesArray& src, COLLADAFW::IntValuesArray& dest);
00087 
00088     void transfer_uint_array_data_const(const COLLADAFW::UIntValuesArray& src, COLLADAFW::UIntValuesArray& dest);
00089 
00090     void borrow_skin_controller_data(const COLLADAFW::SkinControllerData* skin);
00091         
00092     void free();
00093 
00094     // using inverse bind matrices to construct armature
00095     // it is safe to invert them to get the original matrices
00096     // because if they are inverse matrices, they can be inverted
00097     void add_joint(const COLLADABU::Math::Matrix4& matrix);
00098 
00099     void set_controller(const COLLADAFW::SkinController* co);
00100 
00101     // called from write_controller
00102     Object *create_armature(Scene *scene);
00103 
00104     Object* set_armature(Object *ob_arm);
00105 
00106     bool get_joint_inv_bind_matrix(float inv_bind_mat[][4], COLLADAFW::Node *node);
00107 
00108     Object *get_armature();
00109 
00110     const COLLADAFW::UniqueId& get_controller_uid();
00111 
00112     // check if this skin controller references a joint or any descendant of it
00113     // 
00114     // some nodes may not be referenced by SkinController,
00115     // in this case to determine if the node belongs to this armature,
00116     // we need to search down the tree
00117     bool uses_joint_or_descendant(COLLADAFW::Node *node);
00118 
00119     void link_armature(bContext *C, Object *ob, std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& joint_by_uid, TransformReader *tm);
00120 
00121     bPoseChannel *get_pose_channel_from_node(COLLADAFW::Node *node);
00122 
00123     void set_parent(Object *_parent);
00124 
00125     Object* get_parent();
00126 
00127     void find_root_joints(const std::vector<COLLADAFW::Node*> &root_joints,
00128                           std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& joint_by_uid,
00129                           std::vector<COLLADAFW::Node*>& result);
00130 
00131     bool find_node_in_tree(COLLADAFW::Node *node, COLLADAFW::Node *tree_root);
00132 
00133 };
00134 
00135 #endif