From 4bf34d9591a30247e89fa670fa69df4e72a1b5cc Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 11 Dec 2024 21:06:41 +0100 Subject: [PATCH] Nodes: Simplify location storage, remove hidden offfsets Currently each node's position is stored in the coordinate space of its parent. To find the location of a node on the canvas, we have to apply the translation of each of its parents. Also, nodes have hidden "offset" values used while transforming frame nodes. Together, those made the system much more complicated than necessary, and they made the Python API ineffective. This commit removes usage of the offset values and moves nodes to be stored in the "global" space of the node canvas. It also resolves some weird behavior when resizing frame nodes, and fixes a few bugs. The change is forward compatible, so we still write files with nodes in the old parent-space format. In 5.0 the conversion when writing can be removed. The existing Python API also stays the same. A new "location_absolute" property gives node locations in global space, and changing the old property also moves the child nodes of frames. Resolves #92458, #72904. Pull Request: https://projects.blender.org/blender/blender/pulls/131335 --- .../blender/blenkernel/BKE_blender_version.h | 2 +- source/blender/blenkernel/BKE_node.hh | 4 - source/blender/blenkernel/BKE_node_runtime.hh | 2 +- .../intern/grease_pencil_convert_legacy.cc | 28 ++-- source/blender/blenkernel/intern/linestyle.cc | 12 +- source/blender/blenkernel/intern/material.cc | 24 +-- .../blenkernel/intern/mesh_legacy_convert.cc | 40 ++--- source/blender/blenkernel/intern/node.cc | 50 ++---- .../blenloader/intern/versioning_260.cc | 20 +-- .../blenloader/intern/versioning_280.cc | 86 +++++----- .../blenloader/intern/versioning_300.cc | 58 ++++--- .../blenloader/intern/versioning_400.cc | 155 ++++++++++-------- .../blenloader/intern/versioning_common.cc | 4 +- .../editors/curves/intern/curves_add.cc | 6 +- .../blender/editors/space_node/clipboard.cc | 4 +- .../editors/space_node/link_drag_search.cc | 6 +- source/blender/editors/space_node/node_add.cc | 10 +- .../blender/editors/space_node/node_draw.cc | 91 +++++----- .../blender/editors/space_node/node_edit.cc | 71 +++----- .../blender/editors/space_node/node_group.cc | 23 ++- .../blender/editors/space_node/node_intern.hh | 4 +- .../editors/space_node/node_relationships.cc | 10 +- .../editors/space_node/node_templates.cc | 6 +- .../transform/transform_convert_node.cc | 32 ++-- .../BlenderStrokeRenderer.cpp | 44 ++--- source/blender/io/collada/Materials.cpp | 4 +- source/blender/io/collada/collada_utils.cpp | 4 +- .../io/usd/intern/usd_light_convert.cc | 10 +- .../io/usd/intern/usd_reader_material.cc | 4 +- .../usd/intern/usd_reader_pointinstancer.cc | 26 +-- .../wavefront_obj/importer/obj_import_mtl.cc | 4 +- source/blender/makesdna/DNA_node_types.h | 8 +- .../blender/makesdna/intern/dna_rename_defs.h | 4 + .../blender/makesrna/intern/rna_nodetree.cc | 45 ++++- 34 files changed, 463 insertions(+), 438 deletions(-) diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index 7ac27fe8fa3..68755a5dea8 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -31,7 +31,7 @@ extern "C" { /* Blender file format version. */ #define BLENDER_FILE_VERSION BLENDER_VERSION -#define BLENDER_FILE_SUBVERSION 11 +#define BLENDER_FILE_SUBVERSION 12 /* 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 diff --git a/source/blender/blenkernel/BKE_node.hh b/source/blender/blenkernel/BKE_node.hh index 206241a4406..2079208db34 100644 --- a/source/blender/blenkernel/BKE_node.hh +++ b/source/blender/blenkernel/BKE_node.hh @@ -1557,10 +1557,6 @@ bool node_link_is_selected(const bNodeLink *link); void node_internal_relink(bNodeTree *ntree, bNode *node); -float2 node_to_view(const bNode *node, float2 loc); - -float2 node_from_view(const bNode *node, float2 view_loc); - void node_position_relative(bNode *from_node, const bNode *to_node, const bNodeSocket *from_sock, diff --git a/source/blender/blenkernel/BKE_node_runtime.hh b/source/blender/blenkernel/BKE_node_runtime.hh index a8776f6c18f..fe7a1ad128a 100644 --- a/source/blender/blenkernel/BKE_node_runtime.hh +++ b/source/blender/blenkernel/BKE_node_runtime.hh @@ -334,7 +334,7 @@ class bNodeRuntime : NonCopyable, NonMovable { */ /** Reserved size of the preview rect. */ short preview_xsize, preview_ysize = 0; - /** Entire bound-box (world-space). */ + /** Calculated bounding box of node in the view space of the node editor (including UI scale). */ rctf totr{}; /** Used at runtime when going through the tree. Initialize before use. */ diff --git a/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc b/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc index 3ae643fabfc..cbb3cc1ffbf 100644 --- a/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc +++ b/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc @@ -1208,31 +1208,31 @@ static bNodeTree *offset_radius_node_tree_add(ConversionData &conversion_data, L DATA_("Layer"), "", "NodeSocketString", NODE_INTERFACE_SOCKET_INPUT, nullptr); bNode *group_output = bke::node_add_node(nullptr, group, "NodeGroupOutput"); - group_output->locx = 800; - group_output->locy = 160; + group_output->location[0] = 800; + group_output->location[1] = 160; bNode *group_input = bke::node_add_node(nullptr, group, "NodeGroupInput"); - group_input->locx = 0; - group_input->locy = 160; + group_input->location[0] = 0; + group_input->location[1] = 160; bNode *set_curve_radius = bke::node_add_node(nullptr, group, "GeometryNodeSetCurveRadius"); - set_curve_radius->locx = 600; - set_curve_radius->locy = 160; + set_curve_radius->location[0] = 600; + set_curve_radius->location[1] = 160; bNode *named_layer_selection = bke::node_add_node( nullptr, group, "GeometryNodeInputNamedLayerSelection"); - named_layer_selection->locx = 200; - named_layer_selection->locy = 100; + named_layer_selection->location[0] = 200; + named_layer_selection->location[1] = 100; bNode *input_radius = bke::node_add_node(nullptr, group, "GeometryNodeInputRadius"); - input_radius->locx = 0; - input_radius->locy = 0; + input_radius->location[0] = 0; + input_radius->location[1] = 0; bNode *add = bke::node_add_node(nullptr, group, "ShaderNodeMath"); add->custom1 = NODE_MATH_ADD; - add->locx = 200; - add->locy = 0; + add->location[0] = 200; + add->location[1] = 0; bNode *clamp_radius = bke::node_add_node(nullptr, group, "ShaderNodeClamp"); - clamp_radius->locx = 400; - clamp_radius->locy = 0; + clamp_radius->location[0] = 400; + clamp_radius->location[1] = 0; bNodeSocket *sock_max = bke::node_find_socket(clamp_radius, SOCK_IN, "Max"); static_cast(sock_max->default_value)->value = FLT_MAX; diff --git a/source/blender/blenkernel/intern/linestyle.cc b/source/blender/blenkernel/intern/linestyle.cc index 2351a97c845..d504acec04a 100644 --- a/source/blender/blenkernel/intern/linestyle.cc +++ b/source/blender/blenkernel/intern/linestyle.cc @@ -1935,17 +1935,17 @@ void BKE_linestyle_default_shader(const bContext *C, FreestyleLineStyle *linesty nullptr, &linestyle->id, "stroke_shader", "ShaderNodeTree"); uv_along_stroke = blender::bke::node_add_static_node(C, ntree, SH_NODE_UVALONGSTROKE); - uv_along_stroke->locx = 0.0f; - uv_along_stroke->locy = 300.0f; + uv_along_stroke->location[0] = 0.0f; + uv_along_stroke->location[1] = 300.0f; uv_along_stroke->custom1 = 0; /* use_tips */ input_texture = blender::bke::node_add_static_node(C, ntree, SH_NODE_TEX_IMAGE); - input_texture->locx = 200.0f; - input_texture->locy = 300.0f; + input_texture->location[0] = 200.0f; + input_texture->location[1] = 300.0f; output_linestyle = blender::bke::node_add_static_node(C, ntree, SH_NODE_OUTPUT_LINESTYLE); - output_linestyle->locx = 400.0f; - output_linestyle->locy = 300.0f; + output_linestyle->location[0] = 400.0f; + output_linestyle->location[1] = 300.0f; output_linestyle->custom1 = MA_RAMP_BLEND; output_linestyle->custom2 = 0; /* use_clamp */ diff --git a/source/blender/blenkernel/intern/material.cc b/source/blender/blenkernel/intern/material.cc index fa35c868cd5..96553048beb 100644 --- a/source/blender/blenkernel/intern/material.cc +++ b/source/blender/blenkernel/intern/material.cc @@ -1999,10 +1999,10 @@ static void material_default_surface_init(Material *ma) output, blender::bke::node_find_socket(output, SOCK_IN, "Surface")); - principled->locx = 10.0f; - principled->locy = 300.0f; - output->locx = 300.0f; - output->locy = 300.0f; + principled->location[0] = 10.0f; + principled->location[1] = 300.0f; + output->location[0] = 300.0f; + output->location[1] = 300.0f; blender::bke::node_set_active(ntree, output); } @@ -2025,10 +2025,10 @@ static void material_default_volume_init(Material *ma) output, blender::bke::node_find_socket(output, SOCK_IN, "Volume")); - principled->locx = 10.0f; - principled->locy = 300.0f; - output->locx = 300.0f; - output->locy = 300.0f; + principled->location[0] = 10.0f; + principled->location[1] = 300.0f; + output->location[0] = 300.0f; + output->location[1] = 300.0f; blender::bke::node_set_active(ntree, output); } @@ -2050,10 +2050,10 @@ static void material_default_holdout_init(Material *ma) output, blender::bke::node_find_socket(output, SOCK_IN, "Surface")); - holdout->locx = 10.0f; - holdout->locy = 300.0f; - output->locx = 300.0f; - output->locy = 300.0f; + holdout->location[0] = 10.0f; + holdout->location[1] = 300.0f; + output->location[0] = 300.0f; + output->location[1] = 300.0f; blender::bke::node_set_active(ntree, output); } diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc b/source/blender/blenkernel/intern/mesh_legacy_convert.cc index 3ab649d4a46..5c6dbb62b29 100644 --- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc +++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc @@ -2142,19 +2142,19 @@ static bNodeTree *add_auto_smooth_node_tree(Main &bmain, Library *owner_library) angle_data.subtype = PROP_ANGLE; bNode *group_output = node_add_node(nullptr, group, "NodeGroupOutput"); - group_output->locx = 480.0f; - group_output->locy = -100.0f; + group_output->location[0] = 480.0f; + group_output->location[1] = -100.0f; bNode *group_input_angle = node_add_node(nullptr, group, "NodeGroupInput"); - group_input_angle->locx = -420.0f; - group_input_angle->locy = -300.0f; + group_input_angle->location[0] = -420.0f; + group_input_angle->location[1] = -300.0f; LISTBASE_FOREACH (bNodeSocket *, socket, &group_input_angle->outputs) { if (!STREQ(socket->identifier, "Socket_2")) { socket->flag |= SOCK_HIDDEN; } } bNode *group_input_mesh = node_add_node(nullptr, group, "NodeGroupInput"); - group_input_mesh->locx = -60.0f; - group_input_mesh->locy = -100.0f; + group_input_mesh->location[0] = -60.0f; + group_input_mesh->location[1] = -100.0f; LISTBASE_FOREACH (bNodeSocket *, socket, &group_input_mesh->outputs) { if (!STREQ(socket->identifier, "Socket_1")) { socket->flag |= SOCK_HIDDEN; @@ -2162,30 +2162,30 @@ static bNodeTree *add_auto_smooth_node_tree(Main &bmain, Library *owner_library) } bNode *shade_smooth_edge = node_add_node(nullptr, group, "GeometryNodeSetShadeSmooth"); shade_smooth_edge->custom1 = int16_t(bke::AttrDomain::Edge); - shade_smooth_edge->locx = 120.0f; - shade_smooth_edge->locy = -100.0f; + shade_smooth_edge->location[0] = 120.0f; + shade_smooth_edge->location[1] = -100.0f; bNode *shade_smooth_face = node_add_node(nullptr, group, "GeometryNodeSetShadeSmooth"); shade_smooth_face->custom1 = int16_t(bke::AttrDomain::Face); - shade_smooth_face->locx = 300.0f; - shade_smooth_face->locy = -100.0f; + shade_smooth_face->location[0] = 300.0f; + shade_smooth_face->location[1] = -100.0f; bNode *edge_angle = node_add_node(nullptr, group, "GeometryNodeInputMeshEdgeAngle"); - edge_angle->locx = -420.0f; - edge_angle->locy = -220.0f; + edge_angle->location[0] = -420.0f; + edge_angle->location[1] = -220.0f; bNode *edge_smooth = node_add_node(nullptr, group, "GeometryNodeInputEdgeSmooth"); - edge_smooth->locx = -60.0f; - edge_smooth->locy = -160.0f; + edge_smooth->location[0] = -60.0f; + edge_smooth->location[1] = -160.0f; bNode *face_smooth = node_add_node(nullptr, group, "GeometryNodeInputShadeSmooth"); - face_smooth->locx = -240.0f; - face_smooth->locy = -340.0f; + face_smooth->location[0] = -240.0f; + face_smooth->location[1] = -340.0f; bNode *boolean_and = node_add_node(nullptr, group, "FunctionNodeBooleanMath"); boolean_and->custom1 = NODE_BOOLEAN_MATH_AND; - boolean_and->locx = -60.0f; - boolean_and->locy = -220.0f; + boolean_and->location[0] = -60.0f; + boolean_and->location[1] = -220.0f; bNode *less_than_or_equal = node_add_node(nullptr, group, "FunctionNodeCompare"); static_cast(less_than_or_equal->storage)->operation = NODE_COMPARE_LESS_EQUAL; - less_than_or_equal->locx = -240.0f; - less_than_or_equal->locy = -180.0f; + less_than_or_equal->location[0] = -240.0f; + less_than_or_equal->location[1] = -180.0f; node_add_link(group, edge_angle, diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 0a52f6b8f79..c84931f4066 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -670,6 +670,18 @@ static void cleanup_legacy_sockets(bNodeTree *ntree) BLI_listbase_clear(&ntree->outputs_legacy); } +static void update_node_location_legacy(bNodeTree &ntree) +{ + for (bNode *node : ntree.all_nodes()) { + node->locx_legacy = node->location[0]; + node->locy_legacy = node->location[1]; + if (const bNode *parent = node->parent) { + node->locx_legacy -= parent->location[0]; + node->locy_legacy -= parent->location[1]; + } + } +} + } // namespace forward_compat static void write_node_socket_default_value(BlendWriter *writer, const bNodeSocket *sock) @@ -750,6 +762,10 @@ void node_tree_blend_write(BlendWriter *writer, bNodeTree *ntree) BKE_id_blend_write(writer, &ntree->id); BLO_write_string(writer, ntree->description); + if (!BLO_write_is_undo(writer)) { + forward_compat::update_node_location_legacy(*ntree); + } + for (bNode *node : ntree->all_nodes()) { if (ntree->type == NTREE_SHADER && node->type == SH_NODE_BSDF_HAIR_PRINCIPLED) { /* For Principeld Hair BSDF, also write to `node->custom1` for forward compatibility, because @@ -3080,48 +3096,18 @@ void node_internal_relink(bNodeTree *ntree, bNode *node) } } -float2 node_to_view(const bNode *node, const float2 loc) -{ - float2 view_loc = loc; - for (const bNode *node_iter = node; node_iter; node_iter = node_iter->parent) { - view_loc += float2(node_iter->locx, node_iter->locy); - } - return view_loc; -} - -float2 node_from_view(const bNode *node, const float2 view_loc) -{ - float2 loc = view_loc; - for (const bNode *node_iter = node; node_iter; node_iter = node_iter->parent) { - loc -= float2(node_iter->locx, node_iter->locy); - } - return loc; -} - void node_attach_node(bNodeTree *ntree, bNode *node, bNode *parent) { BLI_assert(parent->type == NODE_FRAME); BLI_assert(!node_is_parent_and_child(parent, node)); - - const float2 loc = node_to_view(node, {}); - node->parent = parent; BKE_ntree_update_tag_parent_change(ntree, node); - /* transform to parent space */ - const float2 new_loc = node_from_view(parent, loc); - node->locx = new_loc.x; - node->locy = new_loc.y; } void node_detach_node(bNodeTree *ntree, bNode *node) { if (node->parent) { BLI_assert(node->parent->type == NODE_FRAME); - - /* transform to view space */ - const float2 loc = node_to_view(node, {}); - node->locx = loc.x; - node->locy = loc.y; node->parent = nullptr; BKE_ntree_update_tag_parent_change(ntree, node); } @@ -3165,8 +3151,8 @@ void node_position_relative(bNode *from_node, offset_y -= U.widget_unit * tot_sock_idx; - from_node->locx = to_node->locx + offset_x; - from_node->locy = to_node->locy - offset_y; + from_node->location[0] = to_node->location[0] + offset_x; + from_node->location[1] = to_node->location[1] - offset_y; } void node_position_propagate(bNode *node) diff --git a/source/blender/blenloader/intern/versioning_260.cc b/source/blender/blenloader/intern/versioning_260.cc index 03eefa9998f..7ebceb85222 100644 --- a/source/blender/blenloader/intern/versioning_260.cc +++ b/source/blender/blenloader/intern/versioning_260.cc @@ -2313,10 +2313,10 @@ void blo_do_versions_260(FileData *fd, Library * /*lib*/, Main *bmain) num_inputs++; if (link->tonode) { - if (input_locx > link->tonode->locx - offsetx) { - input_locx = link->tonode->locx - offsetx; + if (input_locx > link->tonode->locx_legacy - offsetx) { + input_locx = link->tonode->locx_legacy - offsetx; } - input_locy += link->tonode->locy; + input_locy += link->tonode->locy_legacy; } } else { @@ -2332,10 +2332,10 @@ void blo_do_versions_260(FileData *fd, Library * /*lib*/, Main *bmain) num_outputs++; if (link->fromnode) { - if (output_locx < link->fromnode->locx + offsetx) { - output_locx = link->fromnode->locx + offsetx; + if (output_locx < link->fromnode->locx_legacy + offsetx) { + output_locx = link->fromnode->locx_legacy + offsetx; } - output_locy += link->fromnode->locy; + output_locy += link->fromnode->locy_legacy; } } else { @@ -2350,13 +2350,13 @@ void blo_do_versions_260(FileData *fd, Library * /*lib*/, Main *bmain) if (num_inputs > 0) { input_locy /= num_inputs; - input_node->locx = input_locx; - input_node->locy = input_locy; + input_node->locx_legacy = input_locx; + input_node->locy_legacy = input_locy; } if (num_outputs > 0) { output_locy /= num_outputs; - output_node->locx = output_locx; - output_node->locy = output_locy; + output_node->locx_legacy = output_locx; + output_node->locy_legacy = output_locy; } } FOREACH_NODETREE_END; diff --git a/source/blender/blenloader/intern/versioning_280.cc b/source/blender/blenloader/intern/versioning_280.cc index c47d0daad03..5892c30b970 100644 --- a/source/blender/blenloader/intern/versioning_280.cc +++ b/source/blender/blenloader/intern/versioning_280.cc @@ -665,8 +665,8 @@ static void do_versions_material_convert_legacy_blend_mode(bNodeTree *ntree, cha blender::bke::node_remove_link(ntree, link); bNode *add_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_ADD_SHADER); - add_node->locx = 0.5f * (fromnode->locx + tonode->locx); - add_node->locy = 0.5f * (fromnode->locy + tonode->locy); + add_node->locx_legacy = 0.5f * (fromnode->locx_legacy + tonode->locx_legacy); + add_node->locy_legacy = 0.5f * (fromnode->locy_legacy + tonode->locy_legacy); bNodeSocket *shader1_socket = static_cast(add_node->inputs.first); bNodeSocket *shader2_socket = static_cast(add_node->inputs.last); @@ -674,8 +674,8 @@ static void do_versions_material_convert_legacy_blend_mode(bNodeTree *ntree, cha bNode *transp_node = blender::bke::node_add_static_node( nullptr, ntree, SH_NODE_BSDF_TRANSPARENT); - transp_node->locx = add_node->locx; - transp_node->locy = add_node->locy - 110.0f; + transp_node->locx_legacy = add_node->locx_legacy; + transp_node->locy_legacy = add_node->locy_legacy - 110.0f; bNodeSocket *transp_socket = blender::bke::node_find_socket(transp_node, SOCK_OUT, "BSDF"); @@ -697,13 +697,13 @@ static void do_versions_material_convert_legacy_blend_mode(bNodeTree *ntree, cha /* If incoming link is from a closure socket, we need to convert it. */ if (fromsock->type == SOCK_SHADER) { - transp_node->locx = 0.33f * fromnode->locx + 0.66f * tonode->locx; - transp_node->locy = 0.33f * fromnode->locy + 0.66f * tonode->locy; + transp_node->locx_legacy = 0.33f * fromnode->locx_legacy + 0.66f * tonode->locx_legacy; + transp_node->locy_legacy = 0.33f * fromnode->locy_legacy + 0.66f * tonode->locy_legacy; bNode *shtorgb_node = blender::bke::node_add_static_node( nullptr, ntree, SH_NODE_SHADERTORGB); - shtorgb_node->locx = 0.66f * fromnode->locx + 0.33f * tonode->locx; - shtorgb_node->locy = 0.66f * fromnode->locy + 0.33f * tonode->locy; + shtorgb_node->locx_legacy = 0.66f * fromnode->locx_legacy + 0.33f * tonode->locx_legacy; + shtorgb_node->locy_legacy = 0.66f * fromnode->locy_legacy + 0.33f * tonode->locy_legacy; bNodeSocket *shader_socket = blender::bke::node_find_socket( shtorgb_node, SOCK_IN, "Shader"); @@ -713,8 +713,8 @@ static void do_versions_material_convert_legacy_blend_mode(bNodeTree *ntree, cha blender::bke::node_add_link(ntree, shtorgb_node, rgba_socket, transp_node, color_socket); } else { - transp_node->locx = 0.5f * (fromnode->locx + tonode->locx); - transp_node->locy = 0.5f * (fromnode->locy + tonode->locy); + transp_node->locx_legacy = 0.5f * (fromnode->locx_legacy + tonode->locx_legacy); + transp_node->locy_legacy = 0.5f * (fromnode->locy_legacy + tonode->locy_legacy); blender::bke::node_add_link(ntree, fromnode, fromsock, transp_node, color_socket); } @@ -1019,8 +1019,8 @@ static void displacement_node_insert(bNodeTree *ntree) /* Add displacement node. */ bNode *node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_DISPLACEMENT); - node->locx = 0.5f * (fromnode->locx + tonode->locx); - node->locy = 0.5f * (fromnode->locy + tonode->locy); + node->locx_legacy = 0.5f * (fromnode->locx_legacy + tonode->locx_legacy); + node->locy_legacy = 0.5f * (fromnode->locy_legacy + tonode->locy_legacy); bNodeSocket *scale_socket = blender::bke::node_find_socket(node, SOCK_IN, "Scale"); bNodeSocket *midlevel_socket = blender::bke::node_find_socket(node, SOCK_IN, "Midlevel"); @@ -1078,8 +1078,8 @@ static void square_roughness_node_insert(bNodeTree *ntree) /* Add `sqrt` node. */ bNode *node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); node->custom1 = NODE_MATH_POWER; - node->locx = 0.5f * (fromnode->locx + tonode->locx); - node->locy = 0.5f * (fromnode->locy + tonode->locy); + node->locx_legacy = 0.5f * (fromnode->locx_legacy + tonode->locx_legacy); + node->locy_legacy = 0.5f * (fromnode->locy_legacy + tonode->locy_legacy); /* Link to input and material output node. */ *version_cycles_node_socket_float_value(static_cast(node->inputs.last)) = 0.5f; @@ -1342,13 +1342,13 @@ static void update_vector_math_node_add_and_subtract_operators(bNodeTree *ntree) bNode *absNode = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_VECTOR_MATH); absNode->custom1 = NODE_VECTOR_MATH_ABSOLUTE; - absNode->locx = node->locx + node->width + 20.0f; - absNode->locy = node->locy; + absNode->locx_legacy = node->locx_legacy + node->width + 20.0f; + absNode->locy_legacy = node->locy_legacy; bNode *dotNode = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_VECTOR_MATH); dotNode->custom1 = NODE_VECTOR_MATH_DOT_PRODUCT; - dotNode->locx = absNode->locx + absNode->width + 20.0f; - dotNode->locy = absNode->locy; + dotNode->locx_legacy = absNode->locx_legacy + absNode->width + 20.0f; + dotNode->locy_legacy = absNode->locy_legacy; bNodeSocket *sockDotB = static_cast(BLI_findlink(&dotNode->inputs, 1)); bNodeSocket *sockDotOutValue = blender::bke::node_find_socket(dotNode, SOCK_OUT, "Value"); copy_v3_fl(version_cycles_node_socket_vector_value(sockDotB), 1 / 3.0f); @@ -1437,8 +1437,8 @@ static void update_vector_math_node_cross_product_operator(bNodeTree *ntree) bNode *normalizeNode = blender::bke::node_add_static_node( nullptr, ntree, SH_NODE_VECTOR_MATH); normalizeNode->custom1 = NODE_VECTOR_MATH_NORMALIZE; - normalizeNode->locx = node->locx + node->width + 20.0f; - normalizeNode->locy = node->locy; + normalizeNode->locx_legacy = node->locx_legacy + node->width + 20.0f; + normalizeNode->locy_legacy = node->locy_legacy; bNodeSocket *sockNormalizeOut = blender::bke::node_find_socket( normalizeNode, SOCK_OUT, "Vector"); @@ -1461,12 +1461,12 @@ static void update_vector_math_node_cross_product_operator(bNodeTree *ntree) bNode *lengthNode = blender::bke::node_add_static_node( nullptr, ntree, SH_NODE_VECTOR_MATH); lengthNode->custom1 = NODE_VECTOR_MATH_LENGTH; - lengthNode->locx = node->locx + node->width + 20.0f; + lengthNode->locx_legacy = node->locx_legacy + node->width + 20.0f; if (version_node_socket_is_used(sockOutVector)) { - lengthNode->locy = node->locy - lengthNode->height - 20.0f; + lengthNode->locy_legacy = node->locy_legacy - lengthNode->height - 20.0f; } else { - lengthNode->locy = node->locy; + lengthNode->locy_legacy = node->locy_legacy; } bNodeSocket *sockLengthOut = blender::bke::node_find_socket( lengthNode, SOCK_OUT, "Value"); @@ -1513,8 +1513,8 @@ static void update_vector_math_node_normalize_operator(bNodeTree *ntree) bNode *lengthNode = blender::bke::node_add_static_node( nullptr, ntree, SH_NODE_VECTOR_MATH); lengthNode->custom1 = NODE_VECTOR_MATH_LENGTH; - lengthNode->locx = node->locx + node->width + 20.0f; - lengthNode->locy = node->locy; + lengthNode->locx_legacy = node->locx_legacy + node->width + 20.0f; + lengthNode->locy_legacy = node->locy_legacy; bNodeSocket *sockLengthValue = blender::bke::node_find_socket( lengthNode, SOCK_OUT, "Value"); @@ -1604,8 +1604,8 @@ static void update_vector_math_node_average_operator(bNodeTree *ntree) bNode *normalizeNode = blender::bke::node_add_static_node( nullptr, ntree, SH_NODE_VECTOR_MATH); normalizeNode->custom1 = NODE_VECTOR_MATH_NORMALIZE; - normalizeNode->locx = node->locx + node->width + 20.0f; - normalizeNode->locy = node->locy; + normalizeNode->locx_legacy = node->locx_legacy + node->width + 20.0f; + normalizeNode->locy_legacy = node->locy_legacy; bNodeSocket *sockNormalizeOut = blender::bke::node_find_socket( normalizeNode, SOCK_OUT, "Vector"); @@ -1628,12 +1628,12 @@ static void update_vector_math_node_average_operator(bNodeTree *ntree) bNode *lengthNode = blender::bke::node_add_static_node( nullptr, ntree, SH_NODE_VECTOR_MATH); lengthNode->custom1 = NODE_VECTOR_MATH_LENGTH; - lengthNode->locx = node->locx + node->width + 20.0f; + lengthNode->locx_legacy = node->locx_legacy + node->width + 20.0f; if (version_node_socket_is_used(sockOutVector)) { - lengthNode->locy = node->locy - lengthNode->height - 20.0f; + lengthNode->locy_legacy = node->locy_legacy - lengthNode->height - 20.0f; } else { - lengthNode->locy = node->locy; + lengthNode->locy_legacy = node->locy_legacy; } bNodeSocket *sockLengthOut = blender::bke::node_find_socket( lengthNode, SOCK_OUT, "Value"); @@ -1767,12 +1767,12 @@ static void update_mapping_node_inputs_and_properties(bNodeTree *ntree) maximumNode = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_VECTOR_MATH); maximumNode->custom1 = NODE_VECTOR_MATH_MAXIMUM; if (mapping->flag & TEXMAP_CLIP_MAX) { - maximumNode->locx = node->locx + (node->width + 20.0f) * 2.0f; + maximumNode->locx_legacy = node->locx_legacy + (node->width + 20.0f) * 2.0f; } else { - maximumNode->locx = node->locx + node->width + 20.0f; + maximumNode->locx_legacy = node->locx_legacy + node->width + 20.0f; } - maximumNode->locy = node->locy; + maximumNode->locy_legacy = node->locy_legacy; bNodeSocket *sockMaximumB = static_cast( BLI_findlink(&maximumNode->inputs, 1)); copy_v3_v3(version_cycles_node_socket_vector_value(sockMaximumB), mapping->min); @@ -1800,8 +1800,8 @@ static void update_mapping_node_inputs_and_properties(bNodeTree *ntree) if (mapping->flag & TEXMAP_CLIP_MAX) { minimumNode = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_VECTOR_MATH); minimumNode->custom1 = NODE_VECTOR_MATH_MINIMUM; - minimumNode->locx = node->locx + node->width + 20.0f; - minimumNode->locy = node->locy; + minimumNode->locx_legacy = node->locx_legacy + node->width + 20.0f; + minimumNode->locy_legacy = node->locy_legacy; bNodeSocket *sockMinimumB = static_cast( BLI_findlink(&minimumNode->inputs, 1)); copy_v3_v3(version_cycles_node_socket_vector_value(sockMinimumB), mapping->max); @@ -1962,8 +1962,8 @@ static void update_voronoi_node_crackle(bNodeTree *ntree) texVoronoi->feature = SHD_VORONOI_F2; texVoronoi->distance = tex->distance; texVoronoi->dimensions = 3; - voronoiNode->locx = node->locx + node->width + 20.0f; - voronoiNode->locy = node->locy; + voronoiNode->locx_legacy = node->locx_legacy + node->width + 20.0f; + voronoiNode->locy_legacy = node->locy_legacy; bNodeSocket *sockVector = blender::bke::node_find_socket(node, SOCK_IN, "Vector"); bNodeSocket *sockScale = blender::bke::node_find_socket(node, SOCK_IN, "Scale"); @@ -2002,8 +2002,8 @@ static void update_voronoi_node_crackle(bNodeTree *ntree) bNode *subtractNode = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); subtractNode->custom1 = NODE_MATH_SUBTRACT; - subtractNode->locx = voronoiNode->locx + voronoiNode->width + 20.0f; - subtractNode->locy = voronoiNode->locy; + subtractNode->locx_legacy = voronoiNode->locx_legacy + voronoiNode->width + 20.0f; + subtractNode->locy_legacy = voronoiNode->locy_legacy; bNodeSocket *sockSubtractOutValue = blender::bke::node_find_socket( subtractNode, SOCK_OUT, "Value"); @@ -2097,8 +2097,8 @@ static void update_voronoi_node_square_distance(bNodeTree *ntree) { bNode *multiplyNode = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); multiplyNode->custom1 = NODE_MATH_MULTIPLY; - multiplyNode->locx = node->locx + node->width + 20.0f; - multiplyNode->locy = node->locy; + multiplyNode->locx_legacy = node->locx_legacy + node->width + 20.0f; + multiplyNode->locy_legacy = node->locy_legacy; bNodeSocket *sockValue = blender::bke::node_find_socket(multiplyNode, SOCK_OUT, "Value"); LISTBASE_FOREACH_BACKWARD_MUTABLE (bNodeLink *, link, &ntree->links) { @@ -2148,8 +2148,8 @@ static void update_noise_and_wave_distortion(bNodeTree *ntree) bNode *mulNode = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); mulNode->custom1 = NODE_MATH_MULTIPLY; - mulNode->locx = node->locx; - mulNode->locy = node->locy - 240.0f; + mulNode->locx_legacy = node->locx_legacy; + mulNode->locy_legacy = node->locy_legacy - 240.0f; mulNode->flag |= NODE_HIDDEN; bNodeSocket *mulSockA = static_cast(BLI_findlink(&mulNode->inputs, 0)); bNodeSocket *mulSockB = static_cast(BLI_findlink(&mulNode->inputs, 1)); diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index 8e8709376c5..a2c04552672 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -561,26 +561,26 @@ static bNodeTree *add_realize_node_tree(Main *bmain) "Geometry", "", "NodeSocketGeometry", NODE_INTERFACE_SOCKET_INPUT, nullptr); bNode *group_input = blender::bke::node_add_static_node(nullptr, node_tree, NODE_GROUP_INPUT); - group_input->locx = -400.0f; + group_input->locx_legacy = -400.0f; bNode *group_output = blender::bke::node_add_static_node(nullptr, node_tree, NODE_GROUP_OUTPUT); - group_output->locx = 500.0f; + group_output->locx_legacy = 500.0f; group_output->flag |= NODE_DO_OUTPUT; bNode *join = blender::bke::node_add_static_node(nullptr, node_tree, GEO_NODE_JOIN_GEOMETRY); - join->locx = group_output->locx - 175.0f; - join->locy = group_output->locy; + join->locx_legacy = group_output->locx_legacy - 175.0f; + join->locy_legacy = group_output->locy_legacy; bNode *conv = blender::bke::node_add_static_node( nullptr, node_tree, GEO_NODE_POINTS_TO_VERTICES); - conv->locx = join->locx - 175.0f; - conv->locy = join->locy - 70.0; + conv->locx_legacy = join->locx_legacy - 175.0f; + conv->locy_legacy = join->locy_legacy - 70.0; bNode *separate = blender::bke::node_add_static_node( nullptr, node_tree, GEO_NODE_SEPARATE_COMPONENTS); - separate->locx = join->locx - 350.0f; - separate->locy = join->locy + 50.0f; + separate->locx_legacy = join->locx_legacy - 350.0f; + separate->locy_legacy = join->locy_legacy + 50.0f; bNode *realize = blender::bke::node_add_static_node( nullptr, node_tree, GEO_NODE_REALIZE_INSTANCES); - realize->locx = separate->locx - 200.0f; - realize->locy = join->locy; + realize->locx_legacy = separate->locx_legacy - 200.0f; + realize->locy_legacy = join->locy_legacy; blender::bke::node_add_link(node_tree, group_input, @@ -697,8 +697,8 @@ static void version_geometry_nodes_replace_transfer_attribute_node(bNodeTree *nt nullptr, ntree, GEO_NODE_SAMPLE_NEAREST_SURFACE); sample_nearest_surface->parent = node->parent; sample_nearest_surface->custom1 = storage->data_type; - sample_nearest_surface->locx = node->locx; - sample_nearest_surface->locy = node->locy; + sample_nearest_surface->locx_legacy = node->locx_legacy; + sample_nearest_surface->locy_legacy = node->locy_legacy; static auto socket_remap = []() { Map map; map.add_new("Attribute", "Value"); @@ -729,8 +729,8 @@ static void version_geometry_nodes_replace_transfer_attribute_node(bNodeTree *nt sample_storage->data_type = storage->data_type; sample_storage->domain = int8_t(domain); sample_index->parent = node->parent; - sample_index->locx = node->locx + 25.0f; - sample_index->locy = node->locy; + sample_index->locx_legacy = node->locx_legacy + 25.0f; + sample_index->locy_legacy = node->locy_legacy; if (old_geometry_socket->link) { blender::bke::node_add_link( ntree, @@ -745,8 +745,8 @@ static void version_geometry_nodes_replace_transfer_attribute_node(bNodeTree *nt sample_nearest->parent = node->parent; sample_nearest->custom1 = storage->data_type; sample_nearest->custom2 = int8_t(domain); - sample_nearest->locx = node->locx - 25.0f; - sample_nearest->locy = node->locy; + sample_nearest->locx_legacy = node->locx_legacy - 25.0f; + sample_nearest->locy_legacy = node->locy_legacy; if (old_geometry_socket->link) { blender::bke::node_add_link( ntree, @@ -791,8 +791,8 @@ static void version_geometry_nodes_replace_transfer_attribute_node(bNodeTree *nt sample_storage->domain = storage->domain; sample_storage->clamp = 1; sample_index->parent = node->parent; - sample_index->locx = node->locx; - sample_index->locy = node->locy; + sample_index->locx_legacy = node->locx_legacy; + sample_index->locy_legacy = node->locy_legacy; const bool index_was_linked = blender::bke::node_find_socket(node, SOCK_IN, "Index")->link != nullptr; static auto socket_remap = []() { @@ -812,8 +812,8 @@ static void version_geometry_nodes_replace_transfer_attribute_node(bNodeTree *nt /* Add an index input node, since the new node doesn't use an implicit input. */ bNode *index = blender::bke::node_add_static_node(nullptr, ntree, GEO_NODE_INPUT_INDEX); index->parent = node->parent; - index->locx = node->locx - 25.0f; - index->locy = node->locy - 25.0f; + index->locx_legacy = node->locx_legacy - 25.0f; + index->locy_legacy = node->locy_legacy - 25.0f; blender::bke::node_add_link( ntree, index, @@ -869,10 +869,8 @@ static void version_geometry_nodes_primitive_uv_maps(bNodeTree &ntree) "GeometryNodeStoreNamedAttribute"); new_nodes.append(store_attribute_node); store_attribute_node->parent = node->parent; - store_attribute_node->locx = node->locx + 25; - store_attribute_node->locy = node->locy; - store_attribute_node->offsetx = node->offsetx; - store_attribute_node->offsety = node->offsety; + store_attribute_node->locx_legacy = node->locx_legacy + 25; + store_attribute_node->locy_legacy = node->locy_legacy; auto &storage = *MEM_cnew(__func__); store_attribute_node->storage = &storage; storage.domain = int8_t(blender::bke::AttrDomain::Corner); @@ -1000,8 +998,8 @@ static void version_geometry_nodes_extrude_smooth_propagation(bNodeTree &ntree) bNode &capture_node = version_node_add_empty(ntree, "GeometryNodeCaptureAttribute"); capture_node.parent = node->parent; - capture_node.locx = node->locx - 25; - capture_node.locy = node->locy; + capture_node.locx_legacy = node->locx_legacy - 25; + capture_node.locy_legacy = node->locy_legacy; new_nodes.append(&capture_node); auto *capture_node_storage = MEM_cnew(__func__); capture_node.storage = capture_node_storage; @@ -1018,8 +1016,8 @@ static void version_geometry_nodes_extrude_smooth_propagation(bNodeTree &ntree) bNode &is_smooth_node = version_node_add_empty(ntree, "GeometryNodeInputShadeSmooth"); is_smooth_node.parent = node->parent; - is_smooth_node.locx = capture_node.locx - 25; - is_smooth_node.locy = capture_node.locy; + is_smooth_node.locx_legacy = capture_node.locx_legacy - 25; + is_smooth_node.locy_legacy = capture_node.locy_legacy; bNodeSocket &is_smooth_out = version_node_add_socket( ntree, is_smooth_node, SOCK_OUT, "NodeSocketBool", "Smooth"); new_nodes.append(&is_smooth_node); @@ -1032,8 +1030,8 @@ static void version_geometry_nodes_extrude_smooth_propagation(bNodeTree &ntree) bNode &set_smooth_node = version_node_add_empty(ntree, "GeometryNodeSetShadeSmooth"); set_smooth_node.custom1 = int16_t(blender::bke::AttrDomain::Face); set_smooth_node.parent = node->parent; - set_smooth_node.locx = node->locx + 25; - set_smooth_node.locy = node->locy; + set_smooth_node.locx_legacy = node->locx_legacy + 25; + set_smooth_node.locy_legacy = node->locy_legacy; new_nodes.append(&set_smooth_node); bNodeSocket &set_smooth_node_geo_in = version_node_add_socket( ntree, set_smooth_node, SOCK_IN, "NodeSocketGeometry", "Geometry"); diff --git a/source/blender/blenloader/intern/versioning_400.cc b/source/blender/blenloader/intern/versioning_400.cc index 76ce47e9350..1397bf7ec9e 100644 --- a/source/blender/blenloader/intern/versioning_400.cc +++ b/source/blender/blenloader/intern/versioning_400.cc @@ -577,8 +577,8 @@ static void versioning_eevee_material_shadow_none(Material *material) bNode *new_output = blender::bke::node_add_node(nullptr, ntree, "ShaderNodeOutputMaterial"); new_output->custom1 = SHD_OUTPUT_EEVEE; new_output->parent = output_node->parent; - new_output->locx = output_node->locx; - new_output->locy = output_node->locy - output_node->height - 120; + new_output->locx_legacy = output_node->locx_legacy; + new_output->locy_legacy = output_node->locy_legacy - output_node->height - 120; auto copy_link = [&](const char *socket_name) { bNodeSocket *sock = blender::bke::node_find_socket(output_node, SOCK_IN, socket_name); @@ -605,8 +605,8 @@ static void versioning_eevee_material_shadow_none(Material *material) STRNCPY(mix_node->label, "Disable Shadow"); mix_node->flag |= NODE_HIDDEN; mix_node->parent = output_node->parent; - mix_node->locx = output_node->locx; - mix_node->locy = output_node->locy - output_node->height - 120; + mix_node->locx_legacy = output_node->locx_legacy; + mix_node->locy_legacy = output_node->locy_legacy - output_node->height - 120; bNodeSocket *mix_fac = static_cast(BLI_findlink(&mix_node->inputs, 0)); bNodeSocket *mix_in_1 = static_cast(BLI_findlink(&mix_node->inputs, 1)); bNodeSocket *mix_in_2 = static_cast(BLI_findlink(&mix_node->inputs, 2)); @@ -624,8 +624,8 @@ static void versioning_eevee_material_shadow_none(Material *material) bNode *lp_node = blender::bke::node_add_node(nullptr, ntree, "ShaderNodeLightPath"); lp_node->flag |= NODE_HIDDEN; lp_node->parent = output_node->parent; - lp_node->locx = output_node->locx; - lp_node->locy = mix_node->locy + 35; + lp_node->locx_legacy = output_node->locx_legacy; + lp_node->locy_legacy = mix_node->locy_legacy + 35; bNodeSocket *is_shadow = blender::bke::node_find_socket(lp_node, SOCK_OUT, "Is Shadow Ray"); blender::bke::node_add_link(ntree, lp_node, is_shadow, mix_node, mix_fac); /* Hide unconnected sockets for cleaner look. */ @@ -639,8 +639,8 @@ static void versioning_eevee_material_shadow_none(Material *material) bNode *bsdf_node = blender::bke::node_add_node(nullptr, ntree, "ShaderNodeBsdfTransparent"); bsdf_node->flag |= NODE_HIDDEN; bsdf_node->parent = output_node->parent; - bsdf_node->locx = output_node->locx; - bsdf_node->locy = mix_node->locy - 35; + bsdf_node->locx_legacy = output_node->locx_legacy; + bsdf_node->locy_legacy = mix_node->locy_legacy - 35; bNodeSocket *bsdf_out = blender::bke::node_find_socket(bsdf_node, SOCK_OUT, "BSDF"); blender::bke::node_add_link(ntree, bsdf_node, bsdf_out, mix_node, mix_in_2); } @@ -905,8 +905,8 @@ static bool versioning_eevee_material_blend_mode_settings(bNodeTree *ntree, floa math_node->custom1 = NODE_MATH_GREATER_THAN; math_node->flag |= NODE_HIDDEN; math_node->parent = to_node->parent; - math_node->locx = to_node->locx - math_node->width - 30; - math_node->locy = min_ff(to_node->locy, from_node->locy); + math_node->locx_legacy = to_node->locx_legacy - math_node->width - 30; + math_node->locy_legacy = min_ff(to_node->locy_legacy, from_node->locy_legacy); bNodeSocket *input_1 = static_cast(BLI_findlink(&math_node->inputs, 0)); bNodeSocket *input_2 = static_cast(BLI_findlink(&math_node->inputs, 1)); @@ -960,8 +960,8 @@ static void versioning_replace_splitviewer(bNodeTree *ntree) bNode *viewer_node = blender::bke::node_add_static_node(nullptr, ntree, CMP_NODE_VIEWER); /* Nodes are created stacked on top of each other, so separate them a bit. */ - viewer_node->locx = node->locx + node->width + viewer_node->width / 4.0f; - viewer_node->locy = node->locy; + viewer_node->locx_legacy = node->locx_legacy + node->width + viewer_node->width / 4.0f; + viewer_node->locy_legacy = node->locy_legacy; viewer_node->flag &= ~NODE_PREVIEW; bNodeSocket *split_out_socket = blender::bke::node_add_static_socket( @@ -1563,8 +1563,8 @@ static void version_refraction_depth_to_thickness_value(bNodeTree *ntree, float } bNode *value_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_VALUE); value_node->parent = node->parent; - value_node->locx = node->locx; - value_node->locy = node->locy - 160.0f; + value_node->locx_legacy = node->locx_legacy; + value_node->locy_legacy = node->locy_legacy - 160.0f; bNodeSocket *socket_value = blender::bke::node_find_socket(value_node, SOCK_OUT, "Value"); *version_cycles_node_socket_float_value(socket_value) = thickness; @@ -1611,8 +1611,8 @@ static void versioning_update_noise_texture_node(bNodeTree *ntree) bNode *clamp_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_CLAMP); clamp_node->parent = node->parent; clamp_node->custom1 = NODE_CLAMP_MINMAX; - clamp_node->locx = node->locx; - clamp_node->locy = node->locy - 300.0f; + clamp_node->locx_legacy = node->locx_legacy; + clamp_node->locy_legacy = node->locy_legacy - 300.0f; clamp_node->flag |= NODE_HIDDEN; bNodeSocket *clamp_socket_value = blender::bke::node_find_socket( clamp_node, SOCK_IN, "Value"); @@ -1706,8 +1706,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *min_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); min_node->parent = node->parent; min_node->custom1 = NODE_MATH_MINIMUM; - min_node->locx = node->locx; - min_node->locy = node->locy - 320.0f; + min_node->locx_legacy = node->locx_legacy; + min_node->locy_legacy = node->locy_legacy - 320.0f; min_node->flag |= NODE_HIDDEN; bNodeSocket *min_socket_A = static_cast(BLI_findlink(&min_node->inputs, 0)); bNodeSocket *min_socket_B = static_cast(BLI_findlink(&min_node->inputs, 1)); @@ -1716,8 +1716,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *sub1_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); sub1_node->parent = node->parent; sub1_node->custom1 = NODE_MATH_SUBTRACT; - sub1_node->locx = node->locx; - sub1_node->locy = node->locy - 360.0f; + sub1_node->locx_legacy = node->locx_legacy; + sub1_node->locy_legacy = node->locy_legacy - 360.0f; sub1_node->flag |= NODE_HIDDEN; bNodeSocket *sub1_socket_A = static_cast(BLI_findlink(&sub1_node->inputs, 0)); bNodeSocket *sub1_socket_B = static_cast(BLI_findlink(&sub1_node->inputs, 1)); @@ -1740,8 +1740,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *greater_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); greater_node->parent = node->parent; greater_node->custom1 = NODE_MATH_GREATER_THAN; - greater_node->locx = node->locx; - greater_node->locy = node->locy - 400.0f; + greater_node->locx_legacy = node->locx_legacy; + greater_node->locy_legacy = node->locy_legacy - 400.0f; greater_node->flag |= NODE_HIDDEN; bNodeSocket *greater_socket_A = static_cast( BLI_findlink(&greater_node->inputs, 0)); @@ -1763,8 +1763,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *clamp_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_CLAMP); clamp_node->parent = node->parent; clamp_node->custom1 = NODE_CLAMP_MINMAX; - clamp_node->locx = node->locx; - clamp_node->locy = node->locy + 40.0f; + clamp_node->locx_legacy = node->locx_legacy; + clamp_node->locy_legacy = node->locy_legacy + 40.0f; clamp_node->flag |= NODE_HIDDEN; bNodeSocket *clamp_socket_value = blender::bke::node_find_socket( clamp_node, SOCK_IN, "Value"); @@ -1776,8 +1776,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *mul_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); mul_node->parent = node->parent; mul_node->custom1 = NODE_MATH_MULTIPLY; - mul_node->locx = node->locx; - mul_node->locy = node->locy + 80.0f; + mul_node->locx_legacy = node->locx_legacy; + mul_node->locy_legacy = node->locy_legacy + 80.0f; mul_node->flag |= NODE_HIDDEN; bNodeSocket *mul_socket_A = static_cast(BLI_findlink(&mul_node->inputs, 0)); bNodeSocket *mul_socket_B = static_cast(BLI_findlink(&mul_node->inputs, 1)); @@ -1793,8 +1793,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) sub2_node->parent = node->parent; sub2_node->custom1 = NODE_MATH_SUBTRACT; sub2_node->custom2 = SHD_MATH_CLAMP; - sub2_node->locx = node->locx; - sub2_node->locy = node->locy + 120.0f; + sub2_node->locx_legacy = node->locx_legacy; + sub2_node->locy_legacy = node->locy_legacy + 120.0f; sub2_node->flag |= NODE_HIDDEN; bNodeSocket *sub2_socket_A = static_cast( BLI_findlink(&sub2_node->inputs, 0)); @@ -1806,8 +1806,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *add_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); add_node->parent = node->parent; add_node->custom1 = NODE_MATH_ADD; - add_node->locx = node->locx; - add_node->locy = node->locy + 160.0f; + add_node->locx_legacy = node->locx_legacy; + add_node->locy_legacy = node->locy_legacy + 160.0f; add_node->flag |= NODE_HIDDEN; bNodeSocket *add_socket_A = static_cast( BLI_findlink(&add_node->inputs, 0)); @@ -1855,8 +1855,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *mul_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); mul_node->parent = node->parent; mul_node->custom1 = NODE_MATH_MULTIPLY; - mul_node->locx = node->locx; - mul_node->locy = node->locy + 40.0f; + mul_node->locx_legacy = node->locx_legacy; + mul_node->locy_legacy = node->locy_legacy + 40.0f; mul_node->flag |= NODE_HIDDEN; bNodeSocket *mul_socket_A = static_cast( BLI_findlink(&mul_node->inputs, 0)); @@ -1873,8 +1873,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *add_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); add_node->parent = node->parent; add_node->custom1 = NODE_MATH_ADD; - add_node->locx = node->locx; - add_node->locy = node->locy + 80.0f; + add_node->locx_legacy = node->locx_legacy; + add_node->locy_legacy = node->locy_legacy + 80.0f; add_node->flag |= NODE_HIDDEN; bNodeSocket *add_socket_A = static_cast( BLI_findlink(&add_node->inputs, 0)); @@ -1930,8 +1930,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *max1_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); max1_node->parent = node->parent; max1_node->custom1 = NODE_MATH_MAXIMUM; - max1_node->locx = node->locx; - max1_node->locy = node->locy - 400.0f + locy_offset; + max1_node->locx_legacy = node->locx_legacy; + max1_node->locy_legacy = node->locy_legacy - 400.0f + locy_offset; max1_node->flag |= NODE_HIDDEN; bNodeSocket *max1_socket_A = static_cast(BLI_findlink(&max1_node->inputs, 0)); bNodeSocket *max1_socket_B = static_cast(BLI_findlink(&max1_node->inputs, 1)); @@ -1940,8 +1940,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *mul_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); mul_node->parent = node->parent; mul_node->custom1 = NODE_MATH_MULTIPLY; - mul_node->locx = node->locx; - mul_node->locy = node->locy - 360.0f + locy_offset; + mul_node->locx_legacy = node->locx_legacy; + mul_node->locy_legacy = node->locy_legacy - 360.0f + locy_offset; mul_node->flag |= NODE_HIDDEN; bNodeSocket *mul_socket_A = static_cast(BLI_findlink(&mul_node->inputs, 0)); bNodeSocket *mul_socket_B = static_cast(BLI_findlink(&mul_node->inputs, 1)); @@ -1950,8 +1950,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *pow_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); pow_node->parent = node->parent; pow_node->custom1 = NODE_MATH_POWER; - pow_node->locx = node->locx; - pow_node->locy = node->locy - 320.0f + locy_offset; + pow_node->locx_legacy = node->locx_legacy; + pow_node->locy_legacy = node->locy_legacy - 320.0f + locy_offset; pow_node->flag |= NODE_HIDDEN; bNodeSocket *pow_socket_A = static_cast(BLI_findlink(&pow_node->inputs, 0)); bNodeSocket *pow_socket_B = static_cast(BLI_findlink(&pow_node->inputs, 1)); @@ -1974,8 +1974,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *max2_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); max2_node->parent = node->parent; max2_node->custom1 = NODE_MATH_MAXIMUM; - max2_node->locx = node->locx; - max2_node->locy = node->locy - 440.0f + locy_offset; + max2_node->locx_legacy = node->locx_legacy; + max2_node->locy_legacy = node->locy_legacy - 440.0f + locy_offset; max2_node->flag |= NODE_HIDDEN; bNodeSocket *max2_socket_A = static_cast( BLI_findlink(&max2_node->inputs, 0)); @@ -2000,8 +2000,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *max2_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); max2_node->parent = node->parent; max2_node->custom1 = NODE_MATH_MAXIMUM; - max2_node->locx = node->locx; - max2_node->locy = node->locy - 360.0f + locy_offset; + max2_node->locx_legacy = node->locx_legacy; + max2_node->locy_legacy = node->locy_legacy - 360.0f + locy_offset; max2_node->flag |= NODE_HIDDEN; bNodeSocket *max2_socket_A = static_cast(BLI_findlink(&max2_node->inputs, 0)); bNodeSocket *max2_socket_B = static_cast(BLI_findlink(&max2_node->inputs, 1)); @@ -2010,8 +2010,8 @@ static void versioning_replace_musgrave_texture_node(bNodeTree *ntree) bNode *pow_node = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MATH); pow_node->parent = node->parent; pow_node->custom1 = NODE_MATH_POWER; - pow_node->locx = node->locx; - pow_node->locy = node->locy - 320.0f + locy_offset; + pow_node->locx_legacy = node->locx_legacy; + pow_node->locy_legacy = node->locy_legacy - 320.0f + locy_offset; pow_node->flag |= NODE_HIDDEN; bNodeSocket *pow_socket_A = static_cast(BLI_findlink(&pow_node->inputs, 0)); bNodeSocket *pow_socket_B = static_cast(BLI_findlink(&pow_node->inputs, 1)); @@ -2084,8 +2084,8 @@ static void version_principled_bsdf_subsurface(bNodeTree *ntree) if (subsurf->link || subsurf_col->link || base_col->link) { bNode *mix = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MIX); static_cast(mix->storage)->data_type = SOCK_RGBA; - mix->locx = node->locx - 170; - mix->locy = node->locy - 120; + mix->locx_legacy = node->locx_legacy - 170; + mix->locy_legacy = node->locy_legacy - 120; bNodeSocket *a_in = blender::bke::node_find_socket(mix, SOCK_IN, "A_Color"); bNodeSocket *b_in = blender::bke::node_find_socket(mix, SOCK_IN, "B_Color"); @@ -2211,8 +2211,8 @@ static void change_input_socket_to_rotation_type(bNodeTree &ntree, } bNode *convert = blender::bke::node_add_node(nullptr, &ntree, "FunctionNodeEulerToRotation"); convert->parent = node.parent; - convert->locx = node.locx - 40; - convert->locy = node.locy; + convert->locx_legacy = node.locx_legacy - 40; + convert->locy_legacy = node.locy_legacy; link->tonode = convert; link->tosock = blender::bke::node_find_socket(convert, SOCK_IN, "Euler"); @@ -2244,8 +2244,8 @@ static void change_output_socket_to_rotation_type(bNodeTree &ntree, } bNode *convert = blender::bke::node_add_node(nullptr, &ntree, "FunctionNodeRotationToEuler"); convert->parent = node.parent; - convert->locx = node.locx + 40; - convert->locy = node.locy; + convert->locx_legacy = node.locx_legacy + 40; + convert->locy_legacy = node.locy_legacy; link->fromnode = convert; link->fromsock = blender::bke::node_find_socket(convert, SOCK_OUT, "Euler"); @@ -2459,8 +2459,8 @@ static void remove_triangulate_node_min_size_input(bNodeTree *tree) tree, &corners_of_face, SOCK_OUT, SOCK_INT, PROP_NONE, "Corner Index", "Corner Index"); version_node_add_socket_if_not_exist( tree, &corners_of_face, SOCK_OUT, SOCK_INT, PROP_NONE, "Total", "Total"); - corners_of_face.locx = triangulate->locx - 200; - corners_of_face.locy = triangulate->locy - 50; + corners_of_face.locx_legacy = triangulate->locx_legacy - 200; + corners_of_face.locy_legacy = triangulate->locy_legacy - 50; corners_of_face.parent = triangulate->parent; LISTBASE_FOREACH (bNodeSocket *, socket, &corners_of_face.inputs) { socket->flag |= SOCK_HIDDEN; @@ -2482,8 +2482,8 @@ static void remove_triangulate_node_min_size_input(bNodeTree *tree) tree, &greater_or_equal, SOCK_IN, SOCK_INT, PROP_NONE, "B_INT", "B"); version_node_add_socket_if_not_exist( tree, &greater_or_equal, SOCK_OUT, SOCK_BOOLEAN, PROP_NONE, "Result", "Result"); - greater_or_equal.locx = triangulate->locx - 100; - greater_or_equal.locy = triangulate->locy - 50; + greater_or_equal.locx_legacy = triangulate->locx_legacy - 100; + greater_or_equal.locy_legacy = triangulate->locy_legacy - 50; greater_or_equal.parent = triangulate->parent; greater_or_equal.flag &= ~NODE_OPTIONS; version_node_add_link(*tree, @@ -2508,8 +2508,8 @@ static void remove_triangulate_node_min_size_input(bNodeTree *tree) tree, &boolean_and, SOCK_IN, SOCK_BOOLEAN, PROP_NONE, "Boolean_001", "Boolean"); version_node_add_socket_if_not_exist( tree, &boolean_and, SOCK_OUT, SOCK_BOOLEAN, PROP_NONE, "Boolean", "Boolean"); - boolean_and.locx = triangulate->locx - 75; - boolean_and.locy = triangulate->locy - 50; + boolean_and.locx_legacy = triangulate->locx_legacy - 75; + boolean_and.locy_legacy = triangulate->locy_legacy - 50; boolean_and.parent = triangulate->parent; boolean_and.flag &= ~NODE_OPTIONS; boolean_and.custom1 = NODE_BOOLEAN_MATH_AND; @@ -2591,8 +2591,8 @@ static void version_principled_bsdf_specular_tint(bNodeTree *ntree) /* Metallic Mix needs to be dynamically mixed. */ bNode *mix = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MIX); static_cast(mix->storage)->data_type = SOCK_RGBA; - mix->locx = node->locx - 270; - mix->locy = node->locy - 120; + mix->locx_legacy = node->locx_legacy - 270; + mix->locy_legacy = node->locy_legacy - 120; bNodeSocket *a_in = blender::bke::node_find_socket(mix, SOCK_IN, "A_Color"); bNodeSocket *b_in = blender::bke::node_find_socket(mix, SOCK_IN, "B_Color"); @@ -2623,8 +2623,8 @@ static void version_principled_bsdf_specular_tint(bNodeTree *ntree) if (specular_tint_sock->link || (metallic_mix_out && specular_tint_old > 0.0f)) { bNode *mix = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MIX); static_cast(mix->storage)->data_type = SOCK_RGBA; - mix->locx = node->locx - 170; - mix->locy = node->locy - 120; + mix->locx_legacy = node->locx_legacy - 170; + mix->locy_legacy = node->locy_legacy - 120; bNodeSocket *a_in = blender::bke::node_find_socket(mix, SOCK_IN, "A_Color"); bNodeSocket *b_in = blender::bke::node_find_socket(mix, SOCK_IN, "B_Color"); @@ -2951,8 +2951,8 @@ static void fix_geometry_nodes_object_info_scale(bNodeTree &ntree) bNode *absolute_value = blender::bke::node_add_node(nullptr, &ntree, "ShaderNodeVectorMath"); absolute_value->custom1 = NODE_VECTOR_MATH_ABSOLUTE; absolute_value->parent = node->parent; - absolute_value->locx = node->locx + 100; - absolute_value->locy = node->locy - 50; + absolute_value->locx_legacy = node->locx_legacy + 100; + absolute_value->locy_legacy = node->locy_legacy - 50; blender::bke::node_add_link(&ntree, node, scale, @@ -3226,8 +3226,8 @@ static void hide_simulation_node_skip_socket_value(Main &bmain) bNode &input_node = version_node_add_empty(*tree, "FunctionNodeInputBool"); input_node.parent = node->parent; - input_node.locx = node->locx - 25; - input_node.locy = node->locy; + input_node.locx_legacy = node->locx_legacy - 25; + input_node.locy_legacy = node->locy_legacy; NodeInputBool *input_node_storage = MEM_cnew(__func__); input_node.storage = input_node_storage; @@ -3273,6 +3273,23 @@ static void add_subsurf_node_limit_surface_option(Main &bmain) } } +static void version_node_locations_to_global(bNodeTree &ntree) +{ + LISTBASE_FOREACH (bNode *, node, &ntree.nodes) { + node->location[0] = node->locx_legacy; + node->location[1] = node->locy_legacy; + for (const bNode *parent = node->parent; parent; parent = parent->parent) { + node->location[0] += parent->locx_legacy; + node->location[1] += parent->locy_legacy; + } + + node->location[0] += node->offsetx_legacy; + node->location[1] += node->offsety_legacy; + node->offsetx_legacy = 0.0f; + node->offsety_legacy = 0.0f; + } +} + void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain) { if (!MAIN_VERSION_FILE_ATLEAST(bmain, 400, 1)) { @@ -5218,6 +5235,12 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain) } } + if (!MAIN_VERSION_FILE_ATLEAST(bmain, 404, 12)) { + LISTBASE_FOREACH (bNodeTree *, ntree, &bmain->nodetrees) { + version_node_locations_to_global(*ntree); + } + } + /* Always run this versioning; meshes are written with the legacy format which always needs to * be converted to the new format on file load. Can be moved to a subversion check in a larger * breaking release. */ diff --git a/source/blender/blenloader/intern/versioning_common.cc b/source/blender/blenloader/intern/versioning_common.cc index dedf1336555..ce8b39a5e86 100644 --- a/source/blender/blenloader/intern/versioning_common.cc +++ b/source/blender/blenloader/intern/versioning_common.cc @@ -431,8 +431,8 @@ void add_realize_instances_before_socket(bNodeTree *ntree, bNode *realize_node = blender::bke::node_add_static_node( nullptr, ntree, GEO_NODE_REALIZE_INSTANCES); realize_node->parent = node->parent; - realize_node->locx = node->locx - 100; - realize_node->locy = node->locy; + realize_node->locx_legacy = node->locx_legacy - 100; + realize_node->locy_legacy = node->locy_legacy; blender::bke::node_add_link(ntree, link->fromnode, link->fromsock, diff --git a/source/blender/editors/curves/intern/curves_add.cc b/source/blender/editors/curves/intern/curves_add.cc index 1b5689d9b02..aa2f6499c3e 100644 --- a/source/blender/editors/curves/intern/curves_add.cc +++ b/source/blender/editors/curves/intern/curves_add.cc @@ -100,9 +100,9 @@ void ensure_surface_deformation_node_exists(bContext &C, Object &curves_ob) group_output, static_cast(group_output->inputs.first)); - group_input->locx = -200; - group_output->locx = 200; - deform_node->locx = 0; + group_input->location[0] = -200; + group_output->location[0] = 200; + deform_node->location[0] = 0; ED_node_tree_propagate_change(&C, bmain, nmd.node_group); } diff --git a/source/blender/editors/space_node/clipboard.cc b/source/blender/editors/space_node/clipboard.cc index ced9bcdeca3..9074ea7a146 100644 --- a/source/blender/editors/space_node/clipboard.cc +++ b/source/blender/editors/space_node/clipboard.cc @@ -439,8 +439,8 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op) for (bNode *new_node : node_map.values()) { /* Skip the offset for parented nodes since the location is in parent space. */ if (new_node->parent == nullptr) { - new_node->locx += offset.x; - new_node->locy += offset.y; + new_node->location[0] += offset.x; + new_node->location[1] += offset.y; } } } diff --git a/source/blender/editors/space_node/link_drag_search.cc b/source/blender/editors/space_node/link_drag_search.cc index c337e03514c..5ac7ecc27d3 100644 --- a/source/blender/editors/space_node/link_drag_search.cc +++ b/source/blender/editors/space_node/link_drag_search.cc @@ -374,10 +374,10 @@ static void link_drag_search_exec_fn(bContext *C, void *arg1, void *arg2) BLI_assert(new_nodes.size() == 1); bNode *new_node = new_nodes.first(); - new_node->locx = storage.cursor.x / UI_SCALE_FAC; - new_node->locy = storage.cursor.y / UI_SCALE_FAC + 20; + new_node->location[0] = storage.cursor.x / UI_SCALE_FAC; + new_node->location[1] = storage.cursor.y / UI_SCALE_FAC + 20; if (storage.in_out() == SOCK_IN) { - new_node->locx -= new_node->width; + new_node->location[0] -= new_node->width; } bke::node_set_selected(new_node, true); diff --git a/source/blender/editors/space_node/node_add.cc b/source/blender/editors/space_node/node_add.cc index 986c83171f4..bb6431738d7 100644 --- a/source/blender/editors/space_node/node_add.cc +++ b/source/blender/editors/space_node/node_add.cc @@ -64,8 +64,8 @@ namespace blender::ed::space_node { static void position_node_based_on_mouse(bNode &node, const float2 &location) { - node.locx = location.x - NODE_DY * 1.5f / UI_SCALE_FAC; - node.locy = location.y + NODE_DY * 0.5f / UI_SCALE_FAC; + node.location[0] = location.x - NODE_DY * 1.5f / UI_SCALE_FAC; + node.location[1] = location.y + NODE_DY * 0.5f / UI_SCALE_FAC; } bNode *add_node(const bContext &C, const StringRef idname, const float2 &location) @@ -210,8 +210,8 @@ static int add_reroute_exec(bContext *C, wmOperator *op) const float2 insert_point = std::accumulate( cuts.values().begin(), cuts.values().end(), float2(0)) / cuts.size(); - reroute->locx = insert_point.x / UI_SCALE_FAC; - reroute->locy = insert_point.y / UI_SCALE_FAC; + reroute->location[0] = insert_point.x / UI_SCALE_FAC; + reroute->location[1] = insert_point.y / UI_SCALE_FAC; /* Attach the reroute node to frame nodes behind it. */ for (const int i : frame_nodes.index_range()) { @@ -718,7 +718,7 @@ static int node_add_file_modal(bContext *C, wmOperator *op, const wmEvent *event float stack_offset = 0.0f; for (bNode *node : data->nodes) { - node->locy -= stack_offset; + node->location[1] -= stack_offset; stack_offset += (node->runtime->totr.ymax - node->runtime->totr.ymin) * delta_factor; redraw = true; } diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 13b9b455466..a6fed64b0c6 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -364,27 +364,30 @@ static Array node_uiblocks_init(const bContext &C, const Span) { const nodes::LayoutDeclaration &decl = *item.decl; /* Round the node origin because text contents are always pixel-aligned. */ - const float2 loc = math::round(node_to_view(node, float2(0))); + const float2 loc = math::round(node_to_view(node.location)); uiLayout *layout = UI_block_layout(&block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, @@ -1220,11 +1220,8 @@ static void node_update_basis(const bContext &C, bNode &node, uiBlock &block) { - /* Get "global" coordinates. */ - float2 loc = node_to_view(node, float2(0)); /* Round the node origin because text contents are always pixel-aligned. */ - loc.x = round(loc.x); - loc.y = round(loc.y); + const float2 loc = math::round(node_to_view(node.location)); int dy = loc.y; @@ -1259,11 +1256,8 @@ static void node_update_hidden(bNode &node, uiBlock &block) { int totin = 0, totout = 0; - /* Get "global" coordinates. */ - float2 loc = node_to_view(node, float2(0)); /* Round the node origin because text contents are always pixel-aligned. */ - loc.x = round(loc.x); - loc.y = round(loc.y); + const float2 loc = math::round(node_to_view(node.location)); /* Calculate minimal radius. */ for (const bNodeSocket *socket : node.input_sockets()) { @@ -3873,11 +3867,18 @@ static float frame_node_label_height(const NodeFrame &frame_data) #define NODE_FRAME_MARGIN (1.5f * U.widget_unit) -/* XXX Does a bounding box update by iterating over all children. +/** + * Does a bounding box update by iterating over all children. * Not ideal to do this in every draw call, but doing as transform callback doesn't work, - * since the child node totr rects are not updated properly at that point. */ -static void frame_node_prepare_for_draw(bNode &node, Span nodes) + * since the frame node automatic size depends on the size of each node which is only calculated + * while drawing. + */ +static rctf calc_node_frame_dimensions(bNode &node) { + if (!node.is_frame()) { + return node.runtime->totr; + } + NodeFrame *data = (NodeFrame *)node.storage; const float margin = NODE_FRAME_MARGIN; @@ -3897,13 +3898,9 @@ static void frame_node_prepare_for_draw(bNode &node, Span nodes) /* For shrinking bounding box, initialize the rect from first child node. */ bool bbinit = (data->flag & NODE_FRAME_SHRINK); /* Fit bounding box to all children. */ - for (const bNode *tnode : nodes) { - if (tnode->parent != &node) { - continue; - } - + for (bNode *child : node.direct_children_in_frame()) { /* Add margin to node rect. */ - rctf noderect = tnode->runtime->totr; + rctf noderect = calc_node_frame_dimensions(*child); noderect.xmin -= margin; noderect.xmax += margin; noderect.ymin -= margin; @@ -3921,19 +3918,20 @@ static void frame_node_prepare_for_draw(bNode &node, Span nodes) } /* Now adjust the frame size from view-space bounding box. */ - const float2 offset = node_from_view(node, {rect.xmin, rect.ymax}); - node.offsetx = offset.x; - node.offsety = offset.y; - const float2 max = node_from_view(node, {rect.xmax, rect.ymin}); - node.width = max.x - node.offsetx; - node.height = -max.y + node.offsety; + const float2 min = node_from_view({rect.xmin, rect.ymin}); + const float2 max = node_from_view({rect.xmax, rect.ymax}); + node.location[0] = min.x; + node.location[1] = max.y; + node.width = max.x - min.x; + node.height = max.y - min.y; node.runtime->totr = rect; + return rect; } static void reroute_node_prepare_for_draw(bNode &node) { - const float2 loc = node_to_view(node, float2(0)); + const float2 loc = node_to_view(node.location); /* When the node is hidden, the input and output socket are both in the same place. */ node.input_socket(0).runtime->location = loc; @@ -3979,12 +3977,9 @@ static void node_update_nodetree(const bContext &C, } } - /* Now calculate the size of frame nodes, which can depend on the size of other nodes. - * Update nodes in reverse, so children sizes get updated before parents. */ - for (int i = nodes.size() - 1; i >= 0; i--) { - if (nodes[i]->is_frame()) { - frame_node_prepare_for_draw(*nodes[i], nodes); - } + /* Now calculate the size of frame nodes, which can depend on the size of other nodes. */ + for (bNode *frame : ntree.root_frames()) { + calc_node_frame_dimensions(*frame); } } diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc index a26ea108e86..6396a856070 100644 --- a/source/blender/editors/space_node/node_edit.cc +++ b/source/blender/editors/space_node/node_edit.cc @@ -603,10 +603,10 @@ void ED_node_shader_default(const bContext *C, ID *id) blender::bke::node_find_socket(output, SOCK_IN, "Surface")); } - shader->locx = 10.0f; - shader->locy = 300.0f; - output->locx = 300.0f; - output->locy = 300.0f; + shader->location[0] = 10.0f; + shader->location[1] = 300.0f; + output->location[0] = 300.0f; + output->location[1] = 300.0f; blender::bke::node_set_active(ntree, output); BKE_ntree_update_main_tree(bmain, ntree, nullptr); } @@ -630,12 +630,12 @@ void ED_node_composit_default(const bContext *C, Scene *sce) nullptr, &sce->id, "Compositing Nodetree", ntreeType_Composite->idname); bNode *out = blender::bke::node_add_static_node(C, sce->nodetree, CMP_NODE_COMPOSITE); - out->locx = 200.0f; - out->locy = 200.0f; + out->location[0] = 200.0f; + out->location[1] = 200.0f; bNode *in = blender::bke::node_add_static_node(C, sce->nodetree, CMP_NODE_R_LAYERS); - in->locx = -200.0f; - in->locy = 200.0f; + in->location[0] = -200.0f; + in->location[1] = 200.0f; blender::bke::node_set_active(sce->nodetree, in); /* Links from color to color. */ @@ -659,12 +659,12 @@ void ED_node_texture_default(const bContext *C, Tex *tex) nullptr, &tex->id, "Texture Nodetree", ntreeType_Texture->idname); bNode *out = blender::bke::node_add_static_node(C, tex->nodetree, TEX_NODE_OUTPUT); - out->locx = 300.0f; - out->locy = 300.0f; + out->location[0] = 300.0f; + out->location[1] = 300.0f; bNode *in = blender::bke::node_add_static_node(C, tex->nodetree, TEX_NODE_CHECKER); - in->locx = 10.0f; - in->locy = 300.0f; + in->location[0] = 10.0f; + in->location[1] = 300.0f; blender::bke::node_set_active(tex->nodetree, in); bNodeSocket *fromsock = (bNodeSocket *)in->outputs.first; @@ -915,7 +915,6 @@ static bool socket_is_occluded(const float2 &location, struct NodeSizeWidget { float mxstart, mystart; float oldlocx, oldlocy; - float oldoffsetx, oldoffsety; float oldwidth, oldheight; int directions; }; @@ -931,10 +930,8 @@ static void node_resize_init( nsw->mystart = cursor.y; /* store old */ - nsw->oldlocx = node->locx; - nsw->oldlocy = node->locy; - nsw->oldoffsetx = node->offsetx; - nsw->oldoffsety = node->offsety; + nsw->oldlocx = node->location[0]; + nsw->oldlocy = node->location[1]; nsw->oldwidth = node->width; nsw->oldheight = node->height; nsw->directions = dir; @@ -954,10 +951,8 @@ static void node_resize_exit(bContext *C, wmOperator *op, bool cancel) bNode *node = bke::node_get_active(snode->edittree); NodeSizeWidget *nsw = (NodeSizeWidget *)op->customdata; - node->locx = nsw->oldlocx; - node->locy = nsw->oldlocy; - node->offsetx = nsw->oldoffsetx; - node->offsety = nsw->oldoffsety; + node->location[0] = nsw->oldlocx; + node->location[1] = nsw->oldlocy; node->width = nsw->oldwidth; node->height = nsw->oldheight; } @@ -1019,9 +1014,9 @@ static int node_resize_modal(bContext *C, wmOperator *op, const wmEvent *event) if (snap_to_grid) { dx = nearest_node_grid_coord(dx); } - node->locx = nsw->oldlocx + dx; - CLAMP(node->locx, locmax - widthmax, locmax - widthmin); - *pwidth = locmax - node->locx; + node->location[0] = nsw->oldlocx + dx; + CLAMP(node->location[0], locmax - widthmax, locmax - widthmin); + *pwidth = locmax - node->location[0]; } } @@ -1032,35 +1027,15 @@ static int node_resize_modal(bContext *C, wmOperator *op, const wmEvent *event) if (nsw->directions & NODE_RESIZE_TOP) { float locmin = nsw->oldlocy - nsw->oldheight; - node->locy = nsw->oldlocy + dy; - CLAMP(node->locy, locmin + heightmin, locmin + heightmax); - node->height = node->locy - locmin; + node->location[1] = nsw->oldlocy + dy; + CLAMP(node->location[1], locmin + heightmin, locmin + heightmax); + node->height = node->location[1] - locmin; } if (nsw->directions & NODE_RESIZE_BOTTOM) { node->height = nsw->oldheight - dy; CLAMP(node->height, heightmin, heightmax); } } - - if (node->type == NODE_FRAME) { - /* Keep the offset symmetric around center point. */ - if (nsw->directions & NODE_RESIZE_LEFT) { - node->locx = nsw->oldlocx + 0.5f * dx; - node->offsetx = nsw->oldoffsetx + 0.5f * dx; - } - if (nsw->directions & NODE_RESIZE_RIGHT) { - node->locx = nsw->oldlocx + 0.5f * dx; - node->offsetx = nsw->oldoffsetx - 0.5f * dx; - } - if (nsw->directions & NODE_RESIZE_TOP) { - node->locy = nsw->oldlocy + 0.5f * dy; - node->offsety = nsw->oldoffsety + 0.5f * dy; - } - if (nsw->directions & NODE_RESIZE_BOTTOM) { - node->locy = nsw->oldlocy + 0.5f * dy; - node->offsety = nsw->oldoffsety - 0.5f * dy; - } - } } ED_region_tag_redraw(region); @@ -1207,7 +1182,7 @@ static bool cursor_isect_multi_input_socket(const float2 &cursor, const bNodeSoc { const float node_socket_height = node_socket_calculate_height(socket); const float2 location = socket.runtime->location; - /* `.xmax = socket->locx + NODE_SOCKSIZE * 5.5f` + /* `.xmax = socket->location[0] + NODE_SOCKSIZE * 5.5f` * would be the same behavior as for regular sockets. * But keep it smaller because for multi-input socket you * sometimes want to drag the link to the other side, if you may diff --git a/source/blender/editors/space_node/node_group.cc b/source/blender/editors/space_node/node_group.cc index 5c47e44e168..4fc4b4ce73d 100644 --- a/source/blender/editors/space_node/node_group.cc +++ b/source/blender/editors/space_node/node_group.cc @@ -321,8 +321,8 @@ static void node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode) } if (!node->parent) { - node->locx += gnode->locx; - node->locy += gnode->locy; + node->location[0] += gnode->location[0]; + node->location[1] += gnode->location[1]; } node->flag |= NODE_SELECT; @@ -557,8 +557,8 @@ static bool node_group_separate_selected( } if (!newnode->parent) { - newnode->locx += offset.x; - newnode->locy += offset.y; + newnode->location[0] += offset.x; + newnode->location[1] += offset.y; } } if (!make_copy) { @@ -820,8 +820,7 @@ static void get_min_max_of_nodes(const Span nodes, INIT_MINMAX2(min, max); for (const bNode *node : nodes) { - const float2 node_offset = {node->offsetx, node->offsety}; - float2 loc = bke::node_to_view(node, node_offset); + float2 loc(node->location); math::min_max(loc, min, max); if (use_size) { loc.x += node->width; @@ -955,13 +954,13 @@ static void node_group_make_insert_selected(const bContext &C, return node; } bNode *output_node = bke::node_add_static_node(&C, &group, NODE_GROUP_OUTPUT); - output_node->locx = real_max[0] - center[0] + 50.0f; + output_node->location[0] = real_max[0] - center[0] + 50.0f; return output_node; }(); /* Create new group input node for easier organization of the new nodes inside the group. */ bNode *input_node = bke::node_add_static_node(&C, &group, NODE_GROUP_INPUT); - input_node->locx = real_min[0] - center[0] - 200.0f; + input_node->location[0] = real_min[0] - center[0] - 200.0f; struct InputSocketInfo { /* The unselected node the original link came from. */ @@ -1124,8 +1123,8 @@ static void node_group_make_insert_selected(const bContext &C, /* move nodes in the group to the center */ for (bNode *node : nodes_to_move) { if (!node->parent) { - node->locx -= center[0]; - node->locy -= center[1]; + node->location[0] -= center[0]; + node->location[1] -= center[1]; } } @@ -1226,8 +1225,8 @@ static bNode *node_group_make_from_nodes(const bContext &C, bNode *gnode = bke::node_add_node(&C, &ntree, ntype); gnode->id = (ID *)ngroup; - gnode->locx = 0.5f * (min[0] + max[0]); - gnode->locy = 0.5f * (min[1] + max[1]); + gnode->location[0] = 0.5f * (min[0] + max[0]); + gnode->location[1] = 0.5f * (min[1] + max[1]); node_group_make_insert_selected(C, ntree, gnode, nodes_to_group); diff --git a/source/blender/editors/space_node/node_intern.hh b/source/blender/editors/space_node/node_intern.hh index c4c65df4cfd..b84b7c10dee 100644 --- a/source/blender/editors/space_node/node_intern.hh +++ b/source/blender/editors/space_node/node_intern.hh @@ -180,9 +180,9 @@ Array tree_draw_order_calc_nodes_reversed(bNodeTree &ntree); void node_set_cursor(wmWindow &win, ARegion ®ion, SpaceNode &snode, const float2 &cursor); /* DPI scaled coords */ -float2 node_to_view(const bNode &node, const float2 &co); +float2 node_to_view(const float2 &co); void node_to_updated_rect(const bNode &node, rctf &r_rect); -float2 node_from_view(const bNode &node, const float2 &co); +float2 node_from_view(const float2 &co); /* `node_ops.cc` */ diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc index 9e94a3996df..c2a611ac9ca 100644 --- a/source/blender/editors/space_node/node_relationships.cc +++ b/source/blender/editors/space_node/node_relationships.cc @@ -334,7 +334,7 @@ static void snode_autoconnect(SpaceNode &snode, const bool allow_multiple, const /* Sort nodes left to right. */ std::sort(sorted_nodes.begin(), sorted_nodes.end(), [](const bNode *a, const bNode *b) { - return a->locx < b->locx; + return a->location[0] < b->location[0]; }); // int numlinks = 0; /* UNUSED */ @@ -705,7 +705,7 @@ static void position_viewer_node(bNodeTree &tree, new_viewer_position = main_candidate; } - const float2 old_position = float2(viewer_node.locx, viewer_node.locy) * UI_SCALE_FAC; + const float2 old_position = float2(viewer_node.location) * UI_SCALE_FAC; if (old_position.x > node_to_view.runtime->totr.xmax) { if (BLI_rctf_inside_rctf(®ion_bounds, &viewer_node.runtime->totr)) { /* Measure distance from right edge of the node to view and the left edge of the @@ -728,8 +728,8 @@ static void position_viewer_node(bNodeTree &tree, } } - viewer_node.locx = new_viewer_position->x / UI_SCALE_FAC; - viewer_node.locy = new_viewer_position->y / UI_SCALE_FAC; + viewer_node.location[0] = new_viewer_position->x / UI_SCALE_FAC; + viewer_node.location[1] = new_viewer_position->y / UI_SCALE_FAC; viewer_node.parent = nullptr; } @@ -2818,7 +2818,7 @@ static int node_insert_offset_modal(bContext *C, wmOperator *op, const wmEvent * clamped_duration, 0.0f, 1.0f, NODE_INSOFS_ANIM_DURATION) - BLI_easing_cubic_ease_in_out( prev_duration, 0.0f, 1.0f, NODE_INSOFS_ANIM_DURATION)); - node->locx += offset_step; + node->location[0] += offset_step; redraw = true; } } diff --git a/source/blender/editors/space_node/node_templates.cc b/source/blender/editors/space_node/node_templates.cc index d457e8d91bd..864db968627 100644 --- a/source/blender/editors/space_node/node_templates.cc +++ b/source/blender/editors/space_node/node_templates.cc @@ -238,10 +238,8 @@ static void node_socket_add_replace(const bContext *C, node_from = bke::node_add_static_node(C, ntree, type); if (node_prev != nullptr) { /* If we're replacing existing node, use its location. */ - node_from->locx = node_prev->locx; - node_from->locy = node_prev->locy; - node_from->offsetx = node_prev->offsetx; - node_from->offsety = node_prev->offsety; + node_from->location[0] = node_prev->location[0]; + node_from->location[1] = node_prev->location[1]; } else { sock_from_tmp = (bNodeSocket *)BLI_findlink(&node_from->outputs, item->socket_index); diff --git a/source/blender/editors/transform/transform_convert_node.cc b/source/blender/editors/transform/transform_convert_node.cc index 65cd1914a78..adb309e01aa 100644 --- a/source/blender/editors/transform/transform_convert_node.cc +++ b/source/blender/editors/transform/transform_convert_node.cc @@ -17,6 +17,7 @@ #include "BKE_context.hh" #include "BKE_node.hh" +#include "BKE_node_runtime.hh" #include "ED_node.hh" @@ -49,9 +50,7 @@ static void create_transform_data_for_node(TransData &td, const float dpi_fac) { /* Account for parents (nested nodes). */ - const float2 node_offset = {node.offsetx, node.offsety}; - float2 loc = bke::node_to_view(&node, math::round(node_offset)); - loc *= dpi_fac; + float2 loc = float2(node.location) * dpi_fac; /* Use top-left corner as the transform origin for nodes. */ /* Weirdo - but the node system is a mix of free 2d elements and DPI sensitive UI. */ @@ -186,6 +185,17 @@ static void node_snap_grid_apply(TransInfo *t) } } +static void move_child_nodes(bNode &node, const float2 &delta) +{ + for (bNode *child : node.direct_children_in_frame()) { + child->location[0] += delta.x; + child->location[1] += delta.y; + if (child->is_frame()) { + move_child_nodes(*child, delta); + } + } +} + static void flushTransNodes(TransInfo *t) { const float dpi_fac = UI_SCALE_FAC; @@ -226,18 +236,18 @@ static void flushTransNodes(TransInfo *t) TransData2D *td2d = &tc->data_2d[i]; bNode *node = static_cast(td->extra); - float2 loc; - add_v2_v2v2(loc, td2d->loc, offset); + float2 loc = float2(td2d->loc) + offset; /* Weirdo - but the node system is a mix of free 2d elements and DPI sensitive UI. */ loc /= dpi_fac; - /* Account for parents (nested nodes). */ - const float2 node_offset = {node->offsetx, node->offsety}; - const float2 new_node_location = loc - math::round(node_offset); - const float2 location = bke::node_from_view(node->parent, new_node_location); - node->locx = location.x; - node->locy = location.y; + if (node->is_frame()) { + const float2 delta = loc - float2(node->location); + move_child_nodes(*node, delta); + } + + node->location[0] = loc.x; + node->location[1] = loc.y; } /* Handle intersection with noodles. */ diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp index 3d27f709d08..70e6197c740 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp @@ -235,60 +235,60 @@ Material *BlenderStrokeRenderer::GetStrokeShader(Main *bmain, ma->blend_method = MA_BM_HASHED; bNode *input_attr_color = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_ATTRIBUTE); - input_attr_color->locx = 0.0f; - input_attr_color->locy = -200.0f; + input_attr_color->location[0] = 0.0f; + input_attr_color->location[1] = -200.0f; storage = (NodeShaderAttribute *)input_attr_color->storage; STRNCPY(storage->name, "Color"); bNode *mix_rgb_color = blender::bke::node_add_static_node( nullptr, ntree, SH_NODE_MIX_RGB_LEGACY); mix_rgb_color->custom1 = MA_RAMP_BLEND; // Mix - mix_rgb_color->locx = 200.0f; - mix_rgb_color->locy = -200.0f; + mix_rgb_color->location[0] = 200.0f; + mix_rgb_color->location[1] = -200.0f; tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_color->inputs, 0); // Fac toptr = RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock); RNA_float_set(&toptr, "default_value", 0.0f); bNode *input_attr_alpha = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_ATTRIBUTE); - input_attr_alpha->locx = 400.0f; - input_attr_alpha->locy = 300.0f; + input_attr_alpha->location[0] = 400.0f; + input_attr_alpha->location[1] = 300.0f; storage = (NodeShaderAttribute *)input_attr_alpha->storage; STRNCPY(storage->name, "Alpha"); bNode *mix_rgb_alpha = blender::bke::node_add_static_node( nullptr, ntree, SH_NODE_MIX_RGB_LEGACY); mix_rgb_alpha->custom1 = MA_RAMP_BLEND; // Mix - mix_rgb_alpha->locx = 600.0f; - mix_rgb_alpha->locy = 300.0f; + mix_rgb_alpha->location[0] = 600.0f; + mix_rgb_alpha->location[1] = 300.0f; tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_alpha->inputs, 0); // Fac toptr = RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, tosock); RNA_float_set(&toptr, "default_value", 0.0f); bNode *shader_emission = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_EMISSION); - shader_emission->locx = 400.0f; - shader_emission->locy = -200.0f; + shader_emission->location[0] = 400.0f; + shader_emission->location[1] = -200.0f; bNode *input_light_path = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_LIGHT_PATH); - input_light_path->locx = 400.0f; - input_light_path->locy = 100.0f; + input_light_path->location[0] = 400.0f; + input_light_path->location[1] = 100.0f; bNode *mix_shader_color = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MIX_SHADER); - mix_shader_color->locx = 600.0f; - mix_shader_color->locy = -100.0f; + mix_shader_color->location[0] = 600.0f; + mix_shader_color->location[1] = -100.0f; bNode *shader_transparent = blender::bke::node_add_static_node( nullptr, ntree, SH_NODE_BSDF_TRANSPARENT); - shader_transparent->locx = 600.0f; - shader_transparent->locy = 100.0f; + shader_transparent->location[0] = 600.0f; + shader_transparent->location[1] = 100.0f; bNode *mix_shader_alpha = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_MIX_SHADER); - mix_shader_alpha->locx = 800.0f; - mix_shader_alpha->locy = 100.0f; + mix_shader_alpha->location[0] = 800.0f; + mix_shader_alpha->location[1] = 100.0f; bNode *output_material = blender::bke::node_add_static_node( nullptr, ntree, SH_NODE_OUTPUT_MATERIAL); - output_material->locx = 1000.0f; - output_material->locy = 100.0f; + output_material->location[0] = 1000.0f; + output_material->location[1] = 100.0f; fromsock = (bNodeSocket *)BLI_findlink(&input_attr_color->outputs, 0); // Color tosock = (bNodeSocket *)BLI_findlink(&mix_rgb_color->inputs, 1); // Color1 @@ -393,8 +393,8 @@ Material *BlenderStrokeRenderer::GetStrokeShader(Main *bmain, // add new UV Map node bNode *input_uvmap = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_UVMAP); - input_uvmap->locx = node->locx - 200.0f; - input_uvmap->locy = node->locy; + input_uvmap->location[0] = node->location[0] - 200.0f; + input_uvmap->location[1] = node->location[1]; NodeShaderUVMap *storage = (NodeShaderUVMap *)input_uvmap->storage; if (node->custom1 & 1) { // use_tips STRNCPY(storage->uv_map, uvNames[1]); diff --git a/source/blender/io/collada/Materials.cpp b/source/blender/io/collada/Materials.cpp index 1f32a378b6f..7963618f004 100644 --- a/source/blender/io/collada/Materials.cpp +++ b/source/blender/io/collada/Materials.cpp @@ -110,8 +110,8 @@ bNode *MaterialNode::add_node(int node_type, int locx, int locy, std::string lab if (label.length() > 0) { STRNCPY(node->label, label.c_str()); } - node->locx = locx; - node->locy = locy; + node->location[0] = locx; + node->location[1] = locy; node->flag |= NODE_SELECT; } node_map[label] = node; diff --git a/source/blender/io/collada/collada_utils.cpp b/source/blender/io/collada/collada_utils.cpp index 88bcb832a1c..6eb3ce02e8b 100644 --- a/source/blender/io/collada/collada_utils.cpp +++ b/source/blender/io/collada/collada_utils.cpp @@ -1123,8 +1123,8 @@ static bNode *bc_add_node( if (label.length() > 0) { STRNCPY(node->label, label.c_str()); } - node->locx = locx; - node->locy = locy; + node->location[0] = locx; + node->location[1] = locy; node->flag |= NODE_SELECT; } return node; diff --git a/source/blender/io/usd/intern/usd_light_convert.cc b/source/blender/io/usd/intern/usd_light_convert.cc index abbe112ce3e..c5bbc38a5ef 100644 --- a/source/blender/io/usd/intern/usd_light_convert.cc +++ b/source/blender/io/usd/intern/usd_light_convert.cc @@ -192,8 +192,8 @@ static bNode *append_node(bNode *dst_node, dst_node, bke::node_find_socket(dst_node, SOCK_IN, in_sock)); - src_node->locx = dst_node->locx - offset; - src_node->locy = dst_node->locy; + src_node->location[0] = dst_node->location[0] - offset; + src_node->location[1] = dst_node->location[1]; return src_node; } @@ -421,7 +421,7 @@ void dome_light_to_world_material(const USDImportParams ¶ms, } else { /* Move existing node out of the way. */ - node->locy += 300; + node->location[1] += 300; } } @@ -434,8 +434,8 @@ void dome_light_to_world_material(const USDImportParams ¶ms, return; } - output->locx = 300.0f; - output->locy = 300.0f; + output->location[0] = 300.0f; + output->location[1] = 300.0f; } if (!bgshader) { diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index ee5bdbbb91c..b988b1958fd 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -136,8 +136,8 @@ static bNode *add_node( bNode *new_node = blender::bke::node_add_static_node(C, ntree, type); if (new_node) { - new_node->locx = locx; - new_node->locy = locy; + new_node->location[0] = locx; + new_node->location[1] = locy; } return new_node; diff --git a/source/blender/io/usd/intern/usd_reader_pointinstancer.cc b/source/blender/io/usd/intern/usd_reader_pointinstancer.cc index 60531f08ca2..3c5143d4b29 100644 --- a/source/blender/io/usd/intern/usd_reader_pointinstancer.cc +++ b/source/blender/io/usd/intern/usd_reader_pointinstancer.cc @@ -169,40 +169,40 @@ void USDPointInstancerReader::read_object_data(Main *bmain, const double motionS ntree->tree_interface.add_socket( "Geometry", "", "NodeSocketGeometry", NODE_INTERFACE_SOCKET_INPUT, nullptr); bNode *group_input = bke::node_add_static_node(nullptr, ntree, NODE_GROUP_INPUT); - group_input->locx = -400.0f; + group_input->location[0] = -400.0f; bNode *group_output = bke::node_add_static_node(nullptr, ntree, NODE_GROUP_OUTPUT); - group_output->locx = 500.0f; + group_output->location[0] = 500.0f; group_output->flag |= NODE_DO_OUTPUT; bNode *instance_on_points_node = bke::node_add_static_node( nullptr, ntree, GEO_NODE_INSTANCE_ON_POINTS); - instance_on_points_node->locx = 300.0f; + instance_on_points_node->location[0] = 300.0f; bNodeSocket *socket = bke::node_find_socket(instance_on_points_node, SOCK_IN, "Pick Instance"); socket->default_value_typed()->value = true; bNode *mask_attrib_node = add_input_named_attrib_node(ntree, "mask", CD_PROP_BOOL); - mask_attrib_node->locx = 100.0f; - mask_attrib_node->locy = -100.0f; + mask_attrib_node->location[0] = 100.0f; + mask_attrib_node->location[1] = -100.0f; bNode *collection_info_node = bke::node_add_static_node( nullptr, ntree, GEO_NODE_COLLECTION_INFO); - collection_info_node->locx = 100.0f; - collection_info_node->locy = -300.0f; + collection_info_node->location[0] = 100.0f; + collection_info_node->location[1] = -300.0f; socket = bke::node_find_socket(collection_info_node, SOCK_IN, "Separate Children"); socket->default_value_typed()->value = true; bNode *indices_attrib_node = add_input_named_attrib_node(ntree, "proto_index", CD_PROP_INT32); - indices_attrib_node->locx = 100.0f; - indices_attrib_node->locy = -500.0f; + indices_attrib_node->location[0] = 100.0f; + indices_attrib_node->location[1] = -500.0f; bNode *rotation_attrib_node = add_input_named_attrib_node( ntree, "orientation", CD_PROP_QUATERNION); - rotation_attrib_node->locx = 100.0f; - rotation_attrib_node->locy = -700.0f; + rotation_attrib_node->location[0] = 100.0f; + rotation_attrib_node->location[1] = -700.0f; bNode *scale_attrib_node = add_input_named_attrib_node(ntree, "scale", CD_PROP_FLOAT3); - scale_attrib_node->locx = 100.0f; - scale_attrib_node->locy = -900.0f; + scale_attrib_node->location[0] = 100.0f; + scale_attrib_node->location[1] = -900.0f; bke::node_add_link(ntree, group_input, diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc index 1cc3e49b343..9003cab051d 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc @@ -157,8 +157,8 @@ const float node_locy_step = 300.0f; static bNode *add_node(bNodeTree *ntree, int type, float x, float y) { bNode *node = bke::node_add_static_node(nullptr, ntree, type); - node->locx = x; - node->locy = y; + node->location[0] = x; + node->location[1] = y; return node; } diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 78440bd0ff9..b09f666690b 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -425,15 +425,15 @@ typedef struct bNode { /** Parent node (for frame nodes). */ struct bNode *parent; - /** Root location in the node canvas (in parent space). */ - float locx, locy; + /** The location of the top left corner of the node on the canvas. */ + float location[2]; /** * Custom width and height controlled by users. Height is calculate automatically for most * nodes. */ float width, height; - /** Additional offset from loc. TODO: Redundant with #locx and #locy, remove/deprecate. */ - float offsetx, offsety; + float locx_legacy, locy_legacy; + float offsetx_legacy, offsety_legacy; /** Custom user-defined label, MAX_NAME. */ char label[64]; diff --git a/source/blender/makesdna/intern/dna_rename_defs.h b/source/blender/makesdna/intern/dna_rename_defs.h index fce4e8c9a2a..13ed44e7f7e 100644 --- a/source/blender/makesdna/intern/dna_rename_defs.h +++ b/source/blender/makesdna/intern/dna_rename_defs.h @@ -215,6 +215,10 @@ DNA_STRUCT_RENAME_MEMBER(View3D, ob_centre_cursor, ob_center_cursor) DNA_STRUCT_RENAME_MEMBER(bArmature, collections, collections_legacy) DNA_STRUCT_RENAME_MEMBER(bGPDstroke, gradient_f, hardness) DNA_STRUCT_RENAME_MEMBER(bGPDstroke, gradient_s, aspect_ratio) +DNA_STRUCT_RENAME_MEMBER(bNode, locx, locx_legacy) +DNA_STRUCT_RENAME_MEMBER(bNode, locy, locy_legacy) +DNA_STRUCT_RENAME_MEMBER(bNode, offsetx, offsetx_legacy) +DNA_STRUCT_RENAME_MEMBER(bNode, offsety, offsety_legacy) DNA_STRUCT_RENAME_MEMBER(bNodeLink, multi_input_socket_index, multi_input_sort_id) DNA_STRUCT_RENAME_MEMBER(bNodeTree, inputs, inputs_legacy) DNA_STRUCT_RENAME_MEMBER(bNodeTree, outputs, outputs_legacy) diff --git a/source/blender/makesrna/intern/rna_nodetree.cc b/source/blender/makesrna/intern/rna_nodetree.cc index 814ee28a59f..6f81c2c3f47 100644 --- a/source/blender/makesrna/intern/rna_nodetree.cc +++ b/source/blender/makesrna/intern/rna_nodetree.cc @@ -659,6 +659,7 @@ static const EnumPropertyItem node_cryptomatte_layer_name_items[] = { # include "DNA_scene_types.h" # include "WM_api.hh" +using blender::float2; using blender::nodes::BakeItemsAccessor; using blender::nodes::CaptureAttributeItemsAccessor; using blender::nodes::ForeachGeometryElementGenerationItemsAccessor; @@ -889,6 +890,39 @@ static const EnumPropertyItem *rna_node_static_type_itemf(bContext * /*C*/, return item; } +static float2 node_parent_offset(const bNode &node) +{ + return node.parent ? float2(node.parent->location[0], node.parent->location[1]) : float2(0); +} + +static void rna_Node_location_get(PointerRNA *ptr, float *value) +{ + const bNode *node = static_cast(ptr->data); + copy_v2_v2(value, float2(node->location[0], node->location[1]) - node_parent_offset(*node)); +} + +static void move_child_nodes(bNode &node, const float2 &delta) +{ + for (bNode *child : node.direct_children_in_frame()) { + child->location[0] += delta.x; + child->location[1] += delta.y; + if (child->is_frame()) { + move_child_nodes(*child, delta); + } + } +} + +static void rna_Node_location_set(PointerRNA *ptr, const float *value) +{ + bNode *node = static_cast(ptr->data); + const float2 new_location = float2(value) + node_parent_offset(*node); + if (node->is_frame()) { + move_child_nodes(*node, new_location - float2(node->location[0], node->location[1])); + } + node->location[0] = new_location.x; + node->location[1] = new_location.y; +} + /* ******** Node Tree ******** */ static StructRNA *rna_NodeTree_refine(PointerRNA *ptr) @@ -10797,10 +10831,17 @@ static void rna_def_node(BlenderRNA *brna) "Node type (deprecated, use bl_static_type or bl_idname for the actual identifier string)"); prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ); - RNA_def_property_float_sdna(prop, nullptr, "locx"); + RNA_def_property_array(prop, 2); + RNA_def_property_float_funcs(prop, "rna_Node_location_get", "rna_Node_location_set", nullptr); + RNA_def_property_range(prop, -100000.0f, 100000.0f); + RNA_def_property_ui_text(prop, "Location", "Location of the node within its parent frame"); + RNA_def_property_update(prop, NC_NODE, "rna_Node_update"); + + prop = RNA_def_property(srna, "location_absolute", PROP_FLOAT, PROP_XYZ); + RNA_def_property_float_sdna(prop, nullptr, "location"); RNA_def_property_array(prop, 2); RNA_def_property_range(prop, -100000.0f, 100000.0f); - RNA_def_property_ui_text(prop, "Location", ""); + RNA_def_property_ui_text(prop, "Absolute Location", "Location of the node in the entire canvas"); RNA_def_property_update(prop, NC_NODE, "rna_Node_update"); prop = RNA_def_property(srna, "width", PROP_FLOAT, PROP_XYZ);