[Bf-blender-cvs] [e0c5ff87b70] master: Realtime Compositor: Implement Track Position node
Omar Emara
noreply at git.blender.org
Wed Nov 23 11:56:28 CET 2022
Commit: e0c5ff87b702209c3d893051889bf09a8cd35919
Author: Omar Emara
Date: Wed Nov 23 12:55:16 2022 +0200
Branches: master
https://developer.blender.org/rBe0c5ff87b702209c3d893051889bf09a8cd35919
Realtime Compositor: Implement Track Position node
This patch implements the Track Position node for the realtime
compositor.
Differential Revision: https://developer.blender.org/D16387
Reviewed By: Clement Foucault
===================================================================
M source/blender/blenkernel/BKE_node.h
M source/blender/compositor/nodes/COM_TrackPositionNode.cc
M source/blender/compositor/operations/COM_TrackPositionOperation.cc
M source/blender/compositor/operations/COM_TrackPositionOperation.h
M source/blender/makesdna/DNA_node_types.h
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/nodes/composite/nodes/node_composite_trackpos.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index dd035dbf537..9e85282ab42 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1337,12 +1337,6 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, struct Scene *scene, i
#define CMP_CHAN_RGB 1
#define CMP_CHAN_A 2
-/* track position node, in custom1 */
-#define CMP_TRACKPOS_ABSOLUTE 0
-#define CMP_TRACKPOS_RELATIVE_START 1
-#define CMP_TRACKPOS_RELATIVE_FRAME 2
-#define CMP_TRACKPOS_ABSOLUTE_FRAME 3
-
/* Cryptomatte source. */
#define CMP_CRYPTOMATTE_SRC_RENDER 0
#define CMP_CRYPTOMATTE_SRC_IMAGE 1
diff --git a/source/blender/compositor/nodes/COM_TrackPositionNode.cc b/source/blender/compositor/nodes/COM_TrackPositionNode.cc
index da12f72b451..25daf3306a1 100644
--- a/source/blender/compositor/nodes/COM_TrackPositionNode.cc
+++ b/source/blender/compositor/nodes/COM_TrackPositionNode.cc
@@ -30,7 +30,7 @@ static TrackPositionOperation *create_motion_operation(NodeConverter &converter,
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_position(CMP_NODE_TRACK_POSITION_ABSOLUTE);
operation->set_relative_frame(frame_number + delta);
operation->set_speed_output(true);
converter.add_operation(operation);
@@ -49,7 +49,7 @@ void TrackPositionNode::convert_to_operations(NodeConverter &converter,
NodeOutput *output_speed = this->get_output_socket(2);
int frame_number;
- if (editor_node->custom1 == CMP_TRACKPOS_ABSOLUTE_FRAME) {
+ if (editor_node->custom1 == CMP_NODE_TRACK_POSITION_ABSOLUTE_FRAME) {
frame_number = editor_node->custom2;
}
else {
@@ -62,7 +62,7 @@ void TrackPositionNode::convert_to_operations(NodeConverter &converter,
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_position(static_cast<CMPNodeTrackPositionMode>(editor_node->custom1));
operationX->set_relative_frame(editor_node->custom2);
converter.add_operation(operationX);
converter.map_output_socket(outputX, operationX->get_output_socket());
@@ -73,7 +73,7 @@ void TrackPositionNode::convert_to_operations(NodeConverter &converter,
operationY->set_track_name(trackpos_data->track_name);
operationY->set_framenumber(frame_number);
operationY->set_axis(1);
- operationY->set_position(editor_node->custom1);
+ operationX->set_position(static_cast<CMPNodeTrackPositionMode>(editor_node->custom1));
operationY->set_relative_frame(editor_node->custom2);
converter.add_operation(operationY);
converter.map_output_socket(outputY, operationY->get_output_socket());
diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.cc b/source/blender/compositor/operations/COM_TrackPositionOperation.cc
index 3e7a2d3cbd9..6763293b519 100644
--- a/source/blender/compositor/operations/COM_TrackPositionOperation.cc
+++ b/source/blender/compositor/operations/COM_TrackPositionOperation.cc
@@ -19,7 +19,7 @@ TrackPositionOperation::TrackPositionOperation()
tracking_object_name_[0] = 0;
track_name_[0] = 0;
axis_ = 0;
- position_ = CMP_TRACKPOS_ABSOLUTE;
+ position_ = CMP_NODE_TRACK_POSITION_ABSOLUTE;
relative_frame_ = 0;
speed_output_ = false;
flags_.is_set_operation = true;
@@ -80,7 +80,7 @@ void TrackPositionOperation::calc_track_position()
swap_v2_v2(relative_pos_, marker_pos_);
}
}
- else if (position_ == CMP_TRACKPOS_RELATIVE_START) {
+ else if (position_ == CMP_NODE_TRACK_POSITION_RELATIVE_START) {
int i;
for (i = 0; i < track->markersnr; i++) {
@@ -93,7 +93,7 @@ void TrackPositionOperation::calc_track_position()
}
}
}
- else if (position_ == CMP_TRACKPOS_RELATIVE_FRAME) {
+ else if (position_ == CMP_NODE_TRACK_POSITION_RELATIVE_FRAME) {
int relative_clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(movie_clip_,
relative_frame_);
diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.h b/source/blender/compositor/operations/COM_TrackPositionOperation.h
index 6130aa20f0e..efe3ec16887 100644
--- a/source/blender/compositor/operations/COM_TrackPositionOperation.h
+++ b/source/blender/compositor/operations/COM_TrackPositionOperation.h
@@ -25,7 +25,7 @@ class TrackPositionOperation : public ConstantOperation {
char tracking_object_name_[64];
char track_name_[64];
int axis_;
- int position_;
+ CMPNodeTrackPositionMode position_;
int relative_frame_;
bool speed_output_;
@@ -63,7 +63,7 @@ class TrackPositionOperation : public ConstantOperation {
{
axis_ = value;
}
- void set_position(int value)
+ void set_position(CMPNodeTrackPositionMode value)
{
position_ = value;
}
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 4e57cd82b22..2831e488322 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -2048,6 +2048,14 @@ typedef enum CMPNodeToneMapType {
CMP_NODE_TONE_MAP_PHOTORECEPTOR = 1,
} CMPNodeToneMapType;
+/* Track Position Node. Stored in custom1. */
+typedef enum CMPNodeTrackPositionMode {
+ CMP_NODE_TRACK_POSITION_ABSOLUTE = 0,
+ CMP_NODE_TRACK_POSITION_RELATIVE_START = 1,
+ CMP_NODE_TRACK_POSITION_RELATIVE_FRAME = 2,
+ CMP_NODE_TRACK_POSITION_ABSOLUTE_FRAME = 3,
+} CMPNodeTrackPositionMode;
+
/* Plane track deform node. */
enum {
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index e57f0af6f7d..b33e5543219 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -8986,18 +8986,22 @@ static void def_cmp_trackpos(StructRNA *srna)
PropertyRNA *prop;
static const EnumPropertyItem position_items[] = {
- {CMP_TRACKPOS_ABSOLUTE, "ABSOLUTE", 0, "Absolute", "Output absolute position of a marker"},
- {CMP_TRACKPOS_RELATIVE_START,
+ {CMP_NODE_TRACK_POSITION_ABSOLUTE,
+ "ABSOLUTE",
+ 0,
+ "Absolute",
+ "Output absolute position of a marker"},
+ {CMP_NODE_TRACK_POSITION_RELATIVE_START,
"RELATIVE_START",
0,
"Relative Start",
"Output position of a marker relative to first marker of a track"},
- {CMP_TRACKPOS_RELATIVE_FRAME,
+ {CMP_NODE_TRACK_POSITION_RELATIVE_FRAME,
"RELATIVE_FRAME",
0,
"Relative Frame",
"Output position of a marker relative to marker at given frame number"},
- {CMP_TRACKPOS_ABSOLUTE_FRAME,
+ {CMP_NODE_TRACK_POSITION_ABSOLUTE_FRAME,
"ABSOLUTE_FRAME",
0,
"Absolute Frame",
diff --git a/source/blender/nodes/composite/nodes/node_composite_trackpos.cc b/source/blender/nodes/composite/nodes/node_composite_trackpos.cc
index 3609c235c4b..fc71160da16 100644
--- a/source/blender/nodes/composite/nodes/node_composite_trackpos.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_trackpos.cc
@@ -5,11 +5,16 @@
* \ingroup cmpnodes
*/
+#include "BLI_index_range.hh"
+#include "BLI_math_vec_types.hh"
+
+#include "DNA_defaults.h"
#include "DNA_movieclip_types.h"
#include "DNA_tracking_types.h"
#include "BKE_context.h"
#include "BKE_lib_id.h"
+#include "BKE_movieclip.h"
#include "BKE_tracking.h"
#include "RNA_access.h"
@@ -24,6 +29,8 @@
namespace blender::nodes::node_composite_trackpos_cc {
+NODE_STORAGE_FUNCS(NodeTrackPosData)
+
static void cmp_node_trackpos_declare(NodeDeclarationBuilder &b)
{
b.add_output<decl::Float>(N_("X"));
@@ -97,7 +104,9 @@ static void node_composit_buts_trackpos(uiLayout *layout, bContext *C, PointerRN
uiItemR(layout, ptr, "position", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
- if (ELEM(node->custom1, CMP_TRACKPOS_RELATIVE_FRAME, CMP_TRACKPOS_ABSOLUTE_FRAME)) {
+ if (ELEM(node->custom1,
+ CMP_NODE_TRACK_POSITION_RELATIVE_FRAME,
+ CMP_NODE_TRACK_POSITION_ABSOLUTE_FRAME)) {
uiItemR(layout, ptr, "frame_relative", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
}
@@ -111,9 +120,234 @@ class TrackPositionOperation : public NodeOperation {
void execute() override
{
- get_result("X").allocate_invalid();
- get_result("Y").allocate_invalid();
- get_result("Speed").allocate_invalid();
+ MovieTrackingTrack *track = get_movie_tracking_track();
+
+ if (!track) {
+ execute_invalid();
+ return;
+ }
+
+ const float2 current_marker_position = compute_marker_position_at_frame(track, get_frame());
+ const int2 size = get_size();
+
+ execute_position(track, current_marker_position, size);
+ execute_speed(track, current_marker_position, size);
+ }
+
+ void execute_position(MovieTrackingTrack *track, float2 current_marker_position, int2 size)
+ {
+ const bool should_compute_x = should_compute_output("X");
+ const bool should_compute_y = should_compute_output("Y");
+ if (!should_compute_x && !should_compute_y) {
+ return;
+ }
+
+ /* Compute the position relative to the reference marker position. Multiply by the size to get
+ * the position in pixel space. */
+ const float2 reference_marker_position = compute_reference_marker_position(track);
+ const float2 position = (current_marker_position - reference_marker_position) * float2(size);
+
+ if (should_compute_x) {
+ Result &result = get_result("X");
+ result.allocate_single_value();
+ result.set_float_value(position.x);
+ }
+
+ if (should_compute_y) {
+ Result &result = get_result("Y");
+ result.allocate_single_value();
+ result.set_float_value(position.y);
+ }
+ }
+
+ void execute_speed(MovieTrackingTrack *track, float2 current_marker_position, int2 size)
+ {
+ if (!should_compute_output("Speed")) {
+ return;
+ }
+
+ /* Compute the speed as the difference between the previous ma
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list