Compositor: Turn Keying Screen options to inputs

This patch turns the options of the Keying Screen node into inputs.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/137851
This commit is contained in:
Omar Emara
2025-04-22 15:57:46 +02:00
committed by Omar Emara
parent 685894b665
commit 8bb1ebb5f7
6 changed files with 97 additions and 8 deletions

View File

@@ -27,7 +27,7 @@
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 44
#define BLENDER_FILE_SUBVERSION 45
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and cancel loading the file, showing a warning to

View File

@@ -881,6 +881,11 @@ static void write_compositor_legacy_properties(bNodeTree &node_tree)
write_input_to_property_float_color("Spill Strength", 1, storage->uspillg);
write_input_to_property_float_color("Spill Strength", 2, storage->uspillb);
}
if (node->type_legacy == CMP_NODE_KEYINGSCREEN) {
NodeKeyingScreenData *storage = static_cast<NodeKeyingScreenData *>(node->storage);
write_input_to_property_float("Smoothness", storage->smoothness);
}
}
}

View File

@@ -3165,6 +3165,51 @@ static void do_version_color_spill_node_options_to_inputs_animation(bNodeTree *n
});
}
/* The options were converted into inputs. */
static void do_version_keying_screen_node_options_to_inputs(bNodeTree *node_tree, bNode *node)
{
NodeKeyingScreenData *storage = static_cast<NodeKeyingScreenData *>(node->storage);
if (!storage) {
return;
}
if (!blender::bke::node_find_socket(*node, SOCK_IN, "Smoothness")) {
bNodeSocket *input = blender::bke::node_add_static_socket(
*node_tree, *node, SOCK_IN, SOCK_FLOAT, PROP_FACTOR, "Smoothness", "Smoothness");
input->default_value_typed<bNodeSocketValueFloat>()->value = storage->smoothness;
}
}
/* The options were converted into inputs. */
static void do_version_keying_screen_node_options_to_inputs_animation(bNodeTree *node_tree,
bNode *node)
{
/* Compute the RNA path of the node. */
char escaped_node_name[sizeof(node->name) * 2 + 1];
BLI_str_escape(escaped_node_name, node->name, sizeof(escaped_node_name));
const std::string node_rna_path = fmt::format("nodes[\"{}\"]", escaped_node_name);
BKE_fcurves_id_cb(&node_tree->id, [&](ID * /*id*/, FCurve *fcurve) {
/* The FCurve does not belong to the node since its RNA path doesn't start with the node's RNA
* path. */
if (!blender::StringRef(fcurve->rna_path).startswith(node_rna_path)) {
return;
}
/* Change the RNA path of the FCurve from the old properties to the new inputs, adjusting the
* values of the FCurves frames when needed. */
char *old_rna_path = fcurve->rna_path;
if (BLI_str_endswith(fcurve->rna_path, "smoothness")) {
fcurve->rna_path = BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[0].default_value");
}
/* The RNA path was changed, free the old path. */
if (fcurve->rna_path != old_rna_path) {
MEM_freeN(old_rna_path);
}
});
}
static void do_version_viewer_shortcut(bNodeTree *node_tree)
{
LISTBASE_FOREACH_MUTABLE (bNode *, node, &node_tree->nodes) {
@@ -3905,6 +3950,19 @@ void do_versions_after_linking_400(FileData *fd, Main *bmain)
FOREACH_NODETREE_END;
}
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 45)) {
FOREACH_NODETREE_BEGIN (bmain, node_tree, id) {
if (node_tree->type == NTREE_COMPOSIT) {
LISTBASE_FOREACH (bNode *, node, &node_tree->nodes) {
if (node->type_legacy == CMP_NODE_KEYINGSCREEN) {
do_version_keying_screen_node_options_to_inputs_animation(node_tree, node);
}
}
}
}
FOREACH_NODETREE_END;
}
/**
* Always bump subversion in BKE_blender_version.h when adding versioning
* code here, and wrap it inside a MAIN_VERSION_FILE_ATLEAST check.
@@ -8763,6 +8821,19 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
FOREACH_NODETREE_END;
}
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 45)) {
FOREACH_NODETREE_BEGIN (bmain, node_tree, id) {
if (node_tree->type == NTREE_COMPOSIT) {
LISTBASE_FOREACH (bNode *, node, &node_tree->nodes) {
if (node->type_legacy == CMP_NODE_KEYINGSCREEN) {
do_version_keying_screen_node_options_to_inputs(node_tree, node);
}
}
}
}
FOREACH_NODETREE_END;
}
/* Always run this versioning (keep at the bottom of the function). Meshes are written with the
* legacy format which always needs to be converted to the new format on file load. To be moved
* to a subversion check in 5.0. */

View File

@@ -1489,7 +1489,7 @@ typedef struct TexNodeOutput {
typedef struct NodeKeyingScreenData {
char tracking_object[64];
float smoothness;
float smoothness DNA_DEPRECATED;
} NodeKeyingScreenData;
typedef struct NodeKeyingData {

View File

@@ -3993,6 +3993,9 @@ static const char node_input_limit_strength[] = "Limit Strength";
static const char node_input_use_spill_strength[] = "Use Spill Strength";
static const char node_input_spill_strength[] = "Spill Strength";
/* Smoothness node. */
static const char node_input_smoothness[] = "Smoothness";
/* --------------------------------------------------------------------
* White Balance Node.
*/
@@ -9729,9 +9732,12 @@ static void def_cmp_keyingscreen(BlenderRNA * /*brna*/, StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
prop = RNA_def_property(srna, "smoothness", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, nullptr, "smoothness");
RNA_def_property_float_funcs(prop,
"rna_node_property_to_input_getter<float, node_input_smoothness>",
"rna_node_property_to_input_setter<float, node_input_smoothness>",
nullptr);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Smoothness", "");
RNA_def_property_ui_text(prop, "Smoothness", "(Deprecated: Use Smoothness input instead.)");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}

View File

@@ -38,6 +38,13 @@ NODE_STORAGE_FUNCS(NodeKeyingScreenData)
static void cmp_node_keyingscreen_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Float>("Smoothness")
.default_value(0.0f)
.subtype(PROP_FACTOR)
.min(0.0f)
.max(1.0f)
.description("Specifies the smoothness of the keying screen");
b.add_output<decl::Color>("Screen").translation_context(BLT_I18NCONTEXT_ID_SCREEN);
}
@@ -46,7 +53,6 @@ static void node_composit_init_keyingscreen(const bContext *C, PointerRNA *ptr)
bNode *node = (bNode *)ptr->data;
NodeKeyingScreenData *data = MEM_callocN<NodeKeyingScreenData>(__func__);
data->smoothness = 0.0f;
node->storage = data;
const Scene *scene = CTX_data_scene(C);
@@ -76,8 +82,6 @@ static void node_composit_buts_keyingscreen(uiLayout *layout, bContext *C, Point
col = uiLayoutColumn(layout, true);
uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA);
}
uiItemR(layout, ptr, "smoothness", UI_ITEM_NONE, std::nullopt, ICON_NONE);
}
using namespace blender::compositor;
@@ -146,7 +150,10 @@ class KeyingScreenOperation : public NodeOperation {
* instability for low smoothness values, so we empirically choose 0.15 as a lower limit. */
float get_smoothness()
{
return math::interpolate(0.15f, 1.0f, node_storage(bnode()).smoothness);
return math::interpolate(
0.15f,
1.0f,
math::clamp(this->get_input("Smoothness").get_single_value_default(0.0f), 0.0f, 1.0f));
}
MovieClip *get_movie_clip()