diff --git a/lib/mayaUsd/nodes/proxyShapeBase.cpp b/lib/mayaUsd/nodes/proxyShapeBase.cpp index a3b45ffb7e..69f1d6b2f0 100644 --- a/lib/mayaUsd/nodes/proxyShapeBase.cpp +++ b/lib/mayaUsd/nodes/proxyShapeBase.cpp @@ -136,6 +136,8 @@ const MString MayaUsdProxyShapeBase::displayFilterName( TfStringPrintf("%sDisplayFilter", MayaUsdProxyShapeBaseTokens->MayaTypeName.GetText()).c_str()); const MString MayaUsdProxyShapeBase::displayFilterLabel("USD Proxies"); +std::atomic g_proxyShapeInstancesCount; + // Attributes MObject MayaUsdProxyShapeBase::filePathAttr; MObject MayaUsdProxyShapeBase::filePathRelativeAttr; @@ -535,6 +537,9 @@ MayaUsdProxyShapeBase* MayaUsdProxyShapeBase::GetShapeAtDagPath(const MDagPath& return pShape; } +/* static */ +int MayaUsdProxyShapeBase::countProxyShapeInstances() { return g_proxyShapeInstancesCount; } + /* static */ void MayaUsdProxyShapeBase::SetClosestPointDelegate(ClosestPointDelegate delegate) { @@ -1971,6 +1976,8 @@ MayaUsdProxyShapeBase::MayaUsdProxyShapeBase( , _unsharedStageRootSublayers() , _incomingLayers() { + g_proxyShapeInstancesCount += 1; + TfRegistryManager::GetInstance().SubscribeTo(); if (useLoadRulesHandling) { @@ -1998,6 +2005,8 @@ MayaUsdProxyShapeBase::~MayaUsdProxyShapeBase() // Deregister from the load-rules handling used to transfer load rules // between the USD stage and a dynamic attribute on the proxy shape. MayaUsdProxyShapeStageExtraData::removeProxyShape(*this); + + g_proxyShapeInstancesCount -= 1; } MSelectionMask MayaUsdProxyShapeBase::getShapeSelectionMask() const diff --git a/lib/mayaUsd/nodes/proxyShapeBase.h b/lib/mayaUsd/nodes/proxyShapeBase.h index b0570d8bf7..19ff35336a 100644 --- a/lib/mayaUsd/nodes/proxyShapeBase.h +++ b/lib/mayaUsd/nodes/proxyShapeBase.h @@ -151,6 +151,9 @@ class MayaUsdProxyShapeBase MAYAUSD_CORE_PUBLIC static MayaUsdProxyShapeBase* GetShapeAtDagPath(const MDagPath& dagPath); + MAYAUSD_CORE_PUBLIC + static int countProxyShapeInstances(); + MAYAUSD_CORE_PUBLIC static void SetClosestPointDelegate(ClosestPointDelegate delegate); diff --git a/lib/mayaUsd/ufe/UsdStageMap.cpp b/lib/mayaUsd/ufe/UsdStageMap.cpp index 179583140a..9637c1cc0c 100644 --- a/lib/mayaUsd/ufe/UsdStageMap.cpp +++ b/lib/mayaUsd/ufe/UsdStageMap.cpp @@ -134,6 +134,12 @@ UsdStageWeakPtr UsdStageMap::stage(const Ufe::Path& path) MObject UsdStageMap::proxyShape(const Ufe::Path& path) { + // Optimization: if there are not proxy shape instances, + // there is nothing that can be mapped. Avoid trying to + // build the proxy shape map. + if (MayaUsdProxyShapeBase::countProxyShapeInstances() == 0) + return MObject(); + rebuildIfDirty(); // In additional to the explicit dirty system it is possible that