Compositor: Turn Pixelate node options into inputs
This patch turns the options of the Pixelate node into inputs. Reference #137223. Pull Request: https://projects.blender.org/blender/blender/pulls/137603
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
|
||||
/* Blender file format version. */
|
||||
#define BLENDER_FILE_VERSION BLENDER_VERSION
|
||||
#define BLENDER_FILE_SUBVERSION 31
|
||||
#define BLENDER_FILE_SUBVERSION 32
|
||||
|
||||
/* 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
|
||||
|
||||
@@ -777,6 +777,10 @@ static void write_compositor_legacy_properties(bNodeTree &node_tree)
|
||||
if (node->type_legacy == CMP_NODE_INPAINT) {
|
||||
write_input_to_property_int16("Size", node->custom2);
|
||||
}
|
||||
|
||||
if (node->type_legacy == CMP_NODE_PIXELATE) {
|
||||
write_input_to_property_int16("Size", node->custom1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2411,6 +2411,45 @@ static void do_version_inpaint_node_options_to_inputs_animation(bNodeTree *node_
|
||||
});
|
||||
}
|
||||
|
||||
/* The options were converted into inputs. */
|
||||
static void do_version_pixelate_node_options_to_inputs(bNodeTree *node_tree, bNode *node)
|
||||
{
|
||||
if (!blender::bke::node_find_socket(*node, SOCK_IN, "Size")) {
|
||||
bNodeSocket *input = blender::bke::node_add_static_socket(
|
||||
*node_tree, *node, SOCK_IN, SOCK_INT, PROP_NONE, "Size", "Size");
|
||||
input->default_value_typed<bNodeSocketValueInt>()->value = node->custom1;
|
||||
}
|
||||
}
|
||||
|
||||
/* The options were converted into inputs. */
|
||||
static void do_version_pixelate_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, "pixel_size")) {
|
||||
fcurve->rna_path = BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[1].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) {
|
||||
@@ -2982,6 +3021,19 @@ void do_versions_after_linking_400(FileData *fd, Main *bmain)
|
||||
FOREACH_NODETREE_END;
|
||||
}
|
||||
|
||||
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 32)) {
|
||||
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_PIXELATE) {
|
||||
do_version_pixelate_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.
|
||||
@@ -7671,6 +7723,19 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
|
||||
FOREACH_NODETREE_END;
|
||||
}
|
||||
|
||||
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 32)) {
|
||||
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_PIXELATE) {
|
||||
do_version_pixelate_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. */
|
||||
|
||||
@@ -9712,10 +9712,14 @@ static void def_cmp_pixelate(BlenderRNA * /*brna*/, StructRNA *srna)
|
||||
* exceed the underlying int16_t type. The size limit matches the maximum size used by blur
|
||||
* nodes. */
|
||||
prop = RNA_def_property(srna, "pixel_size", 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_size>",
|
||||
"rna_node_property_to_input_setter<int, node_input_size>",
|
||||
nullptr);
|
||||
RNA_def_property_range(prop, 1, 2048);
|
||||
RNA_def_property_int_default(prop, 1);
|
||||
RNA_def_property_ui_text(prop, "Pixel Size", "Pixel size of the output image");
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Pixel Size", "Pixel size of the output image. (Deprecated: Use Size input instead.)");
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
}
|
||||
|
||||
|
||||
@@ -26,19 +26,15 @@ namespace blender::nodes::node_composite_pixelate_cc {
|
||||
static void cmp_node_pixelate_declare(NodeDeclarationBuilder &b)
|
||||
{
|
||||
b.add_input<decl::Color>("Color").compositor_domain_priority(0);
|
||||
b.add_input<decl::Int>("Size")
|
||||
.default_value(1)
|
||||
.min(1)
|
||||
.description("The number of pixels that correspond to the same output pixel")
|
||||
.compositor_expects_single_value();
|
||||
|
||||
b.add_output<decl::Color>("Color");
|
||||
}
|
||||
|
||||
static void node_composit_init_pixelate(bNodeTree * /*ntree*/, bNode *node)
|
||||
{
|
||||
node->custom1 = 1;
|
||||
}
|
||||
|
||||
static void node_composit_buts_pixelate(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
|
||||
{
|
||||
uiItemR(layout, ptr, "pixel_size", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
|
||||
}
|
||||
|
||||
using namespace blender::compositor;
|
||||
|
||||
class PixelateOperation : public NodeOperation {
|
||||
@@ -115,7 +111,7 @@ class PixelateOperation : public NodeOperation {
|
||||
|
||||
float get_pixel_size()
|
||||
{
|
||||
return bnode().custom1;
|
||||
return math::max(1, this->get_input("Size").get_single_value_default(1));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -140,8 +136,6 @@ void register_node_type_cmp_pixelate()
|
||||
ntype.enum_name_legacy = "PIXELATE";
|
||||
ntype.nclass = NODE_CLASS_OP_FILTER;
|
||||
ntype.declare = file_ns::cmp_node_pixelate_declare;
|
||||
ntype.draw_buttons = file_ns::node_composit_buts_pixelate;
|
||||
ntype.initfunc = file_ns::node_composit_init_pixelate;
|
||||
ntype.get_compositor_operation = file_ns::get_compositor_operation;
|
||||
|
||||
blender::bke::node_register_type(ntype);
|
||||
|
||||
Reference in New Issue
Block a user