Hypershade-style pin display modes for material graph nodes

Each node gets an All/Conn toggle: connected-only mode hides
unconnected pins behind collapsed connector nubs on the title row;
dragging a link onto (or from) a nub opens a menu to pick which hidden
pin to wire, and the pin appears once connected. The toggle is drawn
and hit-tested geometrically, and its tooltip is deferred to after
NE::End() so it lands at the cursor. A new Preferences > Material
checkbox opts into persisting the per-node mode as USD customData
(uiShowAllPins); otherwise it stays session-only.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-10 23:02:56 +08:00
parent 22406fbe63
commit c7edd145df
6 changed files with 331 additions and 7 deletions
+71
View File
@@ -54,6 +54,12 @@ public:
}
void SetColumnWidths(float browserWidth, float previewWidth);
/// Whether toggling a node's pin display mode / revealing a hidden pin
/// authors USD customData (persisted) or stays session-only. Pushed in by
/// Application from AppPreferences, live-updated when the user flips the
/// checkbox in Preferences -> Material.
void SetKeepGraphNodeViewSettingsInUsd(bool value) { m_keepGraphNodeViewSettingsInUsd = value; }
void Render();
private:
@@ -63,6 +69,12 @@ private:
std::string name;
bool isOutput = false;
pxr::SdfValueTypeName typeName;
/// True for the collapsed "more pins" connector nub rendered on a
/// node's title row when it's hiding unconnected pins (Hypershade
/// style) — name/typeName are unset. Connecting to/from it opens
/// RenderPinPickMenu() to choose which actual pin to wire, instead of
/// creating the connection immediately. See HandleCreateAndDelete().
bool isMeta = false;
};
/// Resolved endpoint of a rendered link, keyed by its ax::NodeEditor LinkId.
struct LinkInfo {
@@ -70,6 +82,24 @@ private:
std::string destInput;
};
/// Hypershade-style per-node pin display state. Always the render-time
/// source of truth (never resync-clobbered); optionally mirrored into USD
/// customData when m_keepGraphNodeViewSettingsInUsd is set. See
/// GetPinDisplayOverride()/IsPinVisible().
struct PinDisplayOverride {
bool showAllPins = true;
};
/// A connection dragged onto/from a collapsed meta pin, awaiting the user
/// picking which actual pin on nodePath/isOutput to wire up. otherPin is
/// the already-resolved endpoint on the far side of the link (itself meta
/// if the user dragged directly between two collapsed nubs, in which case
/// picking chains into a second RenderPinPickMenu() for that side).
struct PendingPinPick {
pxr::SdfPath nodePath;
bool isOutput = false;
PinInfo otherPin;
};
void RenderToolbar();
/// Property editor for the node selected in the graph, shown below the
/// shader-ball preview. Values apply live while a widget is being
@@ -122,6 +152,35 @@ private:
void PersistNodePosition(ax::NodeEditor::NodeId nodeId);
bool IsPinLinked(const pxr::SdfPath& nodePath, const std::string& pinName, bool isOutput) const;
/// Seeds m_pinDisplayOverrides for any node path not already present
/// (i.e. not touched yet this session) from the just-synced m_graph's
/// showAllPins (customData-backed). Never overwrites an existing entry,
/// so in-session toggles survive resyncs.
void SeedPinDisplayOverrides();
/// Creates the entry (defaulted to "show all") on first access.
PinDisplayOverride& GetPinDisplayOverride(const pxr::SdfPath& nodePath);
/// True if pin should be drawn this frame: node is in "show all" mode, or
/// the pin is linked (linked pins are never hidden — Link() unconditionally
/// references pin IDs that must have been drawn). A hidden pin becomes
/// visible the moment it's connected, via RenderPinPickMenu().
bool IsPinVisible(const ShaderGraphNode& node, const std::string& pinName, bool isOutput) const;
/// Flips a node between "show all" and "show connected only".
void TogglePinDisplayMode(const pxr::SdfPath& nodePath);
/// Authors the node's current PinDisplayOverride into USD customData via
/// an undoable command, mirroring PersistNodePosition. No-op unless
/// m_keepGraphNodeViewSettingsInUsd is set.
void PersistPinDisplayState(const pxr::SdfPath& nodePath);
/// Renders the deferred "choose pin" popup for m_pendingPinPick (Maya
/// Hypershade style): a connection was dragged onto/from a collapsed meta
/// pin, and the user now picks which actual attribute it wires to. Must
/// be called from within the NE::Suspend()/Resume() block, like the
/// other popups.
void RenderPinPickMenu();
/// Finishes a pick: creates the real connection to/from chosen, unless
/// the far side of the pending pick was itself a meta pin, in which case
/// this chains into a second pick for that side instead.
void CompletePinPick(const PinInfo& chosen);
static bool SaveNodeSettingsCallback(ax::NodeEditor::NodeId nodeId,
const char* data, size_t size,
ax::NodeEditor::SaveReasonFlags reason,
@@ -170,6 +229,18 @@ private:
bool m_openLinkDragMenu = false;
PinInfo m_linkDragSourcePin;
/// Hypershade-style pin display state, keyed by node path string. Always
/// the render-time source of truth; see PinDisplayOverride.
std::unordered_map<std::string, PinDisplayOverride> m_pinDisplayOverrides;
/// Whether node toggles author USD customData (see
/// SetKeepGraphNodeViewSettingsInUsd).
bool m_keepGraphNodeViewSettingsInUsd = false;
/// Deferred "choose pin" popup request: set from HandleCreateAndDelete()
/// when a link is dropped on/dragged from a collapsed meta pin, actually
/// opened after NE::Suspend(), like m_openLinkDragMenu.
bool m_openPinPickMenu = false;
PendingPinPick m_pendingPinPick;
/// Column widths of the browser (left) and preview (right) sections,
/// user-adjustable via the splitters between them and the canvas.
float m_browserWidth = 220.0f;