Blender V5.3
node_composite_time_curve.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_math_base.hh"
6
7#include "BKE_colortools.hh"
8#include "BKE_node.hh"
9
10#include "COM_node_operation.hh"
11#include "COM_result.hh"
12
14
16
18{
19 b.add_input<decl::Int>("Start Frame"_ustr).default_value(1);
20 b.add_input<decl::Int>("End Frame"_ustr).default_value(250);
21
22 b.add_output<decl::Float>("Factor"_ustr, "Fac"_ustr);
23}
24
25static void node_init(bNodeTree * /*ntree*/, bNode *node)
26{
27 node->storage = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
28}
29
30using namespace blender::compositor;
31
33 public:
35
36 void execute() override
37 {
38 Result &result = this->get_result("Fac");
39 result.allocate_single_value();
40
41 CurveMapping *curve_mapping = const_cast<CurveMapping *>(this->get_curve_mapping());
42 BKE_curvemapping_init(curve_mapping);
43 const float time = BKE_curvemapping_evaluateF(
44 curve_mapping, 0, this->compute_normalized_time());
45 result.set_single_value(math::clamp(time, 0.0f, 1.0f));
46 }
47
49 {
50 const int frame_number = this->context().get_frame_number();
51 if (frame_number < this->get_start_frame()) {
52 return 0.0f;
53 }
54 if (frame_number > this->get_end_frame()) {
55 return 1.0f;
56 }
57 if (this->get_start_frame() == this->get_end_frame()) {
58 return 0.0f;
59 }
60 return float(frame_number - this->get_start_frame()) /
61 float(this->get_end_frame() - this->get_start_frame());
62 }
63
65 {
66 return this->get_input("Start Frame").get_single_value_default<int>();
67 }
68
70 {
71 return this->get_input("End Frame").get_single_value_default<int>();
72 }
73
75 {
76 return static_cast<const CurveMapping *>(node().storage);
77 }
78};
79
81{
82 return new TimeCurveOperation(context, node);
83}
84
85static void node_register()
86{
87 static bke::bNodeType ntype;
88
89 cmp_node_type_base(&ntype, "CompositorNodeTime"_ustr, CMP_NODE_TIME);
90 ntype.ui_name = "Time Curve";
91 ntype.ui_description =
92 "Generate a factor value (from 0.0 to 1.0) between scene start and end time, using a curve "
93 "mapping";
94 ntype.enum_name_legacy = "TIME";
96 ntype.declare = node_declare;
98 ntype.initfunc = node_init;
101
103}
105
106} // namespace blender::nodes::node_composite_time_curves_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define CMP_NODE_TIME
#define NOD_REGISTER_NODE(REGISTER_FUNC)
NodeOperation(Context &context, const bNode &node)
Result & get_result(StringRef identifier)
Definition operation.cc:40
Context & context() const
Definition operation.cc:57
Result & get_input(StringRef identifier) const
Definition operation.cc:35
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
T clamp(const T &a, const T &min, const T &max)
static void node_declare(NodeDeclarationBuilder &b)
static void node_init(bNodeTree *, bNode *node)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition colortools.cc:99
void BKE_curvemapping_init(CurveMapping *cumap)
void node_free_curves(bNode *node)
Definition node_util.cc:40
void node_copy_curves(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:52
float BKE_curvemapping_evaluateF(const CurveMapping *cumap, int cur, float value)
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
static constexpr int _200
Definition BKE_node.hh:248
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:379
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393