Nodes: Move data-block default values with link drag search #105972

Merged
Hans Goudey merged 17 commits from mod_moder/blender:move_value_by_link into main 2023-04-03 19:33:49 +02:00

When creating nodes by dragging a link, it can be convenient to
transfer values from input socket. For references value, like images,
this may be necessary. This patch starts adding such a system.
At this moment this only makes sense for one node (Image Input).
But this can be extended to work with other reference types, different
non-reference types and support auto-casting (if the float is transferred
to the Int Input node).
See task: #102854
Original patch: https://archive.blender.org/developer/D16735

When creating nodes by dragging a link, it can be convenient to transfer values from input socket. For references value, like images, this may be necessary. This patch starts adding such a system. At this moment this only makes sense for one node (Image Input). But this can be extended to work with other reference types, different non-reference types and support auto-casting (if the float is transferred to the Int Input node). See task: https://projects.blender.org/blender/blender/issues/102854 Original patch: https://archive.blender.org/developer/D16735 <video controls src="https://projects.blender.org/attachments/00b1a8b2-3cdc-43fe-991d-3b3c8da9e721">
Iliya Katushenock added 1 commit 2023-03-21 20:57:09 +01:00
Iliya Katushenock added this to the Nodes & Physics project 2023-03-21 20:58:02 +01:00
Iliya Katushenock requested review from Simon Thommes 2023-03-21 20:58:24 +01:00
Iliya Katushenock requested review from Hans Goudey 2023-03-21 20:58:24 +01:00
Iliya Katushenock added 1 commit 2023-03-21 20:58:50 +01:00
Iliya Katushenock added the
Interest
Geometry Nodes
label 2023-03-21 21:00:28 +01:00
Author
Member

Simon requested some changes after Hans accepted the patch.
So I guess it makes sense to be sure that I didn't do anything wrong with how to bypass each node instance.

Simon requested some changes after Hans accepted the patch. So I guess it makes sense to be sure that I didn't do anything wrong with how to bypass each node instance.
Simon Thommes approved these changes 2023-03-22 11:49:42 +01:00
Simon Thommes left a comment
Member

afaict this is in a state that I already approved on phab and only needs potentially another round of code review

afaict this is in a state that I already approved on phab and only needs potentially another round of code review
Hans Goudey changed title from Geometry Node: Gather link searche: Ability to move values to the top using a new link to Nodes: Link Drag Search: Move data-block default values 2023-03-22 16:13:25 +01:00
Hans Goudey changed title from Nodes: Link Drag Search: Move data-block default values to Nodes: Move data-block default values with link drag search 2023-03-22 16:21:23 +01:00
Hans Goudey requested changes 2023-03-25 16:52:30 +01:00
Hans Goudey left a comment
Member

Thanks for updating this patch. I think the functionality works well, but I have some inline comments.

Thanks for updating this patch. I think the functionality works well, but I have some inline comments.
@ -2355,6 +2355,95 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree,
return node_dst;
}
void node_link_move_default_value_back(const bContext &C, bNodeTree &tree, const bNodeLink &link)
Member

A clearer interface for this function might be:

void node_socket_default_value(Main &bmain, bNodeTree &tree, bNodeSocket &src, bNodeSocket &dst)

That would allow moving in either direction, and clarify the source/destination from the link's from/to naming.

