Blender  V2.93
COM_TimeNode.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include "COM_TimeNode.h"
20 #include "COM_ExecutionSystem.h"
21 #include "COM_SetValueOperation.h"
22 
23 #include "BKE_colortools.h"
24 
25 #include "BLI_utildefines.h"
26 
27 namespace blender::compositor {
28 
29 TimeNode::TimeNode(bNode *editorNode) : Node(editorNode)
30 {
31  /* pass */
32 }
33 
35  const CompositorContext &context) const
36 {
37  SetValueOperation *operation = new SetValueOperation();
38  bNode *node = this->getbNode();
39 
40  /* stack order output: fac */
41  float fac = 0.0f;
42  const int framenumber = context.getFramenumber();
43 
44  if (framenumber < node->custom1) {
45  fac = 0.0f;
46  }
47  else if (framenumber > node->custom2) {
48  fac = 1.0f;
49  }
50  else if (node->custom1 < node->custom2) {
51  fac = (context.getFramenumber() - node->custom1) / (float)(node->custom2 - node->custom1);
52  }
53 
55  fac = BKE_curvemapping_evaluateF((CurveMapping *)node->storage, 0, fac);
56  operation->setValue(clamp_f(fac, 0.0f, 1.0f));
57  converter.addOperation(operation);
58 
59  converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket());
60 }
61 
62 } // namespace blender::compositor
void BKE_curvemapping_init(struct CurveMapping *cumap)
Definition: colortools.c:1200
float BKE_curvemapping_evaluateF(const struct CurveMapping *cumap, int cur, float value)
MINLINE float clamp_f(float value, float min, float max)
Overall context of the compositor.
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
NodeOutput * getOutputSocket(const unsigned int index=0) const
Definition: COM_Node.cc:108
bNode * getbNode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:82
TimeNode(bNode *editorNode)
Definition: COM_TimeNode.cc:29
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
Definition: COM_TimeNode.cc:34
OperationNode * node