Compositor: Turn Bokeh Blur options to inputs
This patch turns the options of the Bokeh Blur node into inputs. Reference #137223. Pull Request: https://projects.blender.org/blender/blender/pulls/138664
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
|
||||
/* Blender file format version. */
|
||||
#define BLENDER_FILE_VERSION BLENDER_VERSION
|
||||
#define BLENDER_FILE_SUBVERSION 68
|
||||
#define BLENDER_FILE_SUBVERSION 69
|
||||
|
||||
/* 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
|
||||
|
||||
@@ -1022,6 +1022,10 @@ static void write_compositor_legacy_properties(bNodeTree &node_tree)
|
||||
if (node->type_legacy == CMP_NODE_ALPHAOVER) {
|
||||
write_input_to_property_bool_short("Straight Alpha", node->custom1);
|
||||
}
|
||||
|
||||
if (node->type_legacy == CMP_NODE_BOKEHBLUR) {
|
||||
write_input_to_property_bool_int16_flag("Extend Bounds", node->custom1, (1 << 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3286,6 +3286,46 @@ static void do_version_alpha_over_node_options_to_inputs_animation(bNodeTree *no
|
||||
});
|
||||
}
|
||||
|
||||
/* The options were converted into inputs. */
|
||||
static void do_version_bokeh_blur_node_options_to_inputs(bNodeTree *node_tree, bNode *node)
|
||||
{
|
||||
if (!blender::bke::node_find_socket(*node, SOCK_IN, "Extend Bounds")) {
|
||||
bNodeSocket *input = blender::bke::node_add_static_socket(
|
||||
*node_tree, *node, SOCK_IN, SOCK_BOOLEAN, PROP_NONE, "Extend Bounds", "Extend Bounds");
|
||||
input->default_value_typed<bNodeSocketValueBoolean>()->value = bool(node->custom1);
|
||||
}
|
||||
}
|
||||
|
||||
/* The options were converted into inputs. */
|
||||
static void do_version_bokeh_blur_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, "use_extended_bounds")) {
|
||||
fcurve->rna_path = BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[4].default_value");
|
||||
}
|
||||
|
||||
/* The RNA path was changed, free the old path. */
|
||||
if (fcurve->rna_path != old_rna_path) {
|
||||
MEM_freeN(old_rna_path);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* Turns all instances of "{" and "}" in a string into "{{" and "}}", escaping
|
||||
* them for strings that are processed with templates so that they don't
|
||||
* erroneously get interepreted as template expressions. */
|
||||
@@ -3889,6 +3929,19 @@ void do_versions_after_linking_450(FileData * /*fd*/, Main *bmain)
|
||||
FOREACH_NODETREE_END;
|
||||
}
|
||||
|
||||
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 69)) {
|
||||
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_BOKEHBLUR) {
|
||||
do_version_bokeh_blur_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.
|
||||
@@ -4936,6 +4989,19 @@ void blo_do_versions_450(FileData * /*fd*/, Library * /*lib*/, Main *bmain)
|
||||
}
|
||||
}
|
||||
|
||||
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 69)) {
|
||||
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_BOKEHBLUR) {
|
||||
do_version_bokeh_blur_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. */
|
||||
|
||||
@@ -4227,6 +4227,9 @@ static const char node_input_translation_direction[] = "Translation Direction";
|
||||
/* Alpha Over node. */
|
||||
static const char node_input_straight_alpha[] = "Straight Alpha";
|
||||
|
||||
/* Bokeh Blur node. */
|
||||
static const char node_input_extend_bounds[] = "Extend Bounds";
|
||||
|
||||
/* --------------------------------------------------------------------
|
||||
* White Balance Node.
|
||||
*/
|
||||
@@ -9712,9 +9715,14 @@ static void def_cmp_bokehblur(BlenderRNA * /*brna*/, StructRNA *srna)
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
|
||||
prop = RNA_def_property(srna, "use_extended_bounds", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, nullptr, "custom1", CMP_NODEFLAG_BLUR_EXTEND_BOUNDS);
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Extend Bounds", "Extend bounds of the input image to fully fit blurred image");
|
||||
RNA_def_property_boolean_funcs(
|
||||
prop,
|
||||
"rna_node_property_to_input_getter<bool, node_input_extend_bounds>",
|
||||
"rna_node_property_to_input_setter<bool, node_input_extend_bounds>");
|
||||
RNA_def_property_ui_text(prop,
|
||||
"Extend Bounds",
|
||||
"Extend bounds of the input image to fully fit blurred image. "
|
||||
"(Deprecated: Use Extend Bounds input instead.)");
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
|
||||
prop = RNA_def_property(srna, "blur_max", PROP_FLOAT, PROP_NONE);
|
||||
|
||||
@@ -24,28 +24,15 @@ namespace blender::nodes::node_composite_bokehblur_cc {
|
||||
|
||||
static void cmp_node_bokehblur_declare(NodeDeclarationBuilder &b)
|
||||
{
|
||||
b.add_input<decl::Color>("Image")
|
||||
.default_value({0.8f, 0.8f, 0.8f, 1.0f})
|
||||
.compositor_domain_priority(0);
|
||||
b.add_input<decl::Color>("Image").default_value({0.8f, 0.8f, 0.8f, 1.0f});
|
||||
b.add_input<decl::Color>("Bokeh")
|
||||
.default_value({1.0f, 1.0f, 1.0f, 1.0f})
|
||||
.compositor_realization_mode(CompositorInputRealizationMode::Transforms);
|
||||
b.add_input<decl::Float>("Size")
|
||||
.default_value(1.0f)
|
||||
.min(0.0f)
|
||||
.max(10.0f)
|
||||
.compositor_domain_priority(1);
|
||||
b.add_input<decl::Float>("Bounding box")
|
||||
.default_value(1.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.compositor_domain_priority(2);
|
||||
b.add_output<decl::Color>("Image");
|
||||
}
|
||||
b.add_input<decl::Float>("Size").default_value(1.0f).min(0.0f).max(10.0f);
|
||||
b.add_input<decl::Float>("Bounding box").default_value(1.0f).min(0.0f).max(1.0f);
|
||||
b.add_input<decl::Bool>("Extend Bounds").default_value(false).compositor_expects_single_value();
|
||||
|
||||
static void node_composit_buts_bokehblur(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
|
||||
{
|
||||
layout->prop(ptr, "use_extended_bounds", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
|
||||
b.add_output<decl::Color>("Image");
|
||||
}
|
||||
|
||||
using namespace blender::compositor;
|
||||
@@ -378,7 +365,7 @@ class BokehBlurOperation : public NodeOperation {
|
||||
|
||||
bool get_extend_bounds()
|
||||
{
|
||||
return bnode().custom1 & CMP_NODEFLAG_BLUR_EXTEND_BOUNDS;
|
||||
return this->get_input("Extend Bounds").get_single_value_default(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -403,7 +390,6 @@ void register_node_type_cmp_bokehblur()
|
||||
ntype.enum_name_legacy = "BOKEHBLUR";
|
||||
ntype.nclass = NODE_CLASS_OP_FILTER;
|
||||
ntype.declare = file_ns::cmp_node_bokehblur_declare;
|
||||
ntype.draw_buttons = file_ns::node_composit_buts_bokehblur;
|
||||
ntype.get_compositor_operation = file_ns::get_compositor_operation;
|
||||
|
||||
blender::bke::node_register_type(ntype);
|
||||
|
||||
Reference in New Issue
Block a user