Blender V5.0
fbx_import_util.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_map.hh"
12#include "BLI_set.hh"
13
14#include "ufbx.h"
15
16struct ID;
17struct Object;
18struct Key;
19struct Material;
20struct bPoseChannel;
21
22namespace blender::io::fbx {
23
24const char *get_fbx_name(const ufbx_string &name, const char *def = "Untitled");
25
32
33 /* For the armatures we create, for different use cases we need transform
34 * from world space to the root bone, either in posed transform or in
35 * node transform. */
38
39 /* Which FBX bone nodes got turned into actual armature bones (not all of them
40 * always are; in some cases root bone is the armature object itself). */
42
43 /* Mapping of ufbx node to object name used within blender. If names are too long
44 * or duplicate, they might not match what was in FBX file. */
46 /* Bone node to "bind matrix", i.e. matrix that transforms from bone (in skin bind pose) local
47 * space to world space. This records bone pose or skin cluster bind matrix (skin cluster taking
48 * precedence if it exists). */
52 ufbx_matrix global_conv_matrix;
53
54 ufbx_matrix get_node_bind_matrix(const ufbx_node *node) const
55 {
56 return this->bone_to_bind_matrix.lookup_default(node, node->geometry_to_world);
57 }
58
59 ufbx_matrix calc_local_bind_matrix(const ufbx_node *bone_node,
60 const ufbx_matrix &world_to_arm) const
61 {
62 ufbx_matrix res = this->get_node_bind_matrix(bone_node);
63 ufbx_matrix parent_inv_mtx;
64 if (bone_node->parent != nullptr && !bone_node->parent->is_root) {
65 ufbx_matrix parent_mtx = this->get_node_bind_matrix(bone_node->parent);
66 parent_inv_mtx = ufbx_matrix_invert(&parent_mtx);
67 }
68 else {
69 parent_inv_mtx = world_to_arm;
70 }
71 res = ufbx_matrix_mul(&parent_inv_mtx, &res);
72 return res;
73 }
74};
75
76void matrix_to_m44(const ufbx_matrix &src, float dst[4][4]);
77void ufbx_matrix_to_obj(const ufbx_matrix &mtx, Object *obj);
78void node_matrix_to_obj(const ufbx_node *node, Object *obj, const FbxElementMapping &mapping);
79void read_custom_properties(const ufbx_props &props, ID &id, bool enums_as_strings);
80void read_custom_properties(const ufbx_props &props, bPoseChannel &pchan, bool enums_as_strings);
81
82ufbx_matrix calc_bone_pose_matrix(const ufbx_transform &local_xform,
83 const ufbx_node &node,
84 const ufbx_matrix &local_bind_inv_matrix);
85
86//@TODO remove debug file print once things are working properly
87// #define FBX_DEBUG_PRINT
88
89#ifdef FBX_DEBUG_PRINT
90extern FILE *g_debug_file;
91
92inline double adjf(double f)
93{
94 if (fabs(f) < 0.0005) {
95 return 0.0;
96 }
97 return f;
98}
99
100void print_matrix(const ufbx_matrix &m);
101#endif
102
103} // namespace blender::io::fbx
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:570
ccl_device_inline float2 fabs(const float2 a)
void ufbx_matrix_to_obj(const ufbx_matrix &mtx, Object *obj)
const char * get_fbx_name(const ufbx_string &name, const char *def)
void read_custom_properties(const ufbx_props &props, ID &id, bool enums_as_strings)
void node_matrix_to_obj(const ufbx_node *node, Object *obj, const FbxElementMapping &mapping)
void matrix_to_m44(const ufbx_matrix &src, float dst[4][4])
ufbx_matrix calc_bone_pose_matrix(const ufbx_transform &local_xform, const ufbx_node &node, const ufbx_matrix &local_bind_inv_matrix)
const char * name
Definition DNA_ID.h:414
ufbx_matrix get_node_bind_matrix(const ufbx_node *node) const
Map< const ufbx_node *, ufbx_real > bone_to_length
Map< const Object *, ufbx_matrix > armature_world_to_arm_node_matrix
Map< const ufbx_node *, ufbx_matrix > bone_to_bind_matrix
Set< const ufbx_node * > bone_is_skinned
Map< const ufbx_node *, Object * > bone_to_armature
Map< const ufbx_material *, Material * > mat_to_material
Map< const ufbx_node *, std::string > node_to_name
Set< const ufbx_node * > node_is_blender_bone
Map< const Object *, ufbx_matrix > armature_world_to_arm_pose_matrix
ufbx_matrix calc_local_bind_matrix(const ufbx_node *bone_node, const ufbx_matrix &world_to_arm) const
Map< const ufbx_element *, Object * > el_to_object
Map< const ufbx_element *, Key * > el_to_shape_key