1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright 2012, Blender Foundation.
*/
#include "COM_TrackPositionNode.h"
#include "COM_ConvertOperation.h"
#include "COM_TrackPositionOperation.h"
#include "DNA_movieclip_types.h"
#include "BKE_node.h"
namespace blender::compositor {
TrackPositionNode::TrackPositionNode(bNode *editor_node) : Node(editor_node)
{
/* pass */
}
static TrackPositionOperation *create_motion_operation(NodeConverter &converter,
MovieClip *clip,
NodeTrackPosData *trackpos_data,
int axis,
int frame_number,
int delta)
{
TrackPositionOperation *operation = new TrackPositionOperation();
operation->set_movie_clip(clip);
operation->set_tracking_object(trackpos_data->tracking_object);
operation->set_track_name(trackpos_data->track_name);
operation->set_framenumber(frame_number);
operation->set_axis(axis);
operation->set_position(CMP_TRACKPOS_ABSOLUTE);
operation->set_relative_frame(frame_number + delta);
operation->set_speed_output(true);
converter.add_operation(operation);
return operation;
}
void TrackPositionNode::convert_to_operations(NodeConverter &converter,
const CompositorContext &context) const
{
bNode *editor_node = this->get_bnode();
MovieClip *clip = (MovieClip *)editor_node->id;
NodeTrackPosData *trackpos_data = (NodeTrackPosData *)editor_node->storage;
NodeOutput *outputX = this->get_output_socket(0);
NodeOutput *outputY = this->get_output_socket(1);
NodeOutput *output_speed = this->get_output_socket(2);
int frame_number;
if (editor_node->custom1 == CMP_TRACKPOS_ABSOLUTE_FRAME) {
frame_number = editor_node->custom2;
}
else {
frame_number = context.get_framenumber();
}
TrackPositionOperation *operationX = new TrackPositionOperation();
operationX->set_movie_clip(clip);
operationX->set_tracking_object(trackpos_data->tracking_object);
operationX->set_track_name(trackpos_data->track_name);
operationX->set_framenumber(frame_number);
operationX->set_axis(0);
operationX->set_position(editor_node->custom1);
operationX->set_relative_frame(editor_node->custom2);
converter.add_operation(operationX);
converter.map_output_socket(outputX, operationX->get_output_socket());
TrackPositionOperation *operationY = new TrackPositionOperation();
operationY->set_movie_clip(clip);
operationY->set_tracking_object(trackpos_data->tracking_object);
operationY->set_track_name(trackpos_data->track_name);
operationY->set_framenumber(frame_number);
operationY->set_axis(1);
operationY->set_position(editor_node->custom1);
operationY->set_relative_frame(editor_node->custom2);
converter.add_operation(operationY);
converter.map_output_socket(outputY, operationY->get_output_socket());
TrackPositionOperation *operationMotionPreX = create_motion_operation(
converter, clip, trackpos_data, 0, frame_number, -1);
TrackPositionOperation *operationMotionPreY = create_motion_operation(
converter, clip, trackpos_data, 1, frame_number, -1);
TrackPositionOperation *operationMotionPostX = create_motion_operation(
converter, clip, trackpos_data, 0, frame_number, 1);
TrackPositionOperation *operationMotionPostY = create_motion_operation(
converter, clip, trackpos_data, 1, frame_number, 1);
CombineChannelsOperation *combine_operation = new CombineChannelsOperation();
converter.add_operation(combine_operation);
converter.add_link(operationMotionPreX->get_output_socket(),
combine_operation->get_input_socket(0));
converter.add_link(operationMotionPreY->get_output_socket(),
combine_operation->get_input_socket(1));
converter.add_link(operationMotionPostX->get_output_socket(),
combine_operation->get_input_socket(2));
converter.add_link(operationMotionPostY->get_output_socket(),
combine_operation->get_input_socket(3));
converter.map_output_socket(output_speed, combine_operation->get_output_socket());
}
} // namespace blender::compositor
|