Blender V5.3
fbx_import_anim.cc
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#include <algorithm>
10
11#include "ANIM_action.hh"
12#include "ANIM_animdata.hh"
13
14#include "BKE_action.hh"
15#include "BKE_fcurve.hh"
16#include "BKE_lib_id.hh"
17#include "BKE_object_types.hh"
18
20#include "BLI_map.hh"
23#include "BLI_set.hh"
24#include "BLI_string.hh"
25#include "BLI_vector.hh"
26#include "BLI_vector_set.hh"
27
28#include "DNA_key_types.h"
29#include "DNA_material_types.h"
30#include "DNA_object_types.h"
31
32#include "IO_validate.hh"
33
34#include "fbx_import_anim.hh"
35#include "fbx_import_util.hh"
36
37#include "CLG_log.h"
38
39namespace blender::io::fbx {
40
41static CLG_LogRef LOG = {"io.fbx"};
42
45 int64_t key_count)
46{
47 if (!validate::size_fits_in_int(key_count)) {
48 CLOG_WARN(&LOG, "Animation curve too large to import, exceeds max int size");
49 key_count = 0;
50 }
51 FCurve &cu = channelbag.fcurve_ensure(nullptr, descriptor);
52 BKE_fcurve_bezt_resize(cu, key_count);
53 return &cu;
54}
55
56static void set_curve_sample(FCurve *curve, int64_t key_index, float time, float value)
57{
58 BLI_assert(key_index >= 0 && key_index < curve->totvert);
59 BezTriple &bez = curve->bezt[key_index];
60 bez.vec[1][0] = time;
61 bez.vec[1][1] = value;
62 bez.ipo = BEZT_IPO_LIN;
63 bez.f1 = bez.f2 = bez.f3 = BEZT_FLAG_SELECT;
64 bez.h1 = bez.h2 = HD_AUTO_ANIM;
65}
66
68 const ufbx_element *fbx_elem = nullptr;
69 ID *target_id = nullptr;
72 const ufbx_anim_prop *prop_position = nullptr;
73 const ufbx_anim_prop *prop_rotation = nullptr;
74 const ufbx_anim_prop *prop_scale = nullptr;
75 const ufbx_anim_prop *prop_blend_shape = nullptr;
76 const ufbx_anim_prop *prop_focal_length = nullptr;
77 const ufbx_anim_prop *prop_focus_dist = nullptr;
78 const ufbx_anim_prop *prop_mat_diffuse = nullptr;
79};
80
82 const ufbx_anim_layer &flayer)
83{
84 int64_t order = 0;
86 for (const ufbx_anim_prop &fprop : flayer.anim_props) {
87 if (fprop.anim_value->curves[0] == nullptr && fprop.anim_value->curves[1] == nullptr &&
88 fprop.anim_value->curves[2] == nullptr)
89 {
90 continue;
91 }
92 bool supported_prop = false;
93 //@TODO: "Visibility"?
94 const bool is_position = STREQ(fprop.prop_name.data, "Lcl Translation");
95 const bool is_rotation = STREQ(fprop.prop_name.data, "Lcl Rotation");
96 const bool is_scale = STREQ(fprop.prop_name.data, "Lcl Scaling");
97 const bool is_blend_shape = STREQ(fprop.prop_name.data, "DeformPercent");
98 const bool is_focal_length = STREQ(fprop.prop_name.data, "FocalLength");
99 const bool is_focus_dist = STREQ(fprop.prop_name.data, "FocusDistance");
100 const bool is_diffuse = STREQ(fprop.prop_name.data, "DiffuseColor");
101 if (is_position || is_rotation || is_scale || is_blend_shape || is_focal_length ||
102 is_focus_dist || is_diffuse)
103 {
104 supported_prop = true;
105 }
106
107 if (!supported_prop) {
108 continue;
109 }
110
111 const bool is_anim_camera = is_focal_length || is_focus_dist;
112 const bool is_anim_mat = is_diffuse;
113
114 ID *target_id = nullptr;
115 eRotationModes object_rotmode = ROT_MODE_QUAT;
116
117 if (is_blend_shape) {
118 /* Animating blend shape weight. */
119 Key *target_key = mapping.el_to_shape_key.lookup_default(fprop.element, nullptr);
120 if (target_key != nullptr) {
121 target_id = &target_key->id;
122 }
123 }
124 else if (is_anim_camera) {
125 /* Animating camera property. */
126 if (fprop.element->instances.count > 0) {
127 Object *obj = mapping.el_to_object.lookup_default(&fprop.element->instances[0]->element,
128 nullptr);
129 if (obj != nullptr && obj->type == OB_CAMERA) {
130 target_id = (ID *)obj->data;
131 object_rotmode = static_cast<eRotationModes>(obj->rotmode);
132 }
133 }
134 }
135 else if (is_anim_mat) {
136 /* Animating material property. */
137 Material *mat = mapping.mat_to_material.lookup_default((ufbx_material *)fprop.element,
138 nullptr);
139 if (mat != nullptr) {
140 target_id = (ID *)mat;
141 }
142 }
143 else {
144 /* Animating Bone/Armature/Object property. */
145 const ufbx_node *fnode = ufbx_as_node(fprop.element);
146 Object *obj = nullptr;
147 if (fnode) {
148 obj = mapping.bone_to_armature.lookup_default(fnode, nullptr);
149 }
150 if (obj == nullptr) {
151 obj = mapping.el_to_object.lookup_default(fprop.element, nullptr);
152 }
153 if (obj == nullptr) {
154 continue;
155 }
156 /* Ignore animation of rigged meshes (very hard to handle; matches behavior of python fbx
157 * importer). */
158 if (obj->type == OB_MESH && obj->parent && obj->parent->type == OB_ARMATURE) {
159 continue;
160 }
161 target_id = &obj->id;
162 object_rotmode = static_cast<eRotationModes>(obj->rotmode);
163 }
164
165 if (target_id == nullptr) {
166 continue;
167 }
168
169 ElementAnimations &anims = elem_map.lookup_or_add_default(fprop.element);
170 anims.fbx_elem = fprop.element;
171 anims.order = order++;
172 anims.target_id = target_id;
173 anims.object_rotmode = object_rotmode;
174
175 if (is_position) {
176 anims.prop_position = &fprop;
177 }
178 if (is_rotation) {
179 anims.prop_rotation = &fprop;
180 }
181 if (is_scale) {
182 anims.prop_scale = &fprop;
183 }
184 if (is_blend_shape) {
185 anims.prop_blend_shape = &fprop;
186 }
187 if (is_focal_length) {
188 anims.prop_focal_length = &fprop;
189 }
190 if (is_focus_dist) {
191 anims.prop_focus_dist = &fprop;
192 }
193 if (is_diffuse) {
194 anims.prop_mat_diffuse = &fprop;
195 }
196 }
197
198 /* Sort returned result in the original fbx file order. */
199 Vector<ElementAnimations> animations(elem_map.values().begin(), elem_map.values().end());
200 std::ranges::sort(animations, [](const ElementAnimations &a, const ElementAnimations &b) {
201 return a.order < b.order;
202 });
203 return animations;
204}
205
206static void finalize_curve(FCurve *cu)
207{
208 if (cu != nullptr) {
210 }
211}
212
214 const ElementAnimations &anim,
215 LinearAllocator<> &curve_name_alloc,
217{
218 /* For animated bones, prepend bone path to animation curve path. */
219 std::string rna_prefix;
220 std::string group_name_str = get_fbx_name(anim.fbx_elem->name);
221 const ufbx_node *fnode = ufbx_as_node(anim.fbx_elem);
222 const bool is_bone = mapping.node_is_blender_bone.contains(fnode);
223 if (is_bone) {
224 group_name_str = mapping.node_to_name.lookup_default(fnode, "");
225 rna_prefix = std::string("pose.bones[\"") + BLI_str_escape(group_name_str) + "\"].";
226 }
227
228 StringRefNull group_name = curve_name_alloc.copy_string(group_name_str);
229
230 StringRefNull rna_position = curve_name_alloc.copy_string(rna_prefix + "location");
231
232 StringRefNull rna_rotation;
233 int rot_channels = 3;
234 /* Bones are created with quaternion rotation. */
235 eRotationModes rot_mode = is_bone ? ROT_MODE_QUAT : anim.object_rotmode;
236 switch (rot_mode) {
237 case ROT_MODE_QUAT:
238 rna_rotation = curve_name_alloc.copy_string(rna_prefix + "rotation_quaternion");
239 rot_channels = 4;
240 break;
242 rna_rotation = curve_name_alloc.copy_string(rna_prefix + "rotation_axis_angle");
243 rot_channels = 4;
244 break;
245 default:
246 rna_rotation = curve_name_alloc.copy_string(rna_prefix + "rotation_euler");
247 rot_channels = 3;
248 break;
249 }
250
251 StringRefNull rna_scale = curve_name_alloc.copy_string(rna_prefix + "scale");
252
253 /* Fill the f-curve descriptors. */
254 for (int i = 0; i < 3; i++) {
255 r_curve_desc.append({rna_position, i, {}, {}, group_name});
256 }
257 for (int i = 0; i < rot_channels; i++) {
258 r_curve_desc.append({rna_rotation, i, {}, {}, group_name});
259 }
260 for (int i = 0; i < 3; i++) {
261 r_curve_desc.append({rna_scale, i, {}, {}, group_name});
262 }
263}
264
266 const ufbx_anim *fbx_anim,
267 const ElementAnimations &anim,
268 const double fps,
269 const float anim_offset,
270 FCurve **curves)
271{
272 const ufbx_node *fnode = ufbx_as_node(anim.fbx_elem);
273 ufbx_matrix bone_xform = ufbx_identity_matrix;
274 const bool is_bone = mapping.node_is_blender_bone.contains(fnode);
275 if (is_bone) {
276 /* Bone transform curves need to be transformed to the bind transform
277 * in joint-local space:
278 * - Calculate local space bind matrix: inv(parent_bind) * bind
279 * - Invert the result; this will be used to transform loc/rot/scale curves. */
280
281 const bool bone_at_scene_root = fnode->node_depth <= 1;
282 ufbx_matrix world_to_arm = ufbx_identity_matrix;
283 if (!bone_at_scene_root) {
284 Object *arm_obj = mapping.bone_to_armature.lookup_default(fnode, nullptr);
285 if (arm_obj != nullptr) {
286 world_to_arm = mapping.armature_world_to_arm_pose_matrix.lookup_default(
287 arm_obj, ufbx_identity_matrix);
288 }
289 }
290
291 bone_xform = mapping.calc_local_bind_matrix(fnode, world_to_arm);
292 bone_xform = ufbx_matrix_invert(&bone_xform);
293 }
294
295 int rot_channels = 3;
296 /* Bones are created with quaternion rotation. */
297 eRotationModes rot_mode = is_bone ? ROT_MODE_QUAT : anim.object_rotmode;
298 switch (rot_mode) {
299 case ROT_MODE_QUAT:
300 rot_channels = 4;
301 break;
303 rot_channels = 4;
304 break;
305 default:
306 rot_channels = 3;
307 break;
308 }
309
310 /* Note: Python importer was always creating all pos/rot/scale curves: "due to all FBX
311 * transform magic, we need to add curves for whole loc/rot/scale in any case".
312 *
313 * Also, we create a full transform keyframe at any point where input pos/rot/scale curves have
314 * a keyframe. It should not be needed if we fully imported curves with all their proper
315 * handles, but again currently this is to match Python importer behavior. */
316 const ufbx_anim_curve *input_curves[9] = {};
317 if (anim.prop_position) {
318 input_curves[0] = anim.prop_position->anim_value->curves[0];
319 input_curves[1] = anim.prop_position->anim_value->curves[1];
320 input_curves[2] = anim.prop_position->anim_value->curves[2];
321 }
322 if (anim.prop_rotation) {
323 input_curves[3] = anim.prop_rotation->anim_value->curves[0];
324 input_curves[4] = anim.prop_rotation->anim_value->curves[1];
325 input_curves[5] = anim.prop_rotation->anim_value->curves[2];
326 }
327 if (anim.prop_scale) {
328 input_curves[6] = anim.prop_scale->anim_value->curves[0];
329 input_curves[7] = anim.prop_scale->anim_value->curves[1];
330 input_curves[8] = anim.prop_scale->anim_value->curves[2];
331 }
332
333 /* Figure out timestamps of where any of input curves have a keyframe. */
334 Set<double> unique_key_times;
335 for (int i = 0; i < 9; i++) {
336 if (input_curves[i] != nullptr) {
337 for (const ufbx_keyframe &key : input_curves[i]->keyframes) {
338 if (key.interpolation == UFBX_INTERPOLATION_CUBIC) {
339 /* Hack: force cubic keyframes to be linear, to match Python importer behavior. */
340 const_cast<ufbx_keyframe &>(key).interpolation = UFBX_INTERPOLATION_LINEAR;
341 }
342 unique_key_times.add(key.time);
343 }
344 }
345 }
346 Vector<double> sorted_key_times(unique_key_times.begin(), unique_key_times.end());
347 std::ranges::sort(sorted_key_times);
348
349 int64_t pos_index = 0;
350 int64_t rot_index = pos_index + 3;
351 int64_t scale_index = rot_index + rot_channels;
352 int64_t tot_curves = scale_index + 3;
353 int64_t key_count = sorted_key_times.size();
354 if (!validate::size_fits_in_int(key_count)) {
355 CLOG_WARN(&LOG, "Animation curve too large to import, exceeds max int size");
356 key_count = 0;
357 }
358 for (int64_t i = 0; i < tot_curves; i++) {
359 BLI_assert_msg(curves[i], "fbx: animation curve was not created successfully");
360 if (curves[i]) {
361 BKE_fcurve_bezt_resize(*curves[i], key_count);
362 }
363 }
364
365 /* Evaluate transforms at all the key times. */
367 for (int64_t i = 0; i < key_count; i++) {
368 double t = sorted_key_times[i];
369 float tf = float(t * fps + anim_offset);
370 ufbx_transform xform = ufbx_evaluate_transform(fbx_anim, fnode, t);
371
372 if (is_bone) {
373 ufbx_matrix matrix = calc_bone_pose_matrix(xform, *fnode, bone_xform);
374 xform = ufbx_matrix_to_transform(&matrix);
375 }
376
377 set_curve_sample(curves[pos_index + 0], i, tf, float(xform.translation.x));
378 set_curve_sample(curves[pos_index + 1], i, tf, float(xform.translation.y));
379 set_curve_sample(curves[pos_index + 2], i, tf, float(xform.translation.z));
380
381 math::Quaternion quat(xform.rotation.w, xform.rotation.x, xform.rotation.y, xform.rotation.z);
382 switch (rot_mode) {
383 case ROT_MODE_QUAT:
384 /* Ensure shortest interpolation path between consecutive quaternions. */
385 if (i != 0 && math::dot(quat, quat_prev) < 0.0f) {
386 quat = -quat;
387 }
388 quat_prev = quat;
389 set_curve_sample(curves[rot_index + 0], i, tf, quat.w);
390 set_curve_sample(curves[rot_index + 1], i, tf, quat.x);
391 set_curve_sample(curves[rot_index + 2], i, tf, quat.y);
392 set_curve_sample(curves[rot_index + 3], i, tf, quat.z);
393 break;
394 case ROT_MODE_AXISANGLE: {
395 const math::AxisAngle axis_angle = math::to_axis_angle(quat);
396 set_curve_sample(curves[rot_index + 0], i, tf, axis_angle.angle().radian());
397 set_curve_sample(curves[rot_index + 1], i, tf, axis_angle.axis().x);
398 set_curve_sample(curves[rot_index + 2], i, tf, axis_angle.axis().y);
399 set_curve_sample(curves[rot_index + 3], i, tf, axis_angle.axis().z);
400 } break;
401 default: {
402 math::EulerXYZ euler = math::to_euler(quat);
403 set_curve_sample(curves[rot_index + 0], i, tf, euler.x().radian());
404 set_curve_sample(curves[rot_index + 1], i, tf, euler.y().radian());
405 set_curve_sample(curves[rot_index + 2], i, tf, euler.z().radian());
406 } break;
407 }
408
409 set_curve_sample(curves[scale_index + 0], i, tf, float(xform.scale.x));
410 set_curve_sample(curves[scale_index + 1], i, tf, float(xform.scale.y));
411 set_curve_sample(curves[scale_index + 2], i, tf, float(xform.scale.z));
412 }
413}
414
415static void create_camera_curves(const ufbx_metadata &metadata,
416 const ElementAnimations &anim,
417 animrig::Channelbag &channelbag,
418 const double fps,
419 const float anim_offset)
420{
421 if (anim.target_id == nullptr || GS(anim.target_id->name) != ID_CA) {
422 return;
423 }
424
425 if (anim.prop_focal_length != nullptr) {
426 const ufbx_anim_curve *input_curve = anim.prop_focal_length->anim_value->curves[0];
427 FCurve *curve = create_fcurve(channelbag, {"lens", 0}, input_curve->keyframes.count);
428 for (int64_t i = 0; i < curve->totvert; i++) {
429 const ufbx_keyframe &fkey = input_curve->keyframes[i];
430 float tf = float(fkey.time * fps + anim_offset);
431 float val = float(fkey.value);
432 set_curve_sample(curve, i, tf, val);
433 }
434 finalize_curve(curve);
435 }
436
437 if (anim.prop_focus_dist != nullptr) {
438 const ufbx_anim_curve *input_curve = anim.prop_focus_dist->anim_value->curves[0];
439 FCurve *curve = create_fcurve(
440 channelbag, {"dof.focus_distance", 0}, input_curve->keyframes.count);
441 for (int64_t i = 0; i < curve->totvert; i++) {
442 const ufbx_keyframe &fkey = input_curve->keyframes[i];
443 float tf = float(fkey.time * fps + anim_offset);
444 /* Animation curves containing camera focus distance have values multiplied by 1000.0 */
445 float val = float(fkey.value / 1000.0 * metadata.geometry_scale * metadata.root_scale);
446 set_curve_sample(curve, i, tf, val);
447 }
448 finalize_curve(curve);
449 }
450}
451
453 bAction *action,
454 animrig::Channelbag &channelbag,
455 const double fps,
456 const float anim_offset)
457{
458 if (anim.target_id == nullptr || GS(anim.target_id->name) != ID_MA) {
459 return;
460 }
461
462 const char *rna_path_1 = "diffuse_color";
463 const char *rna_path_2 = "nodes[\"Principled BSDF\"].inputs[0].default_value";
464
465 /* Also create animation curves for the node tree diffuse color input. */
466 Material *target_mat = id_cast<Material *>(anim.target_id);
467 ID *target_ntree = reinterpret_cast<ID *>(target_mat->nodetree);
468 animrig::Action &act = action->wrap();
469 const animrig::Slot *slot = animrig::assign_action_ensure_slot_for_keying(act, *target_ntree);
470 BLI_assert(slot != nullptr);
471 UNUSED_VARS_NDEBUG(slot);
472 animrig::Channelbag &chbag_node = animrig::action_channelbag_ensure(*action, *target_ntree);
473
474 if (anim.prop_mat_diffuse != nullptr) {
475 for (int ch = 0; ch < 3; ch++) {
476 const ufbx_anim_curve *input_curve = anim.prop_mat_diffuse->anim_value->curves[ch];
477 FCurve *curve_1 = create_fcurve(channelbag, {rna_path_1, ch}, input_curve->keyframes.count);
478 FCurve *curve_2 = create_fcurve(chbag_node, {rna_path_2, ch}, input_curve->keyframes.count);
479 for (int64_t i = 0; i < curve_1->totvert; i++) {
480 const ufbx_keyframe &fkey = input_curve->keyframes[i];
481 float tf = float(fkey.time * fps + anim_offset);
482 float val = float(fkey.value);
483 set_curve_sample(curve_1, i, tf, val);
484 set_curve_sample(curve_2, i, tf, val);
485 }
486 finalize_curve(curve_1);
487 finalize_curve(curve_2);
488 }
489 }
490}
491
493 animrig::Channelbag &channelbag,
494 const double fps,
495 const float anim_offset)
496{
497 const ufbx_blend_channel *fchan = ufbx_as_blend_channel(anim.prop_blend_shape->element);
498 BLI_assert(fchan != nullptr);
499 std::string rna_path = std::string("key_blocks[\"") +
500 BLI_str_escape(fchan->target_shape->name.data) + "\"].value";
501 const ufbx_anim_curve *input_curve = anim.prop_blend_shape->anim_value->curves[0];
502 FCurve *curve = create_fcurve(channelbag, {rna_path, 0}, input_curve->keyframes.count);
503 for (int64_t i = 0; i < curve->totvert; i++) {
504 const ufbx_keyframe &fkey = input_curve->keyframes[i];
505 double t = fkey.time;
506 float tf = float(t * fps + anim_offset);
507 float val = float(fkey.value / 100.0); /* FBX shape weights are 0..100 range. */
508 set_curve_sample(curve, i, tf, val);
509 }
510 finalize_curve(curve);
511}
512
514 const ufbx_scene &fbx,
515 const FbxElementMapping &mapping,
516 const double fps,
517 const float anim_offset)
518{
519 /* Note: mixing is completely ignored for now, each layer results in an independent set of
520 * actions. */
521 for (const ufbx_anim_stack *fstack : fbx.anim_stacks) {
522 for (const ufbx_anim_layer *flayer : fstack->layers) {
523 Vector<ElementAnimations> animations = gather_animated_properties(mapping, *flayer);
524 if (animations.is_empty()) {
525 continue;
526 }
527
528 /* Create action for this layer. */
529 std::string action_name = fstack->name.data;
530 if (!STREQ(fstack->name.data, flayer->name.data) && fstack->layers.count != 1) {
531 action_name += '|';
532 action_name += flayer->name.data;
533 }
534 animrig::Action &action = animrig::action_add(bmain, action_name);
535 id_fake_user_set(&action.id);
536 action.layer_keystrip_ensure();
537 animrig::StripKeyframeData &strip_data =
538 action.layer(0)->strip(0)->data<animrig::StripKeyframeData>(action);
539
540 /* Figure out the set of IDs that are animated. We want to preserve the order
541 * of this set to match order of animations inside the FBX file. */
542 VectorSet<ID *> animated_ids;
544 for (const ElementAnimations &anim : animations) {
545 animated_ids.add(anim.target_id);
547 anim.target_id);
548 anims.append(&anim);
549 }
550
551 /* Create action slots for each animated ID. */
552 for (ID *id : animated_ids) {
553 /* Create a slot for this ID. */
554 BLI_assert(id != nullptr);
555 const std::string slot_name = id->name;
556 animrig::Slot &slot = action.slot_add_for_id_type(GS(id->name));
557 action.slot_identifier_define(slot, slot_name);
558
559 /* Assign this action & slot to ID. */
560 const AnimData *adt = BKE_animdata_ensure_id(id);
561 BLI_assert_msg(adt != nullptr, "fbx: could not create animation data for an ID");
562 if (adt->action == nullptr) {
563 bool ok = animrig::assign_action(&action, *id);
564 BLI_assert_msg(ok, "fbx: could not assign action to ID");
566 }
570 "fbx: failed to assign slot to ID");
572 }
573 animrig::Channelbag &channelbag = strip_data.channelbag_for_slot_ensure(slot);
574
575 /* Create animation curves for this ID. */
576 Vector<const ElementAnimations *> id_anims = id_to_anims.lookup(id);
577 /* Batch create the transform curves: creating them one by one is not very fast,
578 * especially for armatures where many bones often are animated. So first create
579 * their descriptors, then create the f-curves in one step, and finally fill their data. */
581 Vector<int64_t> anim_transform_curve_index(id_anims.size());
582 LinearAllocator name_alloc;
583 for (const int64_t index : id_anims.index_range()) {
584 const ElementAnimations *anim = id_anims[index];
585 if (anim->prop_position || anim->prop_rotation || anim->prop_scale) {
586 anim_transform_curve_index[index] = curve_desc.size();
587 create_transform_curve_desc(mapping, *anim, name_alloc, curve_desc);
588 }
589 else {
590 anim_transform_curve_index[index] = -1;
591 }
592 }
593 Vector<FCurve *> transform_curves;
594 if (!curve_desc.is_empty()) {
595 transform_curves = channelbag.fcurve_create_many(nullptr, curve_desc.as_span());
596 }
597
598 for (const int64_t index : id_anims.index_range()) {
599 const ElementAnimations *anim = id_anims[index];
600 if (anim->prop_position || anim->prop_rotation || anim->prop_scale) {
602 flayer->anim,
603 *anim,
604 fps,
605 anim_offset,
606 transform_curves.data() +
607 anim_transform_curve_index[index]);
608 }
609 if (anim->prop_focal_length || anim->prop_focus_dist) {
610 create_camera_curves(fbx.metadata, *anim, channelbag, fps, anim_offset);
611 }
612 if (anim->prop_mat_diffuse) {
613 create_material_curves(*anim, &action, channelbag, fps, anim_offset);
614 }
615 if (anim->prop_blend_shape) {
616 create_blend_shape_curves(*anim, channelbag, fps, anim_offset);
617 }
618 }
619
620 for (FCurve *curve : transform_curves) {
621 finalize_curve(curve);
622 }
623 }
624 }
625 }
626}
627
628} // namespace blender::io::fbx
Functions and classes to work with Actions.
Functions to work with AnimData.
Blender kernel action and pose functionality.
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
Object is a sort of wrapper for general info.
#define UNUSED_VARS_NDEBUG(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
StringRefNull copy_string(StringRef str)
SubIterator begin() const
Definition BLI_map.hh:768
SubIterator end() const
Definition BLI_map.hh:778
Value & lookup_or_add_default(const Key &key)
Definition BLI_map.hh:639
ValueIterator values() const &
Definition BLI_map.hh:884
const Value & lookup(const Key &key) const
Definition BLI_map.hh:545
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:570
Iterator begin() const
Definition BLI_set.hh:499
Iterator end() const
Definition BLI_set.hh:509
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
int64_t size() const
void append(const T &value)
bool is_empty() const
IndexRange index_range() const
Span< T > as_span() const
const Layer * layer(int64_t index) const
Slot & slot_add_for_id_type(ID_Type idtype)
void slot_identifier_define(Slot &slot, StringRefNull new_identifier)
Vector< FCurve * > fcurve_create_many(Main *bmain, Span< FCurveDescriptor > fcurve_descriptors)
FCurve & fcurve_ensure(Main *bmain, const FCurveDescriptor &fcurve_descriptor)
const Strip * strip(int64_t index) const
static constexpr slot_handle_t unassigned
Channelbag & channelbag_for_slot_ensure(const Slot &slot)
const T & data(const Action &owning_action) const
Slot * assign_action_ensure_slot_for_keying(Action &action, ID &animated_id)
Action & action_add(Main &bmain, StringRefNull name)
Channelbag & action_channelbag_ensure(bAction &dna_action, ID &animated_id)
bool assign_action(bAction *action, ID &animated_id)
ActionSlotAssignmentResult assign_action_slot(Slot *slot_to_assign, ID &animated_id)
static void create_transform_curve_desc(const FbxElementMapping &mapping, const ElementAnimations &anim, LinearAllocator<> &curve_name_alloc, Vector< animrig::FCurveDescriptor > &r_curve_desc)
static void create_camera_curves(const ufbx_metadata &metadata, const ElementAnimations &anim, animrig::Channelbag &channelbag, const double fps, const float anim_offset)
const char * get_fbx_name(const ufbx_string &name, const char *def)
static void create_transform_curve_data(const FbxElementMapping &mapping, const ufbx_anim *fbx_anim, const ElementAnimations &anim, const double fps, const float anim_offset, FCurve **curves)
static void create_material_curves(const ElementAnimations &anim, bAction *action, animrig::Channelbag &channelbag, const double fps, const float anim_offset)
static void set_curve_sample(FCurve *curve, int64_t key_index, float time, float value)
static void finalize_curve(FCurve *cu)
static Vector< ElementAnimations > gather_animated_properties(const FbxElementMapping &mapping, const ufbx_anim_layer &flayer)
void import_animations(Main &bmain, const ufbx_scene &fbx, const FbxElementMapping &mapping, const double fps, const float anim_offset)
static FCurve * create_fcurve(animrig::Channelbag &channelbag, const animrig::FCurveDescriptor &descriptor, int64_t key_count)
ufbx_matrix calc_bone_pose_matrix(const ufbx_transform &local_xform, const ufbx_node &node, const ufbx_matrix &local_bind_inv_matrix)
static void create_blend_shape_curves(const ElementAnimations &anim, animrig::Channelbag &channelbag, const double fps, const float anim_offset)
bool size_fits_in_int(const int64_t size)
QuaternionBase< float > Quaternion
AxisAngleBase< float, AngleRadianBase< float > > AxisAngle
EulerXYZBase< float > EulerXYZ
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
AxisAngleBase< T, AngleT > to_axis_angle(const EulerXYZBase< T > &euler)
Euler3Base< T > to_euler(const AxisAngleBase< T, AngleT > &axis_angle, EulerOrder order)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
void id_fake_user_set(ID *id)
Definition lib_id.cc:471
AnimData * BKE_animdata_ensure_id(ID *id)
Definition anim_data.cc:107
void BKE_fcurve_handles_recalc(FCurve &fcu)
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
ID_Type GS(const char *name)
Definition DNA_ID.h:410
static CLG_LogRef LOG
Definition fbx_import.cc:43
void BKE_fcurve_bezt_resize(FCurve &fcu, int new_totvert)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eBezTriple_Flag f2
eBezTriple_Handle h2
eBezTriple_Flag f3
eBezTriple_Flag f1
eBezTriple_Interpolation ipo
eBezTriple_Handle h1
unsigned int totvert
char name[258]
Definition DNA_ID.h:433
const ufbx_anim_prop * prop_focal_length
const ufbx_anim_prop * prop_blend_shape
const ufbx_anim_prop * prop_mat_diffuse
const ufbx_anim_prop * prop_focus_dist
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