Blender  V2.93
ControllerExporter.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #pragma once
22 
23 #include <list>
24 #include <string>
25 //#include <vector>
26 
27 #include "COLLADASWExtraTechnique.h"
28 #include "COLLADASWInputList.h"
29 #include "COLLADASWInstanceController.h"
30 #include "COLLADASWLibraryControllers.h"
31 #include "COLLADASWNode.h"
32 #include "COLLADASWStreamWriter.h"
33 
34 #include "DNA_armature_types.h"
35 #include "DNA_constraint_types.h"
36 #include "DNA_key_types.h"
37 #include "DNA_listBase.h"
38 #include "DNA_mesh_types.h"
39 #include "DNA_object_types.h"
40 #include "DNA_scene_types.h"
41 
42 #include "InstanceWriter.h"
43 #include "TransformWriter.h"
44 
45 #include "ExportSettings.h"
46 
47 #include "BKE_key.h"
48 
49 class SceneExporter;
50 
51 class ControllerExporter : public COLLADASW::LibraryControllers,
52  protected TransformWriter,
53  protected InstanceWriter {
54  private:
55  BlenderContext &blender_context;
56  BCExportSettings export_settings;
57 
58  public:
59  /* XXX exporter writes wrong data for shared armatures. A separate
60  * controller should be written for each armature-mesh binding how do
61  * we make controller ids then? */
62  ControllerExporter(BlenderContext &blender_context,
63  COLLADASW::StreamWriter *sw,
64  BCExportSettings &export_settings)
65  : COLLADASW::LibraryControllers(sw),
66  blender_context(blender_context),
67  export_settings(export_settings)
68  {
69  }
70 
71  bool is_skinned_mesh(Object *ob);
72 
74 
75  void export_controllers();
76 
77  void operator()(Object *ob);
78 
79  private:
80 #if 0
81  std::vector<Object *> written_armatures;
82 
83  bool already_written(Object *ob_arm);
84 
85  void wrote(Object *ob_arm);
86 
87  void find_objects_using_armature(Object *ob_arm, std::vector<Object *> &objects, Scene *sce);
88 #endif
89 
90  std::string get_controller_id(Object *ob_arm, Object *ob);
91 
92  std::string get_controller_id(Key *key, Object *ob);
93 
94  /* ob should be of type OB_MESH
95  * both args are required */
96  void export_skin_controller(Object *ob, Object *ob_arm);
97 
98  void export_morph_controller(Object *ob, Key *key);
99 
100  void add_joints_element(ListBase *defbase,
101  const std::string &joints_source_id,
102  const std::string &inv_bind_mat_source_id);
103 
104  void add_bind_shape_mat(Object *ob);
105 
106  std::string add_morph_targets(Key *key, Object *ob);
107 
108  std::string add_morph_weights(Key *key, Object *ob);
109 
110  void add_weight_extras(Key *key);
111 
112  std::string add_joints_source(Object *ob_arm,
113  ListBase *defbase,
114  const std::string &controller_id);
115 
116  std::string add_inv_bind_mats_source(Object *ob_arm,
117  ListBase *defbase,
118  const std::string &controller_id);
119 
120  Bone *get_bone_from_defgroup(Object *ob_arm, bDeformGroup *def);
121 
122  bool is_bone_defgroup(Object *ob_arm, bDeformGroup *def);
123 
124  std::string add_weights_source(Mesh *me,
125  const std::string &controller_id,
126  const std::list<float> &weights);
127 
128  void add_vertex_weights_element(const std::string &weights_source_id,
129  const std::string &joints_source_id,
130  const std::list<int> &vcount,
131  const std::list<int> &joints);
132 
133  void write_bone_URLs(COLLADASW::InstanceController &ins, Object *ob_arm, Bone *bone);
134 };
These structs are the foundation for all linked lists in the library system.
Object is a sort of wrapper for general info.
ControllerExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
bool add_instance_controller(Object *ob)
void operator()(Object *ob)
bool is_skinned_mesh(Object *ob)