A clearer interface for this function might be: ``` void node_socket_default_value(Main &bmain, bNodeTree &tree, bNodeSocket &src, bNodeSocket &dst) ``` That would allow moving in either direction, and clarify the source/destination from the link's from/to naming.
mod_moder marked this conversation as resolved
@ -2358,0 +2374,4 @@
}
if (&from_node == &to_node) {
/* Stop recursion. */
Member

This doesn't seem necessary, there's no recursion in this function.

This doesn't seem necessary, there's no recursion in this function.
mod_moder marked this conversation as resolved
@ -2358,0 +2385,4 @@
switch (from_socket.type) {
case SOCK_IMAGE: {
Image **src_socket_value = &to_socket.default_value_typed<bNodeSocketValueImage>()->value;
Member

It might be preferable to just use ID * rather than Image * here, since this logic could apply to all data-block socket types in the future, and no specific data from Image needs to be used.

It might be preferable to just use `ID *` rather than `Image *` here, since this logic could apply to all data-block socket types in the future, and no specific data from `Image` needs to be used.
mod_moder marked this conversation as resolved
@ -2358,0 +2417,4 @@
for (bNode *group : other_tree->group_nodes()) {
if (reinterpret_cast<bNodeTree *>(group->id) == &tree) {
bNodeSocket *group_input_socket = reinterpret_cast<bNodeSocket *>(
BLI_findlink(&group->inputs, group_input_index));
Member

Better to find the socket with the identifier in case we change group nodes to not store all the (hidden) sockets in the future.

Better to find the socket with the identifier in case we change group nodes to not store all the (hidden) sockets in the future.
mod_moder marked this conversation as resolved
Iliya Katushenock reviewed 2023-03-25 17:05:37 +01:00
@ -2355,6 +2355,95 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree,
return node_dst;
}
void node_link_move_default_value_back(const bContext &C, bNodeTree &tree, const bNodeLink &link)
Author
Member

Here the problem is that we must update the topology cache in advance in order to have access to the parent nodes of sockets from the function.

Here the problem is that we must update the topology cache in advance in order to have access to the parent nodes of sockets from the function.
mod_moder marked this conversation as resolved
Hans Goudey reviewed 2023-03-25 17:13:21 +01:00
@ -2355,6 +2355,95 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree,
return node_dst;
}
void node_link_move_default_value_back(const bContext &C, bNodeTree &tree, const bNodeLink &link)
Member

Yeah, I think that's okay, it can be documented in the function's doc-string or the function can just ensure the topology cache itself.

Yeah, I think that's okay, it can be documented in the function's doc-string or the function can just ensure the topology cache itself.
mod_moder marked this conversation as resolved
Iliya Katushenock reviewed 2023-03-25 18:21:27 +01:00
@ -2358,0 +2417,4 @@
for (bNode *group : other_tree->group_nodes()) {
if (reinterpret_cast<bNodeTree *>(group->id) == &tree) {
bNodeSocket *group_input_socket = reinterpret_cast<bNodeSocket *>(
BLI_findlink(&group->inputs, group_input_index));
Author
Member

There is some confusion here, it seems.
Hidden sockets that are inaccessible to built-in nodes will be deleted.
But if the user just doesn't want to see them, we shouldn't want to delete them, does it seem redundant that the node declaration store the hidden states for all sockets of all nodes?
So, for group nodes, created sockets will always exist..

There is some confusion here, it seems. Hidden sockets that are inaccessible to built-in nodes will be deleted. But if the user just doesn't want to see them, we shouldn't want to delete them, does it seem redundant that the node declaration store the hidden states for all sockets of all nodes? So, for group nodes, created sockets will always exist..
mod_moder marked this conversation as resolved
Hans Goudey reviewed 2023-03-25 18:36:47 +01:00
@ -2358,0 +2417,4 @@
for (bNode *group : other_tree->group_nodes()) {
if (reinterpret_cast<bNodeTree *>(group->id) == &tree) {
bNodeSocket *group_input_socket = reinterpret_cast<bNodeSocket *>(
BLI_findlink(&group->inputs, group_input_index));
Member

My point is, it's just less fragile to use identifiers rather than indices, and it gives us more flexibility in the future, for very little downside.

My point is, it's just less fragile to use identifiers rather than indices, and it gives us more flexibility in the future, for very little downside.
mod_moder marked this conversation as resolved
Iliya Katushenock added 2 commits 2023-03-25 19:06:46 +01:00
Iliya Katushenock requested review from Hans Goudey 2023-03-25 19:08:45 +01:00
Iliya Katushenock added 2 commits 2023-03-26 14:25:42 +02:00
unified function for visiting all node group socket instances
Hans Goudey requested changes 2023-03-31 23:04:12 +02:00
Hans Goudey left a comment
Member

The code looks great. I'm just confused by the use of group_identifier and node_find_tree_by_name. Maybe I'm missing something though.

The code looks great. I'm just confused by the use of `group_identifier` and `node_find_tree_by_name`. Maybe I'm missing something though.
Author
Member

You mean that it makes no sense to do such a unification for node tree, as with the socket name, getting one extra loop for search tree instance. Or a discrepancy in the naming of the node tree name?

You mean that it makes no sense to do such a unification for node tree, as with the socket name, getting one extra loop for search tree instance. Or a discrepancy in the naming of the node tree name?
Member

Ah sorry, my inline comment disappeared somehow. What I mean is that this seems to retrieve the name from the tree, pass the name into the next function, and then just look up the tree by name again. That looks like equivalent to just passing the tree in the first place and skipping the name lookup.

Ah sorry, my inline comment disappeared somehow. What I mean is that this seems to retrieve the name from the tree, pass the name into the next function, and then just look up the tree by name again. That looks like equivalent to just passing the tree in the first place and skipping the name lookup.
Iliya Katushenock added 2 commits 2023-04-01 21:37:12 +02:00
remove redurand seaching node tree by name, visiting each node group instance
Iliya Katushenock requested review from Hans Goudey 2023-04-01 21:38:02 +02:00
Hans Goudey reviewed 2023-04-03 16:13:49 +02:00
@ -2358,0 +2360,4 @@
const Span<int> tree_types_to_lookup,
const FunctionRef<void(bNode &)> func)
{
BLI_assert(node_group != nullptr);
Member

I think it's clearer to pass the node group as const bNodeTree &group and let this function handle the ID * comparison with something like &group.id.

I think it's clearer to pass the node group as `const bNodeTree &group` and let this function handle the `ID *` comparison with something like `&group.id`.
mod_moder marked this conversation as resolved
Iliya Katushenock added 2 commits 2023-04-03 16:45:50 +02:00
Hans Goudey approved these changes 2023-04-03 16:47:17 +02:00
Hans Goudey reviewed 2023-04-03 17:10:15 +02:00
@ -733,2 +733,4 @@
bNode *node_copy(bNodeTree *dst_tree, const bNode &src_node, int flag, bool use_unique);
/**
* Move socket default_value from TO_SOCKET to FROM_SOCKET or some other other place specified for
Member

Sorry I should have found this this last time. I tried to update your PR directly but couldn't quite figure it out. This comment is a bit out of date. How about this?

/**
 * Move socket default from \a src to locations specified by \a dst (potentially multiple group
 * nodes socket values, if \a dst is a group input node).
 */
Sorry I should have found this this last time. I tried to update your PR directly but couldn't quite figure it out. This comment is a bit out of date. How about this? ``` /** * Move socket default from \a src to locations specified by \a dst (potentially multiple group * nodes socket values, if \a dst is a group input node). */ ```
mod_moder marked this conversation as resolved
Iliya Katushenock reviewed 2023-04-03 17:13:37 +02:00
@ -733,2 +733,4 @@
bNode *node_copy(bNodeTree *dst_tree, const bNode &src_node, int flag, bool use_unique);
/**
* Move socket default_value from TO_SOCKET to FROM_SOCKET or some other other place specified for
Author
Member

I was thinking about expanding with a description of the cases that may now be.
But given the plans to expand this functionality, is it correct to talk about it in a comment in header file?

I was thinking about expanding with a description of the cases that may now be. But given the plans to expand this functionality, is it correct to talk about it in a comment in header file?
mod_moder marked this conversation as resolved
Hans Goudey reviewed 2023-04-03 17:17:15 +02:00
@ -733,2 +733,4 @@
bNode *node_copy(bNodeTree *dst_tree, const bNode &src_node, int flag, bool use_unique);
/**
* Move socket default_value from TO_SOCKET to FROM_SOCKET or some other other place specified for
Member

Maybe not, it's fine to keep it simple too. It's just nice to clarify that it doesn't just move to dst's default value

Maybe not, it's fine to keep it simple too. It's just nice to clarify that it doesn't _just_ move to dst's default value
mod_moder marked this conversation as resolved
Iliya Katushenock added 2 commits 2023-04-03 18:45:13 +02:00
Iliya Katushenock added 1 commit 2023-04-03 18:48:36 +02:00
Iliya Katushenock added 3 commits 2023-04-03 18:58:34 +02:00
Iliya Katushenock added 1 commit 2023-04-03 19:08:52 +02:00
Hans Goudey merged commit 9726e4a0ad into main 2023-04-03 19:33:49 +02:00
Iliya Katushenock deleted branch move_value_by_link 2023-04-03 19:34:47 +02:00
First-time contributor

This is so needed for other socket types as well. It would really speed up workflows and remove an annoying papercut. Sverchok had this kind of function and it was always super handy

This is so needed for other socket types as well. It would really speed up workflows and remove an annoying papercut. Sverchok had this kind of function and it was always super handy
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
4 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#105972
No description provided.