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