|
21 | 21 | #include <maya/MGlobal.h> |
22 | 22 | #include <maya/MQtUtil.h> |
23 | 23 |
|
| 24 | +#if PXR_VERSION >= 2308 |
| 25 | +#include <pxr/usd/sdf/variableExpression.h> |
| 26 | +#endif |
| 27 | + |
24 | 28 | #include <algorithm> |
25 | 29 |
|
26 | 30 | PXR_NAMESPACE_USING_DIRECTIVE |
@@ -81,13 +85,15 @@ const LayerActionDefinitions& LayerTreeItem::actionButtonsDefinition() |
81 | 85 |
|
82 | 86 | LayerTreeItem::LayerTreeItem( |
83 | 87 | SdfLayerRefPtr in_usdLayer, |
| 88 | + UsdStageRefPtr in_stage, |
84 | 89 | LayerType in_layerType, |
85 | 90 | std::string in_subLayerPath, |
86 | 91 | std::set<std::string>* in_incomingLayers, |
87 | 92 | bool in_sharedStage, |
88 | 93 | std::set<std::string>* in_sharedLayers, |
89 | 94 | RecursionDetector* in_recursionDetector) |
90 | 95 | : _layer(std::move(in_usdLayer)) |
| 96 | + , _stage(std::move(in_stage)) |
91 | 97 | , _isTargetLayer(false) |
92 | 98 | , _layerType(in_layerType) |
93 | 99 | , _subLayerPath(in_subLayerPath) |
@@ -138,11 +144,44 @@ void LayerTreeItem::populateChildren(RecursionDetector* recursionDetector) |
138 | 144 | recursionDetector->push(_layer->GetRealPath()); |
139 | 145 |
|
140 | 146 | for (auto const path : subPaths) { |
| 147 | +#if PXR_VERSION >= 2308 |
| 148 | + // Resolve any variable expressions in the path using the stage's expression variables |
| 149 | + std::string resolvedPath = path; |
| 150 | + if (_stage && SdfVariableExpression::IsExpression(path)) { |
| 151 | + auto resolveExprVarsFromLayer = |
| 152 | + [](SdfVariableExpression& varExpr, SdfLayerRefPtr fromLayer, std::string& outPath) { |
| 153 | + if (fromLayer && fromLayer->HasExpressionVariables()) { |
| 154 | + auto expressionVars = fromLayer->GetExpressionVariables(); |
| 155 | + auto result = varExpr.Evaluate(expressionVars); |
| 156 | + if (result.errors.empty() && !result.value.IsEmpty()) { |
| 157 | + outPath = result.value.UncheckedGet<std::string>(); |
| 158 | + } |
| 159 | + } |
| 160 | + }; |
| 161 | + |
| 162 | + SdfVariableExpression varExpr(path); |
| 163 | + // Get the root layer's expression variables for resolution context |
| 164 | + auto rootLayer = _stage->GetRootLayer(); |
| 165 | + resolveExprVarsFromLayer(varExpr, rootLayer, resolvedPath); |
| 166 | + |
| 167 | + // Expression variables are composed across session layer and root |
| 168 | + // layer of a stage. So we do another pass with the session layer |
| 169 | + // to override/set the resolvedPath in case it is present in the |
| 170 | + // session layer |
| 171 | + auto sessionLayer = _stage->GetSessionLayer(); |
| 172 | + resolveExprVarsFromLayer(varExpr, sessionLayer, resolvedPath); |
| 173 | + } |
| 174 | + |
| 175 | + std::string actualPath = SdfComputeAssetPathRelativeToLayer(_layer, resolvedPath); |
| 176 | + auto subLayer = SdfLayer::FindOrOpen(actualPath); |
| 177 | +#else |
141 | 178 | std::string actualPath = SdfComputeAssetPathRelativeToLayer(_layer, path); |
142 | 179 | auto subLayer = SdfLayer::FindOrOpen(actualPath); |
| 180 | +#endif |
143 | 181 | if (!subLayer || !recursionDetector->contains(subLayer->GetRealPath())) { |
144 | 182 | auto item = new LayerTreeItem( |
145 | 183 | subLayer, |
| 184 | + _stage, |
146 | 185 | LayerType::SubLayer, |
147 | 186 | path, |
148 | 187 | &_incomingLayers, |
@@ -230,14 +269,9 @@ AbstractCommandHook* LayerTreeItem::commandHook() const |
230 | 269 | return parentModel()->sessionState()->commandHook(); |
231 | 270 | } |
232 | 271 |
|
233 | | -PXR_NS::UsdStageRefPtr const& LayerTreeItem::stage() const |
234 | | -{ |
235 | | - return parentModel()->sessionState()->stage(); |
236 | | -} |
237 | | - |
238 | 272 | bool LayerTreeItem::isMuted() const |
239 | 273 | { |
240 | | - return isInvalidLayer() || !stage() ? false : stage()->IsLayerMuted(_layer->GetIdentifier()); |
| 274 | + return isInvalidLayer() || !_stage ? false : _stage->IsLayerMuted(_layer->GetIdentifier()); |
241 | 275 | } |
242 | 276 |
|
243 | 277 | bool LayerTreeItem::appearsMuted() const |
|
0 commit comments