Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Shift + C hotkey to create a nodegraph from selected nodes #2048

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

WaffleBoyTom
Copy link

Addresses #2018.
Shift + C will create nodegraph containing selected nodes.
Connections are not preserved.

Copy link

linux-foundation-easycla bot commented Oct 2, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@jstone-lucasfilm
Copy link
Member

@WaffleBoyTom This looks like a great start, and to resolve the EasyCLA issue, I'd recommend following up through the support link that the Linux Foundation provides:

https://jira.linuxfoundation.org/servicedesk/customer/portal/4

@jstone-lucasfilm
Copy link
Member

In parallel with the CLA process, I'm CC'ing @lfl-eholthouser for her thoughts on the implementation of the feature.

Copy link
Contributor

@kwokcb kwokcb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Great to see this worked out.
  • I've left some comments about adding some more conditional checking and code cleanup. Thanks.

source/MaterialXGraphEditor/Graph.cpp Show resolved Hide resolved
source/MaterialXGraphEditor/Graph.cpp Outdated Show resolved Hide resolved
source/MaterialXGraphEditor/Graph.cpp Outdated Show resolved Hide resolved
source/MaterialXGraphEditor/Graph.cpp Show resolved Hide resolved
@jstone-lucasfilm
Copy link
Member

I wanted to follow up on this proposal, @WaffleBoyTom, to see if you might have the bandwidth to address the requests above. Let us know either way!

@WaffleBoyTom
Copy link
Author

I wanted to follow up on this proposal, @WaffleBoyTom, to see if you might have the bandwidth to address the requests above. Let us know either way!

Yes ! Sorry about the radio silence. I was planning on finishing this up this weekend hopefully !

@jstone-lucasfilm
Copy link
Member

This looks very promising, thanks @WaffleBoyTom!

Make sure to resolve the EasyCLA issue above, following the link provided by the Linux Foundation, so that we can merge your work once it's approved by the MaterialX team.

@WaffleBoyTom
Copy link
Author

This looks very promising, thanks @WaffleBoyTom!

Make sure to resolve the EasyCLA issue above, following the link provided by the Linux Foundation, so that we can merge your work once it's approved by the MaterialX team.

Hey ! I followed the link and signed the CLA so I think that should be okay ? I might be missing something

@jstone-lucasfilm
Copy link
Member

@WaffleBoyTom It looks like the EasyCLA system still needs approvals for some of the commits above, so perhaps you can follow up by clicking their support link?

For further assistance with EasyCLA, [please submit a support request ticket] https://jira.linuxfoundation.org/servicedesk/customer/portal/4).

@WaffleBoyTom
Copy link
Author

@WaffleBoyTom It looks like the EasyCLA system still needs approvals for some of the commits above, so perhaps you can follow up by clicking their support link?

For further assistance with EasyCLA, [please submit a support request ticket] jira.linuxfoundation.org/servicedesk/customer/portal/4).

sounds good, let me do that :)

@WaffleBoyTom
Copy link
Author

@WaffleBoyTom It looks like the EasyCLA system still needs approvals for some of the commits above, so perhaps you can follow up by clicking their support link?

For further assistance with EasyCLA, [please submit a support request ticket] jira.linuxfoundation.org/servicedesk/customer/portal/4).

I think we did it :o

Copy link
Contributor

@kwokcb kwokcb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates @WaffleBoyTom . Looks good.

I just have one small addition item which is to clear the copy "buffer" after the action so that it's not accidently pasted erroneously at some later time.

source/MaterialXGraphEditor/Graph.cpp Show resolved Hide resolved
Copy link
Contributor

@kwokcb kwokcb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the cleanup @WaffleBoyTom. Looks good to go!

@jstone-lucasfilm
Copy link
Member

@WaffleBoyTom I've been giving this new feature a try in my local build, but so far it's not behaving as I would expect, though I may be misunderstanding the intended design.

I'm clearing the contents of the Graph Editor, creating a small number of nodes at root scope, then selecting them all, as seen in the following screenshot:

image

I then hit the SHIFT-C key combination, but nothing happens in the editor, and the new logic seems to be hitting this early exit because isNodeGraph is true:

if (!_copiedNodes.empty() && !isNodeGraph)

