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