Skip to content

Add hotkey to group nodes into a node graph - #3002

Open
minhpham1810 wants to merge 11 commits into
AcademySoftwareFoundation:mainfrom
minhpham1810:issue-2018-group-nodes-nodegraph
Open

Add hotkey to group nodes into a node graph#3002
minhpham1810 wants to merge 11 commits into
AcademySoftwareFoundation:mainfrom
minhpham1810:issue-2018-group-nodes-nodegraph

Conversation

@minhpham1810

@minhpham1810 minhpham1810 commented Jul 8, 2026

Copy link
Copy Markdown

Summary

Moves the Graph Editor's node-grouping logic into a reusable, unit-tested core method, per maintainer feedback. The editor now delegates to core, grouping stays top-level-only, and the Shift+C hotkey remains a thin trigger.

Changes

  • source/MaterialXCore/Node.h — Declare new GraphElement::createNodeGraphFromNodes(nodes, name), which groups the given nodes into a new child nodegraph while preserving internal and boundary connections.
  • source/MaterialXCore/Node.cpp — Implement createNodeGraphFromNodes plus file-local helpers (ported from the editor) that copy the selected nodes into a new nodegraph, turn external upstream links into nodegraph interface inputs, rewire external downstream consumers to nodegraph outputs (with fan-out dedup), and remove the originals. The method is general and does not set layout attributes or enforce a document-only policy.
  • source/MaterialXGraphEditor/Graph.cpp — Remove the in-editor grouping helpers and rewrite groupSelectedNodesIntoNodeGraph to collect the selected nodes and delegate to the core method, keeping only editor concerns (top-level guard, average node position, graph rebuild/relink/render).
  • source/MaterialXTest/MaterialXCore/Node.cpp — Add [nodegraph] unit tests covering internal links, upstream/downstream boundary rewiring, fan-out output dedup, original removal, document validation, and the empty-selection case.
  • source/MaterialXCore/Interface.cpp — Remove a redundant duplicate resolveNameReference<NodeGraph> no-op in PortElement::validate left over from the reverted nesting rework.

Testing

  • git diff --check
  • MaterialXTest "Graph editor grouping shortcut"
  • cmake --build build --target MaterialXGraphEditor

Related Issue

Fixes #2018

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 8, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@minhpham1810 minhpham1810 changed the title Issue 2018 group nodes into nodegraph hotkey Add hot key to group nodes into a node graph Jul 8, 2026
@minhpham1810 minhpham1810 changed the title Add hot key to group nodes into a node graph Add hotkey to group nodes into a node graph Jul 8, 2026
@minhpham1810
minhpham1810 marked this pull request as draft July 9, 2026 00:16
@minhpham1810
minhpham1810 marked this pull request as ready for review July 9, 2026 00:17
@jstone-lucasfilm

Copy link
Copy Markdown
Member

This looks very promising, thanks @minhpham1810, and take a look at the comment above for instructions on resolving the EasyCLA errors.

@minhpham1810
minhpham1810 force-pushed the issue-2018-group-nodes-nodegraph branch from 7a4a73e to 027125f Compare July 9, 2026 03:55
@minhpham1810
minhpham1810 marked this pull request as draft July 9, 2026 03:59
@minhpham1810
minhpham1810 force-pushed the issue-2018-group-nodes-nodegraph branch from 027125f to c344edb Compare July 9, 2026 04:06
@minhpham1810
minhpham1810 marked this pull request as ready for review July 9, 2026 04:11
@minhpham1810

Copy link
Copy Markdown
Author

@jstone-lucasfilm I just signed the CLA and changed my commit email, please have a look.

@jstone-lucasfilm

Copy link
Copy Markdown
Member

Thanks for the excellent work here, @minhpham1810. The connection-preservation logic is more thorough than I'd expected, and the hard parts are done well.

