Fix #113014: Improved sorting to keep node group outputs above inputs #113060

Merged
Lukas Tönne merged 6 commits from LukasTonne/blender:node-group-socket-ordering into blender-v4.0-release 2023-10-03 12:18:44 +02:00
Member

The position validation when manipulating node group items now includes
outputs..inputs order in addition to sockets..panels order. The method
for finding a valid position has been simplified, it's just a single
iteration of insertion sort.

Versioning has been added to ensure files from 4.0 alpha with
potentially unsorted sockets get re-sorted. This uses std::stable_sort
so that sockets keep their relative order apart from the input/output
grouping.

The position validation when manipulating node group items now includes outputs..inputs order in addition to sockets..panels order. The method for finding a valid position has been simplified, it's just a single iteration of insertion sort. Versioning has been added to ensure files from 4.0 alpha with potentially unsorted sockets get re-sorted. This uses `std::stable_sort` so that sockets keep their relative order apart from the input/output grouping.
Lukas Tönne added 2 commits 2023-09-29 14:40:05 +02:00
da951f25f6 Added versioning to sort sockets in existing files.
This affects only files from 4.0 alpha where the outputs..inputs order
was not implemented.
Lukas Tönne requested review from Jacques Lucke 2023-09-29 14:40:49 +02:00
Lukas Tönne added this to the Nodes & Physics project 2023-09-29 14:40:55 +02:00
Iliya Katushenock reviewed 2023-09-29 15:02:11 +02:00
@ -815,2 +810,3 @@
return pos;
/* Insertion sort for a single item. */
int test_pos = clamp_i(initial_pos, 0, items.size() - 1);

math::clamp<int>()

`math::clamp<int>()`
Author
Member

I'm never sure which version to use, haha. We have the old-school CLAMP macro, the clamp_i thing, cycles might have its own, and std::clamp as well ...

I'm never sure which version to use, haha. We have the old-school `CLAMP` macro, the `clamp_i` thing, cycles might have its own, and `std::clamp` as well ...

C++ BLI_math with template is the better choose.

C++ `BLI_math` with template is the better choose.
@ -817,0 +811,4 @@
/* Insertion sort for a single item. */
int test_pos = clamp_i(initial_pos, 0, items.size() - 1);
/* Move upward until valid position found. */
while (test_pos > 0 && item_compare(item, *items[test_pos - 1])) {
const int min_index = std::distance(items.rend(), std::find_if(items.rbegin(), items.rend(), item_compare_to_front));
const Span back_items = items.drop_front(min_index);
const int max_index = std::distance(items.begin(), std::find_if(back_items.begin(), back_items.end(), item_compare_to_back));
/* Result can be out of range, this is valid, items get appended. */
return max_index;

The fewer stateful variables, the better.

```Cpp const int min_index = std::distance(items.rend(), std::find_if(items.rbegin(), items.rend(), item_compare_to_front)); const Span back_items = items.drop_front(min_index); const int max_index = std::distance(items.begin(), std::find_if(back_items.begin(), back_items.end(), item_compare_to_back)); /* Result can be out of range, this is valid, items get appended. */ return max_index; ``` The fewer stateful variables, the better.
Author
Member

I find my version easier to read, to be honest. It's a pretty small function, not like this is affecting other code.

I find my version easier to read, to be honest. It's a pretty small function, not like this is affecting other code.
Jacques Lucke requested changes 2023-10-03 11:31:49 +02:00
Jacques Lucke left a comment
Member

I can't move this socket down anymore:
image

I can't move this socket down anymore: ![image](/attachments/e7d110ec-5c4b-48db-b91a-5b528069c2f1)
@ -986,1 +987,4 @@
static void versioning_node_group_sort_sockets_recursive(bNodeTreeInterfacePanel &panel)
{
const bool sockets_above_panels = !(panel.flag &
Member

Feels like at this point in versioning code we can just assume this to be false since it was never allowed?

Feels like at this point in versioning code we can just assume this to be `false` since it was never allowed?
LukasTonne marked this conversation as resolved
@ -1631,2 +1673,4 @@
}
}
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 400, 32)) {
Member

node that the version here has to be updated.

node that the version here has to be updated.
LukasTonne marked this conversation as resolved
Lukas Tönne added 4 commits 2023-10-03 12:09:40 +02:00
Lukas Tönne requested review from Jacques Lucke 2023-10-03 12:10:21 +02:00
Jacques Lucke approved these changes 2023-10-03 12:16:42 +02:00
Lukas Tönne merged commit 71732a9600 into blender-v4.0-release 2023-10-03 12:18:44 +02:00
Lukas Tönne deleted branch node-group-socket-ordering 2023-10-03 12:18:48 +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
Interest: X11
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
3 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#113060
No description provided.