Compositor: Turn ID Mask node options to inputs
This patch turns the options of the ID Mask node into inputs. Reference #137223. Pull Request: https://projects.blender.org/blender/blender/pulls/137905
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
|
||||
/* Blender file format version. */
|
||||
#define BLENDER_FILE_VERSION BLENDER_VERSION
|
||||
#define BLENDER_FILE_SUBVERSION 47
|
||||
#define BLENDER_FILE_SUBVERSION 48
|
||||
|
||||
/* 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
|
||||
|
||||
@@ -901,6 +901,11 @@ static void write_compositor_legacy_properties(bNodeTree &node_tree)
|
||||
write_input_to_property_float("Despill Strength", storage->despill_factor);
|
||||
write_input_to_property_float("Despill Balance", storage->despill_balance);
|
||||
}
|
||||
|
||||
if (node->type_legacy == CMP_NODE_ID_MASK) {
|
||||
write_input_to_property_short("Index", node->custom1);
|
||||
write_input_to_property_bool_short("Anti-Alias", node->custom2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3369,6 +3369,54 @@ static void do_version_keying_node_options_to_inputs_animation(bNodeTree *node_t
|
||||
});
|
||||
}
|
||||
|
||||
/* The options were converted into inputs. */
|
||||
static void do_version_id_mask_node_options_to_inputs(bNodeTree *node_tree, bNode *node)
|
||||
{
|
||||
if (!blender::bke::node_find_socket(*node, SOCK_IN, "Index")) {
|
||||
bNodeSocket *input = blender::bke::node_add_static_socket(
|
||||
*node_tree, *node, SOCK_IN, SOCK_INT, PROP_NONE, "Index", "Index");
|
||||
input->default_value_typed<bNodeSocketValueInt>()->value = node->custom1;
|
||||
}
|
||||
|
||||
if (!blender::bke::node_find_socket(*node, SOCK_IN, "Anti-Alias")) {
|
||||
bNodeSocket *input = blender::bke::node_add_static_socket(
|
||||
*node_tree, *node, SOCK_IN, SOCK_BOOLEAN, PROP_NONE, "Anti-Alias", "Anti-Alias");
|
||||
input->default_value_typed<bNodeSocketValueBoolean>()->value = bool(node->custom2);
|
||||
}
|
||||
}
|
||||
|
||||
/* The options were converted into inputs. */
|
||||
static void do_version_id_mask_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, "index")) {
|
||||
fcurve->rna_path = BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[1].default_value");
|
||||
}
|
||||
else if (BLI_str_endswith(fcurve->rna_path, "use_antialiasing")) {
|
||||
fcurve->rna_path = BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[2].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) {
|
||||
@@ -4135,6 +4183,19 @@ void do_versions_after_linking_400(FileData *fd, Main *bmain)
|
||||
FOREACH_NODETREE_END;
|
||||
}
|
||||
|
||||
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 48)) {
|
||||
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_ID_MASK) {
|
||||
do_version_id_mask_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.
|
||||
@@ -9038,6 +9099,19 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
|
||||
FOREACH_NODETREE_END;
|
||||
}
|
||||
|
||||
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 48)) {
|
||||
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_ID_MASK) {
|
||||
do_version_id_mask_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. */
|
||||
|
||||
@@ -4009,6 +4009,9 @@ static const char node_input_postprocess_feather_size[] = "Postprocess Feather S
|
||||
static const char node_input_despill_strength[] = "Despill Strength";
|
||||
static const char node_input_despill_balance[] = "Despill Balance";
|
||||
|
||||
/* ID Key node. */
|
||||
static const char node_input_index[] = "Index";
|
||||
|
||||
/* --------------------------------------------------------------------
|
||||
* White Balance Node.
|
||||
*/
|
||||
@@ -8239,14 +8242,25 @@ static void def_cmp_id_mask(BlenderRNA * /*brna*/, StructRNA *srna)
|
||||
PropertyRNA *prop;
|
||||
|
||||
prop = RNA_def_property(srna, "index", PROP_INT, PROP_NONE);
|
||||
RNA_def_property_int_sdna(prop, nullptr, "custom1");
|
||||
RNA_def_property_int_funcs(prop,
|
||||
"rna_node_property_to_input_getter<int, node_input_index>",
|
||||
"rna_node_property_to_input_setter<int, node_input_index>",
|
||||
nullptr);
|
||||
RNA_def_property_range(prop, 0, 32767);
|
||||
RNA_def_property_ui_text(prop, "Index", "Pass index number to convert to alpha");
|
||||
RNA_def_property_ui_text(
|
||||
prop,
|
||||
"Index",
|
||||
"Pass index number to convert to alpha. (Deprecated: Use Index input instead.)");
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
|
||||
prop = RNA_def_property(srna, "use_antialiasing", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, nullptr, "custom2", 0);
|
||||
RNA_def_property_ui_text(prop, "Anti-Aliasing", "Apply an anti-aliasing filter to the mask");
|
||||
RNA_def_property_boolean_funcs(prop,
|
||||
"rna_node_property_to_input_getter<bool, node_input_anti_alias>",
|
||||
"rna_node_property_to_input_setter<bool, node_input_anti_alias>");
|
||||
RNA_def_property_ui_text(
|
||||
prop,
|
||||
"Anti-Aliasing",
|
||||
"Apply an anti-aliasing filter to the mask. (Deprecated: Use Anti-Aliasing input instead.)");
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,18 +28,11 @@ namespace blender::nodes::node_composite_id_mask_cc {
|
||||
|
||||
static void cmp_node_idmask_declare(NodeDeclarationBuilder &b)
|
||||
{
|
||||
b.add_input<decl::Float>("ID value")
|
||||
.default_value(1.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.compositor_domain_priority(0);
|
||||
b.add_output<decl::Float>("Alpha");
|
||||
}
|
||||
b.add_input<decl::Float>("ID value").default_value(1.0f).min(0.0f).max(1.0f);
|
||||
b.add_input<decl::Int>("Index").default_value(0).min(0).compositor_expects_single_value();
|
||||
b.add_input<decl::Bool>("Anti-Alias").default_value(false).compositor_expects_single_value();
|
||||
|
||||
static void node_composit_buts_id_mask(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
|
||||
{
|
||||
uiItemR(layout, ptr, "index", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
|
||||
uiItemR(layout, ptr, "use_antialiasing", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
|
||||
b.add_output<decl::Float>("Alpha");
|
||||
}
|
||||
|
||||
using namespace blender::compositor;
|
||||
@@ -121,12 +114,12 @@ class IDMaskOperation : public NodeOperation {
|
||||
|
||||
int get_index()
|
||||
{
|
||||
return bnode().custom1;
|
||||
return math::max(0, this->get_input("Index").get_single_value_default(0));
|
||||
}
|
||||
|
||||
bool use_anti_aliasing()
|
||||
{
|
||||
return bnode().custom2 != 0;
|
||||
return this->get_input("Anti-Alias").get_single_value_default(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -149,7 +142,6 @@ void register_node_type_cmp_idmask()
|
||||
ntype.enum_name_legacy = "ID_MASK";
|
||||
ntype.nclass = NODE_CLASS_CONVERTER;
|
||||
ntype.declare = file_ns::cmp_node_idmask_declare;
|
||||
ntype.draw_buttons = file_ns::node_composit_buts_id_mask;
|
||||
ntype.get_compositor_operation = file_ns::get_compositor_operation;
|
||||
|
||||
blender::bke::node_register_type(ntype);
|
||||
|
||||
Reference in New Issue
Block a user