-
Notifications
You must be signed in to change notification settings - Fork 428
Support token editing within GraphEditor UI #2943
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
Open
mialana
wants to merge
16
commits into
AcademySoftwareFoundation:main
Choose a base branch
from
mialana:support-token-editing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+243
−37
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
019edba
Fix discovery of tokens to accumulate current tokens through traversa…
mialana cc15276
Merge branch 'main' into support-token-editing
mialana 3709caf
Implement token data as persistent map on ui node class
mialana 18b0081
Write out edited token value and store affected inputs per token
mialana ee565f7
Fix for material render preview immediate update and resolve value st…
mialana 090bf5c
Merge branch 'main' into support-token-editing
mialana b526ec7
Clean up comments and allow for tooltips per column in tokens table
mialana 7e81ef7
Create help marker for tokens table, fill in all column tooltips
mialana b3cee30
Lint, supplementary comment
mialana 04f9d02
Match private member function naming convention
mialana 8d0767b
Move token mapping logic to an inline lambda to avoid repeated code
mialana 33fe3a7
Handle tokens defined on custom node instances
mialana 3644bd6
Move inline lambda token mapping handler to static member of UiToken …
mialana 0a6f9e5
Merge branch 'main' into support-token-editing
jstone-lucasfilm 7e9717e
Clean up minor code practice
mialana 74b237a
Merge branch 'main' into support-token-editing
jstone-lucasfilm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,14 +10,19 @@ | |
|
|
||
| #include <imgui_node_editor.h> | ||
|
|
||
| #include <atomic> | ||
| #include <sstream> | ||
|
|
||
| namespace mx = MaterialX; | ||
| namespace ed = ax::NodeEditor; | ||
|
|
||
| class UiNode; | ||
| class UiPin; | ||
| class UiToken; | ||
|
|
||
| using UiNodePtr = std::shared_ptr<UiNode>; | ||
| using UiPinPtr = std::shared_ptr<UiPin>; | ||
| using UiTokenPtr = std::shared_ptr<UiToken>; | ||
|
|
||
| // An edge between two UiNodes, storing the two nodes and connecting input. | ||
| class UiEdge | ||
|
|
@@ -160,6 +165,76 @@ class UiPin | |
| bool _connected; | ||
| }; | ||
|
|
||
| class UiToken | ||
| { | ||
| public: | ||
| UiToken(const mx::TokenPtr& token, const mx::ElementPtr& elem) : _tokenPtr(token), _sourceElement(elem) { } | ||
|
|
||
| std::string getValue() const { return _tokenPtr->getValueString(); } | ||
| void setValue(const std::string& val) const | ||
| { | ||
| _tokenPtr->setValueString(val); | ||
| } | ||
|
|
||
| std::string getSourceElementString() const | ||
| { | ||
| std::string _sourceElementName = _sourceElement->getName(); | ||
| return _sourceElementName.empty() ? "<DOCUMENT>" : _sourceElementName; | ||
| } | ||
|
|
||
| void addAffectedInput(const mx::InputPtr& input) | ||
| { | ||
| _affectedInputs.push_back(input); | ||
| _isAffectedInputsDirty.store(true); | ||
| } | ||
|
|
||
| std::string getAffectedInputsString() | ||
| { | ||
| if (_isAffectedInputsDirty.load()) | ||
| buildAffectedInputsStream(); | ||
| return _affectedInputsStream.str(); | ||
| } | ||
|
|
||
| const std::vector<mx::InputPtr>& getAffectedInputs() const { return _affectedInputs; }; | ||
|
|
||
| // Handle update of given map pointer by iterating through active tokens of an interface element | ||
| static void applyTokenMapping(std::unordered_map<std::string, UiTokenPtr>* uiTokenMapPtr, const mx::ConstInterfaceElementPtr& interfaceElem, mx::ElementPtr sourceElem) | ||
| { | ||
| std::vector<mx::TokenPtr> tokens = interfaceElem->getActiveTokens(); | ||
| for (auto token : tokens) | ||
| { | ||
| std::string key = token->getName(); | ||
|
|
||
| // Insert into map, but do not allow parent values to override child values | ||
| uiTokenMapPtr->try_emplace(key, std::make_shared<UiToken>(token, sourceElem)); | ||
| } | ||
| } | ||
|
|
||
| private: | ||
| const mx::TokenPtr _tokenPtr; | ||
| const mx::ElementPtr _sourceElement; | ||
|
|
||
| std::vector<mx::InputPtr> _affectedInputs{}; | ||
| std::ostringstream _affectedInputsStream{}; | ||
|
|
||
| // Track whether changes were made to inputs in order to re-build stream accordingly | ||
| std::atomic<bool> _isAffectedInputsDirty{ true }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the introduction of |
||
|
|
||
| void buildAffectedInputsStream() | ||
| { | ||
| if (!_isAffectedInputsDirty.load()) | ||
| return; | ||
| _affectedInputsStream.clear(); | ||
| for (size_t i = 0; i < _affectedInputs.size(); ++i) | ||
| { | ||
| _affectedInputsStream << _affectedInputs[i]->getName(); | ||
| if (i < _affectedInputs.size() - 1) | ||
| _affectedInputsStream << ", "; | ||
| } | ||
| _isAffectedInputsDirty.store(false); | ||
| } | ||
| }; | ||
|
|
||
| // The visual representation of a node in a graph. | ||
| class UiNode | ||
| { | ||
|
|
@@ -248,6 +323,11 @@ class UiNode | |
| std::vector<UiPinPtr>& getOutputPins() { return _outputPins; } | ||
| const std::vector<UiPinPtr>& getOutputPins() const { return _outputPins; } | ||
|
|
||
| const std::unordered_map<std::string, UiTokenPtr>& getUiTokenMap() const { return _uiTokenMap; } | ||
|
|
||
| // Build a map of relevant UI info for tokens in scope of this node. Should be called lazily (i.e. only when needed) | ||
| void buildUiTokenMap(); | ||
|
|
||
| // Edge collection accessors | ||
| std::vector<UiEdge>& getEdges() { return _edges; } | ||
| const std::vector<UiEdge>& getEdges() const { return _edges; } | ||
|
|
@@ -277,6 +357,8 @@ class UiNode | |
| std::vector<UiPinPtr> _outputPins; | ||
| std::vector<UiEdge> _edges; | ||
|
|
||
| std::unordered_map<std::string, UiTokenPtr> _uiTokenMap; | ||
|
|
||
| bool _showAllInputs; | ||
| bool _showOutputsInEditor; | ||
| }; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this logic will need to also handle node instances as the corresponding nodedef could also have exposed tokens. I don't think there is an example such as nodedef so may need to make one. Perhaps a simple example is a nodedef implemented as a image node + a token node, where the image node's filename and the token input are exposed as interface inputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Do these new additions cover the cases you are thinking of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks.