Blender  V2.93
ArmatureImporter.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 "COLLADAFWMorphController.h"
24 #include "COLLADAFWNode.h"
25 #include "COLLADAFWUniqueId.h"
26 
27 #include "BKE_context.h"
28 #include "BKE_key.h"
29 
30 #include "DNA_armature_types.h"
31 #include "DNA_key_types.h"
32 #include "DNA_object_types.h"
33 #include "DNA_scene_types.h"
34 
35 #include "ED_armature.h"
36 
37 #include "AnimationImporter.h"
38 #include "ExtraTags.h"
39 #include "MeshImporter.h"
40 #include "SkinInfo.h"
41 #include "TransformReader.h"
42 
43 #include <map>
44 #include <vector>
45 
46 #include "ImportSettings.h"
47 #include "collada_internal.h"
48 #include "collada_utils.h"
49 
50 #define UNLIMITED_CHAIN_MAX INT_MAX
51 #define MINIMUM_BONE_LENGTH 0.000001f
52 
54  private:
55  Main *m_bmain;
56  Scene *scene;
57  ViewLayer *view_layer;
58  UnitConverter *unit_converter;
59  const ImportSettings *import_settings;
60 
61  // std::map<int, JointData> joint_index_to_joint_info_map;
62  // std::map<COLLADAFW::UniqueId, int> joint_id_to_joint_index_map;
63  BoneExtensionManager bone_extension_manager;
64  // int bone_direction_row; /* XXX not used */
65  float leaf_bone_length;
66  int totbone;
67  /* XXX not used */
68  // float min_angle; /* minimum angle between bone head-tail and a row of bone matrix */
69 
70 #if 0
71  struct ArmatureJoints {
72  Object *ob_arm;
73  std::vector<COLLADAFW::Node *> root_joints;
74  };
75  std::vector<ArmatureJoints> armature_joints;
76 #endif
77 
78  Object *empty; /* empty for leaf bones */
79 
80  std::map<COLLADAFW::UniqueId, COLLADAFW::UniqueId> geom_uid_by_controller_uid;
81  std::map<COLLADAFW::UniqueId, COLLADAFW::Node *> joint_by_uid; /* contains all joints */
82  std::vector<COLLADAFW::Node *> root_joints;
83  std::vector<COLLADAFW::Node *> finished_joints;
84  std::vector<COLLADAFW::MorphController *> morph_controllers;
85  std::map<COLLADAFW::UniqueId, Object *> joint_parent_map;
86  std::map<COLLADAFW::UniqueId, Object *> unskinned_armature_map;
87 
88  MeshImporterBase *mesh_importer;
89 
90  /* This is used to store data passed in write_controller_data.
91  * Arrays from COLLADAFW::SkinControllerData lose ownership, so do this class members
92  * so that arrays don't get freed until we free them explicitly. */
93 
94  std::map<COLLADAFW::UniqueId, SkinInfo>
95  skin_by_data_uid; /* data UID = skin controller data UID */
96 #if 0
97  JointData *get_joint_data(COLLADAFW::Node *node);
98 #endif
99 
100  int create_bone(SkinInfo *skin,
101  COLLADAFW::Node *node,
102  EditBone *parent,
103  int totchild,
104  float parent_mat[4][4],
105  bArmature *arm,
106  std::vector<std::string> &layer_labels);
107 
108  BoneExtended &add_bone_extended(EditBone *bone,
109  COLLADAFW::Node *node,
110  int sibcount,
111  std::vector<std::string> &layer_labels,
112  BoneExtensionMap &extended_bones);
113 
114  void fix_leaf_bone_hierarchy(bArmature *armature, Bone *bone, bool fix_orientation);
115  void fix_leaf_bone(bArmature *armature, EditBone *ebone, BoneExtended *be, bool fix_orientation);
116  void fix_parent_connect(bArmature *armature, Bone *bone);
117  void connect_bone_chains(bArmature *armature, Bone *bone, const int max_chain_length);
118 
119  void set_pose(Object *ob_arm,
120  COLLADAFW::Node *root_node,
121  const char *parentname,
122  float parent_mat[4][4]);
123 
124  void set_bone_transformation_type(const COLLADAFW::Node *node, Object *ob_arm);
125  bool node_is_decomposed(const COLLADAFW::Node *node);
126 #if 0
127  void set_leaf_bone_shapes(Object *ob_arm);
128  void set_euler_rotmode();
129 #endif
130 
131  Object *get_empty_for_leaves();
132 
133 #if 0
134  Object *find_armature(COLLADAFW::Node *node);
135 
136  ArmatureJoints &get_armature_joints(Object *ob_arm);
137 #endif
138 
139  Object *create_armature_bones(Main *bmain, SkinInfo &skin);
140  void create_armature_bones(Main *bmain, std::vector<Object *> &arm_objs);
141 
143  typedef std::map<std::string, ExtraTags *> TagsMap;
144  TagsMap uid_tags_map;
145 
146  public:
149  Main *bmain,
150  Scene *sce,
151  ViewLayer *view_layer,
152  const ImportSettings *import_settings);
154 
155  void add_root_joint(COLLADAFW::Node *node, Object *parent);
156 
157  /* here we add bones to armatures, having armatures previously created in write_controller */
158  void make_armatures(bContext *C, std::vector<Object *> &objects_to_scale);
159 
160  void make_shape_keys(bContext *C);
161 
162 #if 0
163  /* link with meshes, create vertex groups, assign weights */
164  void link_armature(Object *ob_arm,
165  const COLLADAFW::UniqueId &geom_id,
166  const COLLADAFW::UniqueId &controller_data_id);
167 #endif
168 
169  bool write_skin_controller_data(const COLLADAFW::SkinControllerData *data);
170 
171  bool write_controller(const COLLADAFW::Controller *controller);
172 
173  COLLADAFW::UniqueId *get_geometry_uid(const COLLADAFW::UniqueId &controller_uid);
174 
175  Object *get_armature_for_joint(COLLADAFW::Node *node);
176 
177  void get_rna_path_for_joint(COLLADAFW::Node *node, char *joint_path, size_t count);
178 
179  /* gives a world-space mat */
180  bool get_joint_bind_mat(float m[4][4], COLLADAFW::Node *joint);
181 
182  void set_tags_map(TagsMap &tags_map);
183 };
Object is a sort of wrapper for general info.
static Controller * controller
#define C
Definition: RandGen.cpp:39
void make_shape_keys(bContext *C)
void get_rna_path_for_joint(COLLADAFW::Node *node, char *joint_path, size_t count)
void make_armatures(bContext *C, std::vector< Object * > &objects_to_scale)
bool write_skin_controller_data(const COLLADAFW::SkinControllerData *data)
bool write_controller(const COLLADAFW::Controller *controller)
void set_tags_map(TagsMap &tags_map)
ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, Main *bmain, Scene *sce, ViewLayer *view_layer, const ImportSettings *import_settings)
Object * get_armature_for_joint(COLLADAFW::Node *node)
void add_root_joint(COLLADAFW::Node *node, Object *parent)
bool get_joint_bind_mat(float m[4][4], COLLADAFW::Node *joint)
COLLADAFW::UniqueId * get_geometry_uid(const COLLADAFW::UniqueId &controller_uid)
std::map< std::string, BoneExtended * > BoneExtensionMap
OperationNode * node
int count
Definition: BKE_main.h:116