Compositor: Remove Offset from Scale node
This patch removes the translation Offset from the Scale node. The reasoning is that it is easy to insert a Translate node afterwards to perform any necessary translation. And since we are moving options to inputs, it doesn't seem worth it to provide those offsets as inputs in the process. Pull Request: https://projects.blender.org/blender/blender/pulls/138668
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
|
||||
/* Blender file format version. */
|
||||
#define BLENDER_FILE_VERSION BLENDER_VERSION
|
||||
#define BLENDER_FILE_SUBVERSION 69
|
||||
#define BLENDER_FILE_SUBVERSION 70
|
||||
|
||||
/* 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
|
||||
|
||||
@@ -3326,6 +3326,53 @@ static void do_version_bokeh_blur_node_options_to_inputs_animation(bNodeTree *no
|
||||
});
|
||||
}
|
||||
|
||||
/* The XY Offset option was removed. If enabled, the image is translated in relative space using X
|
||||
* and Y, so add a Translate node to achieve the same function. */
|
||||
static void do_version_scale_node_remove_translate(bNodeTree *node_tree)
|
||||
{
|
||||
LISTBASE_FOREACH_BACKWARD_MUTABLE (bNodeLink *, link, &node_tree->links) {
|
||||
if (link->fromnode->type_legacy != CMP_NODE_SCALE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (link->fromnode->custom1 != CMP_NODE_SCALE_RENDER_SIZE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const float x = link->fromnode->custom3;
|
||||
const float y = link->fromnode->custom4;
|
||||
if (x == 0.0f && y == 0.0f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bNode *translate_node = blender::bke::node_add_static_node(
|
||||
nullptr, *node_tree, CMP_NODE_TRANSLATE);
|
||||
translate_node->parent = link->fromnode->parent;
|
||||
translate_node->location[0] = link->fromnode->location[0] + link->fromnode->width + 20.0f;
|
||||
translate_node->location[1] = link->fromnode->location[1];
|
||||
static_cast<NodeTranslateData *>(translate_node->storage)->interpolation =
|
||||
static_cast<NodeScaleData *>(link->fromnode->storage)->interpolation;
|
||||
static_cast<NodeTranslateData *>(translate_node->storage)->relative = true;
|
||||
|
||||
bNodeSocket *translate_image_input = blender::bke::node_find_socket(
|
||||
*translate_node, SOCK_IN, "Image");
|
||||
bNodeSocket *translate_x_input = blender::bke::node_find_socket(*translate_node, SOCK_IN, "X");
|
||||
bNodeSocket *translate_y_input = blender::bke::node_find_socket(*translate_node, SOCK_IN, "Y");
|
||||
bNodeSocket *translate_image_output = blender::bke::node_find_socket(
|
||||
*translate_node, SOCK_OUT, "Image");
|
||||
|
||||
translate_x_input->default_value_typed<bNodeSocketValueFloat>()->value = x;
|
||||
translate_y_input->default_value_typed<bNodeSocketValueFloat>()->value = y;
|
||||
|
||||
version_node_add_link(
|
||||
*node_tree, *link->fromnode, *link->fromsock, *translate_node, *translate_image_input);
|
||||
version_node_add_link(
|
||||
*node_tree, *translate_node, *translate_image_output, *link->tonode, *link->tosock);
|
||||
|
||||
blender::bke::node_remove_link(node_tree, *link);
|
||||
}
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
@@ -5002,6 +5049,15 @@ void blo_do_versions_450(FileData * /*fd*/, Library * /*lib*/, Main *bmain)
|
||||
FOREACH_NODETREE_END;
|
||||
}
|
||||
|
||||
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 70)) {
|
||||
FOREACH_NODETREE_BEGIN (bmain, node_tree, id) {
|
||||
if (node_tree->type == NTREE_COMPOSIT) {
|
||||
do_version_scale_node_remove_translate(node_tree);
|
||||
}
|
||||
}
|
||||
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. */
|
||||
|
||||
@@ -8010,12 +8010,18 @@ static void def_cmp_scale(BlenderRNA * /*brna*/, StructRNA *srna)
|
||||
|
||||
prop = RNA_def_property(srna, "offset_x", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, nullptr, "custom3");
|
||||
RNA_def_property_ui_text(prop, "X Offset", "Offset image horizontally (factor of image size)");
|
||||
RNA_def_property_ui_text(prop,
|
||||
"X Offset",
|
||||
"Offset image horizontally (factor of image size). (Deprecated: Use a "
|
||||
"Translate node instead.)");
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
|
||||
prop = RNA_def_property(srna, "offset_y", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, nullptr, "custom4");
|
||||
RNA_def_property_ui_text(prop, "Y Offset", "Offset image vertically (factor of image size)");
|
||||
RNA_def_property_ui_text(
|
||||
prop,
|
||||
"Y Offset",
|
||||
"Offset image vertically (factor of image size). (Deprecated: Use Translate node instead.)");
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
|
||||
RNA_def_struct_sdna_from(srna, "NodeScaleData", "storage");
|
||||
|
||||
@@ -39,18 +39,10 @@ static void cmp_node_scale_declare(NodeDeclarationBuilder &b)
|
||||
{
|
||||
b.add_input<decl::Color>("Image")
|
||||
.default_value({1.0f, 1.0f, 1.0f, 1.0f})
|
||||
.compositor_realization_mode(CompositorInputRealizationMode::None)
|
||||
.compositor_domain_priority(0);
|
||||
b.add_input<decl::Float>("X")
|
||||
.default_value(1.0f)
|
||||
.min(0.0001f)
|
||||
.max(CMP_SCALE_MAX)
|
||||
.compositor_domain_priority(1);
|
||||
b.add_input<decl::Float>("Y")
|
||||
.default_value(1.0f)
|
||||
.min(0.0001f)
|
||||
.max(CMP_SCALE_MAX)
|
||||
.compositor_domain_priority(2);
|
||||
.compositor_realization_mode(CompositorInputRealizationMode::None);
|
||||
b.add_input<decl::Float>("X").default_value(1.0f).min(0.0001f).max(CMP_SCALE_MAX);
|
||||
b.add_input<decl::Float>("Y").default_value(1.0f).min(0.0001f).max(CMP_SCALE_MAX);
|
||||
|
||||
b.add_output<decl::Color>("Image");
|
||||
}
|
||||
|
||||
@@ -84,9 +76,6 @@ static void node_composit_buts_scale(uiLayout *layout, bContext * /*C*/, Pointer
|
||||
UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_EXPAND,
|
||||
std::nullopt,
|
||||
ICON_NONE);
|
||||
uiLayout *row = &layout->row(true);
|
||||
row->prop(ptr, "offset_x", UI_ITEM_R_SPLIT_EMPTY_NAME, "X", ICON_NONE);
|
||||
row->prop(ptr, "offset_y", UI_ITEM_R_SPLIT_EMPTY_NAME, "Y", ICON_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,10 +98,7 @@ class ScaleOperation : public NodeOperation {
|
||||
void execute_constant_size()
|
||||
{
|
||||
const float2 scale = this->get_scale();
|
||||
const math::AngleRadian rotation = 0.0f;
|
||||
const float2 translation = this->get_translation();
|
||||
const float3x3 transformation = math::from_loc_rot_scale<float3x3>(
|
||||
translation, rotation, scale);
|
||||
const float3x3 transformation = math::from_scale<float3x3>(scale);
|
||||
|
||||
const Result &input = this->get_input("Image");
|
||||
Result &output = this->get_result("Image");
|
||||
@@ -314,18 +300,6 @@ class ScaleOperation : public NodeOperation {
|
||||
return float2(math::max(scale.x, scale.y));
|
||||
}
|
||||
|
||||
float2 get_translation()
|
||||
{
|
||||
/* Only the render size option supports offset translation. */
|
||||
if (get_scale_method() != CMP_NODE_SCALE_RENDER_SIZE) {
|
||||
return float2(0.0f);
|
||||
}
|
||||
|
||||
/* Translate by the offset factor relative to the new size. */
|
||||
const float2 input_size = float2(get_input("Image").domain().size);
|
||||
return get_offset() * input_size * get_scale();
|
||||
}
|
||||
|
||||
bool is_variable_size()
|
||||
{
|
||||
/* Only relative scaling can be variable. */
|
||||
@@ -345,11 +319,6 @@ class ScaleOperation : public NodeOperation {
|
||||
{
|
||||
return static_cast<CMPNodeScaleRenderSizeMethod>(bnode().custom2);
|
||||
}
|
||||
|
||||
float2 get_offset()
|
||||
{
|
||||
return float2(bnode().custom3, bnode().custom4);
|
||||
}
|
||||
};
|
||||
|
||||
static NodeOperation *get_compositor_operation(Context &context, DNode node)
|
||||
|
||||
Reference in New Issue
Block a user