Blender V5.3
abc_keyframing.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "abc_keyframing.h"
10#include "abc_reader_archive.h"
11
12#include "DNA_scene_types.h"
13
14#include "ANIM_action.hh"
15#include "ANIM_animdata.hh"
16
17#include "BKE_fcurve.hh"
18
19using Alembic::Abc::ISampleSelector;
20
21namespace blender::io::alembic {
22
23/* Utility: create new fcurve and add it as a channel to a group. */
25 const animrig::FCurveDescriptor &fcurve_descriptor,
26 const int sample_count)
27{
28 FCurve *fcurve = channelbag.fcurve_create_unique(nullptr, fcurve_descriptor);
29 BLI_assert_msg(fcurve, "The same F-Curve is being created twice, this is unexpected.");
30 if (fcurve) {
31 BKE_fcurve_bezt_resize(*fcurve, sample_count);
32 }
33 return fcurve;
34}
35
36/* Utility: fill in a single fcurve sample at the provided index. */
37void set_fcurve_sample(FCurve *fcu, int64_t sample_index, const float frame, const float value)
38{
39 BLI_assert(sample_index >= 0 && sample_index < fcu->totvert);
40 BezTriple &bez = fcu->bezt[sample_index];
41 bez.vec[1][0] = frame;
42 bez.vec[1][1] = value;
43 bez.ipo = BEZT_IPO_LIN;
44 bez.f1 = bez.f2 = bez.f3 = BEZT_FLAG_SELECT;
45 bez.h1 = bez.h2 = HD_AUTO;
46}
47
49
56
58 const int sample_count)
59{
60 return alembic::create_fcurve(*channelbag, fcurve_descriptor, sample_count);
61}
62
64{
66
67 for (FCurve *fcu : channelbag->fcurves()) {
68 if (fcu) {
70 }
71 }
72}
73
75 Scene *scene,
76 Span<std::unique_ptr<FCurveCreationHelper>> helpers,
77 const TimeInfo time_info)
78{
79 if (helpers.is_empty()) {
80 return;
81 }
82
83 const double fps = scene->frames_per_second();
84 const int start_frame = int(round(time_info.min_time * fps));
85 const int end_frame = int(round(time_info.max_time * fps));
86
87 const int sample_count = end_frame - start_frame + 1;
88
89 for (const std::unique_ptr<FCurveCreationHelper> &helper : helpers) {
90 helper->ensure_action_data(bmain, sample_count);
91 }
92
93 int64_t sample_index = 0;
94 for (int i = start_frame; i <= end_frame; i++) {
95 const double frame_time = (double(i) / fps);
96 const ISampleSelector selector = ISampleSelector(frame_time);
97
98 FrameSampleInfo sample_info;
99 sample_info.frame = float(i);
100 sample_info.sample_index = sample_index++;
101 sample_info.selector = selector;
102
103 for (const std::unique_ptr<FCurveCreationHelper> &helper : helpers) {
104 helper->set_fcurves_sample(sample_info);
105 }
106 }
107
108 for (const std::unique_ptr<FCurveCreationHelper> &helper : helpers) {
109 helper->finish();
110 }
111}
112
113} // namespace blender::io::alembic
Functions and classes to work with Actions.
Functions to work with AnimData.
#define BLI_assert_msg(a, msg)
Span< const FCurve * > fcurves() const
FCurve * fcurve_create_unique(Main *bmain, const FCurveDescriptor &fcurve_descriptor)
void ensure_action_data(Main *bmain, const int sample_count)
FCurve * create_fcurve(const animrig::FCurveDescriptor &fcurve_descriptor, const int sample_count)
virtual void create_fcurves(const int sample_count)=0
#define round
bAction * id_action_ensure(Main *bmain, ID *id)
Definition animdata.cc:195
Channelbag & action_channelbag_ensure(bAction &dna_action, ID &animated_id)
void create_keyframes(Main *bmain, Scene *scene, Span< std::unique_ptr< FCurveCreationHelper > > helpers, const TimeInfo time_info)
static FCurve * create_fcurve(animrig::Channelbag &channelbag, const animrig::FCurveDescriptor &fcurve_descriptor, const int sample_count)
void set_fcurve_sample(FCurve *fcu, int64_t sample_index, const float frame, const float value)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
void BKE_fcurve_handles_recalc(FCurve &fcu)
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
Alembic::Abc::ISampleSelector selector
Alembic::Abc::chrono_t max_time
Alembic::Abc::chrono_t min_time