Add Collapsed pin display mode with a 3-dot state icon

Cycle each node through All -> Connected -> Collapsed -> All via a
custom-drawn icon (filled-dot count encodes how much is shown: 3/2/1).
Collapsed hides every pin on a side, linked or not, behind one
connector nub; existing links now redirect to that nub too
(EffectivePinId), so they visually converge like Hypershade's collapse
view instead of only hiding unconnected pins. Also moved the connector
nubs off the title row onto the node's bottom row. Persisted mode
switches from a bool (uiShowAllPins) to an int (uiPinDisplayMode).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-11 01:52:52 +08:00
parent c7edd145df
commit bff42082a5
4 changed files with 149 additions and 78 deletions
+7 -4
View File
@@ -138,7 +138,7 @@ ShaderGraphSnapshot MaterialManager::GetShaderGraph(const pxr::SdfPath& material
if (!materialPrim.IsValid()) return snapshot;
static const pxr::TfToken kUiPositionKey("uiPosition");
static const pxr::TfToken kUiShowAllPinsKey("uiShowAllPins");
static const pxr::TfToken kUiPinDisplayModeKey("uiPinDisplayMode");
// Seed with every shader under the material, recursing into nested node
// graphs (usdMtlx nests a material's nodes inside UsdShadeNodeGraph
@@ -180,9 +180,12 @@ ShaderGraphSnapshot MaterialManager::GetShaderGraph(const pxr::SdfPath& material
node.hasAuthoredPosition = true;
}
pxr::VtValue showAllValue = child.GetCustomDataByKey(kUiShowAllPinsKey);
if (showAllValue.IsHolding<bool>())
node.showAllPins = showAllValue.UncheckedGet<bool>();
pxr::VtValue pinModeValue = child.GetCustomDataByKey(kUiPinDisplayModeKey);
if (pinModeValue.IsHolding<int>()) {
int raw = pinModeValue.UncheckedGet<int>();
if (raw >= static_cast<int>(PinDisplayMode::All) && raw <= static_cast<int>(PinDisplayMode::Collapsed))
node.pinDisplayMode = static_cast<PinDisplayMode>(raw);
}
// Prefer the full Sdr-defined pin set (so unauthored pins can still be
// dragged to create a connection); fall back to authored attributes
+14 -6
View File
@@ -33,6 +33,17 @@ struct ShaderPinInfo {
pxr::SdfValueTypeName typeName;
};
/// Hypershade-style pin display mode for a node in the graph canvas.
/// All: every Sdr-defined pin shown (today's default). Connected: only
/// linked pins shown, the rest collapsed behind a single connectable nub per
/// side. Collapsed: every pin — linked or not — collapses behind that one
/// nub per side, so existing connections visually converge on it too.
enum class PinDisplayMode {
All = 0,
Connected = 1,
Collapsed = 2,
};
/// One UsdShadeShader prim read back from an existing material network.
/// inputs/outputs list the full Sdr-defined pin set (not just authored
/// attributes) so unauthored pins can still be dragged to create a connection.
@@ -48,12 +59,9 @@ struct ShaderGraphNode {
/// False when no uiPosition custom data is authored (typical for networks
/// referenced from .mtlx) — the editor auto-lays such nodes out instead.
bool hasAuthoredPosition = false;
/// Hypershade-style pin display mode, read from customData when the
/// "keep graph node view settings in USD" preference authored it; true
/// (show every pin) when unauthored. False hides unconnected pins,
/// collapsing them into a single connectable "more pins" nub per side
/// (see MaterialEditorPanel) until a new connection reveals one by name.
bool showAllPins = true;
/// Pin display mode, read from customData when the "keep graph node view
/// settings in USD" preference authored it; All when unauthored.
PinDisplayMode pinDisplayMode = PinDisplayMode::All;
std::vector<ShaderPinInfo> inputs;
std::vector<ShaderPinInfo> outputs;
};