Fix #111593: Auto-offset when inserting nodes on links inside frames #111637

Merged
Leon Schittek merged 2 commits from lone_noel/blender:fix-111593-node-insert-bug into main 2023-08-30 22:08:31 +02:00
Member

Apply auto-offset animation in relative steps, to avoid issues, when
the parent space of the currently offset node changes.


Issue

The auto-offset was calculated by adding the offset to the inital node
location. Since the node location is always in "parent space", this
broke, when the node was attached to (or detached from) a frame during
the offset animation.

Previously this couldn't happen, because the insert_offset operator
was only called in macros after handling the attachement to frames.
This changed with commit cc9c720aae, which made it so the link insertion
operatior is called from inside the node transform operator, which
runs before handling the parenting to frames.

Here's a .blend-file to reproduce the issue: 111593.blend
Just insert a node a new node on the links insde the frames.

Proposed Solution

Rather than calculating the absolute node location based on the inital
location, this PR makes it so that with each call of
node_insert_offset_modal the node is offset a bit based on the
current duration and the delta (time) since the last call.

This makes the animation independent of the origin of the parent space
the node is currently in.
It also means anim_init_locx can be removed from the node runtime
since it's not used anymore.

Alternative

A small alternative fix is to also handle anim_init_locx, when
attaching (and detaching) nodes (see diff below.)
This change looks a bit safer, but I didn't like how the inner workings
of the auto-offset were leaking into unrelated code, so I prefer the
solution above.

diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 0acb9760b58..3280a9c1545 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -2764,23 +2764,34 @@ void nodeAttachNode(bNodeTree *ntree, bNode *node, bNode *parent)
   BKE_ntree_update_tag_parent_change(ntree, node);
   /* transform to parent space */
   const blender::float2 new_loc = blender::bke::nodeFromView(parent, loc);
   node->locx = new_loc.x;
   node->locy = new_loc.y;
+
+  if (node->runtime->anim_ofsx) {
+    const float offset = new_loc.x - loc.x;
+    node->runtime->anim_init_locx += offset;
+  }
 }
 
 void nodeDetachNode(bNodeTree *ntree, bNode *node)
 {
   if (node->parent) {
     BLI_assert(node->parent->type == NODE_FRAME);
+    const blender::float2 old_loc{node->locx, node->locy};
 
     /* transform to view space */
     const blender::float2 loc = blender::bke::nodeToView(node, {});
     node->locx = loc.x;
     node->locy = loc.y;
     node->parent = nullptr;
     BKE_ntree_update_tag_parent_change(ntree, node);
+
+    if (node->runtime->anim_ofsx) {
+      const float offset = loc.x - old_loc.x;
+      node->runtime->anim_init_locx += offset;
+    }
   }
 }
 
 namespace blender::bke {

Apply auto-offset animation in relative steps, to avoid issues, when the parent space of the currently offset node changes. --- #### Issue The auto-offset was calculated by adding the offset to the inital node location. Since the node location is always in "parent space", this broke, when the node was attached to (or detached from) a frame during the offset animation. Previously this couldn't happen, because the `insert_offset` operator was only called in macros *after* handling the attachement to frames. This changed with commit cc9c720aae, which made it so the link insertion operatior is called from inside the node transform operator, which runs *before* handling the parenting to frames. Here's a .blend-file to reproduce the issue: [111593.blend](https://projects.blender.org/attachments/efeabc25-fc66-4a28-8339-641fc837bfda) Just insert a node a new node on the links insde the frames. #### Proposed Solution Rather than calculating the absolute node location based on the inital location, this PR makes it so that with each call of `node_insert_offset_modal` the node is offset a bit based on the current `duration` and the `delta` (time) since the last call. This makes the animation independent of the origin of the parent space the node is currently in. It also means `anim_init_locx` can be removed from the node runtime since it's not used anymore. #### Alternative A small alternative fix is to also handle `anim_init_locx`, when attaching (and detaching) nodes (see diff below.) This change looks a bit safer, but I didn't like how the inner workings of the auto-offset were leaking into unrelated code, so I prefer the solution above. ```Diff diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 0acb9760b58..3280a9c1545 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -2764,23 +2764,34 @@ void nodeAttachNode(bNodeTree *ntree, bNode *node, bNode *parent) BKE_ntree_update_tag_parent_change(ntree, node); /* transform to parent space */ const blender::float2 new_loc = blender::bke::nodeFromView(parent, loc); node->locx = new_loc.x; node->locy = new_loc.y; + + if (node->runtime->anim_ofsx) { + const float offset = new_loc.x - loc.x; + node->runtime->anim_init_locx += offset; + } } void nodeDetachNode(bNodeTree *ntree, bNode *node) { if (node->parent) { BLI_assert(node->parent->type == NODE_FRAME); + const blender::float2 old_loc{node->locx, node->locy}; /* transform to view space */ const blender::float2 loc = blender::bke::nodeToView(node, {}); node->locx = loc.x; node->locy = loc.y; node->parent = nullptr; BKE_ntree_update_tag_parent_change(ntree, node); + + if (node->runtime->anim_ofsx) { + const float offset = loc.x - old_loc.x; + node->runtime->anim_init_locx += offset; + } } } namespace blender::bke { ```
Leon Schittek added 1 commit 2023-08-28 23:00:23 +02:00
00c6d38242 Fix #111593: Auto-offset when inserting nodes on links inside frames
Apply auto-offset animation in relative steps, to avoid issues, when
the parent space of the currently offset node changes.
Leon Schittek added this to the Nodes & Physics project 2023-08-28 23:01:01 +02:00
Leon Schittek added the
Module
Nodes & Physics
Interest
Geometry Nodes
labels 2023-08-28 23:01:20 +02:00
Leon Schittek added 1 commit 2023-08-30 20:42:24 +02:00
Leon Schittek changed title from WIP: Fix #111593: Auto-offset when inserting nodes on links inside frames to Fix #111593: Auto-offset when inserting nodes on links inside frames 2023-08-30 20:42:50 +02:00
Hans Goudey approved these changes 2023-08-30 21:20:03 +02:00
Hans Goudey left a comment
Member

Pretty nice! Good to remove this runtime data, and storing less data tends to make things simpler in the end.

At some point maybe runtime->anim_ofsx could be moved to a Map<bNode *, float> stored in the node editor runtime data too :)

Pretty nice! Good to remove this runtime data, and storing less data tends to make things simpler in the end. At some point maybe `runtime->anim_ofsx` could be moved to a `Map<bNode *, float>` stored in the node editor runtime data too :)
Leon Schittek merged commit 30114476c7 into main 2023-08-30 22:08:31 +02:00
Leon Schittek deleted branch fix-111593-node-insert-bug 2023-08-30 22:08:33 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#111637
No description provided.