Just to make sure I didn't accidentally break anything with my own merges and formatting fixes, I tried the same process again with the codebase at the time of your most recent commit, but I get the same results.

What might I be missing?

@WaffleBoyTom
Copy link
Author

I then hit the SHIFT-C key combination, but nothing happens in the editor, and the new logic seems to be hitting this early exit because isNodeGraph is true:

if (!_copiedNodes.empty() && !isNodeGraph)

Just to make sure I didn't accidentally break anything with my own merges and formatting fixes, I tried the same process again with the codebase at the time of your most recent commit, but I get the same results.

What might I be missing?

Hey Jonathan !
It seems you're right.. !isNodeGraph was added to prevent nested node graphs but that means that the code fails in your example because tiledhexagons_color3 is a nodegraph.
I struggled to find what the right checks should be to prevent nested nodegraphs and this clearly isn't it unfortunately.
Would you happen to know how I can correct this ?
Thanks :)

@kwokcb
Copy link
Contributor

kwokcb commented Dec 13, 2024

@WaffleBoyTom, @jstone-lucasfilm : I'll take a quick look. The current logic does need some changes. It should be:

  1. Are we currently inside a nodegraph: _isNodeGraph
  2. Have we selected any nodes which are nodegraphs: selectedNode->getCategory() == "nodegraph".

@WaffleBoyTom
Copy link
Author

Thank you, I should be able to make these changes this weekend

@kwokcb
Copy link
Contributor

kwokcb commented Dec 13, 2024

This is what I've found that works:

           bool isNodeGraph = _isNodeGraph; // Check if we're already inside a nodegraph
            if (_currUiNode)
            {
                // Check if current node is a nodegraph (also caught below but a faster "early out"
                isNodeGraph |= (_currUiNode->getCategory() == mx::NodeGraph::CATEGORY);
            }
            if (!isNodeGraph)
            {
                for (ed::NodeId selected : selectedNodes)
                {
                    int pos = findNode((int)selected.Get());
                    if (pos >= 0)
                    {
                        UiNodePtr node = _graphNodes[pos];

                        // Check if the selected node is a nodegraph
                        isNodeGraph |= (node->getCategory() == mx::NodeGraph::CATEGORY);
                        if (isNodeGraph)
                        {
                            // Skip all nodes if one of the nodes is a nodegraph
                            break;
                        }

                        _copiedNodes.insert(
                            std::pair<UiNodePtr, UiNodePtr>(_graphNodes[pos], nullptr));
                    }
                }
            }

I checked if you dive in to a node which has a nodegraph implementation that this code isn't even reached since I assume any hot key is prevented from triggering. You probably want to hammer on this a bit more though :).

@WaffleBoyTom
Copy link
Author

Thanks !

for (std::map<UiNodePtr, UiNodePtr>::iterator iter = _copiedNodes.begin(); iter != _copiedNodes.end(); iter++)
{
UiNodePtr node = iter->first;
deleteNode(node);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to break the links between nodes so even though they are copied the links are not copied over?

Tried moving this later after the paste but it crashes with some shared ptr de-refencing error. Even with this as is, I've seen hang in refresh if you try and select the surfaceshader in the default marble graph and try this operation then try and go back to the parent.

@lfl-eholthouser pinging you as you know this code much better than I. If you don't delete then a nodegraph is created properly with linked nodes and have not experienced any side-effects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a fix for the linking. Remove this code and add in a new flag to know that a graph has been built. I called this isBuildGraph and set it here::

   // Paste                                
                for (std::map<UiNodePtr, UiNodePtr>::iterator iter = _copiedNodes.begin(); iter != _copiedNodes.end(); iter++)
                {
                    copyUiNode(iter->first);
                }
                _addNewNode = true;
                isBuildGraph = true;

Test this flag later on and go up back to the parent and perform a proper "cut".

  if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootWindow))
        {
            if (isBuildGraph)
            {
                upNodeGraph();
                _isCut = true;
                isBuildGraph = false;
            }

            if (ImGui::IsKeyReleased(ImGuiKey_Delete) || _isCut)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add this to my code, thank you !!

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

Successfully merging this pull request may close these issues.

3 participants