diff --git a/lib/usd/ui/layerEditor/layerTreeModel.cpp b/lib/usd/ui/layerEditor/layerTreeModel.cpp index 3028b8115a..fe1fb098db 100644 --- a/lib/usd/ui/layerEditor/layerTreeModel.cpp +++ b/lib/usd/ui/layerEditor/layerTreeModel.cpp @@ -28,6 +28,8 @@ #include #include +#include +#include #include #include @@ -300,13 +302,7 @@ void LayerTreeModel::rebuildModel(bool refreshLockState /*= false*/) _lastAskedAnonLayerNameSinceRebuild = 0; beginResetModel(); - - // Note: do *not* call clear() here! Unfortunately, clear() itself calls, - // beginResetModel() and endResetModel(). Qt does not detect the nested - // begin/end/ So calling clear() would make the layer manager flicker - // to be empty for a brief time. - if (rowCount() > 0) - removeRows(0, rowCount()); + clear(); if (_sessionState->isValid()) { auto rootLayer = _sessionState->stage()->GetRootLayer(); @@ -349,6 +345,11 @@ void LayerTreeModel::rebuildModel(bool refreshLockState /*= false*/) sharedStage, &sharedLayers)); } + /* + * Here we need to create a resolver context to be able to update the target layer + */ + auto ctx = ArGetResolver().CreateDefaultContextForAsset(rootLayer->GetIdentifier()); + const ArResolverContextBinder binder(ctx); appendRow(new LayerTreeItem( rootLayer, LayerType::RootLayer, "", &incomingLayers, sharedStage, &sharedLayers)); @@ -412,8 +413,36 @@ void LayerTreeModel::updateTargetLayer(InRebuildModel inRebuild) void LayerTreeModel::usd_layerChanged(SdfNotice::LayersDidChangeSentPerLayer const& notice) { // experienced crashes in python prototype For now, rebuild everything - if (!_blockUsdNotices) - rebuildModelOnIdle(); + if (!_blockUsdNotices) { + /* + * Here we filter the cases where we need a refresh as it takes time. + * We only refresh in the case the identifier, the resolved path, + * the content or a sublayer has been changed. + */ + bool rebuildModelRequired { false }; + for (auto changePair : notice.GetChangeListVec()) { + const auto &entryList = changePair.second.GetEntryList(); + for (const auto &entryPair : entryList) { + + if (entryPair.second.flags.didChangeIdentifier || + entryPair.second.flags.didChangeResolvedPath || + entryPair.second.flags.didReplaceContent || + entryPair.second.flags.didReloadContent || + entryPair.second.subLayerChanges.size() > 0 + ) { + rebuildModelRequired = true; + break; + } + } + if (rebuildModelRequired) { + break; + } + } + + if (rebuildModelRequired) { + rebuildModelOnIdle(); + } + } } // notification from USD diff --git a/lib/usd/ui/layerEditor/mayaCommandHook.cpp b/lib/usd/ui/layerEditor/mayaCommandHook.cpp index 15e04e5f03..0062db0bf7 100644 --- a/lib/usd/ui/layerEditor/mayaCommandHook.cpp +++ b/lib/usd/ui/layerEditor/mayaCommandHook.cpp @@ -114,7 +114,10 @@ void MayaCommandHook::insertSubLayerPath(UsdLayer usdLayer, Path path, int index cmd = "mayaUsdLayerEditor -edit -insertSubPath "; cmd += std::to_string(index); cmd += quote(path); - cmd += quote(usdLayer->GetIdentifier()); + // Here we choose the identifier only if the layer is anonymous + std::string layerPath{usdLayer->IsAnonymous() ? usdLayer->GetIdentifier() : + usdLayer->GetRealPath()}; + cmd += quote(layerPath); executeMel(cmd); } @@ -127,7 +130,10 @@ void MayaCommandHook::removeSubLayerPath(UsdLayer usdLayer, Path path) cmd = "mayaUsdLayerEditor -edit -removeSubPath "; cmd += std::to_string(index); cmd += quote(proxyShapePath()); - cmd += quote(usdLayer->GetIdentifier()); + // Here we choose the identifier only if the layer is anonymous + std::string layerPath{usdLayer->IsAnonymous() ? usdLayer->GetIdentifier() : + usdLayer->GetRealPath()}; + cmd += quote(layerPath); executeMel(cmd); } @@ -140,9 +146,15 @@ void MayaCommandHook::moveSubLayerPath( std::string cmd; cmd = "mayaUsdLayerEditor -edit -moveSubPath "; cmd += quote(path); - cmd += quote(newParentUsdLayer->GetIdentifier()); + // Here we choose the identifier only if the layer is anonymous + std::string newParentUsdLayerPath{newParentUsdLayer->IsAnonymous() ? newParentUsdLayer->GetIdentifier() : + newParentUsdLayer->GetRealPath()}; + cmd += quote(newParentUsdLayerPath); cmd += std::to_string(index); - cmd += quote(oldParentUsdLayer->GetIdentifier()); + // Here we choose the identifier only if the layer is anonymous + std::string oldParentUsdLayerPath{oldParentUsdLayer->IsAnonymous() ? oldParentUsdLayer->GetIdentifier() : + oldParentUsdLayer->GetRealPath()}; + cmd += quote(oldParentUsdLayerPath); executeMel(cmd); } @@ -153,7 +165,10 @@ void MayaCommandHook::replaceSubLayerPath(UsdLayer usdLayer, Path oldPath, Path cmd = "mayaUsdLayerEditor -edit -replaceSubPath "; cmd += quote(oldPath); cmd += quote(newPath); - cmd += quote(usdLayer->GetIdentifier()); + // Here we choose the identifier only if the layer is anonymous + std::string layerPath{usdLayer->IsAnonymous() ? usdLayer->GetIdentifier() : + usdLayer->GetRealPath()}; + cmd += quote(layerPath); executeMel(cmd); } @@ -162,7 +177,10 @@ void MayaCommandHook::discardEdits(UsdLayer usdLayer) { std::string cmd; cmd = "mayaUsdLayerEditor -edit -discardEdits "; - cmd += quote(usdLayer->GetIdentifier()); + // Here we choose the identifier only if the layer is anonymous + std::string layerPath{usdLayer->IsAnonymous() ? usdLayer->GetIdentifier() : + usdLayer->GetRealPath()}; + cmd += quote(layerPath); executeMel(cmd); refreshLayerSystemLock(usdLayer); @@ -173,7 +191,10 @@ void MayaCommandHook::clearLayer(UsdLayer usdLayer) { std::string cmd; cmd = "mayaUsdLayerEditor -edit -clear "; - cmd += quote(usdLayer->GetIdentifier()); + // Here we choose the identifier only if the layer is anonymous + std::string layerPath{usdLayer->IsAnonymous() ? usdLayer->GetIdentifier() : + usdLayer->GetRealPath()}; + cmd += quote(layerPath); executeMel(cmd); } @@ -183,8 +204,12 @@ UsdLayer MayaCommandHook::addAnonymousSubLayer(UsdLayer usdLayer, std::string ne std::string cmd; cmd = "mayaUsdLayerEditor -edit -addAnonymous "; cmd += quote(newName); - cmd += quote(usdLayer->GetIdentifier()); + // Here we choose the identifier only if the layer is anonymous + std::string layerPath{usdLayer->IsAnonymous() ? usdLayer->GetIdentifier() : + usdLayer->GetRealPath()}; + cmd += quote(layerPath); std::string result = executeMel(cmd); + if (result.size() > 0) return PXR_NS::SdfLayer::FindOrOpen(result); else @@ -198,7 +223,10 @@ void MayaCommandHook::muteSubLayer(UsdLayer usdLayer, bool muteIt) cmd = "mayaUsdLayerEditor -edit -muteLayer "; cmd += muteIt ? "1" : "0"; cmd += quote(proxyShapePath()); - cmd += quote(usdLayer->GetIdentifier()); + // Here we choose the identifier only if the layer is anonymous + std::string layerPath{usdLayer->IsAnonymous() ? usdLayer->GetIdentifier() : + usdLayer->GetRealPath()}; + cmd += quote(layerPath); executeMel(cmd); } @@ -218,7 +246,10 @@ void MayaCommandHook::lockLayer( cmd += std::to_string(lockState); cmd += includeSubLayers ? " 1" : " 0"; cmd += quote(proxyShapePath()); - cmd += quote(usdLayer->GetIdentifier()); + // Here we choose the identifier only if the layer is anonymous + std::string layerPath{usdLayer->IsAnonymous() ? usdLayer->GetIdentifier() : + usdLayer->GetRealPath()}; + cmd += quote(layerPath); executeMel(cmd); } @@ -229,7 +260,10 @@ void MayaCommandHook::refreshLayerSystemLock(UsdLayer usdLayer, bool refreshSubL cmd += quote(proxyShapePath()); cmd += " "; cmd += std::to_string(refreshSubLayers); - cmd += quote(usdLayer->GetIdentifier()); + // Here we choose the identifier only if the layer is anonymous + std::string layerPath{usdLayer->IsAnonymous() ? usdLayer->GetIdentifier() : + usdLayer->GetRealPath()}; + cmd += quote(layerPath); executeMel(cmd); }