Blender  V2.59
ArmatureExporter.h
Go to the documentation of this file.
00001 /*
00002  * $Id: ArmatureExporter.h 38079 2011-07-04 08:59:28Z 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, Jan Diederich, Tod Liverseed,
00021  *                 Nathan Letwory
00022  *
00023  * ***** END GPL LICENSE BLOCK *****
00024  */
00025 
00030 #ifndef __ARMATUREEXPORTER_H__
00031 #define __ARMATUREEXPORTER_H__
00032 
00033 #include <string>
00034 //#include <vector>
00035 
00036 #include "COLLADASWStreamWriter.h"
00037 #include "COLLADASWLibraryControllers.h"
00038 #include "COLLADASWInputList.h"
00039 #include "COLLADASWNode.h"
00040 
00041 #include "DNA_armature_types.h"
00042 #include "DNA_listBase.h"
00043 #include "DNA_mesh_types.h"
00044 #include "DNA_object_types.h"
00045 #include "DNA_scene_types.h"
00046 
00047 #include "TransformWriter.h"
00048 #include "InstanceWriter.h"
00049 
00050 // XXX exporter writes wrong data for shared armatures.  A separate
00051 // controller should be written for each armature-mesh binding how do
00052 // we make controller ids then?
00053 class ArmatureExporter: public COLLADASW::LibraryControllers, protected TransformWriter, protected InstanceWriter
00054 {
00055 private:
00056         Scene *scene;
00057 
00058 public:
00059         ArmatureExporter(COLLADASW::StreamWriter *sw);
00060 
00061         // write bone nodes
00062         void add_armature_bones(Object *ob_arm, Scene *sce);
00063 
00064         bool is_skinned_mesh(Object *ob);
00065 
00066         void add_instance_controller(Object *ob);
00067 
00068         void export_controllers(Scene *sce, bool export_selected);
00069 
00070         void operator()(Object *ob);
00071 
00072 private:
00073 
00074         UnitConverter converter;
00075 
00076 #if 0
00077         std::vector<Object*> written_armatures;
00078 
00079         bool already_written(Object *ob_arm);
00080 
00081         void wrote(Object *ob_arm);
00082 
00083         void find_objects_using_armature(Object *ob_arm, std::vector<Object *>& objects, Scene *sce);
00084 #endif
00085 
00086         Object *get_assigned_armature(Object *ob);
00087 
00088         std::string get_joint_sid(Bone *bone, Object *ob_arm);
00089 
00090         // parent_mat is armature-space
00091         void add_bone_node(Bone *bone, Object *ob_arm);
00092 
00093         void add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW::Node& node);
00094 
00095         std::string get_controller_id(Object *ob_arm, Object *ob);
00096 
00097         // ob should be of type OB_MESH
00098         // both args are required
00099         void export_controller(Object* ob, Object *ob_arm);
00100 
00101         void add_joints_element(ListBase *defbase,
00102                                                         const std::string& joints_source_id, const std::string& inv_bind_mat_source_id);
00103 
00104         void add_bind_shape_mat(Object *ob);
00105 
00106         std::string add_joints_source(Object *ob_arm, ListBase *defbase, const std::string& controller_id);
00107 
00108         std::string add_inv_bind_mats_source(Object *ob_arm, ListBase *defbase, const std::string& controller_id);
00109 
00110         Bone *get_bone_from_defgroup(Object *ob_arm, bDeformGroup* def);
00111 
00112         bool is_bone_defgroup(Object *ob_arm, bDeformGroup* def);
00113 
00114         std::string add_weights_source(Mesh *me, const std::string& controller_id);
00115 
00116         void add_vertex_weights_element(const std::string& weights_source_id, const std::string& joints_source_id, Mesh *me,
00117                                                                         Object *ob_arm, ListBase *defbase);
00118 };
00119 
00120 /*
00121 struct GeometryFunctor {
00122         // f should have
00123         // void operator()(Object* ob)
00124         template<class Functor>
00125         void forEachMeshObjectInScene(Scene *sce, Functor &f)
00126         {
00127                 
00128                 Base *base= (Base*) sce->base.first;
00129                 while(base) {
00130                         Object *ob = base->object;
00131                         
00132                         if (ob->type == OB_MESH && ob->data) {
00133                                 f(ob);
00134                         }
00135                         base= base->next;
00136                         
00137                 }
00138         }
00139 };*/
00140 
00141 #endif