This PR has grown into something larger than the summary suggests, though, so before we dive into code review I'd like to align on scope. Two recommended next steps would be:

  1. Update the PR description to reflect the full change. It currently reads as a Shift+C shortcut fix, but it implements the whole grouping feature along with some MaterialXCore changes.
  2. The key decision is nested nodegraphs. When this was first scoped, @kwokcb suggested the editor guard against nesting; this PR adds support for it instead, which is what motivates the Interface.cpp changes. I'd suggest we start with grouping at the top document level only, which would cover the original use case, keep us on well-supported ground, and require no MaterialXCore changes. We can then take up nested nodegraphs (and the resolution work they require) as a deliberate follow-up.

Once we've settled the scope, I'm glad to go deep on the grouping logic itself. Thanks again for the strong contribution!

@minhpham1810

Copy link
Copy Markdown
Author

@jstone-lucasfilm Thank you so much for the detailed feedback! I admitted that I want a bit out of scope in this PR, so I reverted the changes I made in MaterialXCore, as well as editing the safeguard for top-level document node grouping. Please let me know if there is any other parts that I should look at.

@kwokcb

kwokcb commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

I would agree that to only allow top level / document level grouping to occur.

( For reference, I did rework to support graph nesting and fix a other related issues in this PR . )

BTW, there was another PR proposal which took advantage of the cut/paste mechanism.

From a cursory look and revisit of the previous PR, my suggested approach is to

  1. Put new "grouping" functionality in core so it's a reusable and testable function.
  2. Then expose it in editor.
  3. Then add the hotkey as a minor addition.

@minhpham1810

minhpham1810 commented Jul 15, 2026

Copy link
Copy Markdown
Author

Thank you for the constructive review and feedback. From what we've been discussing so far, I will proceed with what @kwokcb suggested in the comment above. Please let me know if there is any further instructions or directions that you want to highlight @kwokcb @jstone-lucasfilm .

@minhpham1810

Copy link
Copy Markdown
Author

@jstone-lucasfilm @kwokcb I just push the changes that relocate grouping logic into core. Please have a look.

@jstone-lucasfilm

Copy link
Copy Markdown
Member

Thanks for the revisions, @minhpham1810!

This is looking very promising, but I see two important issues to resolve before we dive into line-level review:

  1. Several editor changes from the original nested-nodegraph implementation are still present in the diff, and together they reintroduce the nesting we agreed to defer. The "Disallow creating nested nodegraphs" guard in Graph::addNodePopup is removed, and Graph::addNode and Graph::copyUiNode now create nodegraphs under _state.graphElem rather than the document, so the TAB menu inside a compound nodegraph creates a nested nodegraph even though the Shift+C path is guarded. The child-nodegraph handling added to Graph::buildUiNodeGraph and the nested walk in Graph::scanNestedGraphDiagnostics are part of the same earlier work, and they overlap with Add support for nested NodeGraphs : Core Traversal, Validation and ShaderGen #2999, where nesting support is being developed as a whole. I'd suggest reverting these and limiting the editor diff to groupSelectedNodesIntoNodeGraph, rebuildCurrentGraph, the hotkey, and the help text, which keeps this changelist on well-supported ground.

  2. One of the merges from main appears to have reverted part of Fix graph area keyboard input in Graph Editor #3012, which introduced the graphShortcutContext guard for keyboard input in the graph area. The copy/paste block retains the guard, but the delete/traverse block in Graph::drawGraph is back to a bare ImGui::IsWindowFocused check, so Delete, Backspace, the arrow keys, F, and U would once again fire while a popup or file dialog is open, or while a text field has focus. Restoring if (graphShortcutContext) for that block should resolve it. Since the new GraphShortcuts.h predicate duplicates this same guard, I'd also suggest expressing the Shift+C check inline alongside the other hotkeys, which would let us drop the header and the new test directory.

With these two broader items addressed, we should be able to dive into deeper review, and this looks like it will be a welcome addition to the Graph Editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Graph Editor: Group nodes to create node graph

3 participants