Welcome to mirror list, hosted at ThFree Co, Russian Federation.

COM_TrackPositionNode.cpp « nodes « compositor « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cddb3557498005d5626d1c73a0917fbf792fd81e (plain)
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
119
120
121
/*
 * Copyright 2012, Blender Foundation.
 *
 * 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.
 *
 * Contributor:
 *		Jeroen Bakker
 *		Monique Dewanchand
 *		Sergey Sharybin
 */

#include "COM_TrackPositionNode.h"

#include "COM_ConvertOperation.h"
#include "COM_ExecutionSystem.h"
#include "COM_TrackPositionOperation.h"

extern "C" {
#  include "DNA_movieclip_types.h"

#  include "BKE_node.h"
}

TrackPositionNode::TrackPositionNode(bNode *editorNode) : Node(editorNode)
{
	/* 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->setMovieClip(clip);
	operation->setTrackingObject(trackpos_data->tracking_object);
	operation->setTrackName(trackpos_data->track_name);
	operation->setFramenumber(frame_number);
	operation->setAxis(axis);
	operation->setPosition(CMP_TRACKPOS_ABSOLUTE);
	operation->setRelativeFrame(frame_number + delta);
	operation->setSpeedOutput(true);
	converter.addOperation(operation);
	return operation;
}

void TrackPositionNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const
{
	bNode *editorNode = this->getbNode();
	MovieClip *clip = (MovieClip *) editorNode->id;
	NodeTrackPosData *trackpos_data = (NodeTrackPosData *) editorNode->storage;

	NodeOutput *outputX = this->getOutputSocket(0);
	NodeOutput *outputY = this->getOutputSocket(1);
	NodeOutput *outputSpeed = this->getOutputSocket(2);

	int frame_number;
	if (editorNode->custom1 == CMP_TRACKPOS_ABSOLUTE_FRAME) {
		frame_number = editorNode->custom2;
	}
	else {
		frame_number = context.getFramenumber();
	}

	TrackPositionOperation *operationX = new TrackPositionOperation();
	operationX->setMovieClip(clip);
	operationX->setTrackingObject(trackpos_data->tracking_object);
	operationX->setTrackName(trackpos_data->track_name);
	operationX->setFramenumber(frame_number);
	operationX->setAxis(0);
	operationX->setPosition(editorNode->custom1);
	operationX->setRelativeFrame(editorNode->custom2);
	converter.addOperation(operationX);
	converter.mapOutputSocket(outputX, operationX->getOutputSocket());

	TrackPositionOperation *operationY = new TrackPositionOperation();
	operationY->setMovieClip(clip);
	operationY->setTrackingObject(trackpos_data->tracking_object);
	operationY->setTrackName(trackpos_data->track_name);
	operationY->setFramenumber(frame_number);
	operationY->setAxis(1);
	operationY->setPosition(editorNode->custom1);
	operationY->setRelativeFrame(editorNode->custom2);
	converter.addOperation(operationY);
	converter.mapOutputSocket(outputY, operationY->getOutputSocket());

	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.addOperation(combine_operation);
	converter.addLink(operationMotionPreX->getOutputSocket(),
	                  combine_operation->getInputSocket(0));
	converter.addLink(operationMotionPreY->getOutputSocket(),
	                  combine_operation->getInputSocket(1));
	converter.addLink(operationMotionPostX->getOutputSocket(),
	                  combine_operation->getInputSocket(2));
	converter.addLink(operationMotionPostY->getOutputSocket(),
	                  combine_operation->getInputSocket(3));
	converter.mapOutputSocket(outputSpeed, combine_operation->getOutputSocket());
}