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