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