From b79bb4a9f0e9a1e44880e77bb59f74914177cf77 Mon Sep 17 00:00:00 2001 From: Zhicheng Ye Date: Mon, 2 Nov 2020 11:35:30 +1100 Subject: [PATCH 1/3] Removed tracking selectability and lock metadata --- .../AL_USDMaya/AL/usdmaya/PluginRegister.h | 2 +- .../AL_USDMaya/AL/usdmaya/SelectabilityDB.cpp | 148 ----------- .../AL_USDMaya/AL/usdmaya/SelectabilityDB.h | 129 ---------- .../AL/usdmaya/cmds/ProxyShapeCommands.cpp | 3 +- .../AL/usdmaya/nodes/ProxyShape.cpp | 98 ++++++- .../AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h | 45 ++-- .../AL/usdmaya/nodes/ProxyShapeSelection.cpp | 24 +- .../AL/usdmaya/nodes/proxy/LockManager.cpp | 242 ------------------ .../AL/usdmaya/nodes/proxy/LockManager.h | 103 -------- .../nodes/proxy/ProxyShapeMetaData.cpp | 188 ++------------ plugin/al/lib/AL_USDMaya/CMakeLists.txt | 4 - .../nodes/test_ProxyShapeSelectabilityDB.cpp | 10 +- .../AL/usdmaya/nodes/test_lockPrims.cpp | 26 +- .../AL/usdmaya/test_SelectabilityDB.cpp | 91 ------- .../AL_USDMayaTestPlugin/CMakeLists.txt | 1 - 15 files changed, 168 insertions(+), 946 deletions(-) delete mode 100644 plugin/al/lib/AL_USDMaya/AL/usdmaya/SelectabilityDB.cpp delete mode 100644 plugin/al/lib/AL_USDMaya/AL/usdmaya/SelectabilityDB.h delete mode 100644 plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/LockManager.cpp delete mode 100644 plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/LockManager.h delete mode 100644 plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/test_SelectabilityDB.cpp diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/PluginRegister.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/PluginRegister.h index 962de3a6f9..39a71da4f6 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/PluginRegister.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/PluginRegister.h @@ -346,7 +346,7 @@ template MStatus registerPlugin(AFnPlugin& plugin) true, MGlobal::optionVarIntValue("AL_usdmaya_pushToPrim")); AL::maya::utils::MenuBuilder::addEntry( - "USD/Selection Ignore Lock Prims Enabled", + "USD/Ignore Lock Prims", "optionVar -iv \\\"AL_usdmaya_ignoreLockPrims\\\" #1", true, MGlobal::optionVarIntValue("AL_usdmaya_ignoreLockPrims")); diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/SelectabilityDB.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/SelectabilityDB.cpp deleted file mode 100644 index e890ece8be..0000000000 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/SelectabilityDB.cpp +++ /dev/null @@ -1,148 +0,0 @@ -// -// Copyright 2017 Animal Logic -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#include - -#include -namespace { -const int _selectabilityProfilerCategory = MProfiler::addCategory( -#if MAYA_API_VERSION >= 20190000 - "SelectabilityDB", - "SelectabilityDB" -#else - "SelectabilityDB" -#endif -); -} // namespace - -namespace AL { -namespace usdmaya { - -//---------------------------------------------------------------------------------------------------------------------- -bool SelectabilityDB::isPathUnselectable(const SdfPath& path) const -{ - MProfilingScope profilerScope( - _selectabilityProfilerCategory, MProfiler::kColorE_L3, "Check unselectable paths"); - - auto begin = m_unselectablePaths.begin(); - auto end = m_unselectablePaths.end(); - auto foundPathEntry = end; - auto root = SdfPath::AbsoluteRootPath(); - auto temp(path); - - while (temp != root) { - foundPathEntry = std::lower_bound(begin, foundPathEntry, temp); - if (foundPathEntry != end && temp == *foundPathEntry) { - return true; - } - temp = temp.GetParentPath(); - } - return false; -} - -//---------------------------------------------------------------------------------------------------------------------- -void SelectabilityDB::removePathsAsUnselectable(const SdfPathVector& paths) -{ - MProfilingScope profilerScope( - _selectabilityProfilerCategory, MProfiler::kColorE_L3, "Remove unselectable paths"); - - for (SdfPath path : paths) { - removeUnselectablePath(path); - } - - auto end = m_unselectablePaths.end(); - auto start = m_unselectablePaths.begin(); - for (SdfPath path : paths) { - auto temp = std::lower_bound(start, end, path); - if (temp != end) { - if (*temp == path) { - temp = m_unselectablePaths.erase(temp); - } - start = temp; - } - } -} - -//---------------------------------------------------------------------------------------------------------------------- -void SelectabilityDB::removePathAsUnselectable(const SdfPath& path) -{ - removeUnselectablePath(path); -} - -//---------------------------------------------------------------------------------------------------------------------- -void SelectabilityDB::addPathsAsUnselectable(const SdfPathVector& paths) -{ - MProfilingScope profilerScope( - _selectabilityProfilerCategory, MProfiler::kColorE_L3, "Add unselectable paths"); - - auto end = m_unselectablePaths.end(); - auto start = m_unselectablePaths.begin(); - for (auto iter = paths.begin(), last = paths.end(); iter != last; ++iter) { - start = std::lower_bound(start, end, *iter); - - // If we've hit the end, we can simply append the remaining elements in one go. - if (start == end) { - m_unselectablePaths.insert(end, iter, last); - return; - } - - if (*start != *iter) { - m_unselectablePaths.insert(start, *iter); - } - } -} - -//---------------------------------------------------------------------------------------------------------------------- -void SelectabilityDB::addPathAsUnselectable(const SdfPath& path) { addUnselectablePath(path); } - -//---------------------------------------------------------------------------------------------------------------------- -bool SelectabilityDB::removeUnselectablePath(const SdfPath& path) -{ - MProfilingScope profilerScope( - _selectabilityProfilerCategory, MProfiler::kColorE_L3, "Remove unselectable path"); - - auto end = m_unselectablePaths.end(); - auto foundPathEntry = std::lower_bound(m_unselectablePaths.begin(), end, path); - if (foundPathEntry != end && *foundPathEntry == path) { - m_unselectablePaths.erase(foundPathEntry); - return true; - } - return false; -} - -//---------------------------------------------------------------------------------------------------------------------- -bool SelectabilityDB::addUnselectablePath(const SdfPath& path) -{ - MProfilingScope profilerScope( - _selectabilityProfilerCategory, MProfiler::kColorE_L3, "Add unselectable path"); - - auto end = m_unselectablePaths.end(); - auto iter = std::lower_bound(m_unselectablePaths.begin(), end, path); - if (iter != end) { - if (*iter != path) { - m_unselectablePaths.insert(iter, path); - return true; - } - } else { - m_unselectablePaths.push_back(path); - return true; - } - return false; -} - -//---------------------------------------------------------------------------------------------------------------------- -} // namespace usdmaya -} // namespace AL -//---------------------------------------------------------------------------------------------------------------------- diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/SelectabilityDB.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/SelectabilityDB.h deleted file mode 100644 index 471690fc43..0000000000 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/SelectabilityDB.h +++ /dev/null @@ -1,129 +0,0 @@ -// -// Copyright 2017 Animal Logic -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#pragma once - -#include "AL/usdmaya/Api.h" -#include "AL/usdmaya/ForwardDeclares.h" - -#include -#include - -PXR_NAMESPACE_USING_DIRECTIVE - -namespace AL { -namespace usdmaya { - -///--------------------------------------------------------------------------------------------------------------------- -/// \brief Logic that stores a sorted list of paths which represent Selectable points in the USD -/// hierarchy -///--------------------------------------------------------------------------------------------------------------------- -class SelectabilityDB -{ - // at little unpleasant design wise, however it means the proxy shape can directly modify the - // internal list of unselectable paths. I have looked at moving some of that logic into this - // class, however that would incur a performance penalty (lock & excluded prim processing can be - // done at the same time). - friend class nodes::ProxyShape; - -public: - SelectabilityDB() - : m_unselectablePaths() - { - m_unselectablePaths.reserve(128); - } - - //-------------------------------------------------------------------------------------------------------------------- - /// \brief Determines this path is unselectable - /// \param path that you want to determine if it's unselectable - //-------------------------------------------------------------------------------------------------------------------- - AL_USDMAYA_PUBLIC - bool isPathUnselectable(const SdfPath& path) const; - - //-------------------------------------------------------------------------------------------------------------------- - /// \brief Determines whether there is an internal entry for the path specified (and only this - /// path!). If you wish - /// to determine selectability, call isPathUnselectable instead. - /// \param path the path to check to see if exists - /// \return true if the path is contained, false if not. - //-------------------------------------------------------------------------------------------------------------------- - bool containsPath(const SdfPath& path) const - { - auto foundPathEntry - = std::lower_bound(m_unselectablePaths.begin(), m_unselectablePaths.end(), path); - if (foundPathEntry != m_unselectablePaths.end() && path == *foundPathEntry) { - return true; - } - return false; - } - - //-------------------------------------------------------------------------------------------------------------------- - /// \brief Adds a list of paths to the selectable list - /// \param paths which will be added as selectable. All children paths will be also - /// unselectable - //-------------------------------------------------------------------------------------------------------------------- - AL_USDMAYA_PUBLIC - void addPathsAsUnselectable(const SdfPathVector& paths); - - //-------------------------------------------------------------------------------------------------------------------- - /// \brief Sets a list of paths to the selectable list - /// \param paths which will be added as selectable. All children paths will be also - /// unselectable - //-------------------------------------------------------------------------------------------------------------------- - void setPathsAsUnselectable(const SdfPathVector& paths) - { - m_unselectablePaths = paths; - std::sort(m_unselectablePaths.begin(), m_unselectablePaths.end()); - } - - //-------------------------------------------------------------------------------------------------------------------- - /// \brief Adds a path to the unselectable list - /// \param path which will be added as unselectable. All children paths will be also - /// unselectable - //-------------------------------------------------------------------------------------------------------------------- - AL_USDMAYA_PUBLIC - void addPathAsUnselectable(const SdfPath& path); - - //-------------------------------------------------------------------------------------------------------------------- - /// \brief Gets the currently explictly tracked unseletable paths - //-------------------------------------------------------------------------------------------------------------------- - inline const SdfPathVector& getUnselectablePaths() const { return m_unselectablePaths; } - - ///------------------------------------------------------------------------------------------------------------------- - /// \brief Removes a list of paths from the selectable list if the exist. - /// \param paths the paths to remove from the selectable list - ///------------------------------------------------------------------------------------------------------------------- - AL_USDMAYA_PUBLIC - void removePathsAsUnselectable(const SdfPathVector& paths); - - //-------------------------------------------------------------------------------------------------------------------- - /// \brief Remove a path from the selectable list if the exist. - /// \param path the path to remove from the selectable list - //-------------------------------------------------------------------------------------------------------------------- - AL_USDMAYA_PUBLIC - void removePathAsUnselectable(const SdfPath& path); - -private: - bool addUnselectablePath(const SdfPath& path); - bool removeUnselectablePath(const SdfPath& path); - -private: - SdfPathVector m_unselectablePaths; -}; - -//---------------------------------------------------------------------------------------------------------------------- -} // namespace usdmaya -} // namespace AL -//---------------------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeCommands.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeCommands.cpp index 58766ad470..002bde5d93 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeCommands.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeCommands.cpp @@ -1039,8 +1039,7 @@ MStatus TranslatePrim::redoIt() // construct locks and selectability for imported prims if (m_proxy->isLockPrimFeatureActive()) { - m_proxy->removeMetaData(m_teardownPaths); - m_proxy->processChangedMetaData(SdfPathVector(), newImportPaths); + m_proxy->constructLockPrims(); } if (!m_updatePaths.empty()) { diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp index 658c8be2b2..9f79e2379e 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp @@ -2088,12 +2088,104 @@ void ProxyShape::setChangedSelectionState(const bool hasSelectabilityChanged) } //---------------------------------------------------------------------------------------------------------------------- -AL::usdmaya::SelectabilityDB& ProxyShape::selectabilityDB() { return m_selectabilityDB; } +bool ProxyShape::isPathUnselectable(const SdfPath& path) const +{ + if (!m_stage) + { + return false; + } + auto prim(m_stage->GetPrimAtPath(path)); + if (!prim) + { + return false; + } + UnselectablePrimCache cache; + return isPrimUnselectable(prim, cache); +} + +//---------------------------------------------------------------------------------------------------------------------- +bool ProxyShape::isPrimUnselectable(const UsdPrim& prim, UnselectablePrimCache& cache) const +{ + TfHashSet> cachedPrims; + auto updateCache = [&cache, &cachedPrims](bool value) { + for (auto &&cachedPrim: cachedPrims) + { + cache.insert(std::make_pair(cachedPrim, value)); + } + return value; + }; + + auto parent(prim); + while(parent.IsValid() && !parent.IsPseudoRoot()) + { + auto it = cache.find(parent); + if (it != cache.end()) + { + return it->second; + } + cachedPrims.insert(parent); + TfToken token; + if(parent.GetMetadata(Metadata::selectability, &token) && token == Metadata::unselectable) + { + return updateCache(true); + } + parent = parent.GetParent(); + } + return updateCache(false); +} + +//---------------------------------------------------------------------------------------------------------------------- +bool ProxyShape::isPathLocked(const SdfPath& path) const +{ + if (!m_stage) + { + return false; + } + auto prim(m_stage->GetPrimAtPath(path)); + if (!prim) + { + return false; + } + LockPrimCache cache; + return isPrimLocked(prim, cache); +} //---------------------------------------------------------------------------------------------------------------------- -const AL::usdmaya::SelectabilityDB& ProxyShape::selectabilityDB() const +bool ProxyShape::isPrimLocked(const UsdPrim& prim, LockPrimCache& cache) const { - return const_cast(this)->selectabilityDB(); + TfHashSet> cachedPrims; + auto updateCache = [&cache, &cachedPrims](bool value) { + for (auto &&cachedPrim: cachedPrims) + { + cache.insert(std::make_pair(cachedPrim, value)); + } + return value; + }; + + auto parent(prim); + while(parent.IsValid() && !parent.IsPseudoRoot()) + { + auto it = cache.find(parent); + if (it != cache.end()) + { + return it->second; + } + cachedPrims.insert(parent); + TfToken token; + if (parent.GetMetadata(Metadata::locked, &token)) + { + if (token == Metadata::lockTransform) + { + return updateCache(true); + } + else if (token == Metadata::lockUnlocked) + { + return updateCache(false); + } + } + parent = parent.GetParent(); + } + return updateCache(false); } //---------------------------------------------------------------------------------------------------------------------- diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h index bb2c1d7638..1f2bab647e 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h @@ -21,14 +21,13 @@ #include "AL/usd/transaction/Notice.h" #include "AL/usdmaya/Api.h" #include "AL/usdmaya/ForwardDeclares.h" -#include "AL/usdmaya/SelectabilityDB.h" #include "AL/usdmaya/fileio/translators/TranslatorBase.h" #include "AL/usdmaya/fileio/translators/TranslatorContext.h" -#include "AL/usdmaya/nodes/proxy/LockManager.h" #include "AL/usdmaya/nodes/proxy/PrimFilter.h" #include +#include #include #include #include @@ -42,6 +41,8 @@ #include #include +#include + PXR_NAMESPACE_USING_DIRECTIVE PXR_NAMESPACE_OPEN_SCOPE @@ -184,6 +185,9 @@ class SelectionList typedef std::unordered_map PrimPathToDagPath; +using UnselectablePrimCache = TfHashMap>; +using LockPrimCache = TfHashMap>; + extern AL::event::EventId kPreClearStageCache; extern AL::event::EventId kPostClearStageCache; //---------------------------------------------------------------------------------------------------------------------- @@ -647,7 +651,7 @@ class ProxyShape AL_USDMAYA_PUBLIC void onPrePrimChanged(const SdfPath& path, SdfPathVector& outPathVector); - // \brief process any USD objects which have been changed, normally by a notice of some kind + /// \brief process any USD objects which have been changed, normally by a notice of some kind /// \param[in] resyncedPaths vector of topmost paths for which hierarchy has changed /// \param[in] changedOnlyPaths vector of paths that changed properties /// \note do we need to handle the complex prim locking and selection logic that is curently on @@ -712,15 +716,29 @@ class ProxyShape AL_USDMAYA_PUBLIC void setChangedSelectionState(const bool hasSelectabilityChanged); - /// \brief Returns the SelectionDatabase owned by the ProxyShape - /// \return A SelectableDB owned by the ProxyShape - AL_USDMAYA_PUBLIC - AL::usdmaya::SelectabilityDB& selectabilityDB(); - - /// \brief Returns the SelectionDatabase owned by the ProxyShape - /// \return A constant SelectableDB owned by the ProxyShape - AL_USDMAYA_PUBLIC - const AL::usdmaya::SelectabilityDB& selectabilityDB() const; + /// \brief convenience method to check if a path is unselectable. + /// \param path Usd prim path. + /// \return true if unselectable, false otherwise. + AL_USDMAYA_PUBLIC + bool isPathUnselectable(const SdfPath& path) const; + + /// \brief convenience method to check if a prim is unselectable. + /// \param path Usd prim. + /// \return true if unselectable, false otherwise. + AL_USDMAYA_PUBLIC + bool isPrimUnselectable(const UsdPrim& prim, UnselectablePrimCache& cache) const; + + /// \brief convenience method to check if a path is locked. + /// \param path Usd prim path. + /// \return true if locked, false otherwise. + AL_USDMAYA_PUBLIC + bool isPathLocked(const SdfPath& path) const; + + /// \brief convenience method to check if a prim is locked. + /// \param path Usd prim. + /// \return true if locked, false otherwise. + AL_USDMAYA_PUBLIC + bool isPrimLocked(const UsdPrim& prim, LockPrimCache& cache) const; /// \brief used to reload the stage after file open AL_USDMAYA_PUBLIC @@ -1012,7 +1030,6 @@ class ProxyShape void processChangedMetaData( const SdfPathVector& resyncedPaths, const SdfPathVector& changedOnlyPaths); - void removeMetaData(const SdfPathVector& removedPaths); bool isPrimDirty(const UsdPrim& prim) override { @@ -1038,7 +1055,6 @@ class ProxyShape AL_USDMAYA_PUBLIC static std::vector m_unloadedProxyShapes; - AL::usdmaya::SelectabilityDB m_selectabilityDB; SelectionList m_selectionList; SdfPathHashSet m_selectedPaths; PrimPathToDagPath m_primPathToDagPath; @@ -1051,7 +1067,6 @@ class ProxyShape SdfPathVector m_excludedGeometry; SdfPathVector m_excludedTaggedGeometry; - proxy::LockManager m_lockManager; static MObject m_transformTranslate; static MObject m_transformRotate; static MObject m_transformScale; diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeSelection.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeSelection.cpp index 8869ef3c71..9ced4adcec 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeSelection.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeSelection.cpp @@ -533,20 +533,6 @@ MObject ProxyShape::makeUsdTransformChain( pushToPrim, readAnimatedValues); - // build up new lock-prim list - TfToken lockPropertyToken; - if (usdPrim.GetMetadata(Metadata::locked, &lockPropertyToken)) { - if (lockPropertyToken == Metadata::lockTransform) { - m_lockManager.setLocked(usdPrim.GetPath()); - } else if (lockPropertyToken == Metadata::lockUnlocked) { - m_lockManager.setUnlocked(usdPrim.GetPath()); - } else if (lockPropertyToken == Metadata::lockInherited) { - m_lockManager.setInherited(usdPrim.GetPath()); - } - } else { - m_lockManager.setInherited(usdPrim.GetPath()); - } - if (resultingPath) *resultingPath = recordUsdPrimToMayaPath(usdPrim, node); else @@ -677,7 +663,6 @@ void ProxyShape::removeUsdTransformChain_internal( modifier.reparentNode(object); modifier.deleteNode(object); } - m_lockManager.setInherited(primPath); } parentPrim = parentPrim.GetParent(); @@ -701,8 +686,6 @@ void ProxyShape::removeUsdTransformChain( MObject parentTM = MObject::kNullObj; MObject object = MObject::kNullObj; - // ensure the transforms have been removed from the selectability and lock db's. - m_lockManager.setInherited(path); while (!parentPrim.IsEmpty()) { auto it = m_requiredPaths.find(parentPrim); if (it == m_requiredPaths.end()) { @@ -717,8 +700,6 @@ void ProxyShape::removeUsdTransformChain( if (h.isAlive() && h.isValid()) { modifier.reparentNode(object); modifier.deleteNode(object); - - m_lockManager.setInherited(parentPrim); } } @@ -888,7 +869,7 @@ void SelectionUndoHelper::doIt() MGlobal::setActiveSelectionList(m_newSelection, MGlobal::kReplaceList); } m_proxy->m_pleaseIgnoreSelection = false; - if (!MGlobal::optionVarIntValue("AL_usdmaya_ignoreLockPrims")) { + if (m_proxy->isLockPrimFeatureActive()) { m_proxy->constructLockPrims(); } } @@ -911,7 +892,7 @@ void SelectionUndoHelper::undoIt() MGlobal::setActiveSelectionList(m_previousSelection, MGlobal::kReplaceList); } m_proxy->m_pleaseIgnoreSelection = false; - if (!MGlobal::optionVarIntValue("AL_usdmaya_ignoreLockPrims")) { + if (m_proxy->isLockPrimFeatureActive()) { m_proxy->constructLockPrims(); } } @@ -938,7 +919,6 @@ void ProxyShape::removeTransformRefs( "TransformReference: %s\n", it->first.GetText()); m_requiredPaths.erase(it); - m_lockManager.setInherited(iter.first); } } diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/LockManager.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/LockManager.cpp deleted file mode 100644 index b01786b01b..0000000000 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/LockManager.cpp +++ /dev/null @@ -1,242 +0,0 @@ -// -// Copyright 2017 Animal Logic -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#include "AL/usdmaya/nodes/proxy/LockManager.h" - -#include -namespace { -const int _lockManagerProfilerCategory = MProfiler::addCategory( -#if MAYA_API_VERSION >= 20190000 - "LockManager", - "LockManager" -#else - "LockManager" -#endif -); -} // namespace - -namespace AL { -namespace usdmaya { -namespace nodes { -namespace proxy { - -//---------------------------------------------------------------------------------------------------------------------- -void LockManager::removeEntries(const SdfPathVector& entries) -{ - MProfilingScope profilerScope( - _lockManagerProfilerCategory, MProfiler::kColorE_L3, "Remove entries"); - - auto lockIt = m_lockedPrims.begin(); - auto lockEnd = m_lockedPrims.end(); - - auto unlockIt = m_unlockedPrims.begin(); - auto unlockEnd = m_unlockedPrims.end(); - - for (auto it = entries.begin(), end = entries.end(); lockIt != lockEnd && it != end; ++it) { - const SdfPath path = *it; - lockIt = std::lower_bound(lockIt, lockEnd, path); - if (lockIt != lockEnd && *lockIt == path) { - lockIt = m_lockedPrims.erase(lockIt); - } - } - - for (auto it = entries.begin(), end = entries.end(); unlockIt != unlockEnd && it != end; ++it) { - const SdfPath path = *it; - unlockIt = std::lower_bound(unlockIt, unlockEnd, path); - if (unlockIt != unlockEnd && *unlockIt == path) { - unlockIt = m_unlockedPrims.erase(unlockIt); - } - } -} - -//---------------------------------------------------------------------------------------------------------------------- -void LockManager::removeFromRootPath(const SdfPath& path) -{ - MProfilingScope profilerScope( - _lockManagerProfilerCategory, MProfiler::kColorE_L3, "Remove from root path"); - - { - // find the start of the entries for this path - auto lb = std::lower_bound(m_lockedPrims.begin(), m_lockedPrims.end(), path); - auto ub = lb; - - // keep walking forwards until we hit a new branch in the tree - while (ub != m_lockedPrims.end()) { - if (ub->HasPrefix(path)) { - ++ub; - } else { - break; - } - } - - // if we find a valid range, erase the previous entries - if (lb != ub) { - m_lockedPrims.erase(lb, ub); - } - } - - // remove all previous prims from m_lockInheritedPrims that are children of the current prim. - { - // find the start of the entries for this path - auto lb = std::lower_bound(m_unlockedPrims.begin(), m_unlockedPrims.end(), path); - auto ub = lb; - - // keep walking forwards until we hit a new branch in the tree - while (ub != m_unlockedPrims.end()) { - if (ub->HasPrefix(path)) { - ++ub; - } else { - break; - } - } - - // if we find a valid range, erase the previous entries - if (lb != ub) { - m_unlockedPrims.erase(lb, ub); - } - } -} - -//---------------------------------------------------------------------------------------------------------------------- -void LockManager::setLocked(const SdfPath& path) -{ - auto lockIter = std::lower_bound(m_lockedPrims.begin(), m_lockedPrims.end(), path); - if (lockIter != m_lockedPrims.end()) { - // lock already in the locked array, so return - if (*lockIter == path) - return; - } - m_lockedPrims.insert(lockIter, path); - - auto unlockIter = std::lower_bound(m_unlockedPrims.begin(), m_unlockedPrims.end(), path); - if (unlockIter != m_unlockedPrims.end()) { - if (*unlockIter == path) { - m_unlockedPrims.erase(unlockIter); - } - } -} - -//---------------------------------------------------------------------------------------------------------------------- -void LockManager::setUnlocked(const SdfPath& path) -{ - MProfilingScope profilerScope( - _lockManagerProfilerCategory, MProfiler::kColorE_L3, "Set unlocked"); - - auto unlockIter = std::lower_bound(m_unlockedPrims.begin(), m_unlockedPrims.end(), path); - if (unlockIter != m_unlockedPrims.end()) { - // lock already in the locked array, so return - if (*unlockIter == path) - return; - } - m_unlockedPrims.insert(unlockIter, path); - - auto lockIter = std::lower_bound(m_lockedPrims.begin(), m_lockedPrims.end(), path); - if (lockIter != m_lockedPrims.end()) { - if (*lockIter == path) { - m_lockedPrims.erase(lockIter); - } - } -} - -//---------------------------------------------------------------------------------------------------------------------- -void LockManager::setInherited(const SdfPath& path) -{ - MProfilingScope profilerScope( - _lockManagerProfilerCategory, MProfiler::kColorE_L3, "Set inherited"); - - if (!m_unlockedPrims.empty()) { - auto unlockIter = std::lower_bound(m_unlockedPrims.begin(), m_unlockedPrims.end(), path); - if (unlockIter != m_unlockedPrims.end()) { - // lock already in the locked array, so return - if (*unlockIter == path) { - m_unlockedPrims.erase(unlockIter); - } - } - } - if (!m_lockedPrims.empty()) { - auto lockIter = std::lower_bound(m_lockedPrims.begin(), m_lockedPrims.end(), path); - if (lockIter != m_lockedPrims.end()) { - // lock already in the locked array, so return - if (*lockIter == path) { - m_lockedPrims.erase(lockIter); - } - } - } -} - -//---------------------------------------------------------------------------------------------------------------------- -bool LockManager::isLocked(const SdfPath& path) const -{ - MProfilingScope profilerScope( - _lockManagerProfilerCategory, MProfiler::kColorE_L3, "Check locked state"); - - if (m_lockedPrims.empty()) - return false; - - auto lockIter = std::lower_bound(m_lockedPrims.begin(), m_lockedPrims.end(), path); - - // first check the edge case where this path is in the locked set - if (lockIter != m_lockedPrims.end() && *lockIter == path) { - return true; - } - - // now attempt to see if a parent of this path is in the locked set - bool hasLockedParent = false; - if (lockIter != m_lockedPrims.begin()) { - --lockIter; - { - if (path.HasPrefix(*lockIter)) { - hasLockedParent = true; - } - } - } - - // now attempt to see if a parent of this path is in the unlocked set - bool hasUnlockedParent = false; - auto unlockIter = std::lower_bound(m_unlockedPrims.begin(), m_unlockedPrims.end(), path); - - // first check the edge case where this path is in the locked set - if (unlockIter != m_unlockedPrims.end() && *unlockIter == path) { - return false; - } - - if (unlockIter != m_unlockedPrims.begin()) { - --unlockIter; - { - if (path.HasPrefix(*unlockIter)) { - hasUnlockedParent = true; - } - } - } - - // if we have entries in both the locked and unlocked set..... - if (hasLockedParent && hasUnlockedParent) { - // if the locked path is longer than the unlocked path, the closest parent to path is - // locked. - return (lockIter->GetString().size() >= unlockIter->GetString().size()); - } else if (hasLockedParent) { - return true; - } - - // either the parent is unlocked, or no entry exists at all (treat as unlocked). - return false; -} - -//---------------------------------------------------------------------------------------------------------------------- -} // namespace proxy -} // namespace nodes -} // namespace usdmaya -} // namespace AL -//---------------------------------------------------------------------------------------------------------------------- diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/LockManager.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/LockManager.h deleted file mode 100644 index 2945ba04c3..0000000000 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/LockManager.h +++ /dev/null @@ -1,103 +0,0 @@ -// -// Copyright 2017 Animal Logic -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#pragma once - -#include - -#include - -PXR_NAMESPACE_USING_DIRECTIVE - -namespace AL { -namespace usdmaya { -namespace nodes { -namespace proxy { - -//---------------------------------------------------------------------------------------------------------------------- -/// \brief A class that maintains a list of locked and unlocked prims. -//---------------------------------------------------------------------------------------------------------------------- -struct LockManager -{ - /// \brief removes the specified paths from the locked and unlocked sets - /// \param entries the array of entires to remove. - AL_USDMAYA_PUBLIC - void removeEntries(const SdfPathVector& entries); - - /// \brief removes all entries from the locked and unlocked sets that are a child of the - /// specified path \param path the root path to remove - AL_USDMAYA_PUBLIC - void removeFromRootPath(const SdfPath& path); - - /// \brief sets the specified path as locked (and any paths that inherit their state from their - /// parent). - /// If the path exists within the unlocked set, it will be removed. - /// \param path the path to insert into the locked set - AL_USDMAYA_PUBLIC - void setLocked(const SdfPath& path); - - /// \brief sets the specified path as unlocked (and any paths that inherit their state from - /// their parent). - /// If the path exists within the locked set, it will be removed. - /// \param path the path to insert into the unlocked set - AL_USDMAYA_PUBLIC - void setUnlocked(const SdfPath& path); - - /// \brief adds the specified path to the locked prims list. No checking is done by this method - /// to see whether - /// the path is part of the locked or unlocked sets. The intention for this method is to - /// quickly build up changes in the set of lock prims, and having done that, later sort - /// them by calling sort() - /// \param path the path to insert into the locked set - inline void addLocked(const SdfPath& path) { m_lockedPrims.emplace_back(path); } - - /// \brief adds the specified path to the unlocked prims list. No checking is done by this - /// method to see whether - /// the path is part of the locked or unlocked sets. The intention for this method is to - /// quickly build up changes in the set of lock prims, and having done that, later sort - /// them by calling sort() - /// \param path the path to insert into the unlocked set - inline void addUnlocked(const SdfPath& path) { m_unlockedPrims.emplace_back(path); } - - /// \brief sorts the two sets of locked and unlocked prims for fast lookup - inline void sort() - { - std::sort(m_lockedPrims.begin(), m_lockedPrims.end()); - std::sort(m_unlockedPrims.begin(), m_unlockedPrims.end()); - } - - /// \brief Will remove the path from both the locked and unlocked sets. The lock status will - /// now be inherited. \param path the path to set as inherited - AL_USDMAYA_PUBLIC - void setInherited(const SdfPath& path); - - /// \brief a query function to determine whether the specified path is locked or not. - /// \param path the path to query the lock status for - /// \return true if the prim is locked (either by explicitly being set as locked, or by - /// inheriting a lock status) - AL_USDMAYA_PUBLIC - bool isLocked(const SdfPath& path) const; - -private: - SdfPathVector m_lockedPrims; - SdfPathVector m_unlockedPrims; -}; - -//---------------------------------------------------------------------------------------------------------------------- -} // namespace proxy -} // namespace nodes -} // namespace usdmaya -} // namespace AL -//---------------------------------------------------------------------------------------------------------------------- diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/ProxyShapeMetaData.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/ProxyShapeMetaData.cpp index 1ca77fba81..914f54c709 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/ProxyShapeMetaData.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/ProxyShapeMetaData.cpp @@ -38,18 +38,6 @@ namespace AL { namespace usdmaya { namespace nodes { -//---------------------------------------------------------------------------------------------------------------------- -void ProxyShape::removeMetaData(const SdfPathVector& removedPaths) -{ - MProfilingScope profilerScope( - _proxyShapeMetadataProfilerCategory, MProfiler::kColorE_L3, "Remove metadata"); - - TF_DEBUG(ALUSDMAYA_EVENTS).Msg("ProxyShape::removeMetaData"); - - m_selectabilityDB.removePathsAsUnselectable(removedPaths); - m_lockManager.removeEntries(removedPaths); -} - //---------------------------------------------------------------------------------------------------------------------- void ProxyShape::processChangedMetaData( const SdfPathVector& resyncedPaths, @@ -64,76 +52,19 @@ void ProxyShape::processChangedMetaData( resyncedPaths.size(), changedOnlyPaths.size()); - // if this is just a data change (rather than a variant switch), check for any meta data changes - if (m_variantSwitchedPrims.empty()) { - // figure out whether selectability has changed. - for (const SdfPath& path : changedOnlyPaths) { - UsdPrim changedPrim = m_stage->GetPrimAtPath(path); - if (!changedPrim) { - continue; - } - - TfToken selectabilityPropertyToken; - if (changedPrim.GetMetadata( - Metadata::selectability, &selectabilityPropertyToken)) { - bool hasPath = m_selectabilityDB.containsPath(path); - // Check if this prim is unselectable - if (selectabilityPropertyToken == Metadata::unselectable) { - if (!hasPath) { - m_selectabilityDB.addPathAsUnselectable(path); - } - } - if (hasPath) { - m_selectabilityDB.removePathAsUnselectable(path); - } - } - - // build up new lock-prim list - TfToken lockPropertyToken; - if (changedPrim.GetMetadata(Metadata::locked, &lockPropertyToken)) { - if (lockPropertyToken == Metadata::lockTransform) { - m_lockManager.setLocked(path); - } else if (lockPropertyToken == Metadata::lockUnlocked) { - m_lockManager.setUnlocked(path); - } else { - m_lockManager.setInherited(path); - } - } else { - m_lockManager.setInherited(path); - } - } - } bool excludedPrimsModified = false; { - auto& unselectablePaths = m_selectabilityDB.m_unselectablePaths; - - // figure out whether selectability has changed. - for (const SdfPath& path : resyncedPaths) { - const UsdPrim syncPrimRoot = m_stage->GetPrimAtPath(path); + for (const SdfPath& resyncedPath : resyncedPaths) { + const UsdPrim syncPrimRoot = m_stage->GetPrimAtPath(resyncedPath); if (!syncPrimRoot) { // TODO : Ensure elements have been removed from selectabilityDB, excludeGeom, and // lock prims continue; } - // determine range of selectable prims we need to replace in the selectability DB - auto lb = std::lower_bound(unselectablePaths.begin(), unselectablePaths.end(), path); - auto ub = lb; - if (lb != unselectablePaths.end()) { - while (ub != unselectablePaths.end() && ub->HasPrefix(*lb)) { - ++ub; - } - } - - m_lockManager.removeFromRootPath(path); - // sort the excluded tagged geom to help searching std::sort(m_excludedTaggedGeometry.begin(), m_excludedTaggedGeometry.end()); - // fill these lists as we traverse - SdfPathVector newUnselectables; - SdfPathVector newExcludeGeom; - // keep track of where the last item in the original set of prims is. // As we traverse, lookups will be performed on the first elements in the array, so that // will remain sorted. Items appended to the end of the array will not be sorted. @@ -144,8 +75,8 @@ void ProxyShape::processChangedMetaData( // from the resync prim, traverse downwards through the child prims for (fileio::TransformIterator it(syncPrimRoot, parentTransform(), true); !it.done(); it.next()) { - const auto prim = it.prim(); - const auto path = prim.GetPath(); + const auto& prim = it.prim(); + const auto& path = prim.GetPath(); // first check to see if the excluded geom has changed { @@ -153,9 +84,9 @@ void ProxyShape::processChangedMetaData( if (prim.GetMetadata(Metadata::excludeFromProxyShape, &excludeGeo) && excludeGeo) { const auto last = m_excludedTaggedGeometry.begin() + lastTaggedPrim; - const auto it + const auto geoIt = std::lower_bound(m_excludedTaggedGeometry.begin(), last, path); - if (it != last && *it == path) { + if (geoIt != last && *geoIt == path) { // we already have an entry for this prim } else { // add to back of list @@ -165,59 +96,14 @@ void ProxyShape::processChangedMetaData( } else { // if we aren't excluding the geom, but have an existing entry, remove it. const auto last = m_excludedTaggedGeometry.begin() + lastTaggedPrim; - const auto it + const auto geoIt = std::lower_bound(m_excludedTaggedGeometry.begin(), last, path); - if (it != last && *it == path) { + if (geoIt != last && *geoIt == path) { excludedPrimsModified = true; - m_excludedTaggedGeometry.erase(it); + m_excludedTaggedGeometry.erase(geoIt); --lastTaggedPrim; } } - - // If prim has exclusion tag or is a descendent of a prim with it, create as - // Maya geo - if (excludeGeo || primHasExcludedParent(prim)) { - VtValue schemaName(fileio::ALExcludedPrimSchema.GetString()); - prim.SetCustomDataByKey(fileio::ALSchemaType, schemaName); - } - } - - // build up new unselectable list - TfToken selectabilityPropertyToken; - if (prim.GetMetadata( - Metadata::selectability, &selectabilityPropertyToken)) { - if (selectabilityPropertyToken == Metadata::unselectable) { - newUnselectables.emplace_back(path); - } - } - - // build up new lock-prim list - TfToken lockPropertyToken; - if (prim.GetMetadata(Metadata::locked, &lockPropertyToken)) { - if (lockPropertyToken == Metadata::lockTransform) { - m_lockManager.addLocked(path); - } else if (lockPropertyToken == Metadata::lockUnlocked) { - m_lockManager.addUnlocked(path); - } - } - } - - m_lockManager.sort(); - - // sort and merge into previous selectable database - std::sort(newUnselectables.begin(), newUnselectables.end()); - - if (lb == unselectablePaths.end()) { - if (!newUnselectables.empty()) { - unselectablePaths.insert( - unselectablePaths.end(), newUnselectables.begin(), newUnselectables.end()); - } - } else { - // TODO: could probably overwrite some of old paths here, and then insert the - // remaining new elements. - lb = unselectablePaths.erase(lb, ub); - if (!newUnselectables.empty()) { - unselectablePaths.insert(lb, newUnselectables.begin(), newUnselectables.end()); } } } @@ -259,31 +145,31 @@ void ProxyShape::constructLockPrims() TF_DEBUG(ALUSDMAYA_EVALUATION).Msg("ProxyShape::constructLockPrims\n"); + LockPrimCache cache; // iterate over the - for (auto it : m_requiredPaths) { - Scope* s = it.second.getTransformNode(); - if (!s) { + for (const auto& it : m_requiredPaths) { + Scope* transformScope = it.second.getTransformNode(); + if (!transformScope) { continue; } - const UsdPrim& prim = s->transform()->prim(); + const UsdPrim& prim = transformScope->transform()->prim(); if (prim) { - bool is_locked = m_lockManager.isLocked(prim.GetPath()); + bool isLocked = isPrimLocked(prim, cache); - MObject lockObject = s->thisMObject(); + MObject lockObject = transformScope->thisMObject(); MPlug t(lockObject, m_transformTranslate); MPlug r(lockObject, m_transformRotate); MPlug s(lockObject, m_transformScale); - t.setLocked(is_locked); - r.setLocked(is_locked); - s.setLocked(is_locked); + t.setLocked(isLocked); + r.setLocked(isLocked); + s.setLocked(isLocked); - if (is_locked) { + if (isLocked) { MFnDependencyNode fn(lockObject); - Transform* transformNode = dynamic_cast(fn.userNode()); - if (transformNode) { + if (dynamic_cast(fn.userNode())) { MPlug plug(lockObject, Transform::pushToPrim()); if (plug.asBool()) plug.setBool(false); @@ -327,49 +213,19 @@ void ProxyShape::findPrimsWithMetaData() return; if (isLockPrimFeatureActive()) { - SdfPathVector newUnselectables; for (fileio::TransformIterator it(m_stage, parentTransform(), true); !it.done(); it.next()) { - auto prim = it.prim(); + const auto& prim = it.prim(); bool excludeGeo = false; if (prim.GetMetadata(Metadata::excludeFromProxyShape, &excludeGeo)) { if (excludeGeo) { m_excludedTaggedGeometry.push_back(prim.GetPrimPath()); } } - - // If prim has exclusion tag or is a descendent of a prim with it, create as Maya geo - if (excludeGeo || primHasExcludedParent(prim)) { - VtValue schemaName(fileio::ALExcludedPrimSchema.GetString()); - prim.SetCustomDataByKey(fileio::ALSchemaType, schemaName); - } - - TfToken selectabilityPropertyToken; - if (prim.GetMetadata(Metadata::selectability, &selectabilityPropertyToken)) { - // Check if this prim is unselectable - if (selectabilityPropertyToken == Metadata::unselectable) { - newUnselectables.push_back(prim.GetPath()); - } - } - - // build up new lock-prim list - TfToken lockPropertyToken; - if (prim.GetMetadata(Metadata::locked, &lockPropertyToken)) { - if (lockPropertyToken == Metadata::lockTransform) { - m_lockManager.setLocked(prim.GetPath()); - } else if (lockPropertyToken == Metadata::lockUnlocked) { - m_lockManager.setUnlocked(prim.GetPath()); - } else if (lockPropertyToken == Metadata::lockInherited) { - m_lockManager.setInherited(prim.GetPath()); - } - } else { - m_lockManager.setInherited(prim.GetPath()); - } } constructLockPrims(); constructExcludedPrims(); - m_selectabilityDB.setPathsAsUnselectable(newUnselectables); } } diff --git a/plugin/al/lib/AL_USDMaya/CMakeLists.txt b/plugin/al/lib/AL_USDMaya/CMakeLists.txt index fc4b0d8859..54f13cccb7 100644 --- a/plugin/al/lib/AL_USDMaya/CMakeLists.txt +++ b/plugin/al/lib/AL_USDMaya/CMakeLists.txt @@ -7,7 +7,6 @@ list(APPEND AL_usdmaya_headers AL/usdmaya/DebugCodes.h AL/usdmaya/Metadata.h AL/usdmaya/PluginRegister.h - AL/usdmaya/SelectabilityDB.h AL/usdmaya/StageCache.h AL/usdmaya/TransformOperation.h AL/usdmaya/TypeIDs.h @@ -20,7 +19,6 @@ list(APPEND AL_usdmaya_source AL/usdmaya/DebugCodes.cpp AL/usdmaya/Global.cpp AL/usdmaya/Metadata.cpp - AL/usdmaya/SelectabilityDB.cpp AL/usdmaya/StageCache.cpp AL/usdmaya/TransformOperation.cpp AL/usdmaya/moduleDeps.cpp @@ -115,7 +113,6 @@ list(APPEND AL_usdmaya_nodes_headers list(APPEND AL_usdmaya_nodes_proxy_headers AL/usdmaya/nodes/proxy/PrimFilter.h - AL/usdmaya/nodes/proxy/LockManager.h ) list(APPEND AL_usdmaya_nodes_source @@ -132,7 +129,6 @@ list(APPEND AL_usdmaya_nodes_source AL/usdmaya/nodes/Scope.cpp AL/usdmaya/nodes/BasicTransformationMatrix.cpp AL/usdmaya/nodes/TransformationMatrix.cpp - AL/usdmaya/nodes/proxy/LockManager.cpp AL/usdmaya/nodes/proxy/PrimFilter.cpp AL/usdmaya/nodes/proxy/ProxyShapeMetaData.cpp AL/usdmaya/nodes/proxy/ProxyShapeVariantFallbacks.cpp diff --git a/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_ProxyShapeSelectabilityDB.cpp b/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_ProxyShapeSelectabilityDB.cpp index 639fa58a2a..7b3f026113 100644 --- a/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_ProxyShapeSelectabilityDB.cpp +++ b/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_ProxyShapeSelectabilityDB.cpp @@ -59,7 +59,7 @@ TEST(ProxyShapeSelectabilityDB, selectablesOnOpen) = CreateMayaProxyShape(constructTransformChain, temp_path); // Check that the path is selectable directly using the selectableDB object - EXPECT_TRUE(proxyShape->selectabilityDB().isPathUnselectable(expectedSelectable)); + EXPECT_TRUE(proxyShape->isPathUnselectable(expectedSelectable)); } /* @@ -82,13 +82,13 @@ TEST(ProxyShapeSelectabilityDB, selectablesOnModification) = CreateMayaProxyShape(constructTransformChain, temp_path); SdfPath expectedSelectable("/A/B"); - EXPECT_FALSE(proxyShape->selectabilityDB().isPathUnselectable(expectedSelectable)); + EXPECT_FALSE(proxyShape->isPathUnselectable(expectedSelectable)); UsdPrim b = proxyShape->getUsdStage()->GetPrimAtPath(expectedSelectable); b.SetMetadata(AL::usdmaya::Metadata::selectability, AL::usdmaya::Metadata::unselectable); // Check that the path is selectable directly using the selectableDB object - EXPECT_TRUE(proxyShape->selectabilityDB().isPathUnselectable(expectedSelectable)); + EXPECT_TRUE(proxyShape->isPathUnselectable(expectedSelectable)); } /* @@ -114,11 +114,11 @@ TEST(ProxyShapeSelectabilityDB, selectableIsRemoval) AL::usdmaya::nodes::ProxyShape* proxyShape = CreateMayaProxyShape(constructTransformChain, temp_path); - EXPECT_TRUE(proxyShape->selectabilityDB().isPathUnselectable(expectedSelectable)); + EXPECT_TRUE(proxyShape->isPathUnselectable(expectedSelectable)); UsdPrim b = proxyShape->getUsdStage()->GetPrimAtPath(expectedSelectable); b.SetMetadata(AL::usdmaya::Metadata::selectability, AL::usdmaya::Metadata::selectable); // Check that the path has been removed from the selectable list - EXPECT_FALSE(proxyShape->selectabilityDB().isPathUnselectable(expectedSelectable)); + EXPECT_FALSE(proxyShape->isPathUnselectable(expectedSelectable)); } diff --git a/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_lockPrims.cpp b/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_lockPrims.cpp index 402c22213c..47f7691a9f 100644 --- a/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_lockPrims.cpp +++ b/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_lockPrims.cpp @@ -251,30 +251,28 @@ TEST(Selectability, selectableMetaData) ASSERT_TRUE(world); ASSERT_TRUE(cam); - AL::usdmaya::SelectabilityDB& db = proxy->selectabilityDB(); - - EXPECT_FALSE(db.isPathUnselectable(SdfPath("/hello"))); - EXPECT_TRUE(db.isPathUnselectable(SdfPath("/hello/world"))); - EXPECT_TRUE(db.isPathUnselectable(SdfPath("/hello/world/cam"))); + EXPECT_FALSE(proxy->isPathUnselectable(SdfPath("/hello"))); + EXPECT_TRUE(proxy->isPathUnselectable(SdfPath("/hello/world"))); + EXPECT_TRUE(proxy->isPathUnselectable(SdfPath("/hello/world/cam"))); UsdVariantSets sets = hello.GetVariantSets(); EXPECT_TRUE(sets.SetSelection("slVariant", "selectable")); - EXPECT_FALSE(db.isPathUnselectable(SdfPath("/hello"))); - EXPECT_FALSE(db.isPathUnselectable(SdfPath("/hello/world"))); - EXPECT_FALSE(db.isPathUnselectable(SdfPath("/hello/world/cam"))); + EXPECT_FALSE(proxy->isPathUnselectable(SdfPath("/hello"))); + EXPECT_FALSE(proxy->isPathUnselectable(SdfPath("/hello/world"))); + EXPECT_FALSE(proxy->isPathUnselectable(SdfPath("/hello/world/cam"))); EXPECT_TRUE(sets.SetSelection("slVariant", "unselectable")); - EXPECT_FALSE(db.isPathUnselectable(SdfPath("/hello"))); - EXPECT_TRUE(db.isPathUnselectable(SdfPath("/hello/world"))); - EXPECT_TRUE(db.isPathUnselectable(SdfPath("/hello/world/cam"))); + EXPECT_FALSE(proxy->isPathUnselectable(SdfPath("/hello"))); + EXPECT_TRUE(proxy->isPathUnselectable(SdfPath("/hello/world"))); + EXPECT_TRUE(proxy->isPathUnselectable(SdfPath("/hello/world/cam"))); EXPECT_TRUE(sets.SetSelection("slVariant", "selectable_cam")); - EXPECT_FALSE(db.isPathUnselectable(SdfPath("/hello"))); - EXPECT_TRUE(db.isPathUnselectable(SdfPath("/hello/world"))); - EXPECT_TRUE(db.isPathUnselectable(SdfPath("/hello/world/cam"))); + EXPECT_FALSE(proxy->isPathUnselectable(SdfPath("/hello"))); + EXPECT_TRUE(proxy->isPathUnselectable(SdfPath("/hello/world"))); + EXPECT_TRUE(proxy->isPathUnselectable(SdfPath("/hello/world/cam"))); } // This test loads a usda file containing variants for the permutations of the excludedGeom tag. diff --git a/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/test_SelectabilityDB.cpp b/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/test_SelectabilityDB.cpp deleted file mode 100644 index 857aff4349..0000000000 --- a/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/test_SelectabilityDB.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// -// Copyright 2017 Animal Logic -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#include - -#include -using namespace AL::usdmaya; - -TEST(SelectabilityDB, makingParentPathsSelectable) -{ - SdfPath rootPath("/A"); - SdfPath childPath("/A/B"); - SdfPath grandchildPath("/A/B/C"); - - SelectabilityDB selectableDB; - // Test that adding a single and multiple path works. - { - selectableDB.addPathAsUnselectable(childPath); - const SdfPathVector& selectablePaths = selectableDB.getUnselectablePaths(); - - ASSERT_TRUE(selectablePaths.size() == 1); - EXPECT_TRUE(selectablePaths[0] == childPath); - - selectableDB.addPathAsUnselectable(grandchildPath); - - ASSERT_TRUE(selectablePaths.size() == 2); - EXPECT_TRUE(selectablePaths[1] == grandchildPath); - } -} -/* - * Test that using SelectableDB's adding API is working - */ -// void SelectableDB::addPathAsSelectable(const SdfPath& path) - -TEST(SelectabilityDB, selectedPaths) -{ - SdfPath rootPath("/A"); - SdfPath childPath("/A/B"); - SdfPath grandchildPath("/A/B/C"); - SdfPath secondChildPath("/A/D"); - - SelectabilityDB selectableDB; - // Test that adding a single and multiple path works. - { - selectableDB.addPathAsUnselectable(childPath); - // Test that all the paths that are expected to be selectable are. - EXPECT_TRUE(selectableDB.isPathUnselectable(childPath)); - EXPECT_TRUE(selectableDB.isPathUnselectable(grandchildPath)); - - EXPECT_FALSE(selectableDB.isPathUnselectable(rootPath)); - EXPECT_FALSE(selectableDB.isPathUnselectable(secondChildPath)); - } -} -/* - * Test that using UnselectableDB's removal API is working - */ -// void SelectableDB::addPathAsUnselectable(const SdfPath& path) -// void SelectableDB::removePathAsUnselectable(const SdfPath& path) -TEST(SelectabilityDB, removePaths) -{ - SdfPath rootPath("/A"); - SdfPath childPath("/A/B"); - SdfPath grandchildPath("/A/B/C"); - SdfPath secondChildPath("/A/D"); - - SelectabilityDB selectable; - // Test that removing selectable paths from the SelectionDB works. - { - // - selectable.addPathAsUnselectable(childPath); - const SdfPathVector& unselectablePaths = selectable.getUnselectablePaths(); - EXPECT_TRUE(unselectablePaths.size() == 1); - selectable.addPathAsUnselectable(grandchildPath); - EXPECT_TRUE(unselectablePaths.size() == 2); - selectable.removePathAsUnselectable(childPath); - EXPECT_TRUE(unselectablePaths.size() == 1); - } -} diff --git a/plugin/al/plugin/AL_USDMayaTestPlugin/CMakeLists.txt b/plugin/al/plugin/AL_USDMayaTestPlugin/CMakeLists.txt index 7c88f6499d..689dbc540f 100644 --- a/plugin/al/plugin/AL_USDMayaTestPlugin/CMakeLists.txt +++ b/plugin/al/plugin/AL_USDMayaTestPlugin/CMakeLists.txt @@ -42,7 +42,6 @@ target_sources(${TARGET_NAME} AL/usdmaya/nodes/test_VariantFallbacks.cpp AL/usdmaya/test_DiffGeom.cpp AL/usdmaya/test_DiffPrimVar.cpp - AL/usdmaya/test_SelectabilityDB.cpp test_translators_AnimationTranslator.cpp test_translators_CameraTranslator.cpp test_translators_DgTranslator.cpp From cbee99607d1c5dac741fc67c052fcb1a0d323851 Mon Sep 17 00:00:00 2001 From: Zhicheng Ye Date: Thu, 12 Nov 2020 13:05:12 +1100 Subject: [PATCH 2/3] Changed selectability logic to match lock prim which checks metadata from itself or the closest ancestor. --- .../AL/usdmaya/nodes/ProxyShape.cpp | 140 ++++++++---------- .../AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h | 64 ++++---- .../nodes/proxy/ProxyShapeMetaData.cpp | 2 +- .../AL/usdmaya/nodes/test_lockPrims.cpp | 2 +- 4 files changed, 93 insertions(+), 115 deletions(-) diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp index 9f79e2379e..3196d5d669 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp @@ -2087,105 +2087,83 @@ void ProxyShape::setChangedSelectionState(const bool hasSelectabilityChanged) m_hasChangedSelection = hasSelectabilityChanged; } +//---------------------------------------------------------------------------------------------------------------------- +template +bool checkPrimMetadata( + const UsdPrim& prim, + const TfToken& key, + const TfToken& trueToken, + const TfToken& falseToken, + CacheT& cache) +{ + TfHashSet> cachedPrims; + auto updateCache = [&cache, &cachedPrims](bool value) { + for (auto&& cachedPrim : cachedPrims) { + cache.insert(std::make_pair(cachedPrim, value)); + } + return value; + }; + + auto parent(prim); + while (parent.IsValid() && !parent.IsPseudoRoot()) { + auto it = cache.find(parent); + if (it != cache.end()) { + return it->second; + } + cachedPrims.insert(parent); + TfToken token; + if (parent.GetMetadata(key, &token)) { + if (token == trueToken) { + return updateCache(true); + } else if (token == falseToken) { + return updateCache(false); + } + } + parent = parent.GetParent(); + } + return updateCache(false); +} + //---------------------------------------------------------------------------------------------------------------------- bool ProxyShape::isPathUnselectable(const SdfPath& path) const { - if (!m_stage) - { - return false; - } - auto prim(m_stage->GetPrimAtPath(path)); - if (!prim) - { - return false; - } - UnselectablePrimCache cache; - return isPrimUnselectable(prim, cache); + if (!m_stage) { + return false; + } + auto prim(m_stage->GetPrimAtPath(path)); + if (!prim) { + return false; + } + UnselectablePrimCache cache; + return isPrimUnselectable(prim, cache); } //---------------------------------------------------------------------------------------------------------------------- bool ProxyShape::isPrimUnselectable(const UsdPrim& prim, UnselectablePrimCache& cache) const { - TfHashSet> cachedPrims; - auto updateCache = [&cache, &cachedPrims](bool value) { - for (auto &&cachedPrim: cachedPrims) - { - cache.insert(std::make_pair(cachedPrim, value)); - } - return value; - }; - - auto parent(prim); - while(parent.IsValid() && !parent.IsPseudoRoot()) - { - auto it = cache.find(parent); - if (it != cache.end()) - { - return it->second; - } - cachedPrims.insert(parent); - TfToken token; - if(parent.GetMetadata(Metadata::selectability, &token) && token == Metadata::unselectable) - { - return updateCache(true); - } - parent = parent.GetParent(); - } - return updateCache(false); + return checkPrimMetadata( + prim, Metadata::selectability, Metadata::unselectable, Metadata::selectable, cache); } //---------------------------------------------------------------------------------------------------------------------- bool ProxyShape::isPathLocked(const SdfPath& path) const { - if (!m_stage) - { - return false; - } - auto prim(m_stage->GetPrimAtPath(path)); - if (!prim) - { - return false; - } - LockPrimCache cache; - return isPrimLocked(prim, cache); + if (!m_stage) { + return false; + } + auto prim(m_stage->GetPrimAtPath(path)); + if (!prim) { + return false; + } + LockPrimCache cache; + return isPrimLocked(prim, cache); } //---------------------------------------------------------------------------------------------------------------------- bool ProxyShape::isPrimLocked(const UsdPrim& prim, LockPrimCache& cache) const { - TfHashSet> cachedPrims; - auto updateCache = [&cache, &cachedPrims](bool value) { - for (auto &&cachedPrim: cachedPrims) - { - cache.insert(std::make_pair(cachedPrim, value)); - } - return value; - }; - - auto parent(prim); - while(parent.IsValid() && !parent.IsPseudoRoot()) - { - auto it = cache.find(parent); - if (it != cache.end()) - { - return it->second; - } - cachedPrims.insert(parent); - TfToken token; - if (parent.GetMetadata(Metadata::locked, &token)) - { - if (token == Metadata::lockTransform) - { - return updateCache(true); - } - else if (token == Metadata::lockUnlocked) - { - return updateCache(false); - } - } - parent = parent.GetParent(); - } - return updateCache(false); + return checkPrimMetadata( + prim, Metadata::locked, Metadata::lockTransform, Metadata::lockUnlocked, cache); } //---------------------------------------------------------------------------------------------------------------------- diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h index 1f2bab647e..a781e9f198 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h @@ -716,29 +716,29 @@ class ProxyShape AL_USDMAYA_PUBLIC void setChangedSelectionState(const bool hasSelectabilityChanged); - /// \brief convenience method to check if a path is unselectable. - /// \param path Usd prim path. - /// \return true if unselectable, false otherwise. - AL_USDMAYA_PUBLIC - bool isPathUnselectable(const SdfPath& path) const; - - /// \brief convenience method to check if a prim is unselectable. - /// \param path Usd prim. - /// \return true if unselectable, false otherwise. - AL_USDMAYA_PUBLIC - bool isPrimUnselectable(const UsdPrim& prim, UnselectablePrimCache& cache) const; - - /// \brief convenience method to check if a path is locked. - /// \param path Usd prim path. - /// \return true if locked, false otherwise. - AL_USDMAYA_PUBLIC - bool isPathLocked(const SdfPath& path) const; - - /// \brief convenience method to check if a prim is locked. - /// \param path Usd prim. - /// \return true if locked, false otherwise. - AL_USDMAYA_PUBLIC - bool isPrimLocked(const UsdPrim& prim, LockPrimCache& cache) const; + /// \brief convenience method to check if a path is unselectable. + /// \param path Usd prim path. + /// \return true if unselectable, false otherwise. + AL_USDMAYA_PUBLIC + bool isPathUnselectable(const SdfPath& path) const; + + /// \brief convenience method to check if a prim is unselectable. + /// \param path Usd prim. + /// \return true if unselectable, false otherwise. + AL_USDMAYA_PUBLIC + bool isPrimUnselectable(const UsdPrim& prim, UnselectablePrimCache& cache) const; + + /// \brief convenience method to check if a path is locked. + /// \param path Usd prim path. + /// \return true if locked, false otherwise. + AL_USDMAYA_PUBLIC + bool isPathLocked(const SdfPath& path) const; + + /// \brief convenience method to check if a prim is locked. + /// \param path Usd prim. + /// \return true if locked, false otherwise. + AL_USDMAYA_PUBLIC + bool isPrimLocked(const UsdPrim& prim, LockPrimCache& cache) const; /// \brief used to reload the stage after file open AL_USDMAYA_PUBLIC @@ -1055,15 +1055,15 @@ class ProxyShape AL_USDMAYA_PUBLIC static std::vector m_unloadedProxyShapes; - SelectionList m_selectionList; - SdfPathHashSet m_selectedPaths; - PrimPathToDagPath m_primPathToDagPath; - std::vector m_paths; - std::vector m_prims; - TfNotice::Key m_objectsChangedNoticeKey; - TfNotice::Key m_variantChangedNoticeKey; - TfNotice::Key m_editTargetChanged; - TfNotice::Key m_transactionNoticeKey; + SelectionList m_selectionList; + SdfPathHashSet m_selectedPaths; + PrimPathToDagPath m_primPathToDagPath; + std::vector m_paths; + std::vector m_prims; + TfNotice::Key m_objectsChangedNoticeKey; + TfNotice::Key m_variantChangedNoticeKey; + TfNotice::Key m_editTargetChanged; + TfNotice::Key m_transactionNoticeKey; SdfPathVector m_excludedGeometry; SdfPathVector m_excludedTaggedGeometry; diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/ProxyShapeMetaData.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/ProxyShapeMetaData.cpp index 914f54c709..83e4afa8b7 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/ProxyShapeMetaData.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/ProxyShapeMetaData.cpp @@ -216,7 +216,7 @@ void ProxyShape::findPrimsWithMetaData() for (fileio::TransformIterator it(m_stage, parentTransform(), true); !it.done(); it.next()) { const auto& prim = it.prim(); - bool excludeGeo = false; + bool excludeGeo = false; if (prim.GetMetadata(Metadata::excludeFromProxyShape, &excludeGeo)) { if (excludeGeo) { m_excludedTaggedGeometry.push_back(prim.GetPrimPath()); diff --git a/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_lockPrims.cpp b/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_lockPrims.cpp index 47f7691a9f..8a0cad8854 100644 --- a/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_lockPrims.cpp +++ b/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_lockPrims.cpp @@ -272,7 +272,7 @@ TEST(Selectability, selectableMetaData) EXPECT_FALSE(proxy->isPathUnselectable(SdfPath("/hello"))); EXPECT_TRUE(proxy->isPathUnselectable(SdfPath("/hello/world"))); - EXPECT_TRUE(proxy->isPathUnselectable(SdfPath("/hello/world/cam"))); + EXPECT_FALSE(proxy->isPathUnselectable(SdfPath("/hello/world/cam"))); } // This test loads a usda file containing variants for the permutations of the excludedGeom tag. From cb7dfa794593d4d4a9715b273471e5aff576f7a4 Mon Sep 17 00:00:00 2001 From: Zhicheng Ye Date: Fri, 19 Nov 2021 10:12:16 +1100 Subject: [PATCH 3/3] Simplified checks for lock prim metadata and removed AL_usdmaya_ignoreLockPrims optionVar --- .../AL_USDMaya/AL/usdmaya/PluginRegister.h | 9 -------- .../AL/usdmaya/cmds/ProxyShapeCommands.cpp | 6 ++---- .../AL/usdmaya/nodes/ProxyShape.cpp | 15 +++++++------ .../AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h | 8 ------- .../AL/usdmaya/nodes/ProxyShapeSelection.cpp | 8 ++----- .../nodes/proxy/ProxyShapeMetaData.cpp | 21 ++++++++----------- 6 files changed, 22 insertions(+), 45 deletions(-) diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/PluginRegister.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/PluginRegister.h index 39a71da4f6..cd1ebfe402 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/PluginRegister.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/PluginRegister.h @@ -211,10 +211,6 @@ template MStatus registerPlugin(AFnPlugin& plugin) MGlobal::setOptionVarValue("AL_usdmaya_pushToPrim", true); } - if (!MGlobal::optionVarExists("AL_usdmaya_ignoreLockPrims")) { - MGlobal::setOptionVarValue("AL_usdmaya_ignoreLockPrims", false); - } - MStatus status; // gpuCachePluginMain used as an example. @@ -345,11 +341,6 @@ template MStatus registerPlugin(AFnPlugin& plugin) "optionVar -iv \\\"AL_usdmaya_pushToPrim\\\" #1", true, MGlobal::optionVarIntValue("AL_usdmaya_pushToPrim")); - AL::maya::utils::MenuBuilder::addEntry( - "USD/Ignore Lock Prims", - "optionVar -iv \\\"AL_usdmaya_ignoreLockPrims\\\" #1", - true, - MGlobal::optionVarIntValue("AL_usdmaya_ignoreLockPrims")); CHECK_MSTATUS(AL::maya::utils::MenuBuilder::generatePluginUI(plugin, "AL_usdmaya")); AL::usdmaya::Global::onPluginLoad(); diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeCommands.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeCommands.cpp index 002bde5d93..ae981c81cb 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeCommands.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeCommands.cpp @@ -1037,10 +1037,8 @@ MStatus TranslatePrim::redoIt() TF_DEBUG(ALUSDMAYA_COMMANDS).Msg("TranslatePrim::redoIt\n"); m_proxy->translatePrimPathsIntoMaya(newImportPaths, m_teardownPaths, tp); - // construct locks and selectability for imported prims - if (m_proxy->isLockPrimFeatureActive()) { - m_proxy->constructLockPrims(); - } + // construct locks for imported prims + m_proxy->constructLockPrims(); if (!m_updatePaths.empty()) { diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp index 3196d5d669..f7577c83d1 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp @@ -1064,9 +1064,7 @@ void ProxyShape::processChangedObjects( // you need to reselect the proxy before the bounds will be updated). } - if (isLockPrimFeatureActive()) { - processChangedMetaData(resyncedPaths, changedOnlyPaths); - } + processChangedMetaData(resyncedPaths, changedOnlyPaths); // These paths are subtree-roots representing entire subtrees that may have // changed. In this case, we must dump all cached data below these points @@ -1461,9 +1459,7 @@ void ProxyShape::loadStage() if (m_stage && !MFileIO::isReadingFile()) { // execute the post load process to import any custom prims cmds::ProxyShapePostLoadProcess::initialise(this); - if (isLockPrimFeatureActive()) { - findPrimsWithMetaData(); - } + findPrimsWithMetaData(); } destroyGLImagingEngine(); @@ -2141,6 +2137,13 @@ bool ProxyShape::isPathUnselectable(const SdfPath& path) const //---------------------------------------------------------------------------------------------------------------------- bool ProxyShape::isPrimUnselectable(const UsdPrim& prim, UnselectablePrimCache& cache) const { + // If global optionVar is not enabled, disable selection for all paths + if (MGlobal::optionVarExists("AL_usdmaya_selectionEnabled") + && !MGlobal::optionVarIntValue("AL_usdmaya_selectionEnabled")) { + // Return true to indicate the path is not selectable + return true; + } + return checkPrimMetadata( prim, Metadata::selectability, Metadata::unselectable, Metadata::selectable, cache); } diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h index a781e9f198..2324580a75 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h @@ -1019,14 +1019,6 @@ class ProxyShape } public: - bool isLockPrimFeatureActive() const - { - bool ignoreLockPrims = MGlobal::optionVarIntValue("AL_usdmaya_ignoreLockPrims"); - // The lock Prim functionality is a UI thing - no need to have it on in batch mode - // However, this also causes the tests to fail which is bad - return (/*(MGlobal::mayaState() == MGlobal::kInteractive) &&*/ !ignoreLockPrims); - } - void processChangedMetaData( const SdfPathVector& resyncedPaths, const SdfPathVector& changedOnlyPaths); diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeSelection.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeSelection.cpp index 9ced4adcec..60159586da 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeSelection.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeSelection.cpp @@ -869,9 +869,7 @@ void SelectionUndoHelper::doIt() MGlobal::setActiveSelectionList(m_newSelection, MGlobal::kReplaceList); } m_proxy->m_pleaseIgnoreSelection = false; - if (m_proxy->isLockPrimFeatureActive()) { - m_proxy->constructLockPrims(); - } + m_proxy->constructLockPrims(); } //---------------------------------------------------------------------------------------------------------------------- @@ -892,9 +890,7 @@ void SelectionUndoHelper::undoIt() MGlobal::setActiveSelectionList(m_previousSelection, MGlobal::kReplaceList); } m_proxy->m_pleaseIgnoreSelection = false; - if (m_proxy->isLockPrimFeatureActive()) { - m_proxy->constructLockPrims(); - } + m_proxy->constructLockPrims(); } //---------------------------------------------------------------------------------------------------------------------- diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/ProxyShapeMetaData.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/ProxyShapeMetaData.cpp index 83e4afa8b7..d3579a3349 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/ProxyShapeMetaData.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/ProxyShapeMetaData.cpp @@ -212,21 +212,18 @@ void ProxyShape::findPrimsWithMetaData() if (!m_stage) return; - if (isLockPrimFeatureActive()) { - for (fileio::TransformIterator it(m_stage, parentTransform(), true); !it.done(); - it.next()) { - const auto& prim = it.prim(); - bool excludeGeo = false; - if (prim.GetMetadata(Metadata::excludeFromProxyShape, &excludeGeo)) { - if (excludeGeo) { - m_excludedTaggedGeometry.push_back(prim.GetPrimPath()); - } + for (fileio::TransformIterator it(m_stage, parentTransform(), true); !it.done(); it.next()) { + const auto& prim = it.prim(); + bool excludeGeo = false; + if (prim.GetMetadata(Metadata::excludeFromProxyShape, &excludeGeo)) { + if (excludeGeo) { + m_excludedTaggedGeometry.push_back(prim.GetPrimPath()); } } - - constructLockPrims(); - constructExcludedPrims(); } + + constructLockPrims(); + constructExcludedPrims(); } //----------------------------------------------------------------------------------------------------------------------