Blender V5.3
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
16namespace blender {
17
18struct ID;
19struct Object;
20struct Key;
21struct Material;
22struct bPoseChannel;
23
24namespace io::fbx {
25
26const char *get_fbx_name(const ufbx_string &name, const char *def = "Untitled");
27
34
35 /* For the armatures we create, for different use cases we need transform
36 * from world space to the root bone, either in posed transform or in
37 * node transform. */
40
41 /* Which FBX bone nodes got turned into actual armature bones (not all of them
42 * always are; in some cases root bone is the armature object itself). */
44
45 /* Mapping of ufbx node to object name used within blender. If names are too long
46 * or duplicate, they might not match what was in FBX file. */
48 /* Bone node to "bind matrix", i.e. matrix that transforms from bone (in skin bind pose) local
49 * space to world space. This records bone pose or skin cluster bind matrix (skin cluster taking
50 * precedence if it exists). */
54 ufbx_matrix global_conv_matrix;
55
56 ufbx_matrix get_node_bind_matrix(const ufbx_node *node) const
57 {
58 return this->bone_to_bind_matrix.lookup_default(node, node->geometry_to_world);
59 }
60
61 ufbx_matrix calc_local_bind_matrix(const ufbx_node *bone_node,
62 const ufbx_matrix &world_to_arm) const
63 {
64 ufbx_matrix res = this->get_node_bind_matrix(bone_node);
65 ufbx_matrix parent_inv_mtx;
66 if (bone_node->parent != nullptr && !bone_node->parent->is_root) {
67 ufbx_matrix parent_mtx = this->get_node_bind_matrix(bone_node->parent);
68 parent_inv_mtx = ufbx_matrix_invert(&parent_mtx);
69 }
70 else {
71 parent_inv_mtx = world_to_arm;
72 }
73 res = ufbx_matrix_mul(&parent_inv_mtx, &res);
74 return res;
75 }
76};
77
78void matrix_to_m44(const ufbx_matrix &src, float dst[4][4]);
79void ufbx_matrix_to_obj(const ufbx_matrix &mtx, Object *obj);
80void node_matrix_to_obj(const ufbx_node *node, Object *obj, const FbxElementMapping &mapping);
81void read_custom_properties(const ufbx_props &props, ID &id, bool enums_as_strings);
82void read_custom_properties(const ufbx_props &props, bPoseChannel &pchan, bool enums_as_strings);
83
84ufbx_matrix calc_bone_pose_matrix(const ufbx_transform &local_xform,
85 const ufbx_node &node,
86 const ufbx_matrix &local_bind_inv_matrix);
87
88//@TODO remove debug file print once things are working properly
89// #define FBX_DEBUG_PRINT
90
91#ifdef FBX_DEBUG_PRINT
92extern FILE *g_debug_file;
93
94inline double adjf(double f)
95{
96 if (fabs(f) < 0.0005) {
97 return 0.0;
98 }
99 return f;
100}
101
102void print_matrix(const ufbx_matrix &m);
103#endif
104
105} // namespace io::fbx
106} // namespace blender
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:570
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
Definition math_dual.h:241
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)
BMesh Iterators.
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