From 1b9cabd1a2272f6baaaec4e36f5145f717bcf270 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:54:24 -0500 Subject: [PATCH 01/19] EMSUSD-128 - [GitHub #2181] Implement Copy\paste capabilities on USD Data * Moved diffPrims/MergePrims into UsdUfe which meant that MayaUsdUtils was now empty. So removed that library as well. --- lib/mayaUsd/CMakeLists.txt | 1 - lib/mayaUsd/fileio/jobs/jobArgs.cpp | 7 +- lib/mayaUsd/fileio/primUpdater.cpp | 7 +- lib/mayaUsd/ufe/UsdUndoDuplicateCommand.cpp | 8 +- lib/mayaUsd/utils/mayaEditRouter.cpp | 6 +- lib/mayaUsdAPI/utils.cpp | 8 +- lib/usd/CMakeLists.txt | 2 - lib/usd/translators/mayaReferenceUpdater.cpp | 2 +- lib/usd/utils/Api.h | 40 ---- lib/usd/utils/CMakeLists.txt | 99 -------- lib/usdUfe/base/CMakeLists.txt | 1 + .../base/forwardDeclares.h} | 6 +- lib/{usd => usdUfe}/utils/ALHalf.h | 6 +- lib/usdUfe/utils/CMakeLists.txt | 16 ++ lib/{usd => usdUfe}/utils/SIMD.h | 4 +- .../utils/diffAttributes.cpp} | 8 +- .../utils/diffCore.cpp} | 8 +- .../DiffCore.h => usdUfe/utils/diffCore.h} | 48 ++-- .../utils/diffDictionaries.cpp} | 14 +- .../utils/diffLists.cpp} | 36 +-- .../utils/diffMetadatas.cpp} | 14 +- .../utils/diffPrims.cpp} | 34 +-- .../DiffPrims.h => usdUfe/utils/diffPrims.h} | 38 +-- .../utils/diffRelationships.cpp} | 9 +- .../utils/diffValues.cpp} | 165 ++++++------- .../utils/mergePrims.cpp} | 31 ++- .../utils/mergePrims.h} | 22 +- .../utils/mergePrimsOptions.cpp} | 94 ++++---- .../utils/mergePrimsOptions.h} | 21 +- plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.h | 2 +- .../AL/usdmaya/cmds/ProxyShapeCommands.cpp | 4 +- .../AL/usdmaya/fileio/ExportParams.h | 3 +- .../AL/usdmaya/fileio/ImportParams.h | 2 +- .../AL/usdmaya/fileio/SchemaPrims.h | 2 +- .../fileio/translators/DgNodeTranslator.cpp | 2 +- .../fileio/translators/TranslatorContext.h | 3 +- .../AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h | 2 +- .../AL/usdmaya/nodes/proxy/PrimFilter.h | 11 +- plugin/al/lib/AL_USDMaya/CMakeLists.txt | 2 +- plugin/al/mayautils/AL/maya/CMakeLists.txt | 2 +- .../al/plugin/AL_USDMayaPlugin/CMakeLists.txt | 2 +- .../AL_USDMayaTestPlugin/CMakeLists.txt | 2 +- plugin/al/translators/Camera.h | 2 +- plugin/al/translators/DirectionalLight.h | 2 +- .../AL/usdmaya/utils/CMakeLists.txt | 4 +- .../AL/usdmaya}/utils/DebugCodes.cpp | 2 +- .../AL/usdmaya}/utils/DebugCodes.h | 2 +- .../AL/usdmaya/utils/DgNodeHelper.cpp | 101 ++++---- .../AL/usdmaya/utils/DiffPrimVar.cpp | 50 ++-- .../AL/usdmaya/utils/DiffPrimVar.h | 2 +- .../AL/usdmaya/utils/ForwardDeclares.h | 2 +- .../AL/usdmaya/utils/MeshUtils.cpp | 28 +-- .../AL/usdmaya/utils/NurbsCurveUtils.cpp | 10 +- .../usdmayautils/AL/usdmaya/utils/Utils.cpp | 5 +- .../al/usdmayautils/AL/usdmaya/utils/Utils.h | 2 +- test/lib/mayaUsd/utils/CMakeLists.txt | 2 +- test/lib/usd/utils/CMakeLists.txt | 2 +- test/lib/usd/utils/test_DiffAttributes.cpp | 4 +- .../lib/usd/utils/test_DiffComputeOverall.cpp | 4 +- test/lib/usd/utils/test_DiffCore.cpp | 216 +++++++++--------- test/lib/usd/utils/test_DiffDictionaries.cpp | 4 +- test/lib/usd/utils/test_DiffLists.cpp | 4 +- test/lib/usd/utils/test_DiffMetadatas.cpp | 4 +- test/lib/usd/utils/test_DiffPrims.cpp | 4 +- .../usd/utils/test_DiffPrimsAttributes.cpp | 4 +- test/lib/usd/utils/test_DiffPrimsChildren.cpp | 4 +- .../lib/usd/utils/test_DiffPrimsRelations.cpp | 4 +- test/lib/usd/utils/test_DiffRelationships.cpp | 4 +- test/lib/usd/utils/test_DiffValues.cpp | 4 +- test/lib/usd/utils/test_DiffValuesArrays.cpp | 4 +- .../usd/utils/test_DiffValuesDoubleVecs.cpp | 4 +- .../usd/utils/test_DiffValuesFloatVecs.cpp | 4 +- test/lib/usd/utils/test_DiffValuesGeneric.cpp | 4 +- .../lib/usd/utils/test_DiffValuesHalfVecs.cpp | 4 +- test/lib/usd/utils/test_DiffValuesIntVecs.cpp | 4 +- .../lib/usd/utils/test_DiffValuesMatrices.cpp | 4 +- .../usd/utils/test_DiffValuesQuaternions.cpp | 4 +- test/lib/usd/utils/test_MergePrims.cpp | 4 +- 78 files changed, 601 insertions(+), 705 deletions(-) delete mode 100644 lib/usd/utils/Api.h delete mode 100644 lib/usd/utils/CMakeLists.txt rename lib/{usd/utils/ForwardDeclares.h => usdUfe/base/forwardDeclares.h} (92%) rename lib/{usd => usdUfe}/utils/ALHalf.h (98%) rename lib/{usd => usdUfe}/utils/SIMD.h (99%) rename lib/{usd/utils/DiffAttributes.cpp => usdUfe/utils/diffAttributes.cpp} (96%) rename lib/{usd/utils/DiffCore.cpp => usdUfe/utils/diffCore.cpp} (99%) rename lib/{usd/utils/DiffCore.h => usdUfe/utils/diffCore.h} (97%) rename lib/{usd/utils/DiffDictionaries.cpp => usdUfe/utils/diffDictionaries.cpp} (87%) rename lib/{usd/utils/DiffLists.cpp => usdUfe/utils/diffLists.cpp} (79%) rename lib/{usd/utils/DiffMetadatas.cpp => usdUfe/utils/diffMetadatas.cpp} (96%) rename lib/{usd/utils/DiffPrims.cpp => usdUfe/utils/diffPrims.cpp} (89%) rename lib/{usd/utils/DiffPrims.h => usdUfe/utils/diffPrims.h} (97%) rename lib/{usd/utils/DiffRelationships.cpp => usdUfe/utils/diffRelationships.cpp} (92%) rename lib/{usd/utils/DiffValues.cpp => usdUfe/utils/diffValues.cpp} (68%) rename lib/{usd/utils/MergePrims.cpp => usdUfe/utils/mergePrims.cpp} (98%) rename lib/{usd/utils/MergePrims.h => usdUfe/utils/mergePrims.h} (78%) rename lib/{usd/utils/MergePrimsOptions.cpp => usdUfe/utils/mergePrimsOptions.cpp} (55%) rename lib/{usd/utils/MergePrimsOptions.h => usdUfe/utils/mergePrimsOptions.h} (95%) rename {lib/usd => plugin/al/usdmayautils/AL/usdmaya}/utils/DebugCodes.cpp (89%) rename {lib/usd => plugin/al/usdmayautils/AL/usdmaya}/utils/DebugCodes.h (95%) diff --git a/lib/mayaUsd/CMakeLists.txt b/lib/mayaUsd/CMakeLists.txt index 8c3f6f3a4f..2c90dc3aad 100644 --- a/lib/mayaUsd/CMakeLists.txt +++ b/lib/mayaUsd/CMakeLists.txt @@ -267,7 +267,6 @@ target_link_libraries(${PROJECT_NAME} vt ${UFE_LIBRARY} ${MAYA_LIBRARIES} - mayaUsdUtils usdUfe PRIVATE ghc_filesystem diff --git a/lib/mayaUsd/fileio/jobs/jobArgs.cpp b/lib/mayaUsd/fileio/jobs/jobArgs.cpp index 56bdb6838c..c941f5f74e 100644 --- a/lib/mayaUsd/fileio/jobs/jobArgs.cpp +++ b/lib/mayaUsd/fileio/jobs/jobArgs.cpp @@ -21,7 +21,8 @@ #include #include #include -#include + +#include #include #include @@ -519,8 +520,8 @@ bool _MergeJobContexts(bool isExport, const VtDictionary& userArgs, VtDictionary if (element.IsHolding>()) { // vector> is common for chaserArgs and shadingModes auto findElement = [&element](const VtValue& a) { - return MayaUsdUtils::compareValues(element, a) - == MayaUsdUtils::DiffResult::Same; + return UsdUfe::compareValues(element, a) + == UsdUfe::DiffResult::Same; }; if (std::find_if( mergedValues.begin(), mergedValues.end(), findElement) diff --git a/lib/mayaUsd/fileio/primUpdater.cpp b/lib/mayaUsd/fileio/primUpdater.cpp index 16bbacc9f3..af3c566326 100644 --- a/lib/mayaUsd/fileio/primUpdater.cpp +++ b/lib/mayaUsd/fileio/primUpdater.cpp @@ -25,7 +25,8 @@ #include #include #include -#include + +#include #include #include @@ -121,9 +122,9 @@ UsdMayaPrimUpdater::PushCopySpecs UsdMayaPrimUpdater::pushCopySpecs( SdfLayerRefPtr dstLayer, const SdfPath& dstSdfPath) { - MayaUsdUtils::MergePrimsOptions options; + UsdUfe::MergePrimsOptions options; options.ignoreVariants = _context ? _context->GetArgs()._ignoreVariants : false; - return MayaUsdUtils::mergePrims( + return UsdUfe::mergePrims( srcStage, srcLayer, srcSdfPath, dstStage, dstLayer, dstSdfPath, options) ? PushCopySpecs::Continue : PushCopySpecs::Failed; diff --git a/lib/mayaUsd/ufe/UsdUndoDuplicateCommand.cpp b/lib/mayaUsd/ufe/UsdUndoDuplicateCommand.cpp index f87e226630..e90b71fda9 100644 --- a/lib/mayaUsd/ufe/UsdUndoDuplicateCommand.cpp +++ b/lib/mayaUsd/ufe/UsdUndoDuplicateCommand.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -28,6 +27,7 @@ #include #include #include +#include #include #include @@ -109,8 +109,8 @@ void UsdUndoDuplicateCommand::execute() SdfPrimSpecHandleVector authLayerAndPaths = getDefiningPrimStack(prim); std::reverse(authLayerAndPaths.begin(), authLayerAndPaths.end()); - MayaUsdUtils::MergePrimsOptions options; - options.verbosity = MayaUsdUtils::MergeVerbosity::None; + UsdUfe::MergePrimsOptions options; + options.verbosity = UsdUfe::MergeVerbosity::None; options.mergeChildren = true; bool isFirst = true; @@ -119,7 +119,7 @@ void UsdUndoDuplicateCommand::execute() const auto path = layerAndPath->GetPath(); const bool result = isFirst ? SdfCopySpec(layer, path, _dstLayer, _usdDstPath) - : mergePrims(stage, layer, path, stage, _dstLayer, _usdDstPath, options); + : UsdUfe::mergePrims(stage, layer, path, stage, _dstLayer, _usdDstPath, options); TF_VERIFY( result, diff --git a/lib/mayaUsd/utils/mayaEditRouter.cpp b/lib/mayaUsd/utils/mayaEditRouter.cpp index bab0e24fac..b15c3331f0 100644 --- a/lib/mayaUsd/utils/mayaEditRouter.cpp +++ b/lib/mayaUsd/utils/mayaEditRouter.cpp @@ -18,10 +18,10 @@ #include #include #include -#include #include #include +#include #include #include @@ -96,10 +96,10 @@ void copyTransform( // The Maya transform that corresponds to the Maya reference prim // only has its transform attributes unlocked. Bring any transform // attribute edits over to the Maya reference prim. - MayaUsdUtils::MergePrimsOptions options; + UsdUfe::MergePrimsOptions options; options.ignoreUpperLayerOpinions = false; options.ignoreVariants = true; - TF_VERIFY(MayaUsdUtils::mergePrims( + TF_VERIFY(UsdUfe::mergePrims( srcStage, srcLayer, srcSdfPath, dstStage, dstLayer, dstSdfPathForMerge, options)); } } diff --git a/lib/mayaUsdAPI/utils.cpp b/lib/mayaUsdAPI/utils.cpp index d305e00293..6e456927b3 100644 --- a/lib/mayaUsdAPI/utils.cpp +++ b/lib/mayaUsdAPI/utils.cpp @@ -23,7 +23,8 @@ #endif #include #include -#include + +#include namespace MAYAUSDAPI_NS_DEF { @@ -106,10 +107,7 @@ bool mergePrims( const PXR_NS::SdfLayerRefPtr& dstLayer, const PXR_NS::SdfPath& dstPath) { - MayaUsdUtils::MergePrimsOptions options; - options.verbosity = MayaUsdUtils::MergeVerbosity::None; - return MayaUsdUtils::mergePrims( - srcStage, srcLayer, srcPath, dstStage, dstLayer, dstPath, options); + return UsdUfe::mergePrims(srcStage, srcLayer, srcPath, dstStage, dstLayer, dstPath); } std::string getDir(const std::string& fullFilePath) diff --git a/lib/usd/CMakeLists.txt b/lib/usd/CMakeLists.txt index 6d1234f993..d84f13eeca 100644 --- a/lib/usd/CMakeLists.txt +++ b/lib/usd/CMakeLists.txt @@ -21,8 +21,6 @@ add_subdirectory(pxrUsdPreviewSurface) add_subdirectory(translators) add_subdirectory(schemas) -add_subdirectory(utils) - if(Qt_FOUND) add_subdirectory(ui) endif() diff --git a/lib/usd/translators/mayaReferenceUpdater.cpp b/lib/usd/translators/mayaReferenceUpdater.cpp index 525d053941..204e424a0d 100644 --- a/lib/usd/translators/mayaReferenceUpdater.cpp +++ b/lib/usd/translators/mayaReferenceUpdater.cpp @@ -250,7 +250,7 @@ UsdMayaPrimUpdater::PushCopySpecs PxrUsdTranslators_MayaReferenceUpdater::pushCo return PushCopySpecs::Failed; // The Maya reference is meant as a cache, and therefore fully - // overwritten, so we don't call MayaUsdUtils::mergePrims(). + // overwritten, so we don't call UsdUfe::mergePrims(). if (!SdfCopySpec(srcLayer, srcSdfPath, cacheDstLayer, SdfPath(cacheDstPathStr))) return PushCopySpecs::Failed; diff --git a/lib/usd/utils/Api.h b/lib/usd/utils/Api.h deleted file mode 100644 index 0b938af262..0000000000 --- a/lib/usd/utils/Api.h +++ /dev/null @@ -1,40 +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. -// - -#if defined _WIN32 || defined __CYGWIN__ -#ifdef MAYA_USD_UTILS_EXPORT -#ifdef __GNUC__ -#define MAYA_USD_UTILS_PUBLIC __attribute__((dllexport)) -#else -#define MAYA_USD_UTILS_PUBLIC __declspec(dllexport) -#endif -#else -#ifdef __GNUC__ -#define MAYA_USD_UTILS_PUBLIC __attribute__((dllimport)) -#else -#define MAYA_USD_UTILS_PUBLIC __declspec(dllimport) -#endif -#endif -#define MAYA_USD_UTILS_LOCAL -#else -#if __GNUC__ >= 4 -#define MAYA_USD_UTILS_PUBLIC __attribute__((visibility("default"))) -#define MAYA_USD_UTILS_LOCAL __attribute__((visibility("hidden"))) -#else -#define MAYA_USD_UTILS_PUBLIC -#define MAYA_USD_UTILS_LOCAL -#endif -#endif \ No newline at end of file diff --git a/lib/usd/utils/CMakeLists.txt b/lib/usd/utils/CMakeLists.txt deleted file mode 100644 index 8a2c711be4..0000000000 --- a/lib/usd/utils/CMakeLists.txt +++ /dev/null @@ -1,99 +0,0 @@ -set(TARGET_NAME "mayaUsdUtils") - -add_library(${TARGET_NAME} SHARED) - -# ----------------------------------------------------------------------------- -# sources -# ----------------------------------------------------------------------------- -target_sources(${TARGET_NAME} - PRIVATE - DebugCodes.cpp - DiffAttributes.cpp - DiffCore.cpp - DiffDictionaries.cpp - DiffLists.cpp - DiffMetadatas.cpp - DiffPrims.cpp - DiffRelationships.cpp - DiffValues.cpp - MergePrims.cpp - MergePrimsOptions.cpp -) - -# ----------------------------------------------------------------------------- -# compiler configuration -# ----------------------------------------------------------------------------- -target_compile_definitions(${TARGET_NAME} - PRIVATE - MAYA_USD_UTILS_EXPORT - $<$:TBB_USE_DEBUG> - $<$:BOOST_DEBUG_PYTHON> - $<$:BOOST_LINKING_PYTHON> -) - -mayaUsd_compile_config(${TARGET_NAME}) - -# ----------------------------------------------------------------------------- -# include directories -# ----------------------------------------------------------------------------- -target_include_directories(${TARGET_NAME} - PUBLIC - ${CMAKE_BINARY_DIR}/include - INTERFACE - ${USD_INCLUDE_DIR} -) - -# ----------------------------------------------------------------------------- -# link libraries -# ----------------------------------------------------------------------------- -target_link_libraries(${TARGET_NAME} - PUBLIC - gf - usd - sdf - usdGeom -) - -# ----------------------------------------------------------------------------- -# promote headers -# ----------------------------------------------------------------------------- -set(HEADERS - ALHalf.h - Api.h - DebugCodes.h - DiffCore.h - DiffPrims.h - MergePrims.h - MergePrimsOptions.h - ForwardDeclares.h - SIMD.h -) - -mayaUsd_promoteHeaderList( - HEADERS - ${HEADERS} - BASEDIR - ${TARGET_NAME} -) - -# ----------------------------------------------------------------------------- -# install -# ----------------------------------------------------------------------------- -install(TARGETS ${TARGET_NAME} - LIBRARY - DESTINATION ${CMAKE_INSTALL_PREFIX}/lib - ARCHIVE - DESTINATION ${CMAKE_INSTALL_PREFIX}/lib - RUNTIME - DESTINATION ${CMAKE_INSTALL_PREFIX}/lib -) - -install(FILES ${HEADERS} - DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${TARGET_NAME} -) - -if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") - install(FILES $ - DESTINATION ${CMAKE_INSTALL_PREFIX}/lib OPTIONAL - ) -endif() diff --git a/lib/usdUfe/base/CMakeLists.txt b/lib/usdUfe/base/CMakeLists.txt index 589f185b99..27ee34c5ec 100644 --- a/lib/usdUfe/base/CMakeLists.txt +++ b/lib/usdUfe/base/CMakeLists.txt @@ -9,6 +9,7 @@ target_sources(${PROJECT_NAME} set(HEADERS api.h debugCodes.h + forwardDeclares.h tokens.h ) diff --git a/lib/usd/utils/ForwardDeclares.h b/lib/usdUfe/base/forwardDeclares.h similarity index 92% rename from lib/usd/utils/ForwardDeclares.h rename to lib/usdUfe/base/forwardDeclares.h index c8689f6ac2..3f9b0fa226 100644 --- a/lib/usd/utils/ForwardDeclares.h +++ b/lib/usdUfe/base/forwardDeclares.h @@ -16,6 +16,8 @@ #pragma once +#include + #include #include @@ -36,6 +38,6 @@ class UsdReferences; PXR_NAMESPACE_CLOSE_SCOPE -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { typedef std::vector UsdPrimVector; -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/ALHalf.h b/lib/usdUfe/utils/ALHalf.h similarity index 98% rename from lib/usd/utils/ALHalf.h rename to lib/usdUfe/utils/ALHalf.h index b549824ea7..ba7c633a34 100644 --- a/lib/usd/utils/ALHalf.h +++ b/lib/usdUfe/utils/ALHalf.h @@ -26,6 +26,8 @@ //---------------------------------------------------------------------------------------------------------------------- #pragma once +#include + #if __F16C__ #include #endif @@ -35,7 +37,7 @@ PXR_NAMESPACE_USING_DIRECTIVE -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { #ifdef __F16C__ @@ -243,4 +245,4 @@ inline void double2half_4f(const double input[4], GfHalf out[4]) inline GfHalf double2half_1f(const double f) { return GfHalf(float(f)); } #endif -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usdUfe/utils/CMakeLists.txt b/lib/usdUfe/utils/CMakeLists.txt index ae41f9e6dc..b7af5a5bb7 100644 --- a/lib/usdUfe/utils/CMakeLists.txt +++ b/lib/usdUfe/utils/CMakeLists.txt @@ -3,11 +3,21 @@ # ----------------------------------------------------------------------------- target_sources(${PROJECT_NAME} PRIVATE + diffAttributes.cpp + diffCore.cpp + diffDictionaries.cpp + diffLists.cpp + diffMetadatas.cpp + diffPrims.cpp + diffRelationships.cpp + diffValues.cpp editRouter.cpp editRouterContext.cpp layers.cpp loadRules.cpp loadRulesText.cpp + mergePrims.cpp + mergePrimsOptions.cpp usdUtils.cpp Utils.cpp ) @@ -16,10 +26,16 @@ target_sources(${PROJECT_NAME} # promote headers # ----------------------------------------------------------------------------- set(HEADERS + ALHalf.h + diffCore.h + diffPrims.h editRouter.h editRouterContext.h layers.h loadRules.h + mergePrims.h + mergePrimsOptions.h + SIMD.h usdUtils.h Utils.h ) diff --git a/lib/usd/utils/SIMD.h b/lib/usdUfe/utils/SIMD.h similarity index 99% rename from lib/usd/utils/SIMD.h rename to lib/usdUfe/utils/SIMD.h index 622bc6c9c6..2785d119c5 100644 --- a/lib/usd/utils/SIMD.h +++ b/lib/usdUfe/utils/SIMD.h @@ -59,7 +59,7 @@ #define ENABLE_SOME_AVX_ROUTINES 1 #endif -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { #if defined(__SSE__) typedef __m128 f128; @@ -557,4 +557,4 @@ inline f128 loadmask3f(const void* const ptr, size_t count) } #endif -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/DiffAttributes.cpp b/lib/usdUfe/utils/diffAttributes.cpp similarity index 96% rename from lib/usd/utils/DiffAttributes.cpp rename to lib/usdUfe/utils/diffAttributes.cpp index 23df6b7979..41ca5426eb 100644 --- a/lib/usd/utils/DiffAttributes.cpp +++ b/lib/usdUfe/utils/diffAttributes.cpp @@ -1,5 +1,5 @@ // -// Copyright 2021 Autodesk +// Copyright 2024 Autodesk // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -13,9 +13,9 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include "DiffPrims.h" +#include "diffPrims.h" -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { using UsdAttribute = PXR_NS::UsdAttribute; using VtValue = PXR_NS::VtValue; @@ -97,4 +97,4 @@ DiffResult compareAttributes( return compareValues(modifiedValue, baselineValue); } -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/DiffCore.cpp b/lib/usdUfe/utils/diffCore.cpp similarity index 99% rename from lib/usd/utils/DiffCore.cpp rename to lib/usdUfe/utils/diffCore.cpp index 4d2e985727..913d451f32 100644 --- a/lib/usd/utils/DiffCore.cpp +++ b/lib/usdUfe/utils/diffCore.cpp @@ -13,14 +13,14 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include "DiffCore.h" +#include "diffCore.h" -#include +#include #include #include -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { //---------------------------------------------------------------------------------------------------------------------- bool vec2AreAllTheSame(const float* u, const float* v, size_t count) @@ -1329,4 +1329,4 @@ bool compareRGBAArray( return true; } -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/DiffCore.h b/lib/usdUfe/utils/diffCore.h similarity index 97% rename from lib/usd/utils/DiffCore.h rename to lib/usdUfe/utils/diffCore.h index 31c4ad4eb6..98e3154cc3 100644 --- a/lib/usd/utils/DiffCore.h +++ b/lib/usdUfe/utils/diffCore.h @@ -15,12 +15,12 @@ // #pragma once -#include -#include +#include +#include #include -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { //---------------------------------------------------------------------------------------------------------------------- /// \brief tests to see whether the U & V coordinates are identical @@ -29,7 +29,7 @@ namespace MayaUsdUtils { /// \param count the number of elements to test /// \return true if all elements in the arrays are identical //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool vec2AreAllTheSame(const float* u, const float* v, size_t count); //---------------------------------------------------------------------------------------------------------------------- @@ -38,7 +38,7 @@ bool vec2AreAllTheSame(const float* u, const float* v, size_t count); /// \param count the number of elements to test /// \return true if all elements in the arrays are identical //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool vec2AreAllTheSame(const float* array, size_t count); //---------------------------------------------------------------------------------------------------------------------- @@ -47,7 +47,7 @@ bool vec2AreAllTheSame(const float* array, size_t count); /// \param count the number of elements to test /// \return true if all elements in the arrays are identical //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool vec3AreAllTheSame(const float* array, size_t count); //---------------------------------------------------------------------------------------------------------------------- @@ -56,7 +56,7 @@ bool vec3AreAllTheSame(const float* array, size_t count); /// \param count the number of elements to test /// \return true if all elements in the arrays are identical //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool vec4AreAllTheSame(const float* array, size_t count); //---------------------------------------------------------------------------------------------------------------------- @@ -65,7 +65,7 @@ bool vec4AreAllTheSame(const float* array, size_t count); /// \param count the number of elements to test /// \return true if all elements in the arrays are identical //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool vec2AreAllTheSame(const double* array, size_t count); //---------------------------------------------------------------------------------------------------------------------- @@ -74,7 +74,7 @@ bool vec2AreAllTheSame(const double* array, size_t count); /// \param count the number of elements to test /// \return true if all elements in the arrays are identical //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool vec3AreAllTheSame(const double* array, size_t count); //---------------------------------------------------------------------------------------------------------------------- @@ -83,7 +83,7 @@ bool vec3AreAllTheSame(const double* array, size_t count); /// \param count the number of elements to test /// \return true if all elements in the arrays are identical //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool vec4AreAllTheSame(const double* array, size_t count); //---------------------------------------------------------------------------------------------------------------------- @@ -96,7 +96,7 @@ bool vec4AreAllTheSame(const double* array, size_t count); /// \return true if the two arrays are similar to each other, false if their sizes don't match, /// or the contents of the arrays differ //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool compareArray( const GfHalf* const input0, const float* const input1, @@ -134,7 +134,7 @@ inline bool compareArray( /// \return true if the two arrays are similar to each other, false if their sizes don't match, /// or the contents of the arrays differ //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool compareArray( const GfHalf* const input0, const double* const input1, @@ -172,7 +172,7 @@ inline bool compareArray( /// \return true if the two arrays are similar to each other, false if their sizes don't match, /// or the contents of the arrays differ //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool compareArray( const GfHalf* const input0, const GfHalf* const input1, @@ -190,7 +190,7 @@ bool compareArray( /// \return true if the two arrays are similar to each other, false if their sizes don't match, /// or the contents of the arrays differ //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool compareArray( const float* const input0, const float* const input1, @@ -210,7 +210,7 @@ bool compareArray( /// \return true if the two arrays are similar to each other, false if their sizes don't match, /// or the contents of the arrays differ //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool compareArray3Dto4D( const float* const input3d, const float* const input4d, @@ -230,7 +230,7 @@ bool compareArray3Dto4D( /// \return true if the two arrays are similar to each other, false if their sizes don't match, /// or the contents of the arrays differ //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool compareArray3Dto4D( const float* const input3d, const double* const input4d, @@ -248,7 +248,7 @@ bool compareArray3Dto4D( /// \return true if the two arrays are similar to each other, false if their sizes don't match, /// or the contents of the arrays differ //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool compareArray( const double* const input0, const double* const input1, @@ -266,7 +266,7 @@ bool compareArray( /// \return true if the two arrays are similar to each other, false if their sizes don't match, /// or the contents of the arrays differ //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool compareArray( const double* const input0, const float* const input1, @@ -303,7 +303,7 @@ inline bool compareArray( /// \return true if the two arrays are similar to each other, false if their sizes don't match, /// or the contents of the arrays differ //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool compareArray( const int8_t* const input0, const int8_t* const input1, @@ -373,7 +373,7 @@ inline bool compareArray( /// \return true if the two arrays are similar to each other, false if their sizes don't match, /// or the contents of the arrays differ //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool compareArray( const int32_t* const input0, const int32_t* const input1, @@ -445,7 +445,7 @@ inline bool compareArray( /// \return true if the two arrays are similar to each other, false if their sizes don't match, /// or the contents of the arrays differ //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool compareUvArray( const float* const u0, const float* const v0, @@ -465,7 +465,7 @@ bool compareUvArray( /// \return true if the two arrays are similar to each other, false if their sizes don't match, /// or the contents of the arrays differ //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool compareUvArray( const float u0, const float v0, @@ -486,7 +486,7 @@ bool compareUvArray( /// \return true if the two arrays are similar to each other, false if their sizes don't match, /// or the contents of the arrays differ //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool compareRGBAArray( const float r, const float g, @@ -497,4 +497,4 @@ bool compareRGBAArray( const float eps = 1e-5f); //---------------------------------------------------------------------------------------------------------------------- -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/DiffDictionaries.cpp b/lib/usdUfe/utils/diffDictionaries.cpp similarity index 87% rename from lib/usd/utils/DiffDictionaries.cpp rename to lib/usdUfe/utils/diffDictionaries.cpp index 3f41def4a9..6f8eeb54c0 100644 --- a/lib/usd/utils/DiffDictionaries.cpp +++ b/lib/usdUfe/utils/diffDictionaries.cpp @@ -13,13 +13,13 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include "DiffPrims.h" +#include "diffPrims.h" -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { using VtDictionary = PXR_NS::VtDictionary; -#define USD_MAYA_RETURN_QUICK_RESULT(result) \ +#define USDUFE_RETURN_QUICK_RESULT(result) \ do { \ if (quickDiff && result != DiffResult::Same) { \ *quickDiff = result; \ @@ -45,11 +45,11 @@ DiffResultPerKey compareDictionaries( const std::string& key = keyAndValue.first; const auto iter = baseline.find(key); if (iter == baselineEnd) { - USD_MAYA_RETURN_QUICK_RESULT(DiffResult::Created); + USDUFE_RETURN_QUICK_RESULT(DiffResult::Created); results[key] = DiffResult::Created; } else { const DiffResult result = compareValues(keyAndValue.second, iter->second); - USD_MAYA_RETURN_QUICK_RESULT(result); + USDUFE_RETURN_QUICK_RESULT(result); results[key] = result; } } @@ -62,7 +62,7 @@ DiffResultPerKey compareDictionaries( for (const auto& keyAndAttr : baseline) { const auto& key = keyAndAttr.first; if (modified.find(key) == modifiedEnd) { - USD_MAYA_RETURN_QUICK_RESULT(DiffResult::Absent); + USDUFE_RETURN_QUICK_RESULT(DiffResult::Absent); results[key] = DiffResult::Absent; } } @@ -71,4 +71,4 @@ DiffResultPerKey compareDictionaries( return results; } -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/DiffLists.cpp b/lib/usdUfe/utils/diffLists.cpp similarity index 79% rename from lib/usd/utils/DiffLists.cpp rename to lib/usdUfe/utils/diffLists.cpp index da9203b575..b1e9cfce99 100644 --- a/lib/usd/utils/DiffLists.cpp +++ b/lib/usdUfe/utils/diffLists.cpp @@ -13,16 +13,16 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include "DiffPrims.h" +#include "diffPrims.h" -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { using TfToken = PXR_NS::TfToken; using SdfPath = PXR_NS::SdfPath; using SdfReference = PXR_NS::SdfReference; using SdfPayload = PXR_NS::SdfPayload; -#define USD_MAYA_RETURN_QUICK_RESULT(result) \ +#define USDUFE_RETURN_QUICK_RESULT(result) \ do { \ if (quickDiff && result != DiffResult::Same) { \ *quickDiff = result; \ @@ -59,13 +59,13 @@ std::map compareLists( // TODO: improve by finding the first baseline target that matches, mark previous ones absent? for (; modifiedIter != modifiedEnd; ++modifiedIter) { if (baselineIter == baselineEnd) { - USD_MAYA_RETURN_QUICK_RESULT(DiffResult::Prepended); + USDUFE_RETURN_QUICK_RESULT(DiffResult::Prepended); results[*modifiedIter] = DiffResult::Prepended; continue; } else if (*baselineIter == *modifiedIter) { break; } else { - USD_MAYA_RETURN_QUICK_RESULT(DiffResult::Prepended); + USDUFE_RETURN_QUICK_RESULT(DiffResult::Prepended); results[*modifiedIter] = DiffResult::Prepended; } } @@ -85,7 +85,7 @@ std::map compareLists( // Add all final modified targets that didn't match the baseline. // These will correspond to append. for (; modifiedIter != modifiedEnd; ++modifiedIter) { - USD_MAYA_RETURN_QUICK_RESULT(DiffResult::Appended); + USDUFE_RETURN_QUICK_RESULT(DiffResult::Appended); results[*modifiedIter] = DiffResult::Appended; } @@ -95,10 +95,10 @@ std::map compareLists( // at a different position. for (; baselineIter != baselineEnd; ++baselineIter) { if (results.find(*baselineIter) == results.end()) { - USD_MAYA_RETURN_QUICK_RESULT(DiffResult::Absent); + USDUFE_RETURN_QUICK_RESULT(DiffResult::Absent); results[*baselineIter] = DiffResult::Absent; } else { - USD_MAYA_RETURN_QUICK_RESULT(DiffResult::Reordered); + USDUFE_RETURN_QUICK_RESULT(DiffResult::Reordered); results[*baselineIter] = DiffResult::Reordered; } } @@ -106,49 +106,49 @@ std::map compareLists( return results; } -template MAYA_USD_UTILS_PUBLIC std::map compareLists( +template USDUFE_PUBLIC std::map compareLists( const std::vector& modified, const std::vector& baseline, DiffResult* quickDiff); -template MAYA_USD_UTILS_PUBLIC std::map compareLists( +template USDUFE_PUBLIC std::map compareLists( const std::vector& modified, const std::vector& baseline, DiffResult* quickDiff); -template MAYA_USD_UTILS_PUBLIC std::map compareLists( +template USDUFE_PUBLIC std::map compareLists( const std::vector& modified, const std::vector& baseline, DiffResult* quickDiff); -template MAYA_USD_UTILS_PUBLIC std::map compareLists( +template USDUFE_PUBLIC std::map compareLists( const std::vector& modified, const std::vector& baseline, DiffResult* quickDiff); -template MAYA_USD_UTILS_PUBLIC std::map compareLists( +template USDUFE_PUBLIC std::map compareLists( const std::vector& modified, const std::vector& baseline, DiffResult* quickDiff); -template MAYA_USD_UTILS_PUBLIC std::map compareLists( +template USDUFE_PUBLIC std::map compareLists( const std::vector& modified, const std::vector& baseline, DiffResult* quickDiff); -template MAYA_USD_UTILS_PUBLIC std::map compareLists( +template USDUFE_PUBLIC std::map compareLists( const std::vector& modified, const std::vector& baseline, DiffResult* quickDiff); -template MAYA_USD_UTILS_PUBLIC std::map compareLists( +template USDUFE_PUBLIC std::map compareLists( const std::vector& modified, const std::vector& baseline, DiffResult* quickDiff); -template MAYA_USD_UTILS_PUBLIC std::map compareLists( +template USDUFE_PUBLIC std::map compareLists( const std::vector& modified, const std::vector& baseline, DiffResult* quickDiff); -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/DiffMetadatas.cpp b/lib/usdUfe/utils/diffMetadatas.cpp similarity index 96% rename from lib/usd/utils/DiffMetadatas.cpp rename to lib/usdUfe/utils/diffMetadatas.cpp index 1eebb0e814..8f82b90098 100644 --- a/lib/usd/utils/DiffMetadatas.cpp +++ b/lib/usdUfe/utils/diffMetadatas.cpp @@ -13,14 +13,14 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include "DiffPrims.h" +#include "diffPrims.h" #include #include #include #include -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { using UsdObject = PXR_NS::UsdObject; using TfToken = PXR_NS::TfToken; @@ -110,7 +110,7 @@ DiffResult compareMetadatas( return compareValues(modifiedData, baselineData); } -#define USD_MAYA_RETURN_QUICK_RESULT(result) \ +#define USDUFE_RETURN_QUICK_RESULT(result) \ do { \ if (quickDiff && result != DiffResult::Same) { \ *quickDiff = result; \ @@ -147,11 +147,11 @@ compareObjectsMetadatas(const UsdObject& modified, const UsdObject& baseline, Di continue; const auto iter = baselineMetadatas.find(name); if (iter == baselineEnd) { - USD_MAYA_RETURN_QUICK_RESULT(DiffResult::Created); + USDUFE_RETURN_QUICK_RESULT(DiffResult::Created); results[name] = DiffResult::Created; } else { const DiffResult result = compareValues(nameAndValue.second, iter->second); - USD_MAYA_RETURN_QUICK_RESULT(result); + USDUFE_RETURN_QUICK_RESULT(result); results[name] = result; } } @@ -163,7 +163,7 @@ compareObjectsMetadatas(const UsdObject& modified, const UsdObject& baseline, Di if (isIgnored(name)) continue; if (results.find(name) == results.end()) { - USD_MAYA_RETURN_QUICK_RESULT(DiffResult::Absent); + USDUFE_RETURN_QUICK_RESULT(DiffResult::Absent); results[name] = DiffResult::Absent; } } @@ -171,4 +171,4 @@ compareObjectsMetadatas(const UsdObject& modified, const UsdObject& baseline, Di return results; } -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/DiffPrims.cpp b/lib/usdUfe/utils/diffPrims.cpp similarity index 89% rename from lib/usd/utils/DiffPrims.cpp rename to lib/usdUfe/utils/diffPrims.cpp index 82fa34e7b0..fc71d5a8fb 100644 --- a/lib/usd/utils/DiffPrims.cpp +++ b/lib/usdUfe/utils/diffPrims.cpp @@ -1,5 +1,5 @@ // -// Copyright 2021 Autodesk +// Copyright 2024 Autodesk // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -13,11 +13,11 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include "DiffPrims.h" +#include "diffPrims.h" #include -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { using UsdPrim = PXR_NS::UsdPrim; using TfToken = PXR_NS::TfToken; @@ -25,7 +25,7 @@ using SdfPath = PXR_NS::SdfPath; using UsdAttribute = PXR_NS::UsdAttribute; using UsdRelationship = PXR_NS::UsdRelationship; -#define USD_MAYA_RETURN_QUICK_RESULT(result, results) \ +#define USDUFE_RETURN_QUICK_RESULT(result, results) \ do { \ if (quickDiff && result != DiffResult::Same) { \ *quickDiff = result; \ @@ -58,11 +58,11 @@ comparePrimsAttributes(const UsdPrim& modified, const UsdPrim& baseline, DiffRes const TfToken& name = attr.GetName(); const auto iter = baselineAttrs.find(name); if (iter == baselineEnd) { - USD_MAYA_RETURN_QUICK_RESULT(DiffResult::Created, results); + USDUFE_RETURN_QUICK_RESULT(DiffResult::Created, results); results[name] = DiffResult::Created; } else { const DiffResult result = compareAttributes(attr, iter->second, quickDiff); - USD_MAYA_RETURN_QUICK_RESULT(result, results); + USDUFE_RETURN_QUICK_RESULT(result, results); results[name] = result; } } @@ -72,7 +72,7 @@ comparePrimsAttributes(const UsdPrim& modified, const UsdPrim& baseline, DiffRes for (const auto& nameAndAttr : baselineAttrs) { const auto& name = nameAndAttr.first; if (results.find(name) == results.end()) { - USD_MAYA_RETURN_QUICK_RESULT(DiffResult::Absent, results); + USDUFE_RETURN_QUICK_RESULT(DiffResult::Absent, results); results[name] = DiffResult::Absent; } } @@ -106,10 +106,10 @@ comparePrimsRelationships(const UsdPrim& modified, const UsdPrim& baseline, Diff const auto iter = baselineRels.find(name); if (iter == baselineEnd) { results[name] = compareRelationships(rel, UsdRelationship(), quickDiff); - USD_MAYA_RETURN_QUICK_RESULT(*quickDiff, results); + USDUFE_RETURN_QUICK_RESULT(*quickDiff, results); } else { results[name] = compareRelationships(rel, iter->second, quickDiff); - USD_MAYA_RETURN_QUICK_RESULT(*quickDiff, results); + USDUFE_RETURN_QUICK_RESULT(*quickDiff, results); } } } @@ -119,7 +119,7 @@ comparePrimsRelationships(const UsdPrim& modified, const UsdPrim& baseline, Diff const auto& name = nameAndRel.first; if (results.find(name) == results.end()) { results[name] = compareRelationships(UsdRelationship(), nameAndRel.second, quickDiff); - USD_MAYA_RETURN_QUICK_RESULT(*quickDiff, results); + USDUFE_RETURN_QUICK_RESULT(*quickDiff, results); } } @@ -151,11 +151,11 @@ comparePrimsChildren(const UsdPrim& modified, const UsdPrim& baseline, DiffResul const SdfPath& path = child.GetPath(); const auto iter = baselineChildren.find(path); if (iter == baselineEnd) { - USD_MAYA_RETURN_QUICK_RESULT(DiffResult::Created, results); + USDUFE_RETURN_QUICK_RESULT(DiffResult::Created, results); results[path] = DiffResult::Created; } else { results[path] = comparePrims(child, iter->second, quickDiff); - USD_MAYA_RETURN_QUICK_RESULT(*quickDiff, results); + USDUFE_RETURN_QUICK_RESULT(*quickDiff, results); } } } @@ -164,7 +164,7 @@ comparePrimsChildren(const UsdPrim& modified, const UsdPrim& baseline, DiffResul for (const auto& pathAndPrim : baselineChildren) { const auto& path = pathAndPrim.first; if (results.find(path) == results.end()) { - USD_MAYA_RETURN_QUICK_RESULT(DiffResult::Absent, results); + USDUFE_RETURN_QUICK_RESULT(DiffResult::Absent, results); results[path] = DiffResult::Absent; } } @@ -199,7 +199,7 @@ static DiffResult comparePrims( { const auto attrDiffs = comparePrimsAttributes(modified, baseline, quickDiff); - USD_MAYA_RETURN_QUICK_RESULT(*quickDiff, *quickDiff); + USDUFE_RETURN_QUICK_RESULT(*quickDiff, *quickDiff); // Note: no need to quick result when computing overall result as it would already have // returned. @@ -212,7 +212,7 @@ static DiffResult comparePrims( { const auto relDiffs = comparePrimsRelationships(modified, baseline, quickDiff); - USD_MAYA_RETURN_QUICK_RESULT(*quickDiff, *quickDiff); + USDUFE_RETURN_QUICK_RESULT(*quickDiff, *quickDiff); // Note: no need to quick result when computing overall result as it would already have // returned. @@ -233,7 +233,7 @@ static DiffResult comparePrims( if (compareChildren) { const auto childrenDiffs = comparePrimsChildren(modified, baseline, quickDiff); - USD_MAYA_RETURN_QUICK_RESULT(*quickDiff, *quickDiff); + USDUFE_RETURN_QUICK_RESULT(*quickDiff, *quickDiff); // Note: no need to quick result when computing overall result as it would already have // returned. @@ -262,4 +262,4 @@ DiffResult comparePrimsOnly( return comparePrims(modified, baseline, false, quickDiff); } -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/DiffPrims.h b/lib/usdUfe/utils/diffPrims.h similarity index 97% rename from lib/usd/utils/DiffPrims.h rename to lib/usdUfe/utils/diffPrims.h index bd2a292f50..71ff384514 100644 --- a/lib/usd/utils/DiffPrims.h +++ b/lib/usdUfe/utils/diffPrims.h @@ -1,5 +1,5 @@ // -// Copyright 2021 Autodesk +// Copyright 2024 Autodesk // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ // #pragma once -#include +#include #include #include @@ -30,7 +30,7 @@ #include #include -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { //---------------------------------------------------------------------------------------------------------------------- // Comparison result types. @@ -78,7 +78,7 @@ using DiffResultPerPathPerToken = std::map; /// \param subResults the sub-results to analyze. /// \return the overall result, all results are possible. //---------------------------------------------------------------------------------------------------------------------- -template MAYA_USD_UTILS_PUBLIC DiffResult computeOverallResult(const MAP& subResults); +template USDUFE_PUBLIC DiffResult computeOverallResult(const MAP& subResults); //---------------------------------------------------------------------------------------------------------------------- // Comparison of prims. @@ -92,7 +92,7 @@ template MAYA_USD_UTILS_PUBLIC DiffResult computeOverallResult(const /// \param quickDiff if not null, returns a result other than Same when a difference is found. /// \return the overall result, all results are possible. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC DiffResult comparePrims( const PXR_NS::UsdPrim& modified, const PXR_NS::UsdPrim& baseline, @@ -106,7 +106,7 @@ DiffResult comparePrims( /// \param quickDiff if not null, returns a result other than Same when a difference is found. /// \return the overall result, all results are possible. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC DiffResult comparePrimsOnly( const PXR_NS::UsdPrim& modified, const PXR_NS::UsdPrim& baseline, @@ -119,7 +119,7 @@ DiffResult comparePrimsOnly( /// \param quickDiff if not null, returns a result other than Same when a difference is found. /// \return the map of children paths to the result of comparison of that child. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC DiffResultPerPath comparePrimsChildren( const PXR_NS::UsdPrim& modified, const PXR_NS::UsdPrim& baseline, @@ -133,7 +133,7 @@ DiffResultPerPath comparePrimsChildren( /// \return the map of attribute names to the result of comparison of that attribute. /// Currently Subset and Superset are never returned. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC DiffResultPerToken comparePrimsAttributes( const PXR_NS::UsdPrim& modified, const PXR_NS::UsdPrim& baseline, @@ -147,7 +147,7 @@ DiffResultPerToken comparePrimsAttributes( /// \return the map of relationship names to the result of comparison of that relationship. /// Currently only Same, Absent, Reordered, Prepended or Appended are returned. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC DiffResultPerPathPerToken comparePrimsRelationships( const PXR_NS::UsdPrim& modified, const PXR_NS::UsdPrim& baseline, @@ -165,7 +165,7 @@ DiffResultPerPathPerToken comparePrimsRelationships( /// \return the result of the comparison of that modified attribute. /// Currently Subset and Superset are never returned. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC DiffResult compareAttributes( const PXR_NS::UsdAttribute& modified, const PXR_NS::UsdAttribute& baseline, @@ -179,7 +179,7 @@ DiffResult compareAttributes( /// \return the result of the comparison of that modified attribute. /// Currently Subset and Superset are never returned. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC DiffResult compareAttributes( const PXR_NS::UsdAttribute& modified, const PXR_NS::UsdAttribute& baseline, @@ -193,7 +193,7 @@ DiffResult compareAttributes( /// \return the map of target paths to the result of comparison of that target. /// Currently only Same, Absent, Prepended or Appended are returned. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC DiffResultPerPath compareRelationships( const PXR_NS::UsdRelationship& modified, const PXR_NS::UsdRelationship& baseline, @@ -207,7 +207,7 @@ DiffResultPerPath compareRelationships( /// \return the map of metadata names to the result of comparison of that metadata. /// Currently Subset and Superset are never returned. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC DiffResultPerToken compareObjectsMetadatas( const PXR_NS::UsdObject& modified, const PXR_NS::UsdObject& baseline, @@ -220,7 +220,7 @@ DiffResultPerToken compareObjectsMetadatas( /// \param metadata the name of the metadata to compare. /// \return the result of comparison of that metadata. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC DiffResult compareMetadatas( const PXR_NS::UsdObject& modified, const PXR_NS::UsdObject& baseline, @@ -232,7 +232,7 @@ DiffResult compareMetadatas( /// For example, the fact that a prim is a "def" or an "over" or that an attribute can or cannot be /// animated. \return the set of metadata names that should be ignored. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC std::unordered_set& getIgnoredMetadatas(); //---------------------------------------------------------------------------------------------------------------------- @@ -242,7 +242,7 @@ std::unordered_set& getIgnoredMet /// \return the result of the comparison of that modified value. /// Currently Subset and Superset are never returned. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC DiffResult compareValues(const PXR_NS::VtValue& modified, const PXR_NS::VtValue& baseline); //---------------------------------------------------------------------------------------------------------------------- @@ -257,7 +257,7 @@ DiffResult compareValues(const PXR_NS::VtValue& modified, const PXR_NS::VtValue& /// TfToken, std::string, SdfPath, SdfReference and SdfPayload. //---------------------------------------------------------------------------------------------------------------------- template -MAYA_USD_UTILS_PUBLIC std::map compareLists( +USDUFE_PUBLIC std::map compareLists( const std::vector& modified, const std::vector& baseline, DiffResult* quickDiff = nullptr); @@ -270,7 +270,7 @@ MAYA_USD_UTILS_PUBLIC std::map compareLists( /// \return the result of the comparison for each value in that modified dictionary. /// Currently only Same, Differ, Absent and Created are returned. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC DiffResultPerKey compareDictionaries( const PXR_NS::VtDictionary& modified, const PXR_NS::VtDictionary& baseline, @@ -356,4 +356,4 @@ template inline DiffResult computeOverallResult(const MAP& subResult } } -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/DiffRelationships.cpp b/lib/usdUfe/utils/diffRelationships.cpp similarity index 92% rename from lib/usd/utils/DiffRelationships.cpp rename to lib/usdUfe/utils/diffRelationships.cpp index 25cd3a0cd5..4cd817c394 100644 --- a/lib/usd/utils/DiffRelationships.cpp +++ b/lib/usdUfe/utils/diffRelationships.cpp @@ -13,10 +13,11 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include "DiffCore.h" -#include "DiffPrims.h" +#include "diffPrims.h" -namespace MayaUsdUtils { +#include + +namespace USDUFE_NS_DEF { using UsdRelationship = PXR_NS::UsdRelationship; using TfToken = PXR_NS::TfToken; @@ -47,4 +48,4 @@ DiffResultPerPath compareRelationships( return compareLists(modifiedTargets, baselineTargets, quickDiff); } -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/DiffValues.cpp b/lib/usdUfe/utils/diffValues.cpp similarity index 68% rename from lib/usd/utils/DiffValues.cpp rename to lib/usdUfe/utils/diffValues.cpp index 802d1684e3..9b9ad35577 100644 --- a/lib/usd/utils/DiffValues.cpp +++ b/lib/usdUfe/utils/diffValues.cpp @@ -1,5 +1,5 @@ // -// Copyright 2021 Autodesk +// Copyright 2024 Autodesk // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -13,8 +13,9 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include "DiffCore.h" -#include "DiffPrims.h" +#include "diffPrims.h" + +#include #include #include @@ -33,7 +34,7 @@ #include #include -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { using VtValue = PXR_NS::VtValue; using TfType = PXR_NS::TfType; @@ -147,37 +148,37 @@ DiffResult diffEmpties(const VtValue& /*modified*/, const VtValue& /*baseline*/) return DiffResult::Same; } -#define MAYA_USD_DIFF_FUNC_FOR_TYPE_WITH_EPS(T) \ +#define USDUFE_DIFF_FUNC_FOR_TYPE_WITH_EPS(T) \ { DiffKey(typeid(T), typeid(T)), diffOneTypeWithEps }, \ { \ DiffKey(typeid(VtArray), typeid(VtArray)), diffOneArrayTypeWithEps \ } -#define MAYA_USD_DIFF_FUNC_FOR_TYPES_WITH_EPS(T1, T2) \ +#define USDUFE_DIFF_FUNC_FOR_TYPES_WITH_EPS(T1, T2) \ { DiffKey(typeid(T1), typeid(T2)), diffTwoTypesWithEps }, \ { \ DiffKey(typeid(VtArray), typeid(VtArray)), diffTwoArrayTypesWithEps \ } -#define MAYA_USD_DIFF_FUNC_FOR_VEC(T, SIZE) \ +#define USDUFE_DIFF_FUNC_FOR_VEC(T, SIZE) \ { DiffKey(typeid(T), typeid(T)), diffTwoVecs }, \ { \ DiffKey(typeid(VtArray), typeid(VtArray)), diffTwoVecArrays \ } -#define MAYA_USD_DIFF_FUNC_FOR_VECS(T1, T2, SIZE) \ +#define USDUFE_DIFF_FUNC_FOR_VECS(T1, T2, SIZE) \ { DiffKey(typeid(T1), typeid(T2)), diffTwoVecs }, \ { \ DiffKey(typeid(VtArray), typeid(VtArray)), diffTwoVecArrays \ } -#define MAYA_USD_DIFF_FUNC_FOR_QUAT(T, SIZE) \ +#define USDUFE_DIFF_FUNC_FOR_QUAT(T, SIZE) \ { DiffKey(typeid(T), typeid(T)), diffTwoQuats }, \ { \ DiffKey(typeid(VtArray), typeid(VtArray)), diffTwoQuatArrays \ } -#define MAYA_USD_DIFF_FUNC_FOR_QUATS(T1, T2, SIZE) \ +#define USDUFE_DIFF_FUNC_FOR_QUATS(T1, T2, SIZE) \ { DiffKey(typeid(T1), typeid(T2)), diffTwoQuats }, \ { \ DiffKey(typeid(VtArray), typeid(VtArray)), diffTwoQuatArrays \ @@ -188,77 +189,77 @@ const DiffFuncMap& getDiffFuncs() // Initializing static data inside a function makes it automatically initialization-order safe. static DiffFuncMap diffs = { - MAYA_USD_DIFF_FUNC_FOR_TYPE_WITH_EPS(GfHalf), - MAYA_USD_DIFF_FUNC_FOR_TYPES_WITH_EPS(GfHalf, float), - MAYA_USD_DIFF_FUNC_FOR_TYPES_WITH_EPS(GfHalf, double), - - MAYA_USD_DIFF_FUNC_FOR_TYPE_WITH_EPS(float), - MAYA_USD_DIFF_FUNC_FOR_TYPES_WITH_EPS(float, GfHalf), - MAYA_USD_DIFF_FUNC_FOR_TYPES_WITH_EPS(float, double), - - MAYA_USD_DIFF_FUNC_FOR_TYPE_WITH_EPS(double), - MAYA_USD_DIFF_FUNC_FOR_TYPES_WITH_EPS(double, GfHalf), - MAYA_USD_DIFF_FUNC_FOR_TYPES_WITH_EPS(double, float), - - MAYA_USD_DIFF_FUNC_FOR_TYPE_WITH_EPS(int8_t), - MAYA_USD_DIFF_FUNC_FOR_TYPE_WITH_EPS(uint8_t), - MAYA_USD_DIFF_FUNC_FOR_TYPE_WITH_EPS(int16_t), - MAYA_USD_DIFF_FUNC_FOR_TYPE_WITH_EPS(uint16_t), - MAYA_USD_DIFF_FUNC_FOR_TYPE_WITH_EPS(int32_t), - MAYA_USD_DIFF_FUNC_FOR_TYPE_WITH_EPS(uint32_t), - MAYA_USD_DIFF_FUNC_FOR_TYPE_WITH_EPS(int64_t), - MAYA_USD_DIFF_FUNC_FOR_TYPE_WITH_EPS(uint64_t), - - MAYA_USD_DIFF_FUNC_FOR_VEC(GfVec2d, 2), - MAYA_USD_DIFF_FUNC_FOR_VEC(GfVec2f, 2), - MAYA_USD_DIFF_FUNC_FOR_VEC(GfVec2h, 2), - MAYA_USD_DIFF_FUNC_FOR_VEC(GfVec2i, 2), - - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec2d, GfVec2f, 2), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec2d, GfVec2h, 2), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec2f, GfVec2d, 2), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec2f, GfVec2h, 2), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec2h, GfVec2d, 2), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec2h, GfVec2f, 2), - - MAYA_USD_DIFF_FUNC_FOR_VEC(GfVec3d, 3), - MAYA_USD_DIFF_FUNC_FOR_VEC(GfVec3f, 3), - MAYA_USD_DIFF_FUNC_FOR_VEC(GfVec3h, 3), - MAYA_USD_DIFF_FUNC_FOR_VEC(GfVec3i, 3), - - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec3d, GfVec3f, 3), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec3d, GfVec3h, 3), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec3f, GfVec3d, 3), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec3f, GfVec3h, 3), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec3h, GfVec3d, 3), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec3h, GfVec3f, 3), - - MAYA_USD_DIFF_FUNC_FOR_VEC(GfVec4d, 4), - MAYA_USD_DIFF_FUNC_FOR_VEC(GfVec4f, 4), - MAYA_USD_DIFF_FUNC_FOR_VEC(GfVec4h, 4), - MAYA_USD_DIFF_FUNC_FOR_VEC(GfVec4i, 4), - - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec4d, GfVec4f, 4), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec4d, GfVec4h, 4), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec4f, GfVec4d, 4), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec4f, GfVec4h, 4), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec4h, GfVec4d, 4), - MAYA_USD_DIFF_FUNC_FOR_VECS(GfVec4h, GfVec4f, 4), - - MAYA_USD_DIFF_FUNC_FOR_VEC(GfMatrix2d, 4), - MAYA_USD_DIFF_FUNC_FOR_VEC(GfMatrix3d, 9), - MAYA_USD_DIFF_FUNC_FOR_VEC(GfMatrix4d, 16), - - MAYA_USD_DIFF_FUNC_FOR_QUAT(GfQuatd, 4), - MAYA_USD_DIFF_FUNC_FOR_QUAT(GfQuatf, 4), - MAYA_USD_DIFF_FUNC_FOR_QUAT(GfQuath, 4), - - MAYA_USD_DIFF_FUNC_FOR_QUATS(GfQuatd, GfQuatf, 4), - MAYA_USD_DIFF_FUNC_FOR_QUATS(GfQuatd, GfQuath, 4), - MAYA_USD_DIFF_FUNC_FOR_QUATS(GfQuatf, GfQuatd, 4), - MAYA_USD_DIFF_FUNC_FOR_QUATS(GfQuatf, GfQuath, 4), - MAYA_USD_DIFF_FUNC_FOR_QUATS(GfQuath, GfQuatd, 4), - MAYA_USD_DIFF_FUNC_FOR_QUATS(GfQuath, GfQuatf, 4), + USDUFE_DIFF_FUNC_FOR_TYPE_WITH_EPS(GfHalf), + USDUFE_DIFF_FUNC_FOR_TYPES_WITH_EPS(GfHalf, float), + USDUFE_DIFF_FUNC_FOR_TYPES_WITH_EPS(GfHalf, double), + + USDUFE_DIFF_FUNC_FOR_TYPE_WITH_EPS(float), + USDUFE_DIFF_FUNC_FOR_TYPES_WITH_EPS(float, GfHalf), + USDUFE_DIFF_FUNC_FOR_TYPES_WITH_EPS(float, double), + + USDUFE_DIFF_FUNC_FOR_TYPE_WITH_EPS(double), + USDUFE_DIFF_FUNC_FOR_TYPES_WITH_EPS(double, GfHalf), + USDUFE_DIFF_FUNC_FOR_TYPES_WITH_EPS(double, float), + + USDUFE_DIFF_FUNC_FOR_TYPE_WITH_EPS(int8_t), + USDUFE_DIFF_FUNC_FOR_TYPE_WITH_EPS(uint8_t), + USDUFE_DIFF_FUNC_FOR_TYPE_WITH_EPS(int16_t), + USDUFE_DIFF_FUNC_FOR_TYPE_WITH_EPS(uint16_t), + USDUFE_DIFF_FUNC_FOR_TYPE_WITH_EPS(int32_t), + USDUFE_DIFF_FUNC_FOR_TYPE_WITH_EPS(uint32_t), + USDUFE_DIFF_FUNC_FOR_TYPE_WITH_EPS(int64_t), + USDUFE_DIFF_FUNC_FOR_TYPE_WITH_EPS(uint64_t), + + USDUFE_DIFF_FUNC_FOR_VEC(GfVec2d, 2), + USDUFE_DIFF_FUNC_FOR_VEC(GfVec2f, 2), + USDUFE_DIFF_FUNC_FOR_VEC(GfVec2h, 2), + USDUFE_DIFF_FUNC_FOR_VEC(GfVec2i, 2), + + USDUFE_DIFF_FUNC_FOR_VECS(GfVec2d, GfVec2f, 2), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec2d, GfVec2h, 2), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec2f, GfVec2d, 2), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec2f, GfVec2h, 2), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec2h, GfVec2d, 2), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec2h, GfVec2f, 2), + + USDUFE_DIFF_FUNC_FOR_VEC(GfVec3d, 3), + USDUFE_DIFF_FUNC_FOR_VEC(GfVec3f, 3), + USDUFE_DIFF_FUNC_FOR_VEC(GfVec3h, 3), + USDUFE_DIFF_FUNC_FOR_VEC(GfVec3i, 3), + + USDUFE_DIFF_FUNC_FOR_VECS(GfVec3d, GfVec3f, 3), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec3d, GfVec3h, 3), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec3f, GfVec3d, 3), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec3f, GfVec3h, 3), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec3h, GfVec3d, 3), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec3h, GfVec3f, 3), + + USDUFE_DIFF_FUNC_FOR_VEC(GfVec4d, 4), + USDUFE_DIFF_FUNC_FOR_VEC(GfVec4f, 4), + USDUFE_DIFF_FUNC_FOR_VEC(GfVec4h, 4), + USDUFE_DIFF_FUNC_FOR_VEC(GfVec4i, 4), + + USDUFE_DIFF_FUNC_FOR_VECS(GfVec4d, GfVec4f, 4), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec4d, GfVec4h, 4), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec4f, GfVec4d, 4), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec4f, GfVec4h, 4), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec4h, GfVec4d, 4), + USDUFE_DIFF_FUNC_FOR_VECS(GfVec4h, GfVec4f, 4), + + USDUFE_DIFF_FUNC_FOR_VEC(GfMatrix2d, 4), + USDUFE_DIFF_FUNC_FOR_VEC(GfMatrix3d, 9), + USDUFE_DIFF_FUNC_FOR_VEC(GfMatrix4d, 16), + + USDUFE_DIFF_FUNC_FOR_QUAT(GfQuatd, 4), + USDUFE_DIFF_FUNC_FOR_QUAT(GfQuatf, 4), + USDUFE_DIFF_FUNC_FOR_QUAT(GfQuath, 4), + + USDUFE_DIFF_FUNC_FOR_QUATS(GfQuatd, GfQuatf, 4), + USDUFE_DIFF_FUNC_FOR_QUATS(GfQuatd, GfQuath, 4), + USDUFE_DIFF_FUNC_FOR_QUATS(GfQuatf, GfQuatd, 4), + USDUFE_DIFF_FUNC_FOR_QUATS(GfQuatf, GfQuath, 4), + USDUFE_DIFF_FUNC_FOR_QUATS(GfQuath, GfQuatd, 4), + USDUFE_DIFF_FUNC_FOR_QUATS(GfQuath, GfQuatf, 4), // TODO: separate U,V vs combined UV diff. DiffCore support this, but we don't expect // USD to ever have UV that are sometimes spearate attributes, sometimes a single attribute. @@ -288,4 +289,4 @@ DiffResult compareValues(const VtValue& modified, const VtValue& baseline) return diff(modified, baseline); } -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/MergePrims.cpp b/lib/usdUfe/utils/mergePrims.cpp similarity index 98% rename from lib/usd/utils/MergePrims.cpp rename to lib/usdUfe/utils/mergePrims.cpp index 32fa847684..c8c5ecfaf2 100644 --- a/lib/usd/utils/MergePrims.cpp +++ b/lib/usdUfe/utils/mergePrims.cpp @@ -1,5 +1,5 @@ // -// Copyright 2021 Autodesk +// Copyright 2024 Autodesk // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -13,9 +13,9 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include "MergePrims.h" +#include "mergePrims.h" -#include "DiffPrims.h" +#include #include #include @@ -26,7 +26,7 @@ #include #include -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { PXR_NAMESPACE_USING_DIRECTIVE @@ -59,7 +59,7 @@ struct MergeLocation }; //---------------------------------------------------------------------------------------------------------------------- -/// Prints a layer / path / field to the Maya console with some messages. +/// Prints a layer / path / field to the DCC console with some messages. void printAboutField( const MergeContext& ctx, const MergeLocation& loc, @@ -253,7 +253,7 @@ bool isLocalTransformModified(const UsdPrim& srcPrim, const UsdPrim& dstPrim) // // The goal is to detect that a prim normals has *not* changed even though its representation // might have changed. The reason is that normals can be kept in the 'normals' attribute or in -// the 'primvars:normals' attribute, with the latter having priority. Maya export to USD always +// the 'primvars:normals' attribute, with the latter having priority. DCC export to USD always // generates the 'normals' attribute, which would get hidden when merged. We now detect and correct // that situation. //---------------------------------------------------------------------------------------------------------------------- @@ -403,7 +403,7 @@ bool isDataAtPathsModified( // // The only reason we are using the local transformation comparison is for // the somewhat common case where the transform has not changed but how it - // is encoded changed, because the Maya representation and the original + // is encoded changed, because the DCC representation and the original // representation differed, for example for USD data coming from another // tool that use a different transform operation order. if (isTransformProperty(srcProp)) { @@ -925,7 +925,7 @@ bool shouldMergeChildren( } //---------------------------------------------------------------------------------------------------------------------- -/// Copies a minimal prim using diff and merge, printing all fields that are copied to the Maya +/// Copies a minimal prim using diff and merge, printing all fields that are copied to the DCC /// console. bool mergeDiffPrims( const MergePrimsOptions& options, @@ -1047,4 +1047,17 @@ bool mergePrims( } } -} // namespace MayaUsdUtils +bool mergePrims( + const UsdStageRefPtr& srcStage, + const SdfLayerRefPtr& srcLayer, + const SdfPath& srcPath, + const UsdStageRefPtr& dstStage, + const SdfLayerRefPtr& dstLayer, + const SdfPath& dstPath) +{ + MergePrimsOptions options; + options.verbosity = MergeVerbosity::None; + return mergePrims(srcStage, srcLayer, srcPath, dstStage, dstLayer, dstPath, options); +} + +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/MergePrims.h b/lib/usdUfe/utils/mergePrims.h similarity index 78% rename from lib/usd/utils/MergePrims.h rename to lib/usdUfe/utils/mergePrims.h index be3e49822a..8c6676a154 100644 --- a/lib/usd/utils/MergePrims.h +++ b/lib/usdUfe/utils/mergePrims.h @@ -1,5 +1,5 @@ // -// Copyright 2021 Autodesk +// Copyright 2024 Autodesk // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,14 +15,14 @@ // #pragma once -#include -#include +#include +#include #include #include #include -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { //---------------------------------------------------------------------------------------------------------------------- /// \brief merges prims starting at a source path from a source layer and stage to a destination. @@ -35,7 +35,7 @@ namespace MayaUsdUtils { /// \param options merging options. /// \return true if the merge was successful. //---------------------------------------------------------------------------------------------------------------------- -MAYA_USD_UTILS_PUBLIC +USDUFE_PUBLIC bool mergePrims( const PXR_NS::UsdStageRefPtr& srcStage, const PXR_NS::SdfLayerRefPtr& srcLayer, @@ -45,4 +45,14 @@ bool mergePrims( const PXR_NS::SdfPath& dstPath, const MergePrimsOptions& options); -} // namespace MayaUsdUtils +//! \brief merge prims with default options, but no verbosity. +USDUFE_PUBLIC +bool mergePrims( + const PXR_NS::UsdStageRefPtr& srcStage, + const PXR_NS::SdfLayerRefPtr& srcLayer, + const PXR_NS::SdfPath& srcPath, + const PXR_NS::UsdStageRefPtr& dstStage, + const PXR_NS::SdfLayerRefPtr& dstLayer, + const PXR_NS::SdfPath& dstPath); + +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/MergePrimsOptions.cpp b/lib/usdUfe/utils/mergePrimsOptions.cpp similarity index 55% rename from lib/usd/utils/MergePrimsOptions.cpp rename to lib/usdUfe/utils/mergePrimsOptions.cpp index efd6af264a..7c65319567 100644 --- a/lib/usd/utils/MergePrimsOptions.cpp +++ b/lib/usdUfe/utils/mergePrimsOptions.cpp @@ -1,5 +1,5 @@ // -// Copyright 2021 Autodesk +// Copyright 2024 Autodesk // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -13,13 +13,13 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include "MergePrimsOptions.h" +#include "mergePrimsOptions.h" #include -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { -TF_DEFINE_PUBLIC_TOKENS(UsdMayaMergeOptionsTokens, USDMAYA_MERGE_OPTIONS_TOKENS); +TF_DEFINE_PUBLIC_TOKENS(MergeOptionsTokens, USDUFE_MERGE_OPTIONS_TOKENS); namespace { @@ -55,21 +55,21 @@ MergeVerbosity parseVerbosity( const auto tokens = VtDictionaryGet>(options, key); for (const auto& token : tokens) { - if (UsdMayaMergeOptionsTokens->None == token) + if (MergeOptionsTokens->None == token) verbosity = verbosity | MergeVerbosity::None; - if (UsdMayaMergeOptionsTokens->Same == token) + if (MergeOptionsTokens->Same == token) verbosity = verbosity | MergeVerbosity::Same; - if (UsdMayaMergeOptionsTokens->Differ == token) + if (MergeOptionsTokens->Differ == token) verbosity = verbosity | MergeVerbosity::Differ; - if (UsdMayaMergeOptionsTokens->Child == token) + if (MergeOptionsTokens->Child == token) verbosity = verbosity | MergeVerbosity::Child; - if (UsdMayaMergeOptionsTokens->Children == token) + if (MergeOptionsTokens->Children == token) verbosity = verbosity | MergeVerbosity::Children; - if (UsdMayaMergeOptionsTokens->Failure == token) + if (MergeOptionsTokens->Failure == token) verbosity = verbosity | MergeVerbosity::Failure; - if (UsdMayaMergeOptionsTokens->Default == token) + if (MergeOptionsTokens->Default == token) verbosity = verbosity | MergeVerbosity::Default; - if (UsdMayaMergeOptionsTokens->All == token) + if (MergeOptionsTokens->All == token) verbosity = verbosity | MergeVerbosity::All; } @@ -95,13 +95,13 @@ MergeMissing parseMissingHandling( const auto tokens = VtDictionaryGet>(options, key); for (const auto& token : tokens) { - if (UsdMayaMergeOptionsTokens->None == token) + if (MergeOptionsTokens->None == token) missingHandling = missingHandling | MergeMissing::None; - if (UsdMayaMergeOptionsTokens->Create == token) + if (MergeOptionsTokens->Create == token) missingHandling = missingHandling | MergeMissing::Create; - if (UsdMayaMergeOptionsTokens->Preserve == token) + if (MergeOptionsTokens->Preserve == token) missingHandling = missingHandling | MergeMissing::Preserve; - if (UsdMayaMergeOptionsTokens->All == token) + if (MergeOptionsTokens->All == token) missingHandling = missingHandling | MergeMissing::All; } @@ -116,26 +116,22 @@ const VtDictionary& MergePrimsOptions::getDefaultDictionary() static VtDictionary d; static std::once_flag once; std::call_once(once, []() { - d[UsdMayaMergeOptionsTokens->verbosity] - = VtValue(std::vector({ VtValue(UsdMayaMergeOptionsTokens->Default) })); - - d[UsdMayaMergeOptionsTokens->mergeChildren] = false; - d[UsdMayaMergeOptionsTokens->ignoreUpperLayerOpinions] = false; - - static const TfToken handlingTokens[] = { UsdMayaMergeOptionsTokens->propertiesHandling, - UsdMayaMergeOptionsTokens->primsHandling, - UsdMayaMergeOptionsTokens->connectionsHandling, - UsdMayaMergeOptionsTokens->relationshipsHandling, - UsdMayaMergeOptionsTokens->variantsHandling, - UsdMayaMergeOptionsTokens->variantSetsHandling, - UsdMayaMergeOptionsTokens->expressionsHandling, - UsdMayaMergeOptionsTokens->mappersHandling, - UsdMayaMergeOptionsTokens->mapperArgsHandling, - UsdMayaMergeOptionsTokens->propMetadataHandling, - UsdMayaMergeOptionsTokens->primMetadataHandling }; + d[MergeOptionsTokens->verbosity] + = VtValue(std::vector({ VtValue(MergeOptionsTokens->Default) })); + + d[MergeOptionsTokens->mergeChildren] = false; + d[MergeOptionsTokens->ignoreUpperLayerOpinions] = false; + + static const TfToken handlingTokens[] + = { MergeOptionsTokens->propertiesHandling, MergeOptionsTokens->primsHandling, + MergeOptionsTokens->connectionsHandling, MergeOptionsTokens->relationshipsHandling, + MergeOptionsTokens->variantsHandling, MergeOptionsTokens->variantSetsHandling, + MergeOptionsTokens->expressionsHandling, MergeOptionsTokens->mappersHandling, + MergeOptionsTokens->mapperArgsHandling, MergeOptionsTokens->propMetadataHandling, + MergeOptionsTokens->primMetadataHandling }; for (const auto& ht : handlingTokens) { - d[ht] = VtValue(std::vector({ VtValue(UsdMayaMergeOptionsTokens->All) })); + d[ht] = VtValue(std::vector({ VtValue(MergeOptionsTokens->All) })); } }); @@ -147,29 +143,29 @@ MergePrimsOptions::MergePrimsOptions(const VtDictionary& options) // Make sure we have all options filled by merging over the default dictionary. const VtDictionary optionsWithDef = VtDictionaryOver(options, getDefaultDictionary()); - verbosity = parseVerbosity(optionsWithDef, UsdMayaMergeOptionsTokens->verbosity); + verbosity = parseVerbosity(optionsWithDef, MergeOptionsTokens->verbosity); - mergeChildren = parseBoolean(optionsWithDef, UsdMayaMergeOptionsTokens->mergeChildren); + mergeChildren = parseBoolean(optionsWithDef, MergeOptionsTokens->mergeChildren); ignoreUpperLayerOpinions - = parseBoolean(optionsWithDef, UsdMayaMergeOptionsTokens->ignoreUpperLayerOpinions); + = parseBoolean(optionsWithDef, MergeOptionsTokens->ignoreUpperLayerOpinions); const struct { TfToken handlingToken; MergeMissing& handlingValue; } missingHandlings[] - = { { UsdMayaMergeOptionsTokens->propertiesHandling, this->propertiesHandling }, - { UsdMayaMergeOptionsTokens->primsHandling, this->primsHandling }, - { UsdMayaMergeOptionsTokens->connectionsHandling, this->connectionsHandling }, - { UsdMayaMergeOptionsTokens->relationshipsHandling, this->relationshipsHandling }, - { UsdMayaMergeOptionsTokens->variantsHandling, this->variantsHandling }, - { UsdMayaMergeOptionsTokens->variantSetsHandling, this->variantSetsHandling }, - { UsdMayaMergeOptionsTokens->expressionsHandling, this->expressionsHandling }, - { UsdMayaMergeOptionsTokens->mappersHandling, this->mappersHandling }, - { UsdMayaMergeOptionsTokens->mapperArgsHandling, this->mapperArgsHandling }, - { UsdMayaMergeOptionsTokens->propMetadataHandling, this->propMetadataHandling }, - { UsdMayaMergeOptionsTokens->primMetadataHandling, this->primMetadataHandling } }; + = { { MergeOptionsTokens->propertiesHandling, this->propertiesHandling }, + { MergeOptionsTokens->primsHandling, this->primsHandling }, + { MergeOptionsTokens->connectionsHandling, this->connectionsHandling }, + { MergeOptionsTokens->relationshipsHandling, this->relationshipsHandling }, + { MergeOptionsTokens->variantsHandling, this->variantsHandling }, + { MergeOptionsTokens->variantSetsHandling, this->variantSetsHandling }, + { MergeOptionsTokens->expressionsHandling, this->expressionsHandling }, + { MergeOptionsTokens->mappersHandling, this->mappersHandling }, + { MergeOptionsTokens->mapperArgsHandling, this->mapperArgsHandling }, + { MergeOptionsTokens->propMetadataHandling, this->propMetadataHandling }, + { MergeOptionsTokens->primMetadataHandling, this->primMetadataHandling } }; for (const auto& handling : missingHandlings) { handling.handlingValue = parseMissingHandling(optionsWithDef, handling.handlingToken); @@ -181,4 +177,4 @@ MergePrimsOptions::MergePrimsOptions() { } -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/lib/usd/utils/MergePrimsOptions.h b/lib/usdUfe/utils/mergePrimsOptions.h similarity index 95% rename from lib/usd/utils/MergePrimsOptions.h rename to lib/usdUfe/utils/mergePrimsOptions.h index e398308519..49d0103afb 100644 --- a/lib/usd/utils/MergePrimsOptions.h +++ b/lib/usdUfe/utils/mergePrimsOptions.h @@ -1,5 +1,5 @@ // -// Copyright 2021 Autodesk +// Copyright 2024 Autodesk // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ // #pragma once -#include +#include #include #include #include -namespace MayaUsdUtils { +namespace USDUFE_NS_DEF { //---------------------------------------------------------------------------------------------------------------------- /// MergeVerbosity level flags. @@ -145,16 +145,16 @@ struct MergePrimsOptions MergeMissing primMetadataHandling { MergeMissing::All }; // Create a VtDictionary containing the default values for the merge options. - MAYA_USD_UTILS_PUBLIC + USDUFE_PUBLIC static const PXR_NS::VtDictionary& getDefaultDictionary(); // Constructs a MergePrimsOptions with the given options. // Not all options need to be filled, missing ones will use the defaults. - MAYA_USD_UTILS_PUBLIC + USDUFE_PUBLIC MergePrimsOptions(const PXR_NS::VtDictionary& options); // Constructs a MergePrimsOptions with the default options. - MAYA_USD_UTILS_PUBLIC + USDUFE_PUBLIC MergePrimsOptions(); }; @@ -162,7 +162,7 @@ struct MergePrimsOptions // Options tokens used in the default options dictionary. // clang-format off -#define USDMAYA_MERGE_OPTIONS_TOKENS \ +#define USDUFE_MERGE_OPTIONS_TOKENS \ /* Dictionary keys */ \ (verbosity) \ \ @@ -200,9 +200,6 @@ struct MergePrimsOptions // so we're forced to use the types it uses here. PXR_NAMESPACE_USING_DIRECTIVE -TF_DECLARE_PUBLIC_TOKENS( - UsdMayaMergeOptionsTokens, - MAYA_USD_UTILS_PUBLIC, - USDMAYA_MERGE_OPTIONS_TOKENS); +TF_DECLARE_PUBLIC_TOKENS(MergeOptionsTokens, USDUFE_PUBLIC, USDUFE_MERGE_OPTIONS_TOKENS); -} // namespace MayaUsdUtils +} // namespace USDUFE_NS_DEF diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.h index 0573dc587d..02a24f56ac 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.h @@ -18,7 +18,7 @@ #include "AL/event/EventHandler.h" #include "AL/usdmaya/Api.h" -#include +#include namespace AL { namespace usdmaya { 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 52bd6201a3..3fcf9692b6 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeCommands.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeCommands.cpp @@ -1043,8 +1043,8 @@ MStatus TranslatePrim::redoIt() if (!m_updatePaths.empty()) { // check paths refer to valid prims for this stage - auto stage = m_proxy->usdStage(); - MayaUsdUtils::UsdPrimVector updatePrims; + auto stage = m_proxy->usdStage(); + UsdUfe::UsdPrimVector updatePrims; AL::usdmaya::fileio::translators::TranslatorManufacture manufacture(nullptr); for (const SdfPath& path : m_updatePaths) { diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/ExportParams.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/ExportParams.h index 101aac5a2b..748d132781 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/ExportParams.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/ExportParams.h @@ -17,7 +17,8 @@ #include "AL/maya/utils/FileTranslatorOptions.h" #include -#include + +#include #include diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/ImportParams.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/ImportParams.h index 5f96120908..91335196b0 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/ImportParams.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/ImportParams.h @@ -16,7 +16,7 @@ #pragma once #include "AL/maya/utils/FileTranslatorOptions.h" -#include +#include #include diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/SchemaPrims.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/SchemaPrims.h index b0d8dc801e..40ae7c3268 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/SchemaPrims.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/SchemaPrims.h @@ -19,7 +19,7 @@ #include "AL/usdmaya/fileio/translators/TranslatorBase.h" #include "AL/usdmaya/fileio/translators/TranslatorContext.h" -#include +#include #include #include diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/translators/DgNodeTranslator.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/translators/DgNodeTranslator.cpp index fa0d1800f0..0b564a0f43 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/translators/DgNodeTranslator.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/translators/DgNodeTranslator.cpp @@ -19,7 +19,7 @@ #include "AL/usdmaya/fileio/ExportParams.h" #include "AL/usdmaya/fileio/ImportParams.h" -#include +#include #include #include diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/translators/TranslatorContext.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/translators/TranslatorContext.h index d75ee3b9e3..409ce98761 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/translators/TranslatorContext.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/translators/TranslatorContext.h @@ -18,7 +18,8 @@ #include #include #include -#include + +#include #include #include 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 f0ca51cd78..2c86732af8 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.h @@ -769,7 +769,7 @@ class ProxyShape /// \param affectedPaths affected paths during translation AL_USDMAYA_PUBLIC void translatePrimsIntoMaya( - const MayaUsdUtils::UsdPrimVector& importPrims, + const UsdUfe::UsdPrimVector& importPrims, const SdfPathVector& teardownPaths, const fileio::translators::TranslatorParameters& param = fileio::translators::TranslatorParameters(), diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/PrimFilter.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/PrimFilter.h index c7c59af0b9..daaef949b2 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/PrimFilter.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/PrimFilter.h @@ -16,7 +16,8 @@ #pragma once #include -#include + +#include #include #include @@ -85,10 +86,10 @@ class PrimFilter /// \param forceImport mirrors the status of the -fi flag AL_USDMAYA_PUBLIC PrimFilter( - const SdfPathVector& previousPrims, - const MayaUsdUtils::UsdPrimVector& newPrimSet, - PrimFilterInterface* proxy, - bool forceImport = false); + const SdfPathVector& previousPrims, + const UsdUfe::UsdPrimVector& newPrimSet, + PrimFilterInterface* proxy, + bool forceImport = false); /// \brief returns the set of prims to create inline const std::vector& newPrimSet() const { return m_newPrimSet; } diff --git a/plugin/al/lib/AL_USDMaya/CMakeLists.txt b/plugin/al/lib/AL_USDMaya/CMakeLists.txt index 0794381f26..aa52c390ae 100644 --- a/plugin/al/lib/AL_USDMaya/CMakeLists.txt +++ b/plugin/al/lib/AL_USDMaya/CMakeLists.txt @@ -185,7 +185,6 @@ target_link_libraries(${LIBRARY_NAME} AL_EventSystem AL_USDMayaUtils AL_MayaUtils - mayaUsdUtils AL_USDTransaction ar gf @@ -206,6 +205,7 @@ target_link_libraries(${LIBRARY_NAME} ${MAYA_OpenMaya_LIBRARY} ${MAYA_OpenMayaRender_LIBRARY} mayaUsd + usdUfe ${UFE_LIBRARY} ghc_filesystem ) diff --git a/plugin/al/mayautils/AL/maya/CMakeLists.txt b/plugin/al/mayautils/AL/maya/CMakeLists.txt index d47f18c11a..26e8732748 100644 --- a/plugin/al/mayautils/AL/maya/CMakeLists.txt +++ b/plugin/al/mayautils/AL/maya/CMakeLists.txt @@ -69,7 +69,7 @@ target_link_libraries(${MAYAUTILS_LIBRARY_NAME} ${MAYA_OpenMaya_LIBRARY} ${MAYA_OpenMayaAnim_LIBRARY} ${MAYA_OpenMayaUI_LIBRARY} - mayaUsdUtils + usdUfe ) #################################################################################################### diff --git a/plugin/al/plugin/AL_USDMayaPlugin/CMakeLists.txt b/plugin/al/plugin/AL_USDMayaPlugin/CMakeLists.txt index ea564cd6b7..f99427b7ea 100644 --- a/plugin/al/plugin/AL_USDMayaPlugin/CMakeLists.txt +++ b/plugin/al/plugin/AL_USDMayaPlugin/CMakeLists.txt @@ -21,7 +21,7 @@ target_link_libraries(${PXR_PACKAGE} AL_EventSystem AL_USDMayaUtils AL_MayaUtils - mayaUsdUtils + usdUfe AL_USDMaya ${MAYA_LIBRARIES} ) diff --git a/plugin/al/plugin/AL_USDMayaTestPlugin/CMakeLists.txt b/plugin/al/plugin/AL_USDMayaTestPlugin/CMakeLists.txt index 689dbc540f..da5935055a 100644 --- a/plugin/al/plugin/AL_USDMayaTestPlugin/CMakeLists.txt +++ b/plugin/al/plugin/AL_USDMayaTestPlugin/CMakeLists.txt @@ -88,7 +88,7 @@ target_link_libraries(${TARGET_NAME} AL_EventSystem AL_USDMayaUtils AL_MayaUtils - mayaUsdUtils + usdUfe AL_USDMaya #Adding this recursively pulls in lots of things AL_MayaTest AL_USDMayaSchemas diff --git a/plugin/al/translators/Camera.h b/plugin/al/translators/Camera.h index 327e29462c..2123922cb6 100644 --- a/plugin/al/translators/Camera.h +++ b/plugin/al/translators/Camera.h @@ -17,7 +17,7 @@ #include "AL/usdmaya/fileio/translators/TranslatorBase.h" -#include +#include #include diff --git a/plugin/al/translators/DirectionalLight.h b/plugin/al/translators/DirectionalLight.h index 22ec6a4f05..1250b04e7a 100644 --- a/plugin/al/translators/DirectionalLight.h +++ b/plugin/al/translators/DirectionalLight.h @@ -18,7 +18,7 @@ #include "AL/usdmaya/fileio/translators/TranslatorBase.h" -#include +#include namespace AL { namespace usdmaya { diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/CMakeLists.txt b/plugin/al/usdmayautils/AL/usdmaya/utils/CMakeLists.txt index 5916ed15c2..4a2a7ece49 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/CMakeLists.txt +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/CMakeLists.txt @@ -14,6 +14,7 @@ list(APPEND usdmaya_utils_headers AnimationTranslator.h Api.h AttributeType.h + DebugCodes.h DgNodeHelper.h Utils.h ForwardDeclares.h @@ -25,6 +26,7 @@ list(APPEND usdmaya_utils_headers list(APPEND usdmaya_utils_source AnimationTranslator.cpp AttributeType.cpp + DebugCodes.cpp DgNodeHelper.cpp Utils.cpp MeshUtils.cpp @@ -51,7 +53,7 @@ target_compile_definitions(${USDMAYA_UTILS_LIBRARY_NAME} ) target_link_libraries(${USDMAYA_UTILS_LIBRARY_NAME} - mayaUsdUtils + usdUfe AL_MayaUtils ar gf diff --git a/lib/usd/utils/DebugCodes.cpp b/plugin/al/usdmayautils/AL/usdmaya/utils/DebugCodes.cpp similarity index 89% rename from lib/usd/utils/DebugCodes.cpp rename to plugin/al/usdmayautils/AL/usdmaya/utils/DebugCodes.cpp index d050cbd146..ace791f8f3 100644 --- a/lib/usd/utils/DebugCodes.cpp +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/DebugCodes.cpp @@ -22,7 +22,7 @@ PXR_NAMESPACE_OPEN_SCOPE TF_REGISTRY_FUNCTION(TfDebug) { - TF_DEBUG_ENVIRONMENT_SYMBOL(MAYAUSDUTILS_INFO, "MAYAUSDUTILS' General debug messages"); + TF_DEBUG_ENVIRONMENT_SYMBOL(ALUSDMAYA_INFO, "UsdMaya General debug messages"); } PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/usd/utils/DebugCodes.h b/plugin/al/usdmayautils/AL/usdmaya/utils/DebugCodes.h similarity index 95% rename from lib/usd/utils/DebugCodes.h rename to plugin/al/usdmayautils/AL/usdmaya/utils/DebugCodes.h index e2d81d06a7..1f28b0dc99 100644 --- a/lib/usd/utils/DebugCodes.h +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/DebugCodes.h @@ -19,5 +19,5 @@ #include PXR_NAMESPACE_OPEN_SCOPE -TF_DEBUG_CODES(MAYAUSDUTILS_INFO); +TF_DEBUG_CODES(ALUSDMAYA_INFO); PXR_NAMESPACE_CLOSE_SCOPE diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/DgNodeHelper.cpp b/plugin/al/usdmayautils/AL/usdmaya/utils/DgNodeHelper.cpp index 31d915213b..0cb7c167a0 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/DgNodeHelper.cpp +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/DgNodeHelper.cpp @@ -17,8 +17,8 @@ #include "AL/maya/utils/NodeHelper.h" -#include -#include +#include +#include #include #include @@ -306,7 +306,7 @@ MStatus DgNodeHelper::setHalfArray( size_t count8 = count & ~0x7ULL; for (size_t j = 0; j != count8; j += 8) { float f[8]; - MayaUsdUtils::half2float_8f(values + j, f); + UsdUfe::half2float_8f(values + j, f); plug.elementByLogicalIndex(j + 0).setFloat(f[0]); plug.elementByLogicalIndex(j + 1).setFloat(f[1]); plug.elementByLogicalIndex(j + 2).setFloat(f[2]); @@ -319,7 +319,7 @@ MStatus DgNodeHelper::setHalfArray( if (count & 0x4) { float f[4]; - MayaUsdUtils::half2float_4f(values + count8, f); + UsdUfe::half2float_4f(values + count8, f); plug.elementByLogicalIndex(count8 + 0).setFloat(f[0]); plug.elementByLogicalIndex(count8 + 1).setFloat(f[1]); plug.elementByLogicalIndex(count8 + 2).setFloat(f[2]); @@ -329,14 +329,11 @@ MStatus DgNodeHelper::setHalfArray( switch (count & 0x3) { case 3: - plug.elementByLogicalIndex(count8 + 2) - .setFloat(MayaUsdUtils::half2float_1f(values[count8 + 2])); + plug.elementByLogicalIndex(count8 + 2).setFloat(UsdUfe::half2float_1f(values[count8 + 2])); case 2: - plug.elementByLogicalIndex(count8 + 1) - .setFloat(MayaUsdUtils::half2float_1f(values[count8 + 1])); + plug.elementByLogicalIndex(count8 + 1).setFloat(UsdUfe::half2float_1f(values[count8 + 1])); case 1: - plug.elementByLogicalIndex(count8 + 0) - .setFloat(MayaUsdUtils::half2float_1f(values[count8 + 0])); + plug.elementByLogicalIndex(count8 + 0).setFloat(UsdUfe::half2float_1f(values[count8 + 0])); default: break; } @@ -445,7 +442,7 @@ MStatus DgNodeHelper::setVec2Array( size_t count4 = count & ~0x3ULL; for (size_t i = 0, j = 0; i != count4; i += 4, j += 8) { float f[8]; - MayaUsdUtils::half2float_8f(values + j, f); + UsdUfe::half2float_8f(values + j, f); auto v0 = plug.elementByLogicalIndex(i + 0); auto v1 = plug.elementByLogicalIndex(i + 1); auto v2 = plug.elementByLogicalIndex(i + 2); @@ -462,7 +459,7 @@ MStatus DgNodeHelper::setVec2Array( if (count & 0x2) { float f[4]; - MayaUsdUtils::half2float_4f(values + count4 * 2, f); + UsdUfe::half2float_4f(values + count4 * 2, f); auto v0 = plug.elementByLogicalIndex(count4 + 0); auto v1 = plug.elementByLogicalIndex(count4 + 1); v0.child(0).setFloat(f[0]); @@ -474,8 +471,8 @@ MStatus DgNodeHelper::setVec2Array( if (count & 0x1) { auto v0 = plug.elementByLogicalIndex(count4); - v0.child(0).setFloat(MayaUsdUtils::half2float_1f(values[count4 * 2])); - v0.child(1).setFloat(MayaUsdUtils::half2float_1f(values[count4 * 2 + 1])); + v0.child(0).setFloat(UsdUfe::half2float_1f(values[count4 * 2])); + v0.child(1).setFloat(UsdUfe::half2float_1f(values[count4 * 2 + 1])); } return MS::kSuccess; @@ -565,9 +562,9 @@ MStatus DgNodeHelper::setVec3Array( size_t count8 = count & ~0x7ULL; for (size_t i = 0, j = 0; i != count8; i += 8, j += 24) { float f[24]; - MayaUsdUtils::half2float_8f(values + j, f); - MayaUsdUtils::half2float_8f(values + j + 8, f + 8); - MayaUsdUtils::half2float_8f(values + j + 16, f + 16); + UsdUfe::half2float_8f(values + j, f); + UsdUfe::half2float_8f(values + j + 8, f + 8); + UsdUfe::half2float_8f(values + j + 16, f + 16); for (int k = 0; k < 8; ++k) { auto v = plug.elementByLogicalIndex(i + k); @@ -583,7 +580,7 @@ MStatus DgNodeHelper::setVec3Array( h[0] = values[j]; h[1] = values[j + 1]; h[2] = values[j + 2]; - MayaUsdUtils::half2float_4f(h, f); + UsdUfe::half2float_4f(h, f); auto v = plug.elementByLogicalIndex(i); v.child(0).setFloat(f[0]); v.child(1).setFloat(f[1]); @@ -659,7 +656,7 @@ MStatus DgNodeHelper::setVec4Array( for (size_t i = 0, j = 0; i != count2; i += 2, j += 8) { float f[8]; - MayaUsdUtils::half2float_8f(values + j, f); + UsdUfe::half2float_8f(values + j, f); auto v0 = plug.elementByLogicalIndex(i); auto v1 = plug.elementByLogicalIndex(i + 1); v0.child(0).setFloat(f[0]); @@ -673,7 +670,7 @@ MStatus DgNodeHelper::setVec4Array( } if (count & 0x1) { float f[4]; - MayaUsdUtils::half2float_4f(values + count2 * 4, f); + UsdUfe::half2float_4f(values + count2 * 4, f); auto v0 = plug.elementByLogicalIndex(count2); v0.child(0).setFloat(f[0]); v0.child(1).setFloat(f[1]); @@ -1734,7 +1731,7 @@ MStatus DgNodeHelper::getHalfArray( f[5] = plug.elementByLogicalIndex(i + 5).asFloat(); f[6] = plug.elementByLogicalIndex(i + 6).asFloat(); f[7] = plug.elementByLogicalIndex(i + 7).asFloat(); - MayaUsdUtils::float2half_8f(f, values + i); + UsdUfe::float2half_8f(f, values + i); } if (count & 0x4) { @@ -1743,20 +1740,20 @@ MStatus DgNodeHelper::getHalfArray( f[1] = plug.elementByLogicalIndex(count8 + 1).asFloat(); f[2] = plug.elementByLogicalIndex(count8 + 2).asFloat(); f[3] = plug.elementByLogicalIndex(count8 + 3).asFloat(); - MayaUsdUtils::float2half_4f(f, values + count8); + UsdUfe::float2half_4f(f, values + count8); count8 += 4; } switch (count & 0x3) { case 3: values[count8 + 2] - = MayaUsdUtils::float2half_1f(plug.elementByLogicalIndex(count8 + 2).asFloat()); + = UsdUfe::float2half_1f(plug.elementByLogicalIndex(count8 + 2).asFloat()); case 2: values[count8 + 1] - = MayaUsdUtils::float2half_1f(plug.elementByLogicalIndex(count8 + 1).asFloat()); + = UsdUfe::float2half_1f(plug.elementByLogicalIndex(count8 + 1).asFloat()); case 1: values[count8 + 0] - = MayaUsdUtils::float2half_1f(plug.elementByLogicalIndex(count8 + 0).asFloat()); + = UsdUfe::float2half_1f(plug.elementByLogicalIndex(count8 + 0).asFloat()); default: break; } return MS::kSuccess; @@ -2002,7 +1999,7 @@ MStatus DgNodeHelper::getVec2Array( f[5] = v2.child(1).asFloat(); f[6] = v3.child(0).asFloat(); f[7] = v3.child(1).asFloat(); - MayaUsdUtils::float2half_8f(f, values + j); + UsdUfe::float2half_8f(f, values + j); } if (count & 0x2) { @@ -2013,14 +2010,14 @@ MStatus DgNodeHelper::getVec2Array( f[1] = v0.child(1).asFloat(); f[2] = v1.child(0).asFloat(); f[3] = v1.child(1).asFloat(); - MayaUsdUtils::float2half_4f(f, values + count4 * 2); + UsdUfe::float2half_4f(f, values + count4 * 2); count4 += 2; } if (count & 0x1) { auto v = plug.elementByLogicalIndex(count4); - values[count4 * 2 + 0] = MayaUsdUtils::float2half_1f(v.child(0).asFloat()); - values[count4 * 2 + 1] = MayaUsdUtils::float2half_1f(v.child(1).asFloat()); + values[count4 * 2 + 0] = UsdUfe::float2half_1f(v.child(0).asFloat()); + values[count4 * 2 + 1] = UsdUfe::float2half_1f(v.child(1).asFloat()); } return MS::kSuccess; @@ -2398,9 +2395,9 @@ MStatus DgNodeHelper::getVec3Array( r[21] = v7.child(0).asFloat(); r[22] = v7.child(1).asFloat(); r[23] = v7.child(2).asFloat(); - MayaUsdUtils::float2half_8f(r, values + j); - MayaUsdUtils::float2half_8f(r + 8, values + j + 8); - MayaUsdUtils::float2half_8f(r + 16, values + j + 16); + UsdUfe::float2half_8f(r, values + j); + UsdUfe::float2half_8f(r + 8, values + j + 8); + UsdUfe::float2half_8f(r + 16, values + j + 16); } for (uint32_t i = count8, j = count8 * 3; i < count; ++i, j += 3) { @@ -2411,7 +2408,7 @@ MStatus DgNodeHelper::getVec3Array( v[1] = elem.child(1).asFloat(); v[2] = elem.child(2).asFloat(); v[3] = 0; - MayaUsdUtils::float2half_4f(v, h); + UsdUfe::float2half_4f(v, h); values[j + 0] = h[0]; values[j + 1] = h[1]; values[j + 2] = h[2]; @@ -2784,7 +2781,7 @@ MStatus DgNodeHelper::getVec4Array( f[5] = v1.child(1).asFloat(); f[6] = v1.child(2).asFloat(); f[7] = v1.child(3).asFloat(); - MayaUsdUtils::float2half_8f(f, values + j); + UsdUfe::float2half_8f(f, values + j); } if (count & 0x1) { MPlug v0 = plug.elementByLogicalIndex(count2); @@ -2793,7 +2790,7 @@ MStatus DgNodeHelper::getVec4Array( f[1] = v0.child(1).asFloat(); f[2] = v0.child(2).asFloat(); f[3] = v0.child(3).asFloat(); - MayaUsdUtils::float2half_4f(f, values + count2 * 4); + UsdUfe::float2half_4f(f, values + count2 * 4); } return MS::kSuccess; @@ -3396,8 +3393,8 @@ MStatus DgNodeHelper::setVec2(MObject node, MObject attr, const GfHalf* const xy { const char* const errorString = "vec2h error"; MPlug plug(node, attr); - AL_MAYA_CHECK_ERROR(plug.child(0).setValue(MayaUsdUtils::float2half_1f(xy[0])), errorString); - AL_MAYA_CHECK_ERROR(plug.child(1).setValue(MayaUsdUtils::float2half_1f(xy[1])), errorString); + AL_MAYA_CHECK_ERROR(plug.child(0).setValue(UsdUfe::float2half_1f(xy[0])), errorString); + AL_MAYA_CHECK_ERROR(plug.child(1).setValue(UsdUfe::float2half_1f(xy[1])), errorString); return MS::kSuccess; } @@ -3438,9 +3435,9 @@ MStatus DgNodeHelper::setVec3(MObject node, MObject attr, const GfHalf* const xy { const char* const errorString = "vec3h error"; MPlug plug(node, attr); - AL_MAYA_CHECK_ERROR(plug.child(0).setValue(MayaUsdUtils::float2half_1f(xyz[0])), errorString); - AL_MAYA_CHECK_ERROR(plug.child(1).setValue(MayaUsdUtils::float2half_1f(xyz[1])), errorString); - AL_MAYA_CHECK_ERROR(plug.child(2).setValue(MayaUsdUtils::float2half_1f(xyz[2])), errorString); + AL_MAYA_CHECK_ERROR(plug.child(0).setValue(UsdUfe::float2half_1f(xyz[0])), errorString); + AL_MAYA_CHECK_ERROR(plug.child(1).setValue(UsdUfe::float2half_1f(xyz[1])), errorString); + AL_MAYA_CHECK_ERROR(plug.child(2).setValue(UsdUfe::float2half_1f(xyz[2])), errorString); return MS::kSuccess; } @@ -3496,10 +3493,10 @@ MStatus DgNodeHelper::setVec4(MObject node, MObject attr, const GfHalf* const xy { const char* const errorString = "vec4h error"; MPlug plug(node, attr); - AL_MAYA_CHECK_ERROR(plug.child(0).setValue(MayaUsdUtils::float2half_1f(xyzw[0])), errorString); - AL_MAYA_CHECK_ERROR(plug.child(1).setValue(MayaUsdUtils::float2half_1f(xyzw[1])), errorString); - AL_MAYA_CHECK_ERROR(plug.child(2).setValue(MayaUsdUtils::float2half_1f(xyzw[2])), errorString); - AL_MAYA_CHECK_ERROR(plug.child(3).setValue(MayaUsdUtils::float2half_1f(xyzw[3])), errorString); + AL_MAYA_CHECK_ERROR(plug.child(0).setValue(UsdUfe::float2half_1f(xyzw[0])), errorString); + AL_MAYA_CHECK_ERROR(plug.child(1).setValue(UsdUfe::float2half_1f(xyzw[1])), errorString); + AL_MAYA_CHECK_ERROR(plug.child(2).setValue(UsdUfe::float2half_1f(xyzw[2])), errorString); + AL_MAYA_CHECK_ERROR(plug.child(3).setValue(UsdUfe::float2half_1f(xyzw[3])), errorString); return MS::kSuccess; } @@ -3532,10 +3529,10 @@ MStatus DgNodeHelper::setQuat(MObject node, MObject attr, const GfHalf* const xy { const char* const errorString = "quath error"; MPlug plug(node, attr); - AL_MAYA_CHECK_ERROR(plug.child(0).setValue(MayaUsdUtils::float2half_1f(xyzw[0])), errorString); - AL_MAYA_CHECK_ERROR(plug.child(1).setValue(MayaUsdUtils::float2half_1f(xyzw[1])), errorString); - AL_MAYA_CHECK_ERROR(plug.child(2).setValue(MayaUsdUtils::float2half_1f(xyzw[2])), errorString); - AL_MAYA_CHECK_ERROR(plug.child(3).setValue(MayaUsdUtils::float2half_1f(xyzw[3])), errorString); + AL_MAYA_CHECK_ERROR(plug.child(0).setValue(UsdUfe::float2half_1f(xyzw[0])), errorString); + AL_MAYA_CHECK_ERROR(plug.child(1).setValue(UsdUfe::float2half_1f(xyzw[1])), errorString); + AL_MAYA_CHECK_ERROR(plug.child(2).setValue(UsdUfe::float2half_1f(xyzw[2])), errorString); + AL_MAYA_CHECK_ERROR(plug.child(3).setValue(UsdUfe::float2half_1f(xyzw[3])), errorString); return MS::kSuccess; } @@ -4199,8 +4196,8 @@ MStatus DgNodeHelper::getVec2(MObject node, MObject attr, GfHalf* xy) { float fxy[2]; MStatus status = getVec2(node, attr, fxy); - xy[0] = MayaUsdUtils::float2half_1f(fxy[0]); - xy[1] = MayaUsdUtils::float2half_1f(fxy[1]); + xy[0] = UsdUfe::float2half_1f(fxy[0]); + xy[1] = UsdUfe::float2half_1f(fxy[1]); return status; } @@ -4255,7 +4252,7 @@ MStatus DgNodeHelper::getVec3(MObject node, MObject attr, GfHalf* xyz) float fxyz[4]; GfHalf xyzw[4]; MStatus status = getVec3(node, attr, fxyz); - MayaUsdUtils::float2half_4f(fxyz, xyzw); + UsdUfe::float2half_4f(fxyz, xyzw); xyz[0] = xyzw[0]; xyz[1] = xyzw[1]; xyz[2] = xyzw[2]; @@ -4315,7 +4312,7 @@ MStatus DgNodeHelper::getVec4(MObject node, MObject attr, GfHalf* xyzw) { float fxyzw[4]; MStatus status = getVec4(node, attr, fxyzw); - MayaUsdUtils::float2half_4f(fxyzw, xyzw); + UsdUfe::float2half_4f(fxyzw, xyzw); return status; } diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp b/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp index 0c631e00d8..9b43f90986 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp @@ -15,8 +15,8 @@ // #include "AL/usdmaya/utils/DiffPrimVar.h" -#include -#include +#include +#include #include @@ -28,8 +28,6 @@ PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; - namespace AL { namespace usdmaya { namespace utils { @@ -49,7 +47,7 @@ uint32_t diffGeom(UsdGeomPointBased& geom, MFnMesh& mesh, UsdTimeCode timeCode, const size_t mayaPointsCount = mesh.numVertices(); if (mayaPointsCount != usdPointsCount) { result |= kPoints; - } else if (!MayaUsdUtils::compareArray( + } else if (!UsdUfe::compareArray( usdPoints, mayaPoints, usdPointsCount * 3, mayaPointsCount * 3)) { result |= kPoints; } @@ -119,7 +117,7 @@ uint32_t diffGeom(UsdGeomPointBased& geom, MFnMesh& mesh, UsdTimeCode timeCode, const float* const mayaNormals = (const float* const)mesh.getRawNormals(&status); const size_t usdNormalsCount = normalData.size(); const size_t mayaNormalsCount = mesh.numNormals(); - if (!MayaUsdUtils::compareArray( + if (!UsdUfe::compareArray( usdNormals, mayaNormals, usdNormalsCount * 3, mayaNormalsCount * 3)) { result |= kNormals; } @@ -153,14 +151,14 @@ diffFaceVertices(UsdGeomMesh& geom, MFnMesh& mesh, UsdTimeCode timeCode, uint32_ if (mesh.getVertices(vertexCount, vertexList)) { } if (numPolygons - && !MayaUsdUtils::compareArray( + && !UsdUfe::compareArray( &vertexCount[0], pFaceVertexCounts, numPolygons, numPolygons)) { result |= kFaceVertexCounts; } const int* const pFaceVertexIndices = faceVertexIndices.cdata(); if (numFaceVerts - && !MayaUsdUtils::compareArray( + && !UsdUfe::compareArray( &vertexList[0], pFaceVertexIndices, numFaceVerts, numFaceVerts)) { result |= kFaceVertexIndices; } @@ -194,7 +192,7 @@ diffFaceVertices(UsdGeomMesh& geom, MFnMesh& mesh, UsdTimeCode timeCode, uint32_ result |= kHoleIndices; } else if ( numMayaHoleIndices - && !MayaUsdUtils::compareArray( + && !UsdUfe::compareArray( (int32_t*)&mayaHoleIndices[0], holeIndices.cdata(), numMayaHoleIndices, @@ -228,7 +226,7 @@ diffFaceVertices(UsdGeomMesh& geom, MFnMesh& mesh, UsdTimeCode timeCode, uint32_ result |= kCreaseIndices; } else if ( numMayaCreaseIndices - && !MayaUsdUtils::compareArray( + && !UsdUfe::compareArray( (const int32_t*)&mayaCreaseIndices[0], creasesIndices.cdata(), numMayaCreaseIndices, @@ -248,7 +246,7 @@ diffFaceVertices(UsdGeomMesh& geom, MFnMesh& mesh, UsdTimeCode timeCode, uint32_ result |= kCreaseWeights; } else if ( numMayaCreaseWeights - && !MayaUsdUtils::compareArray( + && !UsdUfe::compareArray( &mayaCreaseWeights[0], creasesWeights.cdata(), numMayaCreaseWeights, @@ -279,7 +277,7 @@ diffFaceVertices(UsdGeomMesh& geom, MFnMesh& mesh, UsdTimeCode timeCode, uint32_ result |= kCornerIndices; } else { if (numMayaVertexIds - && !MayaUsdUtils::compareArray( + && !UsdUfe::compareArray( (const int32_t*)&mayaVertexIdValues[0], vertexIdValues.cdata(), numVertexIds, @@ -294,7 +292,7 @@ diffFaceVertices(UsdGeomMesh& geom, MFnMesh& mesh, UsdTimeCode timeCode, uint32_ result |= kCornerSharpness; } else { if (numMayaCreaseValues - && !MayaUsdUtils::compareArray( + && !UsdUfe::compareArray( &mayaCreaseValues[0], creaseValues.cdata(), numCreaseValues, @@ -457,7 +455,7 @@ void ColourSetBuilder::performDiffTest(PrimVarDiffReport& report) if (definition.m_primVar.Get(&vtValue, UsdTimeCode::Default())) { if (vtValue.IsHolding>()) { const VtArray rawVal = vtValue.Get>(); - if (!MayaUsdUtils::compareArray( + if (!UsdUfe::compareArray( (const double*)rawVal.cdata(), &definition.m_colours[0].r, rawVal.size(), @@ -473,7 +471,7 @@ void ColourSetBuilder::performDiffTest(PrimVarDiffReport& report) } } else if (vtValue.IsHolding>()) { const VtArray rawVal = vtValue.Get>(); - if (!MayaUsdUtils::compareArray( + if (!UsdUfe::compareArray( &definition.m_colours[0].r, (const float*)rawVal.cdata(), definition.m_colours.length() * 4, @@ -489,7 +487,7 @@ void ColourSetBuilder::performDiffTest(PrimVarDiffReport& report) } } else if (vtValue.IsHolding>()) { const VtArray rawVal = vtValue.Get>(); - if (!MayaUsdUtils::compareArray( + if (!UsdUfe::compareArray( (const double*)rawVal.cdata(), &definition.m_colours[0].r, rawVal.size(), @@ -505,7 +503,7 @@ void ColourSetBuilder::performDiffTest(PrimVarDiffReport& report) } } else if (vtValue.IsHolding>()) { const VtArray rawVal = vtValue.Get>(); - if (!MayaUsdUtils::compareArray( + if (!UsdUfe::compareArray( &definition.m_colours[0].r, (const float*)rawVal.cdata(), definition.m_colours.length() * 4, @@ -679,7 +677,7 @@ void UvSetBuilder::performDiffTest(PrimVarDiffReport& report) definition.m_primVar.GetIndices(&usdindices); bool uv_indices_have_changed = false; bool data_has_changed = false; - if (!MayaUsdUtils::compareArray( + if (!UsdUfe::compareArray( (const int32_t*)&definition.m_mayaUvIndices[0], usdindices.cdata(), definition.m_mayaUvIndices.length(), @@ -687,7 +685,7 @@ void UvSetBuilder::performDiffTest(PrimVarDiffReport& report) uv_indices_have_changed = true; } - if (!MayaUsdUtils::compareUvArray( + if (!UsdUfe::compareUvArray( (const float*)&definition.m_u[0], (const float*)&definition.m_v[0], (const float*)rawVal.cdata(), @@ -705,7 +703,7 @@ void UvSetBuilder::performDiffTest(PrimVarDiffReport& report) definition.m_mayaInterpolation); } } else { - if (!MayaUsdUtils::compareUvArray( + if (!UsdUfe::compareUvArray( (const float*)&definition.m_u[0], (const float*)&definition.m_v[0], (const float*)rawVal.cdata(), @@ -759,12 +757,12 @@ TfToken guessUVInterpolationType( MIntArray& pointIndices) { // if UV coords are all identical, we have a constant value - if (MayaUsdUtils::vec2AreAllTheSame(&u[0], &v[0], u.length())) { + if (UsdUfe::vec2AreAllTheSame(&u[0], &v[0], u.length())) { return UsdGeomTokens->constant; } // if the UV indices match the vertex indices, we have per-vertex assignment - if (MayaUsdUtils::compareArray( + if (UsdUfe::compareArray( &indices[0], &pointIndices[0], indices.length(), pointIndices.length())) { return UsdGeomTokens->vertex; } @@ -823,7 +821,7 @@ TfToken guessUVInterpolationTypeExtensive( } // if UV coords are all identical, we have a constant value - if (MayaUsdUtils::vec2AreAllTheSame(&u[0], &v[0], u.length())) { + if (UsdUfe::vec2AreAllTheSame(&u[0], &v[0], u.length())) { return UsdGeomTokens->constant; } @@ -905,7 +903,7 @@ TfToken guessUVInterpolationTypeExtensive( TfToken guessColourSetInterpolationType(const float* rgba, const size_t numElements) { // if prim vars are all identical, we have a constant value - if (MayaUsdUtils::vec4AreAllTheSame(rgba, numElements)) { + if (UsdUfe::vec4AreAllTheSame(rgba, numElements)) { return UsdGeomTokens->constant; } @@ -921,7 +919,7 @@ inline bool isNearlyEqual(const float& a, const float& b, const float& threshold //---------------------------------------------------------------------------------------------------------------------- static bool isWithinThreshold(const float* array, const size_t count, float threshold) { - // TODO: This function is extracted from MayaUsdUtils::vec4AreAllTheSame(), + // TODO: This function is extracted from UsdUfe::vec4AreAllTheSame(), // it is generally slower then the SSE/AVX version. // Improve it with SSE/AVX at some point when needed, for now the optimization is left for // the compiler. @@ -963,7 +961,7 @@ TfToken guessColourSetInterpolationTypeExtensive( std::vector& indicesToExtract) { // if prim vars are all identical, we have a constant value - if (MayaUsdUtils::vec4AreAllTheSame(rgba, numElements)) { + if (UsdUfe::vec4AreAllTheSame(rgba, numElements)) { return UsdGeomTokens->constant; } diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.h b/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.h index 7ff249bbd6..3b888b1e5e 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.h +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.h @@ -17,7 +17,7 @@ #include "AL/usdmaya/utils/Api.h" -#include +#include #include diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/ForwardDeclares.h b/plugin/al/usdmayautils/AL/usdmaya/utils/ForwardDeclares.h index a3bf279c5e..ed7ed7c7b9 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/ForwardDeclares.h +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/ForwardDeclares.h @@ -2,4 +2,4 @@ #include "AL/maya/utils/ForwardDeclares.h" -#include +#include diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp b/plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp index 699550e1a9..191a060409 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp @@ -17,11 +17,11 @@ #include "AL/usdmaya/utils/MeshUtils.h" #include "AL/maya/utils/Utils.h" +#include "AL/usdmaya/utils/DebugCodes.h" #include "AL/usdmaya/utils/DiffPrimVar.h" #include "AL/usdmaya/utils/Utils.h" -#include -#include +#include #include #include @@ -775,7 +775,7 @@ void MeshImportContext::applyColourSetData() // Set colors if (!fnMesh.setColors(colours, &colourSetName, representation)) { - TF_DEBUG(MAYAUSDUTILS_INFO) + TF_DEBUG(ALUSDMAYA_INFO) .Msg( "Failed to set colours for colour set \"%s\" on mesh \"%s\", " "error: %s\n", @@ -793,7 +793,7 @@ void MeshImportContext::applyColourSetData() std::memcpy( &mayaIndices[0], usdindices.cdata(), sizeof(int) * usdindices.size()); if (mayaIndices.length() != connects.length()) { - TF_DEBUG(MAYAUSDUTILS_INFO) + TF_DEBUG(ALUSDMAYA_INFO) .Msg( "Retrieved indexed values are not compatible with topology for " "colour set \"%s\" on mesh \"%s\"\n", @@ -824,7 +824,7 @@ void MeshImportContext::applyColourSetData() } if (mayaIndices.length() != uint32_t(fnMesh.numFaceVertices())) { - TF_DEBUG(MAYAUSDUTILS_INFO) + TF_DEBUG(ALUSDMAYA_INFO) .Msg( "Incompatible colour indices for colour set \"%s\" on mesh " "\"%s\"\n", @@ -834,7 +834,7 @@ void MeshImportContext::applyColourSetData() } // Assign colors to indices if (!fnMesh.assignColors(mayaIndices, &colourSetName)) { - TF_DEBUG(MAYAUSDUTILS_INFO) + TF_DEBUG(ALUSDMAYA_INFO) .Msg( "Failed to assign colour indices for colour set \"%s\" on mesh " "\"%s\", error: %s\n", @@ -899,7 +899,7 @@ void MeshImportContext::applyUVs() sizeof(int) * usdindices.size()); s = fnMesh.assignUVs(counts, mayaIndices, uv_set); if (!s) { - TF_DEBUG(MAYAUSDUTILS_INFO) + TF_DEBUG(ALUSDMAYA_INFO) .Msg( "Failed to assign UVS for uvset \"%s\" on mesh \"%s\", " "error: %s\n", @@ -908,7 +908,7 @@ void MeshImportContext::applyUVs() s.errorString().asChar()); } } else { - TF_DEBUG(MAYAUSDUTILS_INFO) + TF_DEBUG(ALUSDMAYA_INFO) .Msg( "Failed to set UVS for uvset \"%s\" on mesh \"%s\", error: " "%s\n", @@ -923,7 +923,7 @@ void MeshImportContext::applyUVs() generateIncrementingIndices(mayaIndices, rawVal.size()); MStatus s = fnMesh.assignUVs(counts, mayaIndices, uv_set); if (!s) { - TF_DEBUG(MAYAUSDUTILS_INFO) + TF_DEBUG(ALUSDMAYA_INFO) .Msg( "Failed to assign UVS for uvset \"%s\" on mesh \"%s\", " "error: %s\n", @@ -934,7 +934,7 @@ void MeshImportContext::applyUVs() } else if (interpolation == UsdGeomTokens->vertex) { MStatus s = fnMesh.assignUVs(counts, connects, uv_set); if (!s) { - TF_DEBUG(MAYAUSDUTILS_INFO) + TF_DEBUG(ALUSDMAYA_INFO) .Msg( "Failed to assign UVS for uvset \"%s\" on mesh \"%s\", " "error: %s\n", @@ -951,7 +951,7 @@ void MeshImportContext::applyUVs() } MStatus s = fnMesh.assignUVs(counts, mayaIndices, uv_set); if (!s) { - TF_DEBUG(MAYAUSDUTILS_INFO) + TF_DEBUG(ALUSDMAYA_INFO) .Msg( "Failed to assign UVS for uvset \"%s\" on mesh \"%s\", " "error: %s\n", @@ -965,7 +965,7 @@ void MeshImportContext::applyUVs() std::memset(&mayaIndices[0], 0, sizeof(int) * mayaIndices.length()); MStatus s = fnMesh.assignUVs(counts, mayaIndices, uv_set); if (!s) { - TF_DEBUG(MAYAUSDUTILS_INFO) + TF_DEBUG(ALUSDMAYA_INFO) .Msg( "Failed to assign UVS for uvset \"%s\" on mesh \"%s\", " "error: %s\n", @@ -1953,7 +1953,7 @@ void MeshExportContext::copyNormalData(UsdTimeCode time, bool copyAsPrimvar) fnMesh.getNormalIds(normalCounts, normalIndices); // if prim vars are all identical, we have a constant value - if (MayaUsdUtils::vec3AreAllTheSame(normalsData, numNormals)) { + if (UsdUfe::vec3AreAllTheSame(normalsData, numNormals)) { VtArray normals(1); if (copyAsPrimvar) { primvar.SetInterpolation(UsdGeomTokens->constant); @@ -1965,7 +1965,7 @@ void MeshExportContext::copyNormalData(UsdTimeCode time, bool copyAsPrimvar) normals[0][2] = normalsData[2]; normalsAttr.Set(normals, time); } else if (numNormals != normalIndices.length()) { - if (MayaUsdUtils::compareArray( + if (UsdUfe::compareArray( &normalIndices[0], &faceConnects[0], normalIndices.length(), diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/NurbsCurveUtils.cpp b/plugin/al/usdmayautils/AL/usdmaya/utils/NurbsCurveUtils.cpp index 904f5e2b4c..44d9928116 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/NurbsCurveUtils.cpp +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/NurbsCurveUtils.cpp @@ -20,7 +20,7 @@ #include "AL/usdmaya/utils/DgNodeHelper.h" #include "AL/usdmaya/utils/Utils.h" -#include +#include #include #include @@ -405,7 +405,7 @@ uint32_t diffNurbsCurve( const size_t numPoints = dataPoints.size(); const float* const usdPoints = (const float* const)dataPoints.cdata(); const double* const mayaCVs = (const double* const) & controlVertices[0]; - if (!MayaUsdUtils::compareArray3Dto4D(usdPoints, mayaCVs, numPoints, numControlVertices)) { + if (!UsdUfe::compareArray3Dto4D(usdPoints, mayaCVs, numPoints, numControlVertices)) { result |= kCurvePoints; } } @@ -450,7 +450,7 @@ uint32_t diffNurbsCurve( const size_t numMayaKnots = knots.length(); const double* const usdKnots = (const double* const)dataKnots.cdata(); const double* const mayaKnots = (const double* const) & knots[0]; - if (!MayaUsdUtils::compareArray(usdKnots, mayaKnots, numKnots, numMayaKnots)) { + if (!UsdUfe::compareArray(usdKnots, mayaKnots, numKnots, numMayaKnots)) { result |= kKnots; } } @@ -461,7 +461,7 @@ uint32_t diffNurbsCurve( VtArray dataRanges; usdCurves.GetRangesAttr().Get(&dataRanges); const float* const usdRanges = (const float* const)dataRanges.cdata(); - if (dataRanges.size() != 1 || !MayaUsdUtils::compareArray(usdRanges, knotDomain, 2, 2)) { + if (dataRanges.size() != 1 || !UsdUfe::compareArray(usdRanges, knotDomain, 2, 2)) { result |= kRanges; } } @@ -489,7 +489,7 @@ uint32_t diffNurbsCurve( const size_t numMayaWidth = widthArray.length(); const float* const usdWidths = dataWidths.cdata(); const double* const mayaWidth = &widthArray[0]; - if (!MayaUsdUtils::compareArray(usdWidths, mayaWidth, numUsdWidths, numMayaWidth)) { + if (!UsdUfe::compareArray(usdWidths, mayaWidth, numUsdWidths, numMayaWidth)) { result |= kWidths; } } else if ( diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/Utils.cpp b/plugin/al/usdmayautils/AL/usdmaya/utils/Utils.cpp index 69ac2515c2..5ed3441f66 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/Utils.cpp +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/Utils.cpp @@ -16,8 +16,7 @@ #include "AL/usdmaya/utils/Utils.h" #include "AL/maya/utils/Utils.h" - -#include +#include "AL/usdmaya/utils/DebugCodes.h" #include #include @@ -113,7 +112,7 @@ MString mapUsdPrimToMayaNode( std::replace(mayaElementPath.begin(), mayaElementPath.end(), '/', '|'); } - TF_DEBUG(MAYAUSDUTILS_INFO) + TF_DEBUG(ALUSDMAYA_INFO) .Msg( "Mapped the path for prim=%s to mayaObject=%s\n", usdPrim.GetName().GetText(), diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/Utils.h b/plugin/al/usdmayautils/AL/usdmaya/utils/Utils.h index 7f533d7033..de19fe36ce 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/Utils.h +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/Utils.h @@ -19,7 +19,7 @@ #include "AL/maya/utils/ForwardDeclares.h" #include "AL/usdmaya/utils/Api.h" -#include +#include #include diff --git a/test/lib/mayaUsd/utils/CMakeLists.txt b/test/lib/mayaUsd/utils/CMakeLists.txt index 84cb6073ce..340a603d14 100644 --- a/test/lib/mayaUsd/utils/CMakeLists.txt +++ b/test/lib/mayaUsd/utils/CMakeLists.txt @@ -75,9 +75,9 @@ function(add_mayaUsdLibUtils_test TARGET_NAME) target_link_libraries(${TARGET_NAME} PRIVATE GTest::GTest - mayaUsdUtils ${MAYA_LIBRARIES} mayaUsd + usdUfe ) # ----------------------------------------------------------------------------- diff --git a/test/lib/usd/utils/CMakeLists.txt b/test/lib/usd/utils/CMakeLists.txt index 0ae4605297..e7594d5547 100644 --- a/test/lib/usd/utils/CMakeLists.txt +++ b/test/lib/usd/utils/CMakeLists.txt @@ -28,7 +28,7 @@ function(add_mayaUsdUtils_test TARGET_NAME) target_link_libraries(${TARGET_NAME} PRIVATE GTest::GTest - mayaUsdUtils + usdUfe ) # ----------------------------------------------------------------------------- diff --git a/test/lib/usd/utils/test_DiffAttributes.cpp b/test/lib/usd/utils/test_DiffAttributes.cpp index 4703f92e1e..c206a6acd1 100644 --- a/test/lib/usd/utils/test_DiffAttributes.cpp +++ b/test/lib/usd/utils/test_DiffAttributes.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -6,7 +6,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; //---------------------------------------------------------------------------------------------------------------------- TEST(DiffAttributes, compareAttributesEmpty) diff --git a/test/lib/usd/utils/test_DiffComputeOverall.cpp b/test/lib/usd/utils/test_DiffComputeOverall.cpp index 219bca0cce..009b5ea032 100644 --- a/test/lib/usd/utils/test_DiffComputeOverall.cpp +++ b/test/lib/usd/utils/test_DiffComputeOverall.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -6,7 +6,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; namespace { diff --git a/test/lib/usd/utils/test_DiffCore.cpp b/test/lib/usd/utils/test_DiffCore.cpp index fa3dbabbdf..72a1cba993 100644 --- a/test/lib/usd/utils/test_DiffCore.cpp +++ b/test/lib/usd/utils/test_DiffCore.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include @@ -17,24 +17,24 @@ TEST(DiffCore, vec2AreAllTheSame) a.push_back(0); a.push_back(0); - EXPECT_TRUE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 8)); - EXPECT_TRUE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 10)); - EXPECT_TRUE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 11)); + EXPECT_TRUE(UsdUfe::vec2AreAllTheSame(a.data(), 8)); + EXPECT_TRUE(UsdUfe::vec2AreAllTheSame(a.data(), 10)); + EXPECT_TRUE(UsdUfe::vec2AreAllTheSame(a.data(), 11)); a[2] = 4; - EXPECT_FALSE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 8)); - EXPECT_FALSE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 10)); - EXPECT_FALSE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 11)); + EXPECT_FALSE(UsdUfe::vec2AreAllTheSame(a.data(), 8)); + EXPECT_FALSE(UsdUfe::vec2AreAllTheSame(a.data(), 10)); + EXPECT_FALSE(UsdUfe::vec2AreAllTheSame(a.data(), 11)); a[2] = 2; a[16] = 4; - EXPECT_TRUE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 8)); - EXPECT_FALSE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 10)); - EXPECT_FALSE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 11)); + EXPECT_TRUE(UsdUfe::vec2AreAllTheSame(a.data(), 8)); + EXPECT_FALSE(UsdUfe::vec2AreAllTheSame(a.data(), 10)); + EXPECT_FALSE(UsdUfe::vec2AreAllTheSame(a.data(), 11)); a[16] = 2; a[20] = 4; - EXPECT_TRUE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 8)); - EXPECT_TRUE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 10)); - EXPECT_FALSE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 11)); + EXPECT_TRUE(UsdUfe::vec2AreAllTheSame(a.data(), 8)); + EXPECT_TRUE(UsdUfe::vec2AreAllTheSame(a.data(), 10)); + EXPECT_FALSE(UsdUfe::vec2AreAllTheSame(a.data(), 11)); } //---------------------------------------------------------------------------------------------------------------------- @@ -50,24 +50,24 @@ TEST(DiffCore, vec3AreAllTheSame) a.push_back(0); a.push_back(0); - EXPECT_TRUE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 8)); - EXPECT_TRUE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 12)); - EXPECT_TRUE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 13)); + EXPECT_TRUE(UsdUfe::vec3AreAllTheSame(a.data(), 8)); + EXPECT_TRUE(UsdUfe::vec3AreAllTheSame(a.data(), 12)); + EXPECT_TRUE(UsdUfe::vec3AreAllTheSame(a.data(), 13)); a[3] = 4; - EXPECT_FALSE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 8)); - EXPECT_FALSE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 12)); - EXPECT_FALSE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 13)); + EXPECT_FALSE(UsdUfe::vec3AreAllTheSame(a.data(), 8)); + EXPECT_FALSE(UsdUfe::vec3AreAllTheSame(a.data(), 12)); + EXPECT_FALSE(UsdUfe::vec3AreAllTheSame(a.data(), 13)); a[3] = 2; a[24] = 4; - EXPECT_TRUE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 8)); - EXPECT_FALSE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 12)); - EXPECT_FALSE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 13)); + EXPECT_TRUE(UsdUfe::vec3AreAllTheSame(a.data(), 8)); + EXPECT_FALSE(UsdUfe::vec3AreAllTheSame(a.data(), 12)); + EXPECT_FALSE(UsdUfe::vec3AreAllTheSame(a.data(), 13)); a[24] = 2; a[36] = 4; - EXPECT_TRUE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 8)); - EXPECT_TRUE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 12)); - EXPECT_FALSE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 13)); + EXPECT_TRUE(UsdUfe::vec3AreAllTheSame(a.data(), 8)); + EXPECT_TRUE(UsdUfe::vec3AreAllTheSame(a.data(), 12)); + EXPECT_FALSE(UsdUfe::vec3AreAllTheSame(a.data(), 13)); } //---------------------------------------------------------------------------------------------------------------------- @@ -85,15 +85,15 @@ TEST(DiffCore, vec4AreAllTheSame) a.push_back(0); a.push_back(0); - EXPECT_TRUE(MayaUsdUtils::vec4AreAllTheSame(a.data(), 8)); - EXPECT_TRUE(MayaUsdUtils::vec4AreAllTheSame(a.data(), 9)); + EXPECT_TRUE(UsdUfe::vec4AreAllTheSame(a.data(), 8)); + EXPECT_TRUE(UsdUfe::vec4AreAllTheSame(a.data(), 9)); a[4] = 4; - EXPECT_FALSE(MayaUsdUtils::vec4AreAllTheSame(a.data(), 8)); - EXPECT_FALSE(MayaUsdUtils::vec4AreAllTheSame(a.data(), 9)); + EXPECT_FALSE(UsdUfe::vec4AreAllTheSame(a.data(), 8)); + EXPECT_FALSE(UsdUfe::vec4AreAllTheSame(a.data(), 9)); a[4] = 2; a[32] = 3; - EXPECT_TRUE(MayaUsdUtils::vec4AreAllTheSame(a.data(), 8)); - EXPECT_FALSE(MayaUsdUtils::vec4AreAllTheSame(a.data(), 9)); + EXPECT_TRUE(UsdUfe::vec4AreAllTheSame(a.data(), 8)); + EXPECT_FALSE(UsdUfe::vec4AreAllTheSame(a.data(), 9)); } //---------------------------------------------------------------------------------------------------------------------- @@ -107,24 +107,24 @@ TEST(DiffCore, vec2AreAllTheSameDouble) a.push_back(0); a.push_back(0); - EXPECT_TRUE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 8)); - EXPECT_TRUE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 10)); - EXPECT_TRUE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 11)); + EXPECT_TRUE(UsdUfe::vec2AreAllTheSame(a.data(), 8)); + EXPECT_TRUE(UsdUfe::vec2AreAllTheSame(a.data(), 10)); + EXPECT_TRUE(UsdUfe::vec2AreAllTheSame(a.data(), 11)); a[2] = 4; - EXPECT_FALSE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 8)); - EXPECT_FALSE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 10)); - EXPECT_FALSE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 11)); + EXPECT_FALSE(UsdUfe::vec2AreAllTheSame(a.data(), 8)); + EXPECT_FALSE(UsdUfe::vec2AreAllTheSame(a.data(), 10)); + EXPECT_FALSE(UsdUfe::vec2AreAllTheSame(a.data(), 11)); a[2] = 2; a[16] = 4; - EXPECT_TRUE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 8)); - EXPECT_FALSE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 10)); - EXPECT_FALSE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 11)); + EXPECT_TRUE(UsdUfe::vec2AreAllTheSame(a.data(), 8)); + EXPECT_FALSE(UsdUfe::vec2AreAllTheSame(a.data(), 10)); + EXPECT_FALSE(UsdUfe::vec2AreAllTheSame(a.data(), 11)); a[16] = 2; a[20] = 4; - EXPECT_TRUE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 8)); - EXPECT_TRUE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 10)); - EXPECT_FALSE(MayaUsdUtils::vec2AreAllTheSame(a.data(), 11)); + EXPECT_TRUE(UsdUfe::vec2AreAllTheSame(a.data(), 8)); + EXPECT_TRUE(UsdUfe::vec2AreAllTheSame(a.data(), 10)); + EXPECT_FALSE(UsdUfe::vec2AreAllTheSame(a.data(), 11)); } //---------------------------------------------------------------------------------------------------------------------- @@ -140,24 +140,24 @@ TEST(DiffCore, vec3AreAllTheSameDouble) a.push_back(0); a.push_back(0); - EXPECT_TRUE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 8)); - EXPECT_TRUE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 12)); - EXPECT_TRUE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 13)); + EXPECT_TRUE(UsdUfe::vec3AreAllTheSame(a.data(), 8)); + EXPECT_TRUE(UsdUfe::vec3AreAllTheSame(a.data(), 12)); + EXPECT_TRUE(UsdUfe::vec3AreAllTheSame(a.data(), 13)); a[3] = 4; - EXPECT_FALSE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 8)); - EXPECT_FALSE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 12)); - EXPECT_FALSE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 13)); + EXPECT_FALSE(UsdUfe::vec3AreAllTheSame(a.data(), 8)); + EXPECT_FALSE(UsdUfe::vec3AreAllTheSame(a.data(), 12)); + EXPECT_FALSE(UsdUfe::vec3AreAllTheSame(a.data(), 13)); a[3] = 2; a[24] = 4; - EXPECT_TRUE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 8)); - EXPECT_FALSE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 12)); - EXPECT_FALSE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 13)); + EXPECT_TRUE(UsdUfe::vec3AreAllTheSame(a.data(), 8)); + EXPECT_FALSE(UsdUfe::vec3AreAllTheSame(a.data(), 12)); + EXPECT_FALSE(UsdUfe::vec3AreAllTheSame(a.data(), 13)); a[24] = 2; a[36] = 4; - EXPECT_TRUE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 8)); - EXPECT_TRUE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 12)); - EXPECT_FALSE(MayaUsdUtils::vec3AreAllTheSame(a.data(), 13)); + EXPECT_TRUE(UsdUfe::vec3AreAllTheSame(a.data(), 8)); + EXPECT_TRUE(UsdUfe::vec3AreAllTheSame(a.data(), 12)); + EXPECT_FALSE(UsdUfe::vec3AreAllTheSame(a.data(), 13)); } //---------------------------------------------------------------------------------------------------------------------- @@ -175,15 +175,15 @@ TEST(DiffCore, vec4AreAllTheSameDouble) a.push_back(0); a.push_back(0); - EXPECT_TRUE(MayaUsdUtils::vec4AreAllTheSame(a.data(), 8)); - EXPECT_TRUE(MayaUsdUtils::vec4AreAllTheSame(a.data(), 9)); + EXPECT_TRUE(UsdUfe::vec4AreAllTheSame(a.data(), 8)); + EXPECT_TRUE(UsdUfe::vec4AreAllTheSame(a.data(), 9)); a[4] = 4; - EXPECT_FALSE(MayaUsdUtils::vec4AreAllTheSame(a.data(), 8)); - EXPECT_FALSE(MayaUsdUtils::vec4AreAllTheSame(a.data(), 9)); + EXPECT_FALSE(UsdUfe::vec4AreAllTheSame(a.data(), 8)); + EXPECT_FALSE(UsdUfe::vec4AreAllTheSame(a.data(), 9)); a[4] = 2; a[32] = 3; - EXPECT_TRUE(MayaUsdUtils::vec4AreAllTheSame(a.data(), 8)); - EXPECT_FALSE(MayaUsdUtils::vec4AreAllTheSame(a.data(), 9)); + EXPECT_TRUE(UsdUfe::vec4AreAllTheSame(a.data(), 8)); + EXPECT_FALSE(UsdUfe::vec4AreAllTheSame(a.data(), 9)); } //---------------------------------------------------------------------------------------------------------------------- @@ -196,12 +196,12 @@ TEST(DiffCore, compareHalfFloatArray) } // should pass - EXPECT_TRUE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47, 1e-3f)); - EXPECT_TRUE(MayaUsdUtils::compareArray(b.data(), a.data(), 47, 47, 1e-3f)); + EXPECT_TRUE(UsdUfe::compareArray(a.data(), b.data(), 47, 47, 1e-3f)); + EXPECT_TRUE(UsdUfe::compareArray(b.data(), a.data(), 47, 47, 1e-3f)); // fail on differing array sizes - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 46, 47, 1e-5f)); - EXPECT_FALSE(MayaUsdUtils::compareArray(b.data(), a.data(), 46, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 46, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(b.data(), a.data(), 46, 47, 1e-5f)); // test the switch cases at the ends of the array for (int i = 0; i < 7; ++i) { @@ -209,16 +209,16 @@ TEST(DiffCore, compareHalfFloatArray) a[40 + i] += 1.0f; // should now fail - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); - EXPECT_FALSE(MayaUsdUtils::compareArray(b.data(), a.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(b.data(), a.data(), 47, 47, 1e-5f)); a[40 + i] -= 1.0f; } // modify value in SIMD blocks a[22] += 1.0f; - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); - EXPECT_FALSE(MayaUsdUtils::compareArray(b.data(), a.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(b.data(), a.data(), 47, 47, 1e-5f)); } //---------------------------------------------------------------------------------------------------------------------- @@ -232,12 +232,12 @@ TEST(DiffCore, compareHalfDoubleArray) } // should pass - EXPECT_TRUE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47, 1e-3f)); - EXPECT_TRUE(MayaUsdUtils::compareArray(b.data(), a.data(), 47, 47, 1e-3f)); + EXPECT_TRUE(UsdUfe::compareArray(a.data(), b.data(), 47, 47, 1e-3f)); + EXPECT_TRUE(UsdUfe::compareArray(b.data(), a.data(), 47, 47, 1e-3f)); // fail on differing array sizes - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 46, 47, 1e-5f)); - EXPECT_FALSE(MayaUsdUtils::compareArray(b.data(), a.data(), 46, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 46, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(b.data(), a.data(), 46, 47, 1e-5f)); // test the switch cases at the ends of the array for (int i = 0; i < 7; ++i) { @@ -245,16 +245,16 @@ TEST(DiffCore, compareHalfDoubleArray) a[40 + i] += 1.0f; // should now fail - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); - EXPECT_FALSE(MayaUsdUtils::compareArray(b.data(), a.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(b.data(), a.data(), 47, 47, 1e-5f)); a[40 + i] -= 1.0f; } // modify value in SIMD blocks a[22] += 1.0f; - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); - EXPECT_FALSE(MayaUsdUtils::compareArray(b.data(), a.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(b.data(), a.data(), 47, 47, 1e-5f)); } //---------------------------------------------------------------------------------------------------------------------- @@ -266,10 +266,10 @@ TEST(DiffCore, compareFloatArray) } // should pass - EXPECT_TRUE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); + EXPECT_TRUE(UsdUfe::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); // fail on differing array sizes - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 46, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 46, 47, 1e-5f)); // test the switch cases at the ends of the array for (int i = 0; i < 7; ++i) { @@ -277,14 +277,14 @@ TEST(DiffCore, compareFloatArray) a[40 + i] += 1.0f; // should now fail - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); a[40 + i] -= 1.0f; } // modify value in SIMD blocks a[22] += 1.0f; - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); } //---------------------------------------------------------------------------------------------------------------------- @@ -296,10 +296,10 @@ TEST(DiffCore, compareDoubleArray) } // should pass - EXPECT_TRUE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); + EXPECT_TRUE(UsdUfe::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); // fail on differing array sizes - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 46, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 46, 47, 1e-5f)); // test the switch cases at the ends of the array for (int i = 0; i < 7; ++i) { @@ -307,14 +307,14 @@ TEST(DiffCore, compareDoubleArray) a[40 + i] += 1.0; // should now fail - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); a[40 + i] -= 1.0; } // modify value in SIMD blocks a[22] += 1.0; - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47, 1e-5f)); } //---------------------------------------------------------------------------------------------------------------------- @@ -326,10 +326,10 @@ TEST(DiffCore, compareInt8Array) } // should pass - EXPECT_TRUE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47)); + EXPECT_TRUE(UsdUfe::compareArray(a.data(), b.data(), 47, 47)); // fail on differing array sizes - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 46, 47)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 46, 47)); // test the switch cases at the ends of the array for (int i = 0; i < 7; ++i) { @@ -337,14 +337,14 @@ TEST(DiffCore, compareInt8Array) a[40 + i] += 1; // should now fail - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47)); a[40 + i] -= 1; } // modify value in SIMD blocks a[22] += 1; - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47)); } //---------------------------------------------------------------------------------------------------------------------- @@ -356,10 +356,10 @@ TEST(DiffCore, compareInt16Array) } // should pass - EXPECT_TRUE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47)); + EXPECT_TRUE(UsdUfe::compareArray(a.data(), b.data(), 47, 47)); // fail on differing array sizes - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 46, 47)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 46, 47)); // test the switch cases at the ends of the array for (int i = 0; i < 7; ++i) { @@ -367,14 +367,14 @@ TEST(DiffCore, compareInt16Array) a[40 + i] += 1; // should now fail - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47)); a[40 + i] -= 1; } // modify value in SIMD blocks a[22] += 1; - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47)); } //---------------------------------------------------------------------------------------------------------------------- @@ -386,10 +386,10 @@ TEST(DiffCore, compareInt32Array) } // should pass - EXPECT_TRUE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47)); + EXPECT_TRUE(UsdUfe::compareArray(a.data(), b.data(), 47, 47)); // fail on differing array sizes - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 46, 47)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 46, 47)); // test the switch cases at the ends of the array for (int i = 0; i < 7; ++i) { @@ -397,14 +397,14 @@ TEST(DiffCore, compareInt32Array) a[40 + i] += 1; // should now fail - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47)); a[40 + i] -= 1; } // modify value in SIMD blocks a[22] += 1; - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47)); } //---------------------------------------------------------------------------------------------------------------------- @@ -416,10 +416,10 @@ TEST(DiffCore, compareInt64Array) } // should pass - EXPECT_TRUE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47)); + EXPECT_TRUE(UsdUfe::compareArray(a.data(), b.data(), 47, 47)); // fail on differing array sizes - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 46, 47)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 46, 47)); // test the switch cases at the ends of the array for (int i = 0; i < 7; ++i) { @@ -427,14 +427,14 @@ TEST(DiffCore, compareInt64Array) a[40 + i] += 1; // should now fail - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47)); a[40 + i] -= 1; } // modify value in SIMD blocks a[22] += 1; - EXPECT_FALSE(MayaUsdUtils::compareArray(a.data(), b.data(), 47, 47)); + EXPECT_FALSE(UsdUfe::compareArray(a.data(), b.data(), 47, 47)); } //---------------------------------------------------------------------------------------------------------------------- @@ -449,10 +449,10 @@ TEST(DiffCore, compareUvArray) } // should pass - EXPECT_TRUE(MayaUsdUtils::compareUvArray(u.data(), v.data(), uv.data(), 47, 47, 1e-5f)); + EXPECT_TRUE(UsdUfe::compareUvArray(u.data(), v.data(), uv.data(), 47, 47, 1e-5f)); // fail on differing array sizes - EXPECT_FALSE(MayaUsdUtils::compareUvArray(u.data(), v.data(), uv.data(), 46, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareUvArray(u.data(), v.data(), uv.data(), 46, 47, 1e-5f)); // test the switch cases at the ends of the array for (int i = 0; i < 7; ++i) { @@ -460,7 +460,7 @@ TEST(DiffCore, compareUvArray) u[40 + i] += 1.0f; // should now fail - EXPECT_FALSE(MayaUsdUtils::compareUvArray(u.data(), v.data(), uv.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareUvArray(u.data(), v.data(), uv.data(), 47, 47, 1e-5f)); u[40 + i] -= 1.0f; @@ -468,16 +468,16 @@ TEST(DiffCore, compareUvArray) v[40 + i] += 1.0f; // should now fail - EXPECT_FALSE(MayaUsdUtils::compareUvArray(u.data(), v.data(), uv.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareUvArray(u.data(), v.data(), uv.data(), 47, 47, 1e-5f)); v[40 + i] -= 1.0f; } // modify value in SIMD blocks v[22] += 1.0f; - EXPECT_FALSE(MayaUsdUtils::compareUvArray(u.data(), v.data(), uv.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareUvArray(u.data(), v.data(), uv.data(), 47, 47, 1e-5f)); v[22] -= 1.0f; u[22] += 1.0f; - EXPECT_FALSE(MayaUsdUtils::compareUvArray(u.data(), v.data(), uv.data(), 47, 47, 1e-5f)); + EXPECT_FALSE(UsdUfe::compareUvArray(u.data(), v.data(), uv.data(), 47, 47, 1e-5f)); u[22] -= 1.0f; } diff --git a/test/lib/usd/utils/test_DiffDictionaries.cpp b/test/lib/usd/utils/test_DiffDictionaries.cpp index 8869571684..05eea3a843 100644 --- a/test/lib/usd/utils/test_DiffDictionaries.cpp +++ b/test/lib/usd/utils/test_DiffDictionaries.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -6,7 +6,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; //---------------------------------------------------------------------------------------------------------------------- // Single-item tests. diff --git a/test/lib/usd/utils/test_DiffLists.cpp b/test/lib/usd/utils/test_DiffLists.cpp index af15728aa7..c6df642146 100644 --- a/test/lib/usd/utils/test_DiffLists.cpp +++ b/test/lib/usd/utils/test_DiffLists.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -6,7 +6,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; //---------------------------------------------------------------------------------------------------------------------- // Integers list. diff --git a/test/lib/usd/utils/test_DiffMetadatas.cpp b/test/lib/usd/utils/test_DiffMetadatas.cpp index a61bc05936..13371cdf75 100644 --- a/test/lib/usd/utils/test_DiffMetadatas.cpp +++ b/test/lib/usd/utils/test_DiffMetadatas.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -6,7 +6,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; // Note: metadata must be registered, for tests we used a pre-registered one. static TfToken testMetaName(SdfFieldKeys->Comment); diff --git a/test/lib/usd/utils/test_DiffPrims.cpp b/test/lib/usd/utils/test_DiffPrims.cpp index d28c7c93fa..de2c2e8534 100644 --- a/test/lib/usd/utils/test_DiffPrims.cpp +++ b/test/lib/usd/utils/test_DiffPrims.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -6,7 +6,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; namespace { diff --git a/test/lib/usd/utils/test_DiffPrimsAttributes.cpp b/test/lib/usd/utils/test_DiffPrimsAttributes.cpp index f2b6a95f80..aae07e48f5 100644 --- a/test/lib/usd/utils/test_DiffPrimsAttributes.cpp +++ b/test/lib/usd/utils/test_DiffPrimsAttributes.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -6,7 +6,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; static TfToken testAttrName("test_attr"); diff --git a/test/lib/usd/utils/test_DiffPrimsChildren.cpp b/test/lib/usd/utils/test_DiffPrimsChildren.cpp index eae32768e2..4a8a8fbc69 100644 --- a/test/lib/usd/utils/test_DiffPrimsChildren.cpp +++ b/test/lib/usd/utils/test_DiffPrimsChildren.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -6,7 +6,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; namespace { diff --git a/test/lib/usd/utils/test_DiffPrimsRelations.cpp b/test/lib/usd/utils/test_DiffPrimsRelations.cpp index 050cedee15..0b10ad1d4a 100644 --- a/test/lib/usd/utils/test_DiffPrimsRelations.cpp +++ b/test/lib/usd/utils/test_DiffPrimsRelations.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -6,7 +6,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; namespace { diff --git a/test/lib/usd/utils/test_DiffRelationships.cpp b/test/lib/usd/utils/test_DiffRelationships.cpp index 1c7ba31472..430df2b2ba 100644 --- a/test/lib/usd/utils/test_DiffRelationships.cpp +++ b/test/lib/usd/utils/test_DiffRelationships.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -6,7 +6,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; namespace { TfToken testRelName("test_rel"); diff --git a/test/lib/usd/utils/test_DiffValues.cpp b/test/lib/usd/utils/test_DiffValues.cpp index 68ae79c0a5..f0cb4eec13 100644 --- a/test/lib/usd/utils/test_DiffValues.cpp +++ b/test/lib/usd/utils/test_DiffValues.cpp @@ -1,9 +1,9 @@ -#include +#include #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; //---------------------------------------------------------------------------------------------------------------------- TEST(DiffValues, compareValuesEmpty) diff --git a/test/lib/usd/utils/test_DiffValuesArrays.cpp b/test/lib/usd/utils/test_DiffValuesArrays.cpp index b4f42ff22b..98fd6270ab 100644 --- a/test/lib/usd/utils/test_DiffValuesArrays.cpp +++ b/test/lib/usd/utils/test_DiffValuesArrays.cpp @@ -1,9 +1,9 @@ -#include +#include #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; //---------------------------------------------------------------------------------------------------------------------- TEST(DiffValuesArrays, doubleCompareValueArraysSame) diff --git a/test/lib/usd/utils/test_DiffValuesDoubleVecs.cpp b/test/lib/usd/utils/test_DiffValuesDoubleVecs.cpp index a2ca49b792..77234cf999 100644 --- a/test/lib/usd/utils/test_DiffValuesDoubleVecs.cpp +++ b/test/lib/usd/utils/test_DiffValuesDoubleVecs.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -18,7 +18,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; //---------------------------------------------------------------------------------------------------------------------- TEST(DiffValuesDoubleVecs, vec2dCompareValuesSame) diff --git a/test/lib/usd/utils/test_DiffValuesFloatVecs.cpp b/test/lib/usd/utils/test_DiffValuesFloatVecs.cpp index 1487b2b83b..6812a09637 100644 --- a/test/lib/usd/utils/test_DiffValuesFloatVecs.cpp +++ b/test/lib/usd/utils/test_DiffValuesFloatVecs.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -18,7 +18,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; //---------------------------------------------------------------------------------------------------------------------- TEST(DiffValuesFloatVecs, vec2fCompareValuesSame) diff --git a/test/lib/usd/utils/test_DiffValuesGeneric.cpp b/test/lib/usd/utils/test_DiffValuesGeneric.cpp index 9f12e7690c..7109936fff 100644 --- a/test/lib/usd/utils/test_DiffValuesGeneric.cpp +++ b/test/lib/usd/utils/test_DiffValuesGeneric.cpp @@ -1,9 +1,9 @@ -#include +#include #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; //---------------------------------------------------------------------------------------------------------------------- TEST(DiffValuesGeneric, boolCompareValuesSame) diff --git a/test/lib/usd/utils/test_DiffValuesHalfVecs.cpp b/test/lib/usd/utils/test_DiffValuesHalfVecs.cpp index 31b3df861e..895cd37cd0 100644 --- a/test/lib/usd/utils/test_DiffValuesHalfVecs.cpp +++ b/test/lib/usd/utils/test_DiffValuesHalfVecs.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -18,7 +18,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; //---------------------------------------------------------------------------------------------------------------------- TEST(DiffValuesHalfVecs, vec2hCompareValuesSame) diff --git a/test/lib/usd/utils/test_DiffValuesIntVecs.cpp b/test/lib/usd/utils/test_DiffValuesIntVecs.cpp index 67084e61bc..fe0adba69d 100644 --- a/test/lib/usd/utils/test_DiffValuesIntVecs.cpp +++ b/test/lib/usd/utils/test_DiffValuesIntVecs.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -18,7 +18,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; //---------------------------------------------------------------------------------------------------------------------- TEST(DiffValuesIntVecs, vec2iCompareValuesSame) diff --git a/test/lib/usd/utils/test_DiffValuesMatrices.cpp b/test/lib/usd/utils/test_DiffValuesMatrices.cpp index 25b773d01c..ab2946f0a7 100644 --- a/test/lib/usd/utils/test_DiffValuesMatrices.cpp +++ b/test/lib/usd/utils/test_DiffValuesMatrices.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -8,7 +8,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; namespace { GfMatrix2d m2d1(1, 12, 15, 16); diff --git a/test/lib/usd/utils/test_DiffValuesQuaternions.cpp b/test/lib/usd/utils/test_DiffValuesQuaternions.cpp index 2aa82e6b47..4106888110 100644 --- a/test/lib/usd/utils/test_DiffValuesQuaternions.cpp +++ b/test/lib/usd/utils/test_DiffValuesQuaternions.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -8,7 +8,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; namespace { GfQuatd qd1(1, 12, 15, 16); diff --git a/test/lib/usd/utils/test_MergePrims.cpp b/test/lib/usd/utils/test_MergePrims.cpp index 74a1b337ab..2848e84380 100644 --- a/test/lib/usd/utils/test_MergePrims.cpp +++ b/test/lib/usd/utils/test_MergePrims.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -13,7 +13,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE -using namespace MayaUsdUtils; +using namespace UsdUfe; namespace { From 331bdaa7161f0d8a3c15388e8cf8d69a9f656a2e Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:39:00 -0500 Subject: [PATCH 02/19] EMSUSD-128 - [GitHub #2181] Implement Copy\paste capabilities on USD Data * Moved function "isMaterialsScope" to UsdUfe. * Exposed function "appendToPath" to UsdUfe. * Added DCC function for default material scope name. --- lib/mayaUsd/ufe/Global.cpp | 8 ++ lib/mayaUsd/ufe/UsdUndoMaterialCommands.cpp | 3 +- lib/mayaUsd/ufe/Utils.cpp | 30 ------- lib/mayaUsd/ufe/Utils.h | 4 - lib/mayaUsdAPI/utils.cpp | 6 +- lib/usdUfe/ufe/Global.cpp | 2 + lib/usdUfe/ufe/Global.h | 9 +- lib/usdUfe/ufe/UsdUndoAddNewPrimCommand.cpp | 16 ---- lib/usdUfe/ufe/Utils.cpp | 97 ++++++++++++++++++--- lib/usdUfe/ufe/Utils.h | 24 +++++ 10 files changed, 130 insertions(+), 69 deletions(-) diff --git a/lib/mayaUsd/ufe/Global.cpp b/lib/mayaUsd/ufe/Global.cpp index 41f5326d23..de25e56249 100644 --- a/lib/mayaUsd/ufe/Global.cpp +++ b/lib/mayaUsd/ufe/Global.cpp @@ -17,6 +17,7 @@ #include "private/UfeNotifGuard.h" +#include #include #include #include @@ -120,6 +121,12 @@ void mayaStopWaitCursor() { MGlobal::executeCommand("waitCursor -state 0"); } // Note: MayaUsd::ufe::getStage takes two parameters, so wrap it in a function taking only one. PXR_NS::UsdStageWeakPtr mayaGetStage(const Ufe::Path& path) { return MayaUsd::ufe::getStage(path); } +// Wrapped to return std::string from static function returning const std::string. +std::string defaultMaterialsScopeName() +{ + return UsdMayaJobExportArgs::GetDefaultMaterialsScopeName(); +} + } // namespace namespace MAYAUSD_NS_DEF { @@ -180,6 +187,7 @@ MStatus initialize() dccFunctions.uniqueChildNameFn = MayaUsd::ufe::uniqueChildNameMayaStandard; dccFunctions.startWaitCursorFn = mayaStartWaitCursor; dccFunctions.stopWaitCursorFn = mayaStopWaitCursor; + dccFunctions.defaultMaterialScopeNameFn = defaultMaterialsScopeName; // Replace the Maya hierarchy handler with ours. auto& runTimeMgr = Ufe::RunTimeMgr::instance(); diff --git a/lib/mayaUsd/ufe/UsdUndoMaterialCommands.cpp b/lib/mayaUsd/ufe/UsdUndoMaterialCommands.cpp index 923a19a6c0..c8ed2db937 100644 --- a/lib/mayaUsd/ufe/UsdUndoMaterialCommands.cpp +++ b/lib/mayaUsd/ufe/UsdUndoMaterialCommands.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -523,7 +524,7 @@ Ufe::SceneItem::Ptr UsdUndoAddNewMaterialCommand::insertedChild() const bool UsdUndoAddNewMaterialCommand::CompatiblePrim(const Ufe::SceneItem::Ptr& target) { // Must be a materials scope. - return isMaterialsScope(target); + return UsdUfe::isMaterialsScope(target); } void UsdUndoAddNewMaterialCommand::execute() diff --git a/lib/mayaUsd/ufe/Utils.cpp b/lib/mayaUsd/ufe/Utils.cpp index d7f4b60910..d441163362 100644 --- a/lib/mayaUsd/ufe/Utils.cpp +++ b/lib/mayaUsd/ufe/Utils.cpp @@ -211,36 +211,6 @@ bool isAGatewayType(const std::string& mayaNodeType) return isInherited; } -bool isMaterialsScope(const Ufe::SceneItem::Ptr& item) -{ - if (!item) { - return false; - } - - // Must be a scope. - if (item->nodeType() != "Scope") { - return false; - } - - // With the magic name. - if (item->nodeName() == UsdMayaJobExportArgs::GetDefaultMaterialsScopeName()) { - return true; - } - - // Or with only materials inside - auto scopeHierarchy = Ufe::Hierarchy::hierarchy(item); - if (scopeHierarchy) { - for (auto&& child : scopeHierarchy->children()) { - if (child->nodeType() != "Material") { - // At least one non material - return false; - } - } - } - - return true; -} - Ufe::Path dagPathToUfe(const MDagPath& dagPath) { // This function can only create UFE Maya scene items with a single diff --git a/lib/mayaUsd/ufe/Utils.h b/lib/mayaUsd/ufe/Utils.h index 7753b911b5..9bc2f5feb2 100644 --- a/lib/mayaUsd/ufe/Utils.h +++ b/lib/mayaUsd/ufe/Utils.h @@ -81,10 +81,6 @@ std::string uniqueChildNameMayaStandard(const PXR_NS::UsdPrim& usdParent, const MAYAUSD_CORE_PUBLIC bool isAGatewayType(const std::string& mayaNodeType); -//! Returns true if \p item is a materials scope. -MAYAUSD_CORE_PUBLIC -bool isMaterialsScope(const Ufe::SceneItem::Ptr& item); - MAYAUSD_CORE_PUBLIC Ufe::Path dagPathToUfe(const MDagPath& dagPath); diff --git a/lib/mayaUsdAPI/utils.cpp b/lib/mayaUsdAPI/utils.cpp index 6e456927b3..6d0c6d8028 100644 --- a/lib/mayaUsdAPI/utils.cpp +++ b/lib/mayaUsdAPI/utils.cpp @@ -24,6 +24,7 @@ #include #include +#include #include namespace MAYAUSDAPI_NS_DEF { @@ -89,10 +90,7 @@ Ufe::UndoableCommand::Ptr createStageWithNewLayerCommand(const Ufe::SceneItem::P #endif -bool isMaterialsScope(const Ufe::SceneItem::Ptr& item) -{ - return MayaUsd::ufe::isMaterialsScope(item); -} +bool isMaterialsScope(const Ufe::SceneItem::Ptr& item) { return UsdUfe::isMaterialsScope(item); } bool isAGatewayType(const std::string& mayaNodeType) { diff --git a/lib/usdUfe/ufe/Global.cpp b/lib/usdUfe/ufe/Global.cpp index 15dc170ef0..165b7caefd 100644 --- a/lib/usdUfe/ufe/Global.cpp +++ b/lib/usdUfe/ufe/Global.cpp @@ -80,6 +80,8 @@ Ufe::Rtid initialize( UsdUfe::setIsRootChildFn(dccFunctions.isRootChildFn); if (dccFunctions.uniqueChildNameFn) UsdUfe::setUniqueChildNameFn(dccFunctions.uniqueChildNameFn); + if (dccFunctions.defaultMaterialScopeNameFn) + UsdUfe::setDefaultMaterialScopeNameFn(dccFunctions.defaultMaterialScopeNameFn); // Create a default stages subject if none is provided. if (nullptr == ss) { diff --git a/lib/usdUfe/ufe/Global.h b/lib/usdUfe/ufe/Global.h index a194b7eb57..78708e9dfe 100644 --- a/lib/usdUfe/ufe/Global.h +++ b/lib/usdUfe/ufe/Global.h @@ -44,10 +44,11 @@ struct USDUFE_PUBLIC DCCFunctions TimeAccessorFn timeAccessorFn = nullptr; // Optional: default values will be used if no function is supplied. - IsAttributeLockedFn isAttributeLockedFn = nullptr; - SaveStageLoadRulesFn saveStageLoadRulesFn = nullptr; - IsRootChildFn isRootChildFn = nullptr; - UniqueChildNameFn uniqueChildNameFn = nullptr; + IsAttributeLockedFn isAttributeLockedFn = nullptr; + SaveStageLoadRulesFn saveStageLoadRulesFn = nullptr; + IsRootChildFn isRootChildFn = nullptr; + UniqueChildNameFn uniqueChildNameFn = nullptr; + DefaultMaterialScopeNameFn defaultMaterialScopeNameFn = nullptr; // Optional: nothing will be done if no function is supplied. WaitCursorFn startWaitCursorFn = nullptr; diff --git a/lib/usdUfe/ufe/UsdUndoAddNewPrimCommand.cpp b/lib/usdUfe/ufe/UsdUndoAddNewPrimCommand.cpp index 8ef6778f2b..ba1b3b5658 100644 --- a/lib/usdUfe/ufe/UsdUndoAddNewPrimCommand.cpp +++ b/lib/usdUfe/ufe/UsdUndoAddNewPrimCommand.cpp @@ -24,22 +24,6 @@ #include #include -namespace { - -Ufe::Path appendToPath(const Ufe::Path& path, const std::string& name) -{ - Ufe::Path newUfePath; - if (1 == path.getSegments().size()) { - newUfePath - = path + Ufe::PathSegment(Ufe::PathComponent(name), UsdUfe::getUsdRunTimeId(), '/'); - } else { - newUfePath = path + name; - } - return newUfePath; -} - -} // namespace - namespace USDUFE_NS_DEF { UsdUndoAddNewPrimCommand::UsdUndoAddNewPrimCommand( diff --git a/lib/usdUfe/ufe/Utils.cpp b/lib/usdUfe/ufe/Utils.cpp index 42545014b9..e5bbc052dd 100644 --- a/lib/usdUfe/ufe/Utils.cpp +++ b/lib/usdUfe/ufe/Utils.cpp @@ -89,16 +89,17 @@ uint32_t findLayerIndex(const UsdPrim& prim, const SdfLayerHandle& layer) int gWaitCursorCount = 0; -UsdUfe::StageAccessorFn gStageAccessorFn = nullptr; -UsdUfe::StagePathAccessorFn gStagePathAccessorFn = nullptr; -UsdUfe::UfePathToPrimFn gUfePathToPrimFn = nullptr; -UsdUfe::TimeAccessorFn gTimeAccessorFn = nullptr; -UsdUfe::IsAttributeLockedFn gIsAttributeLockedFn = nullptr; -UsdUfe::SaveStageLoadRulesFn gSaveStageLoadRulesFn = nullptr; -UsdUfe::IsRootChildFn gIsRootChildFn = nullptr; -UsdUfe::UniqueChildNameFn gUniqueChildNameFn = nullptr; -UsdUfe::WaitCursorFn gStartWaitCursorFn = nullptr; -UsdUfe::WaitCursorFn gStopWaitCursorFn = nullptr; +UsdUfe::StageAccessorFn gStageAccessorFn = nullptr; +UsdUfe::StagePathAccessorFn gStagePathAccessorFn = nullptr; +UsdUfe::UfePathToPrimFn gUfePathToPrimFn = nullptr; +UsdUfe::TimeAccessorFn gTimeAccessorFn = nullptr; +UsdUfe::IsAttributeLockedFn gIsAttributeLockedFn = nullptr; +UsdUfe::SaveStageLoadRulesFn gSaveStageLoadRulesFn = nullptr; +UsdUfe::IsRootChildFn gIsRootChildFn = nullptr; +UsdUfe::UniqueChildNameFn gUniqueChildNameFn = nullptr; +UsdUfe::WaitCursorFn gStartWaitCursorFn = nullptr; +UsdUfe::WaitCursorFn gStopWaitCursorFn = nullptr; +UsdUfe::DefaultMaterialScopeNameFn gGetDefaultMaterialScopeNameFn = nullptr; } // anonymous namespace @@ -378,6 +379,47 @@ SdfPath uniqueChildPath(const UsdStage& stage, const SdfPath& path) return path.ReplaceName(TfToken(uniqueName)); } +bool isMaterialsScope(const Ufe::SceneItem::Ptr& item) +{ + if (!item) { + return false; + } + + // Must be a scope. + if (item->nodeType() != "Scope") { + return false; + } + + // With the magic name. + if (item->nodeName() == defaultMaterialScopeName()) { + return true; + } + + // Or with only materials inside + auto scopeHierarchy = Ufe::Hierarchy::hierarchy(item); + if (scopeHierarchy) { + for (auto&& child : scopeHierarchy->children()) { + if (child->nodeType() != "Material") { + // At least one non material + return false; + } + } + } + + return true; +} + +Ufe::Path appendToPath(const Ufe::Path& path, const std::string& name) +{ + Ufe::Path newUfePath; + if (1 == path.getSegments().size()) { + newUfePath + = path + Ufe::PathSegment(Ufe::PathComponent(name), UsdUfe::getUsdRunTimeId(), '/'); + } else { + newUfePath = path + name; + } + return newUfePath; +} namespace { @@ -957,4 +999,39 @@ void stopWaitCursor() gStopWaitCursorFn(); } +void setDefaultMaterialScopeNameFn(DefaultMaterialScopeNameFn fn) +{ + // This function is allowed to be null in which case a default + // material scope name of "mtl" will be used. + gGetDefaultMaterialScopeNameFn = fn; +} + +std::string defaultMaterialScopeName() +{ + // Default material scope name as defined by USD Assets working group. + // See https://wiki.aswf.io/display/WGUSD/Guidelines+for+Structuring+USD+Assets + static constexpr auto kDefaultMaterialScopeName = "mtl"; + return gGetDefaultMaterialScopeNameFn ? gGetDefaultMaterialScopeNameFn() + : kDefaultMaterialScopeName; +} + +UsdSceneItem::Ptr getParentMaterial(const UsdSceneItem::Ptr& item) +{ + if (!item) { + return {}; + } + + const TfToken kMaterial = TfToken("Material"); + + auto prim = item->prim(); + auto path = item->path(); + + while (prim.GetTypeName() != kMaterial && prim.GetParent().IsValid()) { + path = path.pop(); + prim = prim.GetParent(); + } + + return prim.GetTypeName() == kMaterial ? UsdSceneItem::create(path, prim) : nullptr; +} + } // namespace USDUFE_NS_DEF diff --git a/lib/usdUfe/ufe/Utils.h b/lib/usdUfe/ufe/Utils.h index 7ff9b1cb89..d3ae0d300a 100644 --- a/lib/usdUfe/ufe/Utils.h +++ b/lib/usdUfe/ufe/Utils.h @@ -53,6 +53,7 @@ typedef void (*SaveStageLoadRulesFn)(const PXR_NS::UsdStageRefPtr&); typedef bool (*IsRootChildFn)(const Ufe::Path& path); typedef std::string (*UniqueChildNameFn)(const PXR_NS::UsdPrim& usdParent, const std::string& name); typedef void (*WaitCursorFn)(); +typedef std::string (*DefaultMaterialScopeNameFn)(); //------------------------------------------------------------------------------ // Helper functions @@ -191,6 +192,13 @@ std::string uniqueChildNameDefault(const PXR_NS::UsdPrim& parent, const std::str USDUFE_PUBLIC PXR_NS::SdfPath uniqueChildPath(const PXR_NS::UsdStage& stage, const PXR_NS::SdfPath& path); +USDUFE_PUBLIC +Ufe::Path appendToPath(const Ufe::Path& path, const std::string& name); + +//! Returns true if \p item is a materials scope. +USDUFE_PUBLIC +bool isMaterialsScope(const Ufe::SceneItem::Ptr& item); + //! Send notification for data model changes template void sendNotification(const Ufe::SceneItem::Ptr& item, const Ufe::Path& previousPath) @@ -342,4 +350,20 @@ struct USDUFE_PUBLIC WaitCursor const bool _showCursor; }; +//! Set the DCC specific default material scope name function. +//! Use of this function is optional, if one is not supplied then +//! a default name will be used. + +USDUFE_PUBLIC +void setDefaultMaterialScopeNameFn(DefaultMaterialScopeNameFn fn); + +//! Returns the default material scope name. +USDUFE_PUBLIC +std::string defaultMaterialScopeName(); + +// Search the parent Material of the item, comparing the type name. +// In the case item is a material, return item itself. +USDUFE_PUBLIC +UsdSceneItem::Ptr getParentMaterial(const UsdSceneItem::Ptr& item); + } // namespace USDUFE_NS_DEF From f47257773ca5e5c9275f6d4872aab65efbf99ba5 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Tue, 13 Feb 2024 14:09:20 -0500 Subject: [PATCH 03/19] EMSUSD-128 - [GitHub #2181] Implement Copy\paste capabilities on USD Data * cmake - detect when Ufe contains clipboard support. * Added clipboardHandler support to UsdUfe, with new duplicate and duplicateSelection commands. * Override clipboard export name for MayaUsd. * Set the clipboard export file format based on USD file format pref. * Added basic unit test for clipboardHandler. --- cmake/compiler_config.cmake | 3 + cmake/modules/FindUFE.cmake | 7 + lib/mayaUsd/CMakeLists.txt | 7 + lib/mayaUsd/ufe/Global.cpp | 21 + lib/mayaUsd/utils/utilSerialization.cpp | 2 +- lib/usdUfe/python/CMakeLists.txt | 1 + lib/usdUfe/python/module.cpp | 1 + lib/usdUfe/python/wrapClipboard.cpp | 40 ++ lib/usdUfe/ufe/CMakeLists.txt | 26 + lib/usdUfe/ufe/Global.cpp | 13 + lib/usdUfe/ufe/Global.h | 8 + lib/usdUfe/ufe/UsdClipboard.cpp | 129 +++++ lib/usdUfe/ufe/UsdClipboard.h | 92 ++++ lib/usdUfe/ufe/UsdClipboardCommands.cpp | 496 ++++++++++++++++++ lib/usdUfe/ufe/UsdClipboardCommands.h | 144 +++++ lib/usdUfe/ufe/UsdClipboardHandler.cpp | 212 ++++++++ lib/usdUfe/ufe/UsdClipboardHandler.h | 72 +++ lib/usdUfe/ufe/UsdUndoDuplicateCommand.cpp | 159 ++++++ lib/usdUfe/ufe/UsdUndoDuplicateCommand.h | 68 +++ .../ufe/UsdUndoDuplicateSelectionCommand.cpp | 212 ++++++++ .../ufe/UsdUndoDuplicateSelectionCommand.h | 95 ++++ plugin/adsk/scripts/mayaUsd_preferenceTab.mel | 10 +- test/lib/ufe/CMakeLists.txt | 7 + test/lib/ufe/testClipboard.py | 288 ++++++++++ 24 files changed, 2111 insertions(+), 2 deletions(-) create mode 100644 lib/usdUfe/python/wrapClipboard.cpp create mode 100644 lib/usdUfe/ufe/UsdClipboard.cpp create mode 100644 lib/usdUfe/ufe/UsdClipboard.h create mode 100644 lib/usdUfe/ufe/UsdClipboardCommands.cpp create mode 100644 lib/usdUfe/ufe/UsdClipboardCommands.h create mode 100644 lib/usdUfe/ufe/UsdClipboardHandler.cpp create mode 100644 lib/usdUfe/ufe/UsdClipboardHandler.h create mode 100644 lib/usdUfe/ufe/UsdUndoDuplicateCommand.cpp create mode 100644 lib/usdUfe/ufe/UsdUndoDuplicateCommand.h create mode 100644 lib/usdUfe/ufe/UsdUndoDuplicateSelectionCommand.cpp create mode 100644 lib/usdUfe/ufe/UsdUndoDuplicateSelectionCommand.h create mode 100644 test/lib/ufe/testClipboard.py diff --git a/cmake/compiler_config.cmake b/cmake/compiler_config.cmake index 0182f5a3a3..74b25b4ce3 100644 --- a/cmake/compiler_config.cmake +++ b/cmake/compiler_config.cmake @@ -28,6 +28,9 @@ set(MSVC_FLAGS $<$>:/permissive-> # enable pdb generation. /Zi + # to see the updated value of the __cplusplus macro + # https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/ + /Zc:__cplusplus # standards compliant. /Zc:rvalueCast # The /Zc:inline option strips out the "arch_ctor_" symbols used for diff --git a/cmake/modules/FindUFE.cmake b/cmake/modules/FindUFE.cmake index 267f0ab892..f0b15aed5d 100644 --- a/cmake/modules/FindUFE.cmake +++ b/cmake/modules/FindUFE.cmake @@ -12,6 +12,7 @@ # UFE_LIGHTS_SUPPORT Presence of UFE lights support # UFE_MATERIALS_SUPPORT Presence of UFE materials support # UFE_SCENE_SEGMENT_SUPPORT Presence of UFE scene segment support +# UFE_CLIPBOARD_SUPPORT Presence of UFE clipboard support # UFE_PREVIEW_FEATURES List of all features introduced gradually in the UFE preview version # @@ -207,3 +208,9 @@ if(UFE_INCLUDE_DIR AND EXISTS "${UFE_INCLUDE_DIR}/ufe/sceneItem.h") message(STATUS "Maya has UFE SceneItem's meta data interface") endif() endif() + +set(UFE_CLIPBOARD_SUPPORT FALSE CACHE INTERNAL "ufeClipboard") +if (UFE_INCLUDE_DIR AND EXISTS "${UFE_INCLUDE_DIR}/ufe/clipboardHandler.h") + set(UFE_CLIPBOARD_SUPPORT TRUE CACHE INTERNAL "ufeClipboard") + message(STATUS "Maya has UFE clipboard API") +endif() diff --git a/lib/mayaUsd/CMakeLists.txt b/lib/mayaUsd/CMakeLists.txt index 2c90dc3aad..48e39c7254 100644 --- a/lib/mayaUsd/CMakeLists.txt +++ b/lib/mayaUsd/CMakeLists.txt @@ -196,6 +196,13 @@ if (MAYA_LIGHTAPI_VERSION GREATER_EQUAL 2) ) endif() +if (UFE_CLIPBOARD_SUPPORT) + target_compile_definitions(${PROJECT_NAME} + PRIVATE + UFE_CLIPBOARD_SUPPORT=1 + ) +endif() + # Some of the UFE classes are exporting STL classes which causes this warning. if(MSVC) target_compile_options(${PROJECT_NAME} diff --git a/lib/mayaUsd/ufe/Global.cpp b/lib/mayaUsd/ufe/Global.cpp index de25e56249..1ba440604c 100644 --- a/lib/mayaUsd/ufe/Global.cpp +++ b/lib/mayaUsd/ufe/Global.cpp @@ -80,6 +80,12 @@ #include #include +#if UFE_CLIPBOARD_SUPPORT +#include + +#include +#endif + #include #include #include @@ -88,6 +94,9 @@ #include #include +#if UFE_CLIPBOARD_SUPPORT +#include +#endif namespace { @@ -323,6 +332,18 @@ MStatus initialize() runTimeMgr.setBatchOpsHandler(usdRtid, handlers.batchOpsHandler); #endif +#if UFE_CLIPBOARD_SUPPORT + // Get the clipboard handler registered by UsdUfe and set a MayaUsd clipboard path. + auto clipboardHandler = std::dynamic_pointer_cast( + runTimeMgr.clipboardHandler(usdRtid)); + if (clipboardHandler) { + auto clipboardFilePath = ghc::filesystem::temp_directory_path(); + clipboardFilePath.append("MayaUsdClipboard.usd"); + clipboardHandler->setClipboardFilePath(clipboardFilePath.string()); + clipboardHandler->setClipboardFileFormat(MayaUsd::utils::usdFormatArgOption()); + } +#endif + MayaUsd::ufe::UsdUIUfeObserver::create(); #ifndef UFE_V4_FEATURES_AVAILABLE diff --git a/lib/mayaUsd/utils/utilSerialization.cpp b/lib/mayaUsd/utils/utilSerialization.cpp index 2aceae0baa..3059d19b16 100644 --- a/lib/mayaUsd/utils/utilSerialization.cpp +++ b/lib/mayaUsd/utils/utilSerialization.cpp @@ -305,7 +305,7 @@ bool saveLayerWithFormat( } } else { PXR_NS::SdfFileFormat::FileFormatArguments args; - args["format"] = formatArg; + args[UsdUsdFileFormatTokens->FormatArg] = formatArg; if (!layer->Export(filePath, "", args)) { return false; } diff --git a/lib/usdUfe/python/CMakeLists.txt b/lib/usdUfe/python/CMakeLists.txt index ff7abe595d..901205e92a 100644 --- a/lib/usdUfe/python/CMakeLists.txt +++ b/lib/usdUfe/python/CMakeLists.txt @@ -17,6 +17,7 @@ add_library(${PYTHON_TARGET_NAME} SHARED) target_sources(${PYTHON_TARGET_NAME} PRIVATE module.cpp + wrapClipboard.cpp wrapEditRouter.cpp wrapGlobal.cpp wrapTokens.cpp diff --git a/lib/usdUfe/python/module.cpp b/lib/usdUfe/python/module.cpp index bf02e21ec1..8c2405248b 100644 --- a/lib/usdUfe/python/module.cpp +++ b/lib/usdUfe/python/module.cpp @@ -20,6 +20,7 @@ PXR_NAMESPACE_USING_DIRECTIVE TF_WRAP_MODULE { + TF_WRAP(Clipboard); TF_WRAP(EditRouter); TF_WRAP(Global); TF_WRAP(Tokens); diff --git a/lib/usdUfe/python/wrapClipboard.cpp b/lib/usdUfe/python/wrapClipboard.cpp new file mode 100644 index 0000000000..eddbb16a3c --- /dev/null +++ b/lib/usdUfe/python/wrapClipboard.cpp @@ -0,0 +1,40 @@ +// +// Copyright 2024 Autodesk +// +// 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 + +#include + +#include +#include + +using namespace boost::python; + +void _setClipboardFileFormat(const std::string& formatTag) +{ + auto clipboardHandler = std::dynamic_pointer_cast( + Ufe::RunTimeMgr::instance().clipboardHandler(UsdUfe::getUsdRunTimeId())); + if (clipboardHandler) { + clipboardHandler->setClipboardFileFormat(formatTag); + } +} + +// clang-format off +void wrapClipboard() +{ + def("setClipboardFileFormat", _setClipboardFileFormat); +} diff --git a/lib/usdUfe/ufe/CMakeLists.txt b/lib/usdUfe/ufe/CMakeLists.txt index db91e37f9a..14b1390ba9 100644 --- a/lib/usdUfe/ufe/CMakeLists.txt +++ b/lib/usdUfe/ufe/CMakeLists.txt @@ -55,6 +55,22 @@ if (UFE_SCENEITEM_HAS_METADATA) ) endif() +if (UFE_CLIPBOARD_SUPPORT) + target_sources(${PROJECT_NAME} + PRIVATE + UsdClipboard.cpp + UsdClipboardCommands.cpp + UsdClipboardHandler.cpp + UsdUndoDuplicateCommand.cpp + UsdUndoDuplicateSelectionCommand.cpp + ) + + target_compile_definitions(${PROJECT_NAME} + PRIVATE + UFE_CLIPBOARD_SUPPORT=1 + ) +endif() + set(HEADERS Global.h SetVariantSelectionCommand.h @@ -106,6 +122,16 @@ if (UFE_SCENEITEM_HAS_METADATA) ) endif() +if (UFE_CLIPBOARD_SUPPORT) + list(APPEND HEADERS + UsdClipboard.h + UsdClipboardCommands.h + UsdClipboardHandler.h + UsdUndoDuplicateCommand.h + UsdUndoDuplicateSelectionCommand.h + ) +endif() + # ----------------------------------------------------------------------------- # promote headers # ----------------------------------------------------------------------------- diff --git a/lib/usdUfe/ufe/Global.cpp b/lib/usdUfe/ufe/Global.cpp index 165b7caefd..500f071e4c 100644 --- a/lib/usdUfe/ufe/Global.cpp +++ b/lib/usdUfe/ufe/Global.cpp @@ -25,6 +25,10 @@ #include +#if UFE_CLIPBOARD_SUPPORT +#include +#endif + #ifndef UFE_V2_FEATURES_AVAILABLE #error "Compiling usdUfe library with Ufe v1 is no longer supported." #endif @@ -104,6 +108,15 @@ Ufe::Rtid initialize( g_USDRtid = Ufe::RunTimeMgr::instance().register_(kUSDRunTimeName, rtHandlers); TF_VERIFY(g_USDRtid != 0); + + // Handlers to register separately since they may or may not be contained within + // the Ufe Handlers struct. But they are always guaranteed to have a set method. +#if UFE_CLIPBOARD_SUPPORT + auto cbhndlr + = handlers.clipboardHandler ? handlers.clipboardHandler : UsdClipboardHandler::create(); + Ufe::RunTimeMgr::instance().setClipboardHandler(g_USDRtid, cbhndlr); +#endif + return g_USDRtid; } diff --git a/lib/usdUfe/ufe/Global.h b/lib/usdUfe/ufe/Global.h index 78708e9dfe..5efe5e76f0 100644 --- a/lib/usdUfe/ufe/Global.h +++ b/lib/usdUfe/ufe/Global.h @@ -28,6 +28,10 @@ #include +#if UFE_CLIPBOARD_SUPPORT +#include +#endif + namespace USDUFE_NS_DEF { /*! Ufe runtime DCC specific functions. @@ -88,6 +92,10 @@ struct USDUFE_PUBLIC Handlers // Ufe::UINodeGraphNodeHandler::Ptr uiNodeGraphNodeHandler; // Ufe::BatchOpsHandler::Ptr batchOpsHandler; #endif + +#if UFE_CLIPBOARD_SUPPORT + Ufe::ClipboardHandler::Ptr clipboardHandler; +#endif }; //! Only intended to be called by the plugin initialization, to diff --git a/lib/usdUfe/ufe/UsdClipboard.cpp b/lib/usdUfe/ufe/UsdClipboard.cpp new file mode 100644 index 0000000000..040446b769 --- /dev/null +++ b/lib/usdUfe/ufe/UsdClipboard.cpp @@ -0,0 +1,129 @@ +// +// Copyright 2024 Autodesk +// +// 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 "UsdClipboard.h" + +#include +#include +#include +#include + +#if (__cplusplus < 201703L) +#error "Compiling ClipboardHandler requires C++17" +#endif +#include // Requires C++17 + +namespace USDUFE_NS_DEF { + +// Ensure that UsdClipboard is properly setup. +static_assert(!std::is_copy_constructible::value); +static_assert(!std::is_copy_assignable::value); +static_assert(!std::is_move_constructible::value); +static_assert(!std::is_move_assignable::value); + +UsdClipboard::UsdClipboard() +{ + setClipboardPath(std::filesystem::temp_directory_path().string()); + setClipboardFileFormat(PXR_NS::UsdUsdcFileFormatTokens->Id.GetText()); // Default = binary +} + +UsdClipboard::~UsdClipboard() { cleanClipboard(); } + +void UsdClipboard::setClipboardData(const PXR_NS::UsdStageWeakPtr& clipboardData) +{ + // Note: if a clipboard file already exists, it automatically gets overridden, so there is no + // need to clear it. + // Note: export the root layer directly as the stage export will flatten which removes + // variant sets, payloads, etc. + PXR_NS::SdfFileFormat::FileFormatArguments args; + args[PXR_NS::UsdUsdFileFormatTokens->FormatArg] = _clipboardFileFormat; + if (!clipboardData->GetRootLayer()->Export(_clipboardFilePath, "UsdUfe clipboard", args)) { + const std::string error + = "Failed to export Clipboard stage with destination: " + _clipboardFilePath + "."; + throw std::runtime_error(error); + } + + // Unload the stage, otherwise when we try to set and get the next clipboard data we end up with + // the old stage. + clipboardData->Unload(); +} + +PXR_NS::UsdStageWeakPtr UsdClipboard::getClipboardData() +{ + // Check if the layer exists + auto layer = PXR_NS::SdfLayer::FindOrOpen(_clipboardFilePath); + if (!layer) + return {}; + + PXR_NS::UsdStageRefPtr clipboardStage = PXR_NS::UsdStage::Open(_clipboardFilePath); + + cleanClipboardStageCache(); + + // Add the clipboard USD stage to UsdUtilsStageCache, otherwise it is destroyed once out of + // scope. + _clipboardStageCacheId = PXR_NS::UsdUtilsStageCache::Get().Insert(clipboardStage); + + // Force the new stage to reload, so we don't end up with the old stage. + clipboardStage->Reload(); + + return clipboardStage; +} + +void UsdClipboard::setClipboardPath(const std::string& clipboardPath) +{ + auto tmpPath = std::filesystem::path(clipboardPath); + tmpPath.append(clipboardFileName); + setClipboardFilePath(tmpPath.string()); +} + +void UsdClipboard::setClipboardFilePath(const std::string& clipboardFilePath) +{ + _clipboardFilePath = clipboardFilePath; +} + +void UsdClipboard::setClipboardFileFormat(const std::string& formatTag) +{ + _clipboardFileFormat = formatTag; +} + +void UsdClipboard::cleanClipboard() +{ + cleanClipboardStageCache(true); + removeClipboardFile(); +} + +void UsdClipboard::cleanClipboardStageCache(bool cleanFile) +{ + // Erase the clipboard stage from the cache. + if (_clipboardStageCacheId.IsValid()) { + auto clipboardStageRef = PXR_NS::UsdUtilsStageCache::Get().Find(_clipboardStageCacheId); + PXR_NS::UsdUtilsStageCache::Get().Erase(clipboardStageRef); + + if (cleanFile && clipboardStageRef && clipboardStageRef->GetRootLayer()) { + // Clean the stage and clipboard file. + // Note: Instead of clearing the file, it might be better to use filenames + // from the stage hash and retain that in a variable or stack. + clipboardStageRef->GetRootLayer()->Clear(); + PXR_NS::SdfFileFormat::FileFormatArguments args; + args["format"] = _clipboardFileFormat; + clipboardStageRef->GetRootLayer()->Export(_clipboardFilePath, "UsdUfe Clipboard", args); + } + } +} + +void UsdClipboard::removeClipboardFile() { std::filesystem::remove(_clipboardFilePath); } + +} // namespace USDUFE_NS_DEF diff --git a/lib/usdUfe/ufe/UsdClipboard.h b/lib/usdUfe/ufe/UsdClipboard.h new file mode 100644 index 0000000000..e076361793 --- /dev/null +++ b/lib/usdUfe/ufe/UsdClipboard.h @@ -0,0 +1,92 @@ +#ifndef USDCLIPBOARD_H +#define USDCLIPBOARD_H + +// +// Copyright 2024 Autodesk +// +// 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 +#include + +namespace USDUFE_NS_DEF { + +//! \brief Class to handle clipboard USD data. +class USDUFE_PUBLIC UsdClipboard +{ +public: + // Clipboard file name and format. + static constexpr auto clipboardFileName = "UsdUfeClipboard.usd"; + using Ptr = std::shared_ptr; + + UsdClipboard(); + ~UsdClipboard(); + + // Delete the copy/move constructors assignment operators. + UsdClipboard(const UsdClipboard&) = delete; + UsdClipboard& operator=(const UsdClipboard&) = delete; + UsdClipboard(UsdClipboard&&) = delete; + UsdClipboard& operator=(UsdClipboard&&) = delete; + + //! \brief Set the clipboard data. + //! \note It is possible to set clipboard data across multiple running instances of DCC. + //! \param clipboard The clipboard data to set (aka the clipboard stage). + void setClipboardData(const PXR_NS::UsdStageWeakPtr& clipboardData); + + //! \brief Get the clipboard data. + //! \note It is possible to set clipboard data across multiple running instances of the + // DCC app (ex: Maya), so we get the last modified clipboard data. + //! \return The clipboard data (aka the clipboard stage). + PXR_NS::UsdStageWeakPtr getClipboardData(); + + //! \brief Set the clipboard path, i.e. where the .usd should be exported and read from. + //! \note The filename "UsdUfeClipboard.usd" will be appended to the input path. + //! \param clipboardPath The new clipboard path. + void setClipboardPath(const std::string& clipboardPath); + + //! \brief Sets the clipboard path (including filename) where data should exported and + //! read from. + //! \param clipboardFilePath The new clipboard path+file. + void setClipboardFilePath(const std::string& clipboardFilePath); + + //! \brief Sets the USD file format for the clipboard file. + //! \param formatTag The USD file format to use. + void setClipboardFileFormat(const std::string& formatTag); + + //! \brief Clean the clipboard data so no paste action will happen. + void cleanClipboard(); + +private: + // The clipboard path (including filename). + std::string _clipboardFilePath; + + // The USD file format to use for the clipboard file. + std::string _clipboardFileFormat; + + // The cache clipboard stage id. + PXR_NS::UsdStageCache::Id _clipboardStageCacheId; + + //! \brief Erase the clipboard stage from the cache. + //! \param cleanFile If true, we clean the root layer stage and the clipboard file. + void cleanClipboardStageCache(bool cleanFile = false); + + //! \brief Remove the clipboard file by deleting it. + void removeClipboardFile(); +}; + +} // namespace USDUFE_NS_DEF + +#endif // USDCLIPBOARD_H diff --git a/lib/usdUfe/ufe/UsdClipboardCommands.cpp b/lib/usdUfe/ufe/UsdClipboardCommands.cpp new file mode 100644 index 0000000000..5a6c9ef312 --- /dev/null +++ b/lib/usdUfe/ufe/UsdClipboardCommands.cpp @@ -0,0 +1,496 @@ +// +// Copyright 2024 Autodesk +// +// 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 "UsdClipboardCommands.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +namespace { + +constexpr std::string_view kClipboardMetadata = "ClipboardMetadata"; +constexpr std::string_view kMaterialName = "materialName"; +constexpr std::string_view kNodeName = "shaderName"; +constexpr std::string_view kStagePath = "stagePath"; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Utility functions +void setClipboardMetadata( + UsdSceneItem::Ptr& item, + const std::string& metadataKey, + const std::string& metadataValue) +{ + const auto setMetadataCmd = item->setGroupMetadataCmd( + std::string(kClipboardMetadata), metadataKey, Ufe::Value(metadataValue)); + + if (setMetadataCmd) { + setMetadataCmd->execute(); + } +} + +void setClipboardMetadata(const UsdUndoDuplicateSelectionCommand::Ptr& duplicateSelectionCmd) +{ + for (const auto& duplicatedItem : duplicateSelectionCmd->getDuplicatedItemsMap()) { + const auto prim = duplicatedItem.first->prim(); + + // Do not set ClipboardMetadata for Materials. + if (PXR_NS::UsdShadeMaterial(prim)) { + continue; + } + + std::string materialName; + const std::string stagePath = duplicatedItem.first->path().popSegment().string(); + const std::string nodeName = duplicatedItem.first->nodeName(); + + const auto parentMaterial = getParentMaterial(duplicatedItem.first); + + // Recursively find the parent material. + if (parentMaterial) { + materialName = parentMaterial->nodeName(); + } + + // Get the usdItem for the copied item in the clipboard. + Ufe::PathSegment segment( + "/" + duplicatedItem.second->prim().GetName().GetString(), + UsdUfe::getUsdRunTimeId(), + '/'); + auto usdItem = UsdSceneItem::create(segment, duplicatedItem.second->prim()); + + // Set the node name in the ClipboardMetadata. + setClipboardMetadata(usdItem, std::string(kNodeName), nodeName); + + // Set the material parent name in the ClipboardMetadata. + setClipboardMetadata(usdItem, std::string(kMaterialName), materialName); + + // Set the stage path in the ClipboardMetadata. + setClipboardMetadata(usdItem, std::string(kStagePath), stagePath); + } +} + +void clearClipboardMetadata(Ufe::SceneItemList& targetItems) +{ + std::shared_ptr compositeClearMetadataCmd + = std::make_shared(); + + // Remove ClipboardMetadata. + for (auto& targetItem : targetItems) { + auto usdItem = std::dynamic_pointer_cast(targetItem); + + if (PXR_NS::UsdShadeMaterial(usdItem->prim())) + continue; + + compositeClearMetadataCmd->append( + usdItem->clearGroupMetadataCmd(std::string(kClipboardMetadata))); + } + + compositeClearMetadataCmd->execute(); +} + +Ufe::SceneItem::Ptr renameItemUsingMetadata(Ufe::SceneItem::Ptr item) +{ + if (item) { + auto usdItem = std::dynamic_pointer_cast(item); + if (usdItem) { + const auto newName + = usdItem->getGroupMetadata(std::string(kClipboardMetadata), std::string(kNodeName)) + .get(); + + // Nothing to rename, return the item. + if (item->nodeName() == newName || newName.empty()) { + return item; + } + + const Ufe::SceneItemOps::Ptr sceneItemOps = Ufe::SceneItemOps::sceneItemOps(item); + if (sceneItemOps) { + Ufe::PathComponent namePathComponent(newName); + const auto renameCmd = sceneItemOps->renameItemCmdNoExecute(namePathComponent); + if (renameCmd) { + renameCmd->execute(); + return renameCmd->sceneItem(); + } + } + } + } + + return {}; +} + +Ufe::SceneItemList pasteItemsToNewMaterial(const UsdSceneItem::Ptr& dstItem, Ufe::Selection& items) +{ + auto compositeCmd = Ufe::CompositeUndoableCommand::create({}); + + // Preserve the scene item order from the selection. + std::map> stageMaterialNamesMap; + Ufe::SceneItemList createdMaterials; + + // Group all the items with the same material name and from the same stage. + for (const auto& item : items) { + const auto materialName + = item->getGroupMetadata(std::string(kClipboardMetadata), std::string(kMaterialName)) + .get(); + const auto originStage + = item->getGroupMetadata(std::string(kClipboardMetadata), std::string(kStagePath)) + .get(); + + stageMaterialNamesMap[originStage][materialName].append(item); + } + + // Create the new Materials taking into consideration also the stage. + for (const auto& stagesNameMap : stageMaterialNamesMap) { + for (const auto& materialNamesMap : stagesNameMap.second) { + // Create a material using the name given from the metadata. + // The uniqueness of the name will be solved by UsdUndoAddNewPrimCommand. + auto createCmd + = UsdUndoAddNewPrimCommand::create(dstItem, materialNamesMap.first, "Material"); + if (createCmd) { + createCmd->execute(); + + // Use the created Material as paste target. + if (createCmd->sceneItem()) { + createdMaterials.push_back(createCmd->sceneItem()); + compositeCmd->append(UsdUndoDuplicateSelectionCommand::create( + materialNamesMap.second, + std::dynamic_pointer_cast(createCmd->sceneItem()))); + } + } + } + } + + // Execute the composite cmd. + compositeCmd->execute(); + + Ufe::SceneItemList pastedItems; + for (const auto& materialItem : createdMaterials) { + auto usdItem = std::dynamic_pointer_cast(materialItem); + const auto matHierarchy = Ufe::Hierarchy::hierarchy(materialItem); + if (matHierarchy) { + for (auto& child : matHierarchy->children()) { + // If necessary, rename the child using the name in the metadata. + pastedItems.push_back(renameItemUsingMetadata(child)); + } + } + } + + // Clear the Clipboard metadata. + clearClipboardMetadata(pastedItems); + + return createdMaterials; +} + +} // namespace + +namespace USDUFE_NS_DEF { + +// Ensure that UsdCopyClipboardCommand is properly setup. +static_assert(std::is_base_of::value); +static_assert(std::has_virtual_destructor::value); +static_assert(!std::is_copy_constructible::value); +static_assert(!std::is_copy_assignable::value); +static_assert(!std::is_move_constructible::value); +static_assert(!std::is_move_assignable::value); + +UsdCopyClipboardCommand::UsdCopyClipboardCommand( + const Ufe::Selection& selection, + const UsdClipboard::Ptr& clipboard) + : _selection(selection) + , _clipboard(clipboard) +{ +} + +UsdCopyClipboardCommand::Ptr +UsdCopyClipboardCommand::create(const Ufe::Selection& selection, const UsdClipboard::Ptr& clipboard) +{ + if (selection.empty()) { + return {}; + } + + return std::make_shared(selection, clipboard); +} + +void UsdCopyClipboardCommand::execute() +{ + // Create a new empty layer and stage for the clipboard. + PXR_NS::SdfLayerRefPtr layer = PXR_NS::SdfLayer::CreateAnonymous(); + PXR_NS::UsdStageRefPtr clipboardStage + = PXR_NS::UsdStage::Open(layer->GetIdentifier(), PXR_NS::UsdStage::LoadNone); + + if (!clipboardStage) { + // It shouldn't be possible to obtain an invalid stage since we are creating it from an + // anonymous layer, however as a precaution we leave this check. + const std::string error = "Failed to create Clipboard stage."; + throw std::runtime_error(error); + } + + // Duplicate the selected items to the Clipboard stage using its pseudo-root as parent + // item destination. + auto usdParentItem = UsdSceneItem::create(Ufe::Path(), clipboardStage->GetPseudoRoot()); + auto duplicateSelectionUndoableCmd + = UsdUndoDuplicateSelectionCommand::create(_selection, usdParentItem); + duplicateSelectionUndoableCmd->execute(); + + // Set Clipboard metadata. + setClipboardMetadata(duplicateSelectionUndoableCmd); + + // Set the clipboard data. + _clipboard->setClipboardData(clipboardStage); +} + +void UsdCopyClipboardCommand::undo() +{ + // Do nothing. +} + +void UsdCopyClipboardCommand::redo() +{ + // Do nothing. +} + +// Ensure that UsdCutClipboardCommand is properly setup. +static_assert(std::is_base_of::value); +static_assert(std::has_virtual_destructor::value); +static_assert(!std::is_copy_constructible::value); +static_assert(!std::is_copy_assignable::value); +static_assert(!std::is_move_constructible::value); +static_assert(!std::is_move_assignable::value); + +UsdCutClipboardCommand::UsdCutClipboardCommand( + const Ufe::Selection& selection, + const UsdClipboard::Ptr& clipboard) + : _selection(selection) + , _clipboard(clipboard) +{ +} + +UsdCutClipboardCommand::Ptr +UsdCutClipboardCommand::create(const Ufe::Selection& selection, const UsdClipboard::Ptr& clipboard) +{ + if (selection.empty()) { + return {}; + } + + return std::make_shared(selection, clipboard); +} + +void UsdCutClipboardCommand::execute() +{ + UsdUndoBlock undoBlock(&_undoableItem); + + // Step 1. Copy the selected items to the Clipboard. + auto copyClipboardCommand = UsdCopyClipboardCommand::create(_selection, _clipboard); + copyClipboardCommand->execute(); + + const auto& sceneItemOpsHandler + = Ufe::RunTimeMgr::instance().sceneItemOpsHandler(UsdUfe::getUsdRunTimeId()); + + // Step 2. Delete the selected items. + for (auto&& item : _selection) { + if (UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast(item)) { + sceneItemOpsHandler->sceneItemOps(usdItem)->deleteItem(); + } + } +} + +void UsdCutClipboardCommand::undo() { _undoableItem.undo(); } + +void UsdCutClipboardCommand::redo() { _undoableItem.redo(); } + +// Ensure that UsdPasteClipboardCommand is properly setup. +static_assert(std::is_base_of::value); +static_assert(std::has_virtual_destructor::value); +static_assert(!std::is_copy_constructible::value); +static_assert(!std::is_copy_assignable::value); +static_assert(!std::is_move_constructible::value); +static_assert(!std::is_move_assignable::value); + +UsdPasteClipboardCommand::UsdPasteClipboardCommand( + const Ufe::Selection& dstParentItems, + const UsdClipboard::Ptr& clipboard) + : _clipboard(clipboard) +{ + for (const auto& parentItem : dstParentItems) { + if (const auto usdParentItem = std::dynamic_pointer_cast(parentItem)) { + _dstParentItems.push_back(usdParentItem); + } + } +} + +UsdPasteClipboardCommand::UsdPasteClipboardCommand( + const Ufe::SceneItem::Ptr& dstParentItem, + const UsdClipboard::Ptr& clipboard) + : _clipboard(clipboard) +{ + if (const auto usdItem = std::dynamic_pointer_cast(dstParentItem)) { + _dstParentItems.push_back(usdItem); + } +} + +UsdPasteClipboardCommand::Ptr UsdPasteClipboardCommand::create( + const Ufe::SceneItem::Ptr& dstParentItem, + const UsdClipboard::Ptr& clipboard) +{ + if (!dstParentItem) + return {}; + return std::make_shared(dstParentItem, clipboard); +} + +UsdPasteClipboardCommand::Ptr UsdPasteClipboardCommand::create( + const Ufe::Selection& dstParentItems, + const UsdClipboard::Ptr& clipboard) +{ + if (dstParentItems.empty()) + return {}; + return std::make_shared(dstParentItems, clipboard); +} + +void UsdPasteClipboardCommand::execute() +{ + UsdUndoBlock undoBlock(&_undoableItem); + + // Get the Clipboard stage. + auto clipboardData = _clipboard->getClipboardData(); + + if (!clipboardData) { + const std::string error = "Failed to load Clipboard stage."; + throw std::runtime_error(error); + } + + // Duplicate the first-level in depth items from the Clipboard stage to the destination + // parent item. + Ufe::Selection clipboardMaterials; + Ufe::Selection clipboardShaders; + Ufe::Selection clipboardPrims; + + for (auto prim : clipboardData->Traverse()) { + // Add to the selection only the first-level in depth items. + if (prim.GetParent() == clipboardData->GetPseudoRoot()) { + Ufe::PathSegment segment( + "/" + prim.GetName().GetString(), UsdUfe::getUsdRunTimeId(), '/'); + + if (auto usdItem = UsdSceneItem::create(segment, prim)) { + if (PXR_NS::UsdShadeMaterial(prim)) { + clipboardMaterials.append(usdItem); + } else if (PXR_NS::UsdShadeShader(prim) || PXR_NS::UsdShadeNodeGraph(prim)) { + clipboardShaders.append(usdItem); + } else { + clipboardPrims.append(usdItem); + } + } + } + } + + if (clipboardPrims.empty() && clipboardMaterials.empty() && clipboardShaders.empty()) { + return; // nothing to paste + } + + auto appendToVector = [](const auto& itemsToAppend, + std::vector& vector, + bool useMetadataNames = false) { + for (const auto& item : itemsToAppend) { + auto itemPath = item->path(); + if (useMetadataNames) { + // If we have the original name, use it. + const auto newName + = item->getGroupMetadata( + std::string(kClipboardMetadata), std::string(kNodeName)) + .template get(); + if (!newName.empty() && newName != item->nodeName()) { + itemPath = itemPath.sibling(newName); + } + } + + vector.push_back(itemPath); + } + }; + + for (const auto& dstParentItem : _dstParentItems) { + Ufe::PasteClipboardCommand::PasteInfo pasteInfo; + pasteInfo.pasteTarget = dstParentItem->path(); + + if (!clipboardMaterials.empty()) { + if (isMaterialsScope(dstParentItem)) { + auto duplicateCmd + = UsdUndoDuplicateSelectionCommand::create(clipboardMaterials, dstParentItem); + duplicateCmd->execute(); + appendToVector(duplicateCmd->targetItems(), pasteInfo.successfulPastes); + auto tmpTargetItems = duplicateCmd->targetItems(); + _targetItems.insert( + _targetItems.end(), tmpTargetItems.begin(), tmpTargetItems.end()); + } else { + appendToVector(clipboardMaterials, pasteInfo.failedPastes, true); + } + } + + if (!clipboardShaders.empty()) { + // If the destination target is a Scope and we have shaders to paste, then before we + // have to create a material using their clipboard metadata and use it as paste target. + if (isMaterialsScope(dstParentItem)) { + auto duplicatedItems = pasteItemsToNewMaterial(dstParentItem, clipboardShaders); + appendToVector(duplicatedItems, pasteInfo.successfulPastes); + _targetItems.insert( + _targetItems.end(), duplicatedItems.begin(), duplicatedItems.end()); + } else if (PXR_NS::UsdShadeNodeGraph(dstParentItem->prim())) { + auto duplicateCmd + = UsdUndoDuplicateSelectionCommand::create(clipboardShaders, dstParentItem); + duplicateCmd->execute(); + appendToVector(duplicateCmd->targetItems(), pasteInfo.successfulPastes); + auto tmpTargetItems = duplicateCmd->targetItems(); + _targetItems.insert( + _targetItems.end(), tmpTargetItems.begin(), tmpTargetItems.end()); + } else { + appendToVector(clipboardShaders, pasteInfo.failedPastes, true); + } + } + + if (!clipboardPrims.empty()) { + auto duplicateCmd + = UsdUndoDuplicateSelectionCommand::create(clipboardPrims, dstParentItem); + duplicateCmd->execute(); + appendToVector(duplicateCmd->targetItems(), pasteInfo.successfulPastes); + auto tmpTargetItems = duplicateCmd->targetItems(); + _targetItems.insert(_targetItems.end(), tmpTargetItems.begin(), tmpTargetItems.end()); + } + + // Add the paste info. + _pasteInfos.push_back(std::move(pasteInfo)); + } + + // Remove ClipboardMetadata. + clearClipboardMetadata(_targetItems); +} + +void UsdPasteClipboardCommand::undo() { _undoableItem.undo(); } + +void UsdPasteClipboardCommand::redo() { _undoableItem.redo(); } + +Ufe::SceneItemList UsdPasteClipboardCommand::targetItems() const { return _targetItems; } + +std::vector UsdPasteClipboardCommand::getPasteInfos() const +{ + return _pasteInfos; +} + +} // namespace USDUFE_NS_DEF diff --git a/lib/usdUfe/ufe/UsdClipboardCommands.h b/lib/usdUfe/ufe/UsdClipboardCommands.h new file mode 100644 index 0000000000..c714682d71 --- /dev/null +++ b/lib/usdUfe/ufe/UsdClipboardCommands.h @@ -0,0 +1,144 @@ +#ifndef USDCLIPBOARDCOMMANDS_H +#define USDCLIPBOARDCOMMANDS_H + +// +// Copyright 2024 Autodesk +// +// 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 +#include +#include + +#include +#include +#include + +namespace USDUFE_NS_DEF { + +//! \brief Command to copy USD prims to the clipboard. +class USDUFE_PUBLIC UsdCopyClipboardCommand : public Ufe::UndoableCommand +{ +public: + using Ptr = std::shared_ptr; + + UsdCopyClipboardCommand(const Ufe::Selection& selection, const UsdClipboard::Ptr& clipboard); + + // Delete the copy/move constructors assignment operators. + UsdCopyClipboardCommand(const UsdCopyClipboardCommand&) = delete; + UsdCopyClipboardCommand& operator=(const UsdCopyClipboardCommand&) = delete; + UsdCopyClipboardCommand(UsdCopyClipboardCommand&&) = delete; + UsdCopyClipboardCommand& operator=(UsdCopyClipboardCommand&&) = delete; + + //! Create a UsdCopyClipboardCommand from a selection. + static Ptr create(const Ufe::Selection& selection, const UsdClipboard::Ptr& clipboard); + + void execute() override; + void undo() override; + void redo() override; + +private: + // The items to copy to the clipboard. + Ufe::Selection _selection; + + // The cmd sets the clipboard data when executed. + UsdClipboard::Ptr _clipboard; + +}; // UsdCopyClipboardCommand + +//! \brief Command to cut USD items to the clipboard and then delete them. +class USDUFE_PUBLIC UsdCutClipboardCommand : public Ufe::UndoableCommand +{ +public: + using Ptr = std::shared_ptr; + + UsdCutClipboardCommand(const Ufe::Selection& selection, const UsdClipboard::Ptr& clipboard); + ~UsdCutClipboardCommand() override = default; + + // Delete the copy/move constructors assignment operators. + UsdCutClipboardCommand(const UsdCutClipboardCommand&) = delete; + UsdCutClipboardCommand& operator=(const UsdCutClipboardCommand&) = delete; + UsdCutClipboardCommand(UsdCutClipboardCommand&&) = delete; + UsdCutClipboardCommand& operator=(UsdCutClipboardCommand&&) = delete; + + //! Create a UsdCutClipboardCommand from a selection. + static Ptr create(const Ufe::Selection& selection, const UsdClipboard::Ptr& clipboard); + + void execute() override; + void undo() override; + void redo() override; + +private: + UsdUndoableItem _undoableItem; + + // The items to cut and copy to the clipboard. + Ufe::Selection _selection; + + // The cmd sets the clipboard data when executed. + UsdClipboard::Ptr _clipboard; + +}; // UsdCutClipboardCommand + +//! \brief Command to paste the USD prims from the clipboard. +class USDUFE_PUBLIC UsdPasteClipboardCommand : public Ufe::PasteClipboardCommand +{ +public: + using Ptr = std::shared_ptr; + + UsdPasteClipboardCommand( + const Ufe::Selection& dstParentItems, + const UsdClipboard::Ptr& clipboard); + UsdPasteClipboardCommand( + const Ufe::SceneItem::Ptr& dstParentItem, + const UsdClipboard::Ptr& clipboard); + + // Delete the copy/move constructors assignment operators. + UsdPasteClipboardCommand(const UsdPasteClipboardCommand&) = delete; + UsdPasteClipboardCommand& operator=(const UsdPasteClipboardCommand&) = delete; + UsdPasteClipboardCommand(UsdPasteClipboardCommand&&) = delete; + UsdPasteClipboardCommand& operator=(UsdPasteClipboardCommand&&) = delete; + + //! Create a UsdPasteClipboardCommand from a scene item or selection. + static Ptr create(const Ufe::SceneItem::Ptr& dstParentItem, const UsdClipboard::Ptr& clipboard); + static Ptr create(const Ufe::Selection& dstParentItems, const UsdClipboard::Ptr& clipboard); + + void execute() override; + void undo() override; + void redo() override; + + // Overridden from Ufe::PasteClipboardCommand + Ufe::SceneItemList targetItems() const override; + std::vector getPasteInfos() const override; + +private: + UsdUndoableItem _undoableItem; + + // The destination parent items for the pasted items. + std::vector _dstParentItems; + + // The target items. + Ufe::SceneItemList _targetItems; + + // The cmd gets the clipboard data when executed. + UsdClipboard::Ptr _clipboard; + + // The info messages for the pasted items. + std::vector _pasteInfos; + +}; // UsdPasteClipboardCommand + +} // namespace USDUFE_NS_DEF + +#endif // USDCLIPBOARDCOMMANDS_H diff --git a/lib/usdUfe/ufe/UsdClipboardHandler.cpp b/lib/usdUfe/ufe/UsdClipboardHandler.cpp new file mode 100644 index 0000000000..46942ab2e8 --- /dev/null +++ b/lib/usdUfe/ufe/UsdClipboardHandler.cpp @@ -0,0 +1,212 @@ +// +// Copyright 2024 Autodesk +// +// 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 "UsdClipboardHandler.h" + +#include +#include +#include + +#include +#include + +#include + +namespace { +bool isAttributeConnected( + const PXR_NS::UsdAttribute& srcUsdAttr, + const PXR_NS::UsdAttribute& dstUsdAttr) +{ + PXR_NS::SdfPathVector connectedAttrs; + dstUsdAttr.GetConnections(&connectedAttrs); + + return std::any_of( + connectedAttrs.begin(), connectedAttrs.end(), [&srcUsdAttr](const auto& path) { + return path == srcUsdAttr.GetPath(); + }); +} + +} // namespace + +namespace USDUFE_NS_DEF { + +// Ensure that UsdClipboardHandler is properly setup. +static_assert(std::is_base_of::value); +static_assert(std::has_virtual_destructor::value); +static_assert(!std::is_copy_constructible::value); +static_assert(!std::is_copy_assignable::value); +static_assert(!std::is_move_constructible::value); +static_assert(!std::is_move_assignable::value); + +UsdClipboardHandler::UsdClipboardHandler() { _clipboard = std::make_shared(); } + +/*static*/ +UsdClipboardHandler::Ptr UsdClipboardHandler::create() +{ + return std::make_shared(); +} + +//------------------------------------------------------------------------------ +// Ufe::ClipboardHandler overrides +//------------------------------------------------------------------------------ + +Ufe::UndoableCommand::Ptr UsdClipboardHandler::cutCmd_(const Ufe::Selection& selection) +{ + return UsdCutClipboardCommand::create(selection, _clipboard); +} + +Ufe::UndoableCommand::Ptr UsdClipboardHandler::copyCmd_(const Ufe::Selection& selection) +{ + return UsdCopyClipboardCommand::create(selection, _clipboard); +} + +Ufe::PasteClipboardCommand::Ptr +UsdClipboardHandler::pasteCmd_(const Ufe::SceneItem::Ptr& parentItem) +{ + return UsdPasteClipboardCommand::create(parentItem, _clipboard); +} + +Ufe::UndoableCommand::Ptr UsdClipboardHandler::pasteCmd_(const Ufe::Selection& parentItems) +{ + return UsdPasteClipboardCommand::create(parentItems, _clipboard); +} + +bool UsdClipboardHandler::hasItemsToPaste_() +{ + if (auto clipboardStage = _clipboard->getClipboardData()) { + for (auto prim : clipboardStage->Traverse()) { + // Return true if there is at least one valid prim to paste. + if (prim) + return true; + } + } + return false; +} + +bool UsdClipboardHandler::canBeCut_(const Ufe::SceneItem::Ptr& item) +{ + auto usdItem = std::dynamic_pointer_cast(item); + if (!usdItem) + return false; + + const auto prim = usdItem->prim(); + if (!prim) + return false; + + const auto primParent = prim.GetParent(); + if (!primParent) + return false; + + // Special cut conditions that only applies to UsdShadeNodeGraph and UsdShadeShader. + if (PXR_NS::UsdShadeNodeGraph(prim) || PXR_NS::UsdShadeShader(prim)) { + const auto primAttrs = prim.GetAuthoredAttributes(); + for (const auto& attr : primAttrs) { + const auto kBaseNameAndType + = PXR_NS::UsdShadeUtils::GetBaseNameAndType(PXR_NS::TfToken(attr.GetName())); + + if (kBaseNameAndType.second != PXR_NS::UsdShadeAttributeType::Output + && kBaseNameAndType.second != PXR_NS::UsdShadeAttributeType::Input) { + continue; + } + + if (kBaseNameAndType.second == PXR_NS::UsdShadeAttributeType::Input) { + // The attribute could be a destination for connected sources, so check for its + // connections. + PXR_NS::UsdShadeSourceInfoVector sourcesInfo + = pxr::UsdShadeConnectableAPI::GetConnectedSources(attr); + + if (!sourcesInfo.empty()) { + return false; + } + } + + if (kBaseNameAndType.second == PXR_NS::UsdShadeAttributeType::Output) { + // The attribute could be a source connection, we have to explore the siblings. + for (auto&& child : primParent.GetChildren()) { + if (child == prim) { + continue; + } + + for (const auto& otherAttr : child.GetAttributes()) { + const auto childAttrBaseNameAndType + = PXR_NS::UsdShadeUtils::GetBaseNameAndType( + PXR_NS::TfToken(otherAttr.GetName())); + + if (childAttrBaseNameAndType.second == PXR_NS::UsdShadeAttributeType::Input + && isAttributeConnected(attr, otherAttr)) { } + return false; + } + } + } + + // Check also if there are connections to the parent. + for (const auto& otherAttr : primParent.GetAttributes()) { + const auto parentAttrBaseNameAndType = PXR_NS::UsdShadeUtils::GetBaseNameAndType( + PXR_NS::TfToken(otherAttr.GetName())); + + if (parentAttrBaseNameAndType.second == PXR_NS::UsdShadeAttributeType::Output + && isAttributeConnected(attr, otherAttr)) { + return false; + } + } + } + + // If there are no connections, then the item can be cut. + return true; + } + + try { + enforceMutedLayer(prim, "remove"); + } catch (const std::runtime_error&) { + return false; + } + + if (!applyCommandRestrictionNoThrow(prim, "delete")) { + return false; + } + + return true; +} + +void UsdClipboardHandler::preCopy_() { _clipboard->cleanClipboard(); } + +void UsdClipboardHandler::preCut_() { _clipboard->cleanClipboard(); } + +bool UsdClipboardHandler::hasItemToPaste(HasItemToPasteTestFn testFn) +{ + if (const auto& clipboardStage = _clipboard->getClipboardData()) { + for (const auto& prim : clipboardStage->Traverse()) { + // Consider only the first-level in depth items. + if (prim && prim.GetParent() == clipboardStage->GetPseudoRoot() && testFn(prim)) { + return true; + } + } + } + + return false; +} + +void UsdClipboardHandler::setClipboardFilePath(const std::string& clipboardPath) +{ + _clipboard->setClipboardFilePath(clipboardPath); +} + +void UsdClipboardHandler::setClipboardFileFormat(const std::string& formatTag) +{ + _clipboard->setClipboardFileFormat(formatTag); +} + +} // namespace USDUFE_NS_DEF diff --git a/lib/usdUfe/ufe/UsdClipboardHandler.h b/lib/usdUfe/ufe/UsdClipboardHandler.h new file mode 100644 index 0000000000..2152bae6f3 --- /dev/null +++ b/lib/usdUfe/ufe/UsdClipboardHandler.h @@ -0,0 +1,72 @@ +#ifndef USDCLIPBOARDHANDLER_H +#define USDCLIPBOARDHANDLER_H + +// +// Copyright 2024 Autodesk +// +// 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 + +#include + +namespace USDUFE_NS_DEF { + +//! \brief Implementation of Ufe::ClipboardHandler interface for USD objects. +class USDUFE_PUBLIC UsdClipboardHandler : public Ufe::ClipboardHandler +{ +public: + using Ptr = std::shared_ptr; + + UsdClipboardHandler(); + + // Delete the copy/move constructors assignment operators. + UsdClipboardHandler(const UsdClipboardHandler&) = delete; + UsdClipboardHandler& operator=(const UsdClipboardHandler&) = delete; + UsdClipboardHandler(UsdClipboardHandler&&) = delete; + UsdClipboardHandler& operator=(UsdClipboardHandler&&) = delete; + + //! Create a UsdClipboardHandler. + static UsdClipboardHandler::Ptr create(); + + // Ufe::ClipboardHandler overrides + Ufe::UndoableCommand::Ptr cutCmd_(const Ufe::Selection& selection) override; + Ufe::UndoableCommand::Ptr copyCmd_(const Ufe::Selection& selection) override; + Ufe::PasteClipboardCommand::Ptr pasteCmd_(const Ufe::SceneItem::Ptr& parentItem) override; + Ufe::UndoableCommand::Ptr pasteCmd_(const Ufe::Selection& parentItems) override; + bool hasItemsToPaste_() override; + bool canBeCut_(const Ufe::SceneItem::Ptr& item) override; + void preCopy_() override; + void preCut_() override; + + // Helper functions + typedef bool (*HasItemToPasteTestFn)(const PXR_NS::UsdPrim& prim); + bool hasItemToPaste(HasItemToPasteTestFn testFn); + + //! Sets the absolute path (with filename) for saving clipboard data to. + void setClipboardFilePath(const std::string& clipboardPath); + + //! Sets the USD file format for the clipboard file. + //! \param[in] formatTag USD file format to save. Must be either "usda" or "usdc". + void setClipboardFileFormat(const std::string& formatTag); + +private: + UsdClipboard::Ptr _clipboard; + +}; // UsdClipboardHandler + +} // namespace USDUFE_NS_DEF + +#endif // USDCLIPBOARDHANDLER_H diff --git a/lib/usdUfe/ufe/UsdUndoDuplicateCommand.cpp b/lib/usdUfe/ufe/UsdUndoDuplicateCommand.cpp new file mode 100644 index 0000000000..80feea203c --- /dev/null +++ b/lib/usdUfe/ufe/UsdUndoDuplicateCommand.cpp @@ -0,0 +1,159 @@ +// +// Copyright 2024 Autodesk +// +// 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 "UsdUndoDuplicateCommand.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace USDUFE_NS_DEF { + +// Ensure that UsdUndoDuplicateCommand is properly setup. +static_assert(std::is_base_of::value); +static_assert(std::has_virtual_destructor::value); +static_assert(!std::is_copy_constructible::value); +static_assert(!std::is_copy_assignable::value); +static_assert(!std::is_move_constructible::value); +static_assert(!std::is_move_assignable::value); + +namespace { + +// Local ufePathToPrim that uses input stage instead of getStage function. +UsdPrim ufePathToPrim(const Ufe::Path& path, const PXR_NS::UsdStageWeakPtr& stage) +{ + if (!stage) + return {}; + + const Ufe::Path ufePrimPath = stripInstanceIndexFromUfePath(path); + const Ufe::Path::Segments& segments = ufePrimPath.getSegments(); + if (segments.empty()) + return {}; + + // Anonymous layer. + if (path.string().at(0) == '/') { + return stage->GetPrimAtPath(SdfPath(path.string()).GetPrimPath()); + } + + // If there is only a single segment in the path, it must point to the + // proxy shape, otherwise we would not have retrieved a valid stage. + // The second path segment is the USD path. + return (segments.size() == 1U) + ? stage->GetPseudoRoot() + : stage->GetPrimAtPath(SdfPath(segments[1].string()).GetPrimPath()); +} + +} // namespace + +UsdUndoDuplicateCommand::UsdUndoDuplicateCommand( + const UsdSceneItem::Ptr& srcItem, + const UsdSceneItem::Ptr& dstParentItem) + : _ufeDstPath(dstParentItem->path()) + , _ufeSrcPath(srcItem->path()) + , _dstStage(dstParentItem->prim().GetStage()) + , _srcStage(srcItem->prim().GetStage()) +{ + auto srcPrim = srcItem->prim(); + auto newName = uniqueChildName(dstParentItem->prim(), srcPrim.GetName()); + _usdDstPath = dstParentItem->prim().GetPath().AppendChild(TfToken(newName)); +} + +UsdUndoDuplicateCommand::Ptr UsdUndoDuplicateCommand::create( + const UsdSceneItem::Ptr& srcItem, + const UsdSceneItem::Ptr& dstParentItem) +{ + return std::make_shared(srcItem, dstParentItem); +} +UsdSceneItem::Ptr UsdUndoDuplicateCommand::duplicatedItem() const +{ + Ufe::Path ufeSrcPath; + + if (!_ufeDstPath.getSegments().empty()) { + ufeSrcPath = appendToPath(_ufeDstPath, _usdDstPath.GetElementString()); + } else { + // Temporary USD stage case. + const auto ufePathAsString = "/" + _usdDstPath.GetElementString(); + ufeSrcPath = Ufe::PathSegment(ufePathAsString, getUsdRunTimeId(), '/'); + } + + UsdPrim prim = ufePathToPrim(ufeSrcPath, _dstStage); + return UsdSceneItem::create(ufeSrcPath, prim); +} + +void UsdUndoDuplicateCommand::execute() +{ + UsdUndoBlock undoBlock(&_undoableItem); + + UsdPrim prim = ufePathToPrim(_ufeSrcPath, _srcStage); + + auto path = prim.GetPath(); + auto stage = prim.GetStage(); + + OperationEditRouterContext ctx(EditRoutingTokens->RouteDuplicate, prim); + + // The loaded state of a model is controlled by the load rules of the stage. + // When duplicating a node, we want the new node to be in the same loaded + // state. + duplicateLoadRules(*stage, path, _usdDstPath); + + const auto dstLayer = _dstStage->GetEditTarget().GetLayer(); + + // Make sure all necessary parent exists in the target layer, at least as over, + // otherwise SdfCopySepc will fail. + SdfJustCreatePrimInLayer(dstLayer, _usdDstPath.GetParentPath()); + + // Retrieve the local layers around where the prim is defined and order them + // from weak to strong. That weak-to-strong order allows us to copy the weakest + // opinions first, so that they will get over-written by the stronger opinions. + SdfPrimSpecHandleVector authLayerAndPaths = getDefiningPrimStack(prim); + std::reverse(authLayerAndPaths.begin(), authLayerAndPaths.end()); + + bool isFirst = true; + + for (const SdfPrimSpecHandle& layerAndPath : authLayerAndPaths) { + const auto layer = layerAndPath->GetLayer(); + const auto localPath = layerAndPath->GetPath(); + const bool result = isFirst + ? SdfCopySpec(layer, localPath, dstLayer, _usdDstPath) + : UsdUfe::mergePrims(stage, layer, localPath, _dstStage, dstLayer, _usdDstPath); + + TF_VERIFY( + result, + "Failed to copy the USD prim at '%s' in layer '%s' to '%s'", + localPath.GetText(), + layer->GetDisplayName().c_str(), + _usdDstPath.GetText()); + + isFirst = false; + } +} + +void UsdUndoDuplicateCommand::undo() { _undoableItem.undo(); } + +void UsdUndoDuplicateCommand::redo() { _undoableItem.redo(); } + +} // namespace USDUFE_NS_DEF diff --git a/lib/usdUfe/ufe/UsdUndoDuplicateCommand.h b/lib/usdUfe/ufe/UsdUndoDuplicateCommand.h new file mode 100644 index 0000000000..a333e75e91 --- /dev/null +++ b/lib/usdUfe/ufe/UsdUndoDuplicateCommand.h @@ -0,0 +1,68 @@ +// +// Copyright 2024 Autodesk +// +// 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. +// +#ifndef USDUFE_USDUNDODUPLICATECOMMAND_H +#define USDUFE_USDUNDODUPLICATECOMMAND_H + +#include +#include +#include + +#include + +#include +#include + +namespace USDUFE_NS_DEF { + +//! \brief UsdUndoDuplicateCommand +class USDUFE_PUBLIC UsdUndoDuplicateCommand : public Ufe::SceneItemResultUndoableCommand +{ +public: + using Ptr = std::shared_ptr; + + UsdUndoDuplicateCommand( + const UsdSceneItem::Ptr& srcItem, + const UsdSceneItem::Ptr& dstParentItem); + + // Delete the copy/move constructors assignment operators. + UsdUndoDuplicateCommand(const UsdUndoDuplicateCommand&) = delete; + UsdUndoDuplicateCommand& operator=(const UsdUndoDuplicateCommand&) = delete; + UsdUndoDuplicateCommand(UsdUndoDuplicateCommand&&) = delete; + UsdUndoDuplicateCommand& operator=(UsdUndoDuplicateCommand&&) = delete; + + //! Create a UsdUndoDuplicateCommand from a SceneItem and its parent destination. + static Ptr create(const UsdSceneItem::Ptr& srcItem, const UsdSceneItem::Ptr& dstParentItem); + + UsdSceneItem::Ptr duplicatedItem() const; + Ufe::SceneItem::Ptr sceneItem() const override { return duplicatedItem(); }; + + void execute() override; + void undo() override; + void redo() override; + +private: + UsdUndoableItem _undoableItem; + + Ufe::Path _ufeDstPath; + Ufe::Path _ufeSrcPath; + PXR_NS::SdfPath _usdDstPath; + PXR_NS::UsdStageWeakPtr _dstStage; + PXR_NS::UsdStageWeakPtr _srcStage; +}; // UsdUndoDuplicateCommand + +} // namespace USDUFE_NS_DEF + +#endif // USDUFE_USDUNDODUPLICATECOMMAND_H diff --git a/lib/usdUfe/ufe/UsdUndoDuplicateSelectionCommand.cpp b/lib/usdUfe/ufe/UsdUndoDuplicateSelectionCommand.cpp new file mode 100644 index 0000000000..b55778216c --- /dev/null +++ b/lib/usdUfe/ufe/UsdUndoDuplicateSelectionCommand.cpp @@ -0,0 +1,212 @@ +// +// Copyright 2024 Autodesk +// +// 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 "UsdUndoDuplicateSelectionCommand.h" + +#include +#include +#include + +namespace USDUFE_NS_DEF { + +// Ensure that UsdUndoDuplicateSelectionCommand is properly setup. +static_assert(std::is_base_of::value); +static_assert(std::has_virtual_destructor::value); +static_assert(!std::is_copy_constructible::value); +static_assert(!std::is_copy_assignable::value); +static_assert(!std::is_move_constructible::value); +static_assert(!std::is_move_assignable::value); + +UsdUndoDuplicateSelectionCommand::UsdUndoDuplicateSelectionCommand( + const Ufe::Selection& selection, + const UsdSceneItem::Ptr& dstParentItem) + : _dstParentItem(dstParentItem) +{ + _sourceItems.reserve(selection.size()); + for (auto&& item : selection) { + if (selection.containsAncestor(item->path())) { + // MAYA-125854: Skip the descendant, it will get duplicated with the ancestor. + continue; + } + UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast(item); + if (!usdItem) { + continue; + } + _sourceItems.push_back(usdItem); + } +} + +UsdUndoDuplicateSelectionCommand::Ptr UsdUndoDuplicateSelectionCommand::create( + const Ufe::Selection& selection, + const UsdSceneItem::Ptr& dstParentItem) +{ + UsdUndoDuplicateSelectionCommand::Ptr retVal + = std::make_shared(selection, dstParentItem); + + if (retVal->_sourceItems.empty() || !dstParentItem) { + return {}; + } + + return retVal; +} + +void UsdUndoDuplicateSelectionCommand::execute() +{ + UsdUndoBlock undoBlock(&_undoableItem); + + for (auto&& usdItem : _sourceItems) { + auto duplicateCmd = UsdUndoDuplicateCommand::create(usdItem, _dstParentItem); + duplicateCmd->execute(); + + _duplicatedItemsMap.emplace( + usdItem, std::dynamic_pointer_cast(duplicateCmd->sceneItem())); + + PXR_NS::UsdPrim srcPrim = usdItem->prim(); + PXR_NS::UsdPrim dstPrim = duplicateCmd->duplicatedItem()->prim(); + + Ufe::Path stgPath = stagePath(dstPrim.GetStage()); + auto stageIt = _duplicatesMap.find(stgPath); + if (stageIt == _duplicatesMap.end()) { + stageIt = _duplicatesMap.insert({ stgPath, DuplicatePathsMap() }).first; + } + + auto stageMapIt = _stagesMap.find(stgPath); + if (stageMapIt == _stagesMap.end()) { + stageMapIt = _stagesMap.insert({ stgPath, dstPrim.GetStage() }).first; + } + + stageIt->second.insert({ srcPrim.GetPath(), dstPrim.GetPath() }); + } + + // Fixups were grouped by stage. + for (const auto& stageData : _duplicatesMap) { + PXR_NS::UsdStageWeakPtr stage; + + auto stageIt = _stagesMap.find(stageData.first); + if (stageIt != _stagesMap.end()) { + stage = stageIt->second; + } + + if (!stage) + continue; + + for (const auto& duplicatePair : stageData.second) { + // Cleanup relationships and connections on the duplicate. + + // Update the connections and the relationships only the first level, in fact, + // SdfCopySpec will remap to target objects beneath \p dstPath: attribute connections, + // relationship targets, inherit and specializes paths, and internal sub-root references + // that target an object beneath \p srcPath + auto p = stage->GetPrimAtPath(duplicatePair.second); + + if (PXR_NS::UsdShadeMaterial(p)) + continue; + + for (auto& prop : p.GetProperties()) { + if (prop.Is()) { + PXR_NS::UsdAttribute attr = prop.As(); + PXR_NS::SdfPathVector sources; + attr.GetConnections(&sources); + if (updateSdfPathVector(sources, duplicatePair, stageData.second)) { + if (sources.empty()) { + attr.ClearConnections(); + if (!attr.HasValue() && !UsdShadeNodeGraph(attr.GetPrim())) { + p.RemoveProperty(prop.GetName()); + } + } else { + attr.SetConnections(sources); + } + } + } else if (prop.Is()) { + PXR_NS::UsdRelationship rel = prop.As(); + PXR_NS::SdfPathVector targets; + rel.GetTargets(&targets); + // Currently always copying external relationships is the right move since + // duplicated geometries will keep their currently assigned material. We + // might need a case by case basis later as we deal with more complex + // relationships. + if (updateSdfPathVector(targets, duplicatePair, stageData.second)) { + if (targets.empty()) { + rel.ClearTargets(true); + } else { + rel.SetTargets(targets); + } + } + } + } + } + } +} + +Ufe::SceneItemList UsdUndoDuplicateSelectionCommand::targetItems() const +{ + Ufe::SceneItemList targetItems; + for (const auto& duplicatedItem : _duplicatedItemsMap) { + targetItems.push_back(duplicatedItem.second); + } + + return targetItems; +} + +bool UsdUndoDuplicateSelectionCommand::updateSdfPathVector( + PXR_NS::SdfPathVector& pathVec, + const DuplicatePathsMap::value_type& duplicatePair, + const DuplicatePathsMap& otherPairs) +{ + bool hasChanged = false; + std::list indicesToRemove; + for (size_t i = 0; i < pathVec.size(); ++i) { + const PXR_NS::SdfPath& path = pathVec[i]; + PXR_NS::SdfPath finalPath = path; + // Paths are lexicographically ordered, this means we can search quickly for bounds of + // candidate paths. + auto itPath = otherPairs.lower_bound(finalPath); + if (itPath != otherPairs.begin()) { + --itPath; + } + const auto endPath = otherPairs.upper_bound(finalPath); + bool isExternalPath = true; + for (; itPath != endPath; ++itPath) { + if (*itPath == duplicatePair) { + // That one was correctly processed by USD when duplicating. + isExternalPath + = !finalPath.HasPrefix(itPath->first) && !finalPath.HasPrefix(itPath->second); + continue; + } + finalPath = finalPath.ReplacePrefix(itPath->first, itPath->second); + if (path != finalPath) { + pathVec[i] = finalPath; + hasChanged = true; + isExternalPath = false; + break; + } + } + if (isExternalPath) { + hasChanged = true; + indicesToRemove.push_front(i); + } + } + for (size_t toRemove : indicesToRemove) { + pathVec.erase(pathVec.cbegin() + toRemove); + } + return hasChanged; +} + +void UsdUndoDuplicateSelectionCommand::undo() { _undoableItem.undo(); } + +void UsdUndoDuplicateSelectionCommand::redo() { _undoableItem.redo(); } + +} // namespace USDUFE_NS_DEF diff --git a/lib/usdUfe/ufe/UsdUndoDuplicateSelectionCommand.h b/lib/usdUfe/ufe/UsdUndoDuplicateSelectionCommand.h new file mode 100644 index 0000000000..8e346db29a --- /dev/null +++ b/lib/usdUfe/ufe/UsdUndoDuplicateSelectionCommand.h @@ -0,0 +1,95 @@ +// +// Copyright 2024 Autodesk +// +// 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. +// +#ifndef USDUFE_USDUNDODUPLICATESELECTIONCOMMAND_H +#define USDUFE_USDUNDODUPLICATESELECTIONCOMMAND_H + +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include + +namespace USDUFE_NS_DEF { + +using DuplicatedItemsMap = std::unordered_map; + +//! \brief UsdUndoDuplicateSelectionCommand +class USDUFE_PUBLIC UsdUndoDuplicateSelectionCommand : public Ufe::UndoableCommand +{ +public: + using Ptr = std::shared_ptr; + + UsdUndoDuplicateSelectionCommand( + const Ufe::Selection& selection, + const UsdSceneItem::Ptr& dstParentItem); + + // Delete the copy/move constructors assignment operators. + UsdUndoDuplicateSelectionCommand(const UsdUndoDuplicateSelectionCommand&) = delete; + UsdUndoDuplicateSelectionCommand& operator=(const UsdUndoDuplicateSelectionCommand&) = delete; + UsdUndoDuplicateSelectionCommand(UsdUndoDuplicateSelectionCommand&&) = delete; + UsdUndoDuplicateSelectionCommand& operator=(UsdUndoDuplicateSelectionCommand&&) = delete; + + //! Create a UsdUndoDuplicateSelectionCommand from a Ufe Selection and its parent destination. + static Ptr create(const Ufe::Selection& selection, const UsdSceneItem::Ptr& dstParentItem); + + void execute() override; + void undo() override; + void redo() override; + + //! Retrieve all the duplicated items. + Ufe::SceneItemList targetItems() const; + + DuplicatedItemsMap getDuplicatedItemsMap() const { return _duplicatedItemsMap; } + +private: + UsdUndoableItem _undoableItem; + + // Transient list of items to duplicate. Needed by execute. + std::vector _sourceItems; + + // Fixup data: + using DuplicatePathsMap = std::map; + using DuplicatesMap = std::unordered_map; + DuplicatesMap _duplicatesMap; + + // Needed for temporary USD stages. + using DstStagesMap = std::unordered_map; + DstStagesMap _stagesMap; + + bool updateSdfPathVector( + PXR_NS::SdfPathVector& pathVec, + const DuplicatePathsMap::value_type& duplicatePair, + const DuplicatePathsMap& otherPairs); + + // Convenience map to have a map between the source item and the duplicated one. + DuplicatedItemsMap _duplicatedItemsMap; + + // The parent item target destination. + UsdSceneItem::Ptr _dstParentItem; + +}; // UsdUndoDuplicateSelectionCommand + +} // namespace USDUFE_NS_DEF + +#endif // USDUFE_USDUNDODUPLICATESELECTIONCOMMAND_H diff --git a/plugin/adsk/scripts/mayaUsd_preferenceTab.mel b/plugin/adsk/scripts/mayaUsd_preferenceTab.mel index 49644a2aa8..c143226077 100644 --- a/plugin/adsk/scripts/mayaUsd_preferenceTab.mel +++ b/plugin/adsk/scripts/mayaUsd_preferenceTab.mel @@ -34,8 +34,8 @@ global proc mayaUsd_PrefSaveMayaSceneFilesChanged() global proc mayaUsd_PrefFileFormatChanged() { + string $saveLayerFormatArgBinaryOptionPref = `python("import mayaUsd.lib as mlib; mlib.OptionVarTokens.SaveLayerFormatArgBinaryOption")`; if (`radioButtonGrp -exists usdPrefSaveFileFormat`) { - string $saveLayerFormatArgBinaryOptionPref = `python("import mayaUsd.lib as mlib; mlib.OptionVarTokens.SaveLayerFormatArgBinaryOption")`; int $sel = `radioButtonGrp -q -select usdPrefSaveFileFormat`; optionVar -iv $saveLayerFormatArgBinaryOptionPref ($sel == 1); // Button 1 is binary } @@ -44,6 +44,14 @@ global proc mayaUsd_PrefFileFormatChanged() int $v = `checkBoxGrp -q -v1 usdPrefConfirmExistFileSave`; optionVar -iv $confirmExistingFileSaveOptionPref $v; } + + // Update the clipboard file format to match the format here. + + if (`optionVar -exists $saveLayerFormatArgBinaryOptionPref`) { + int $isBinary = `optionVar -q $saveLayerFormatArgBinaryOptionPref`; + string $formatTag = $isBinary ? "usdc" : "usda"; + python("import mayaUsd.ufe as mufe; mufe.setClipboardFileFormat('" + $formatTag + "')"); + } } global proc mayaUsd_PrefAllRelative(int $v) diff --git a/test/lib/ufe/CMakeLists.txt b/test/lib/ufe/CMakeLists.txt index 39c820567d..5f7d8c84d6 100644 --- a/test/lib/ufe/CMakeLists.txt +++ b/test/lib/ufe/CMakeLists.txt @@ -101,6 +101,13 @@ if (UFE_MATERIALS_SUPPORT) testMaterial.py ) endif() + +if (UFE_CLIPBOARD_SUPPORT) + list(APPEND TEST_SCRIPT_FILES + testClipboard.py + ) +endif() + if (MAYA_API_VERSION VERSION_GREATER_EQUAL 20220100) list(APPEND TEST_SCRIPT_FILES testCamera.py diff --git a/test/lib/ufe/testClipboard.py b/test/lib/ufe/testClipboard.py new file mode 100644 index 0000000000..cd8e6fcd10 --- /dev/null +++ b/test/lib/ufe/testClipboard.py @@ -0,0 +1,288 @@ +#!/usr/bin/env python + +# +# Copyright 2024 Autodesk +# +# 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. +# + +import fixturesUtils +import mayaUtils +import ufeUtils, usdUtils, mayaUtils +import mayaUsd +import mayaUsd_createStageWithNewLayer + +from maya import standalone + +import ufe + +import unittest + + +class ClipboardHandlerTestCase(unittest.TestCase): + '''Verify ClipboardHandler interface.''' + + pluginsLoaded = False + + @classmethod + def setUpClass(cls): + fixturesUtils.readOnlySetUpClass(__file__, loadPlugin=False) + + if not cls.pluginsLoaded: + cls.pluginsLoaded = mayaUtils.isMayaUsdPluginLoaded() + + @classmethod + def tearDownClass(cls): + standalone.uninitialize() + + def setUp(self): + ''' Called initially to set up the maya test environment ''' + self.assertTrue(self.pluginsLoaded) + + def testClipboardCopyPaste(self): + '''Basic test for the Clipboard copy/paste support.''' + + psPathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer() + stage = mayaUsd.lib.GetPrim(psPathStr).GetStage() + stage.DefinePrim('/Xform1', 'Xform') + stage.DefinePrim('/Xform1/Sphere1', 'Sphere') + + xformItem = ufeUtils.createItem(psPathStr + ',/Xform1') + sphereItem = ufeUtils.createItem(psPathStr + ',/Xform1/Sphere1') + self.assertIsNotNone(xformItem) + self.assertIsNotNone(sphereItem) + + xformHier = ufe.Hierarchy.hierarchy(xformItem) + self.assertIsNotNone(xformHier) + + # Verify that we have a clipboard handler for USD runtime. + ch = ufe.ClipboardHandler.clipboardHandler(sphereItem.runTimeId()) + self.assertIsNotNone(ch) + + # Store how many children the Xform1 currently has (should be 1). + nbChildren = len(xformHier.children()) + + # Initialize the clipboard copy. + ufe.ClipboardHandler.preCopy() + + # We should not have any items to paste now. + self.assertFalse(ch.hasItemsToPaste_()) + + # Copy the sphere item and test that we have an item to paste. + copyCmd = ch.copyCmd_(sphereItem) + self.assertIsNotNone(copyCmd) + copyCmd.execute() + self.assertTrue(ch.hasItemsToPaste_()) + + # We should still have the sphere item. + copiedSphereItem = ufeUtils.createItem(psPathStr + ',/Xform1/Sphere1') + self.assertIsNotNone(copiedSphereItem) + + # Paste (sphere from copy) into the xform1, it will get renamed + # to Sphere1. The Xform1 parent should have one more child. + pasteCmd = ch.pasteCmd_(xformItem) + self.assertIsNotNone(pasteCmd) + pasteCmd.execute() + self.assertEqual(nbChildren+1, len(xformHier.children())) + pastedSphereItem = ufeUtils.createItem(psPathStr + ',/Xform1/Sphere2') + self.assertIsNotNone(pastedSphereItem) + + # Verify that we have the correct pasted item in the paste command. + pastedItems = pasteCmd.targetItems() + self.assertIsNotNone(pastedItems) + self.assertEqual(1, len(pastedItems)) + pastedTargetSphere = pastedItems[0] + self.assertEqual(pastedSphereItem, pastedTargetSphere) + + # Verify that the paste succeeded and no items failed. + pasteInfo = pasteCmd.getPasteInfos() + self.assertIsNotNone(pasteInfo) + # The paste target should be the parent item (Xform1) we pasted into. + self.assertEqual(xformItem.path(), pasteInfo[0].pasteTarget) + # The successful pasted item should be the single pasted target from above + self.assertEqual(1, len(pasteInfo[0].successfulPastes)) + self.assertEqual(pastedSphereItem.path(), pasteInfo[0].successfulPastes[0]) + # No paste failures. + self.assertEqual(0, len(pasteInfo[0].failedPastes)) + + # Undo the paste, copied sphere item should be gone and child count + # should be back to original. + pasteCmd.undo() + self.assertEqual(nbChildren, len(xformHier.children())) + pastedSphereItem = ufeUtils.createItem(psPathStr + ',/Xform1/Sphere2') + self.assertIsNone(pastedSphereItem) + + # Redo the paste, pasted sphere will be back and child count should increase + # by 1 again. + pasteCmd.redo() + self.assertEqual(nbChildren+1, len(xformHier.children())) + pastedSphereItem = ufeUtils.createItem(psPathStr + ',/Xform1/Sphere2') + self.assertIsNotNone(pastedSphereItem) + + def testClipboardCutPaste(self): + '''Basic test for the Clipboard cut/paste support.''' + + psPathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer() + stage = mayaUsd.lib.GetPrim(psPathStr).GetStage() + stage.DefinePrim('/Xform1', 'Xform') + stage.DefinePrim('/Xform1/Sphere1', 'Sphere') + + xformItem = ufeUtils.createItem(psPathStr + ',/Xform1') + sphereItem = ufeUtils.createItem(psPathStr + ',/Xform1/Sphere1') + self.assertIsNotNone(xformItem) + self.assertIsNotNone(sphereItem) + + xformHier = ufe.Hierarchy.hierarchy(xformItem) + self.assertIsNotNone(xformHier) + + # Verify that we have a clipboard handler for USD runtime. + ch = ufe.ClipboardHandler.clipboardHandler(sphereItem.runTimeId()) + self.assertIsNotNone(ch) + + # Store how many children the Xform1 currently has (should be 1). + nbChildren = len(xformHier.children()) + + # Initialize the clipboard cut. + ufe.ClipboardHandler.preCut() + + # We should not have any items to paste now. + self.assertFalse(ch.hasItemsToPaste_()) + + # We should be able to cut the sphere. + self.assertTrue(ch.canBeCut_(sphereItem)) + + # Cut the sphere item and test that we have an item to paste. + cutCmd = ch.cutCmd_(sphereItem) + self.assertIsNotNone(cutCmd) + cutCmd.execute() + self.assertTrue(ch.hasItemsToPaste_()) + + # We should no longer have the sphere item and the parent xform + # should have 1 less child + self.assertEqual(0, len(xformHier.children())) + cutSphereItem = ufeUtils.createItem(psPathStr + ',/Xform1/Sphere1') + self.assertIsNone(cutSphereItem) + + # Undo the cut, which will bring back the sphere. + cutCmd.undo() + cutSphereItem = ufeUtils.createItem(psPathStr + ',/Xform1/Sphere1') + self.assertIsNotNone(cutSphereItem) + + # And redo the cut which means the sphere will be gone again. + cutCmd.redo() + cutSphereItem = ufeUtils.createItem(psPathStr + ',/Xform1/Sphere1') + self.assertIsNone(cutSphereItem) + + # Paste (sphere from cut) into the xform1, it should retain the + # same name. The Xform1 parent should have the same number of children. + xformItem = ufeUtils.createItem(psPathStr + ',/Xform1') + self.assertIsNotNone(xformItem) + pasteCmd = ch.pasteCmd_(xformItem) + self.assertIsNotNone(pasteCmd) + pasteCmd.execute() + self.assertEqual(nbChildren, len(xformHier.children())) + pastedSphereItem = ufeUtils.createItem(psPathStr + ',/Xform1/Sphere1') + self.assertIsNotNone(pastedSphereItem) + + # Verify that we have the correct pasted item in the paste command. + pastedItems = pasteCmd.targetItems() + self.assertIsNotNone(pastedItems) + self.assertEqual(1, len(pastedItems)) + pastedTargetSphere = pastedItems[0] + self.assertEqual(pastedSphereItem, pastedTargetSphere) + + # Verify that the paste succeeded and no items failed. + pasteInfo = pasteCmd.getPasteInfos() + self.assertIsNotNone(pasteInfo) + # The paste target should be the parent item (Xform1) we pasted into. + self.assertEqual(xformItem.path(), pasteInfo[0].pasteTarget) + # The successful pasted item should be the single pasted target from above + self.assertEqual(1, len(pasteInfo[0].successfulPastes)) + self.assertEqual(pastedSphereItem.path(), pasteInfo[0].successfulPastes[0]) + # No paste failures. + self.assertEqual(0, len(pasteInfo[0].failedPastes)) + + # Undo the paste, sphere item should be gone and the child count + # should be back down by 1. + pasteCmd.undo() + self.assertEqual(0, len(xformHier.children())) + pastedSphereItem = ufeUtils.createItem(psPathStr + ',/Xform1/Sphere1') + self.assertIsNone(pastedSphereItem) + + # Redo the paste, sphere will be back and child count should be + # back to original. + pasteCmd.redo() + self.assertEqual(nbChildren, len(xformHier.children())) + pastedSphereItem = ufeUtils.createItem(psPathStr + ',/Xform1/Sphere1') + self.assertIsNotNone(pastedSphereItem) + + def testClipboardCopyPasteWithVariant(self): + '''Basic test for the Clipboard copy/paste of prim with a variant.''' + + # Open Variant.ma scene in testSamples + mayaUtils.openVariantSetScene() + + # Get the stage + mayaPathSegment = mayaUtils.createUfePathSegment('|Variant_usd|Variant_usdShape') + stage = mayaUsd.ufe.getStage(str(mayaPathSegment)) + + # First check that we have a Variant. + objectPrim = stage.GetPrimAtPath('/objects') + self.assertTrue(objectPrim.HasVariantSets()) + + # Get the VariantSets for the object prim. + objectVariantSet = objectPrim.GetVariantSets() + self.assertIsNotNone(objectVariantSet) + + # Get clipboard handler for object prim. + objectItem = ufeUtils.createItem('|Variant_usd|Variant_usdShape,/objects') + self.assertIsNotNone(objectItem) + ch = ufe.ClipboardHandler.clipboardHandler(objectItem.runTimeId()) + self.assertIsNotNone(ch) + + # Create a prim to paste into. + stage.DefinePrim('/Xform1', 'Xform') + xformItem = ufeUtils.createItem('|Variant_usd|Variant_usdShape,/Xform1') + self.assertIsNotNone(xformItem) + + # Initialize the clipboard copy. + ufe.ClipboardHandler.preCopy() + + # We should not have any items to paste now. + self.assertFalse(ch.hasItemsToPaste_()) + + # Copy the ojbect and paste it to the xform. + copyCmd = ch.copyCmd_(objectItem) + self.assertIsNotNone(copyCmd) + copyCmd.execute() + self.assertTrue(ch.hasItemsToPaste_()) + + # Paste (object from copy) into the xform1. + pasteCmd = ch.pasteCmd_(xformItem) + self.assertIsNotNone(pasteCmd) + pasteCmd.execute() + pastedObjectItem = ufeUtils.createItem('|Variant_usd|Variant_usdShape,/Xform1/objects') + self.assertIsNotNone(pastedObjectItem) + + # The pasted object should have the same variant sets as the original. + pastedPrim = usdUtils.getPrimFromSceneItem(pastedObjectItem) + self.assertIsNotNone(pastedPrim) + pastedVariantSet = pastedPrim.GetVariantSets() + self.assertIsNotNone(pastedVariantSet) + self.assertEqual(objectVariantSet.GetNames(), pastedVariantSet.GetNames()) + for name in objectVariantSet.GetNames(): + self.assertTrue(pastedVariantSet.HasVariantSet(name)) + self.assertEqual(objectVariantSet.GetVariantSelection(name), pastedVariantSet.GetVariantSelection(name)) + +if __name__ == '__main__': + unittest.main(verbosity=2) From a2c23a371f393919e27705be49b5efc826ff2441 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Tue, 19 Mar 2024 15:42:03 -0400 Subject: [PATCH 04/19] EMSUSD-128 - [GitHub #2181] Implement Copy\paste capabilities on USD Data * code review comments --- lib/usdUfe/ufe/UsdClipboard.cpp | 14 ++------------ lib/usdUfe/ufe/UsdClipboard.h | 3 +-- lib/usdUfe/ufe/UsdClipboardCommands.cpp | 15 +++++++++++++-- lib/usdUfe/ufe/UsdClipboardHandler.cpp | 7 ++++--- lib/usdUfe/ufe/UsdClipboardHandler.h | 11 ++++++++++- lib/usdUfe/ufe/UsdUndoAddNewPrimCommand.cpp | 6 +++--- lib/usdUfe/ufe/UsdUndoDuplicateCommand.cpp | 2 +- lib/usdUfe/ufe/Utils.cpp | 17 ++++++++++------- lib/usdUfe/ufe/Utils.h | 2 +- 9 files changed, 45 insertions(+), 32 deletions(-) diff --git a/lib/usdUfe/ufe/UsdClipboard.cpp b/lib/usdUfe/ufe/UsdClipboard.cpp index 040446b769..81541621d6 100644 --- a/lib/usdUfe/ufe/UsdClipboard.cpp +++ b/lib/usdUfe/ufe/UsdClipboard.cpp @@ -101,26 +101,16 @@ void UsdClipboard::setClipboardFileFormat(const std::string& formatTag) void UsdClipboard::cleanClipboard() { - cleanClipboardStageCache(true); + cleanClipboardStageCache(); removeClipboardFile(); } -void UsdClipboard::cleanClipboardStageCache(bool cleanFile) +void UsdClipboard::cleanClipboardStageCache() { // Erase the clipboard stage from the cache. if (_clipboardStageCacheId.IsValid()) { auto clipboardStageRef = PXR_NS::UsdUtilsStageCache::Get().Find(_clipboardStageCacheId); PXR_NS::UsdUtilsStageCache::Get().Erase(clipboardStageRef); - - if (cleanFile && clipboardStageRef && clipboardStageRef->GetRootLayer()) { - // Clean the stage and clipboard file. - // Note: Instead of clearing the file, it might be better to use filenames - // from the stage hash and retain that in a variable or stack. - clipboardStageRef->GetRootLayer()->Clear(); - PXR_NS::SdfFileFormat::FileFormatArguments args; - args["format"] = _clipboardFileFormat; - clipboardStageRef->GetRootLayer()->Export(_clipboardFilePath, "UsdUfe Clipboard", args); - } } } diff --git a/lib/usdUfe/ufe/UsdClipboard.h b/lib/usdUfe/ufe/UsdClipboard.h index e076361793..6a6d5f8e28 100644 --- a/lib/usdUfe/ufe/UsdClipboard.h +++ b/lib/usdUfe/ufe/UsdClipboard.h @@ -80,8 +80,7 @@ class USDUFE_PUBLIC UsdClipboard PXR_NS::UsdStageCache::Id _clipboardStageCacheId; //! \brief Erase the clipboard stage from the cache. - //! \param cleanFile If true, we clean the root layer stage and the clipboard file. - void cleanClipboardStageCache(bool cleanFile = false); + void cleanClipboardStageCache(); //! \brief Remove the clipboard file by deleting it. void removeClipboardFile(); diff --git a/lib/usdUfe/ufe/UsdClipboardCommands.cpp b/lib/usdUfe/ufe/UsdClipboardCommands.cpp index 5a6c9ef312..6e289c90cf 100644 --- a/lib/usdUfe/ufe/UsdClipboardCommands.cpp +++ b/lib/usdUfe/ufe/UsdClipboardCommands.cpp @@ -32,6 +32,17 @@ namespace { +// Metadata used for pasting according to specific rules: +// When we paste a shader under a scope, we first create a new material +// (with the name of the original material) and then paste to it. +// We could paste many shaders all together, and we want to group them +// so that we take into consideration whether they are from the same +// material and stage. +// +// For additional info see: +// https://jira.autodesk.com/browse/LOOKDEVX-1639 +// https://jira.autodesk.com/browse/LOOKDEVX-1722 +// constexpr std::string_view kClipboardMetadata = "ClipboardMetadata"; constexpr std::string_view kMaterialName = "materialName"; constexpr std::string_view kNodeName = "shaderName"; @@ -66,9 +77,8 @@ void setClipboardMetadata(const UsdUndoDuplicateSelectionCommand::Ptr& duplicate const std::string stagePath = duplicatedItem.first->path().popSegment().string(); const std::string nodeName = duplicatedItem.first->nodeName(); - const auto parentMaterial = getParentMaterial(duplicatedItem.first); - // Recursively find the parent material. + const auto parentMaterial = getParentMaterial(duplicatedItem.first); if (parentMaterial) { materialName = parentMaterial->nodeName(); } @@ -160,6 +170,7 @@ Ufe::SceneItemList pasteItemsToNewMaterial(const UsdSceneItem::Ptr& dstItem, Ufe } // Create the new Materials taking into consideration also the stage. + // See metadata description above for rules on pasting. for (const auto& stagesNameMap : stageMaterialNamesMap) { for (const auto& materialNamesMap : stagesNameMap.second) { // Create a material using the name given from the metadata. diff --git a/lib/usdUfe/ufe/UsdClipboardHandler.cpp b/lib/usdUfe/ufe/UsdClipboardHandler.cpp index 46942ab2e8..191af054a4 100644 --- a/lib/usdUfe/ufe/UsdClipboardHandler.cpp +++ b/lib/usdUfe/ufe/UsdClipboardHandler.cpp @@ -133,6 +133,9 @@ bool UsdClipboardHandler::canBeCut_(const Ufe::SceneItem::Ptr& item) } } + // As a constraint for the cut in the Outliner, we want to check if an item is + // connected to other items at the same level of the hierarchy, which is why + // we only check its siblings in this case. if (kBaseNameAndType.second == PXR_NS::UsdShadeAttributeType::Output) { // The attribute could be a source connection, we have to explore the siblings. for (auto&& child : primParent.GetChildren()) { @@ -168,9 +171,7 @@ bool UsdClipboardHandler::canBeCut_(const Ufe::SceneItem::Ptr& item) return true; } - try { - enforceMutedLayer(prim, "remove"); - } catch (const std::runtime_error&) { + if (hasMutedLayer(prim)) { return false; } diff --git a/lib/usdUfe/ufe/UsdClipboardHandler.h b/lib/usdUfe/ufe/UsdClipboardHandler.h index 2152bae6f3..9334acdd10 100644 --- a/lib/usdUfe/ufe/UsdClipboardHandler.h +++ b/lib/usdUfe/ufe/UsdClipboardHandler.h @@ -51,7 +51,16 @@ class USDUFE_PUBLIC UsdClipboardHandler : public Ufe::ClipboardHandler void preCopy_() override; void preCut_() override; - // Helper functions + //! Helper function to test if the clipboard contains an item of a given type. + //! The caller provides a test function which will be called for each top-level + //! prim in the clipboard. As an example: + // + // bool isNodeGraph(const PXR_NS::UsdPrim& prim) + // { + // return bool(PXR_NS::UsdShadeNodeGraph(prim)); + // } + // clipboardHandler->hasItemToPaste(&isNodeGraph); + // typedef bool (*HasItemToPasteTestFn)(const PXR_NS::UsdPrim& prim); bool hasItemToPaste(HasItemToPasteTestFn testFn); diff --git a/lib/usdUfe/ufe/UsdUndoAddNewPrimCommand.cpp b/lib/usdUfe/ufe/UsdUndoAddNewPrimCommand.cpp index ba1b3b5658..257300b686 100644 --- a/lib/usdUfe/ufe/UsdUndoAddNewPrimCommand.cpp +++ b/lib/usdUfe/ufe/UsdUndoAddNewPrimCommand.cpp @@ -48,8 +48,8 @@ UsdUndoAddNewPrimCommand::UsdUndoAddNewPrimCommand( // Append the parent path and the requested name into a full ufe path. // Append a '1' to new primitives names if the name does not end with a digit. _newUfePath = splitNumericalSuffix(name, base, suffixStr) - ? appendToPath(ufePath, name) - : appendToPath(ufePath, name + '1'); + ? appendToUsdPath(ufePath, name) + : appendToUsdPath(ufePath, name + '1'); // Ensure the requested name is unique. auto newPrimName @@ -57,7 +57,7 @@ UsdUndoAddNewPrimCommand::UsdUndoAddNewPrimCommand( // If the name had to change then we need to update the full ufe path. if (name != newPrimName) { - _newUfePath = appendToPath(ufePath, newPrimName); + _newUfePath = appendToUsdPath(ufePath, newPrimName); } // Build (and store) the usd path for the new prim with the unique name. diff --git a/lib/usdUfe/ufe/UsdUndoDuplicateCommand.cpp b/lib/usdUfe/ufe/UsdUndoDuplicateCommand.cpp index 80feea203c..e485279dbb 100644 --- a/lib/usdUfe/ufe/UsdUndoDuplicateCommand.cpp +++ b/lib/usdUfe/ufe/UsdUndoDuplicateCommand.cpp @@ -93,7 +93,7 @@ UsdSceneItem::Ptr UsdUndoDuplicateCommand::duplicatedItem() const Ufe::Path ufeSrcPath; if (!_ufeDstPath.getSegments().empty()) { - ufeSrcPath = appendToPath(_ufeDstPath, _usdDstPath.GetElementString()); + ufeSrcPath = appendToUsdPath(_ufeDstPath, _usdDstPath.GetElementString()); } else { // Temporary USD stage case. const auto ufePathAsString = "/" + _usdDstPath.GetElementString(); diff --git a/lib/usdUfe/ufe/Utils.cpp b/lib/usdUfe/ufe/Utils.cpp index e5bbc052dd..df0fee959a 100644 --- a/lib/usdUfe/ufe/Utils.cpp +++ b/lib/usdUfe/ufe/Utils.cpp @@ -409,16 +409,19 @@ bool isMaterialsScope(const Ufe::SceneItem::Ptr& item) return true; } -Ufe::Path appendToPath(const Ufe::Path& path, const std::string& name) +Ufe::Path appendToUsdPath(const Ufe::Path& path, const std::string& name) { - Ufe::Path newUfePath; + // Assumption is that either + // - the input path is comprised of multiple segments with the last segment being USD. + // - single segment path, in which case we append a USD segment. if (1 == path.getSegments().size()) { - newUfePath - = path + Ufe::PathSegment(Ufe::PathComponent(name), UsdUfe::getUsdRunTimeId(), '/'); - } else { - newUfePath = path + name; + return (path + Ufe::PathSegment(Ufe::PathComponent(name), UsdUfe::getUsdRunTimeId(), '/')); + } else if (path.runTimeId() == UsdUfe::getUsdRunTimeId()) { + return (path + name); } - return newUfePath; + + // Input path wasn't of expected type, just return it without appending. + return path; } namespace { diff --git a/lib/usdUfe/ufe/Utils.h b/lib/usdUfe/ufe/Utils.h index d3ae0d300a..7aa423e74b 100644 --- a/lib/usdUfe/ufe/Utils.h +++ b/lib/usdUfe/ufe/Utils.h @@ -193,7 +193,7 @@ USDUFE_PUBLIC PXR_NS::SdfPath uniqueChildPath(const PXR_NS::UsdStage& stage, const PXR_NS::SdfPath& path); USDUFE_PUBLIC -Ufe::Path appendToPath(const Ufe::Path& path, const std::string& name); +Ufe::Path appendToUsdPath(const Ufe::Path& path, const std::string& name); //! Returns true if \p item is a materials scope. USDUFE_PUBLIC From b2bc2e032a3fae35692b5c1ec3b5efc550f095e8 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Thu, 21 Mar 2024 13:59:19 -0400 Subject: [PATCH 05/19] EMSUSD-128 - [GitHub #2181] Implement Copy\paste capabilities on USD Data * Fix build breaks --- lib/usdUfe/base/forwardDeclares.h | 2 +- lib/usdUfe/python/CMakeLists.txt | 13 ++++++++++++- lib/usdUfe/python/module.cpp | 2 ++ .../usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp | 2 +- .../al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp | 2 +- .../AL/usdmaya/utils/NurbsCurveUtils.cpp | 2 +- 6 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/usdUfe/base/forwardDeclares.h b/lib/usdUfe/base/forwardDeclares.h index 3f9b0fa226..36b6248af3 100644 --- a/lib/usdUfe/base/forwardDeclares.h +++ b/lib/usdUfe/base/forwardDeclares.h @@ -16,7 +16,7 @@ #pragma once -#include +#include #include #include diff --git a/lib/usdUfe/python/CMakeLists.txt b/lib/usdUfe/python/CMakeLists.txt index 901205e92a..ab92bb4b44 100644 --- a/lib/usdUfe/python/CMakeLists.txt +++ b/lib/usdUfe/python/CMakeLists.txt @@ -17,7 +17,6 @@ add_library(${PYTHON_TARGET_NAME} SHARED) target_sources(${PYTHON_TARGET_NAME} PRIVATE module.cpp - wrapClipboard.cpp wrapEditRouter.cpp wrapGlobal.cpp wrapTokens.cpp @@ -25,6 +24,18 @@ target_sources(${PYTHON_TARGET_NAME} wrapCommands.cpp ) +if (UFE_CLIPBOARD_SUPPORT) + target_sources(${PROJECT_NAME} + PRIVATE + wrapClipboard.cpp + ) + + target_compile_definitions(${PROJECT_NAME} + PRIVATE + UFE_CLIPBOARD_SUPPORT=1 + ) +endif() + # ----------------------------------------------------------------------------- # compiler configuration # ----------------------------------------------------------------------------- diff --git a/lib/usdUfe/python/module.cpp b/lib/usdUfe/python/module.cpp index 8c2405248b..32e456f256 100644 --- a/lib/usdUfe/python/module.cpp +++ b/lib/usdUfe/python/module.cpp @@ -20,7 +20,9 @@ PXR_NAMESPACE_USING_DIRECTIVE TF_WRAP_MODULE { +#ifdef UFE_CLIPBOARD_SUPPORT TF_WRAP(Clipboard); +#endif TF_WRAP(EditRouter); TF_WRAP(Global); TF_WRAP(Tokens); diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp b/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp index 9b43f90986..65b0d01970 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp @@ -15,8 +15,8 @@ // #include "AL/usdmaya/utils/DiffPrimVar.h" -#include #include +#include #include diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp b/plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp index 191a060409..600d4af0ff 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp @@ -21,7 +21,7 @@ #include "AL/usdmaya/utils/DiffPrimVar.h" #include "AL/usdmaya/utils/Utils.h" -#include +#include #include #include diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/NurbsCurveUtils.cpp b/plugin/al/usdmayautils/AL/usdmaya/utils/NurbsCurveUtils.cpp index 44d9928116..945f19367a 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/NurbsCurveUtils.cpp +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/NurbsCurveUtils.cpp @@ -20,7 +20,7 @@ #include "AL/usdmaya/utils/DgNodeHelper.h" #include "AL/usdmaya/utils/Utils.h" -#include +#include #include #include From 9520479db6f456487e64493031b970db3f00f109 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:57:01 -0400 Subject: [PATCH 06/19] EMSUSD-128 - [GitHub #2181] Implement Copy\paste capabilities on USD Data * Fix test failures on OSX --- cmake/test.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/test.cmake b/cmake/test.cmake index 933faf57f2..f6410f768f 100644 --- a/cmake/test.cmake +++ b/cmake/test.cmake @@ -532,7 +532,7 @@ finally: # Necessary for tests like DiffCore to find python. # See LD_LIBRARY_PATH for Linux above. set_property(TEST "${test_name}" APPEND PROPERTY ENVIRONMENT - "DYLD_LIBRARY_PATH=${MAYA_LOCATION}/MacOS:$ENV{DYLD_LIBRARY_PATH}") + "DYLD_LIBRARY_PATH=${MAYA_LOCATION}/Maya.app/Contents/MacOS:$ENV{DYLD_LIBRARY_PATH}") set_property(TEST "${test_name}" APPEND PROPERTY ENVIRONMENT "DYLD_FRAMEWORK_PATH=${MAYA_LOCATION}/Maya.app/Contents/Frameworks") endif() From ea94923494ed31125acdbb080b861cb708e0f3ab Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:50:28 -0400 Subject: [PATCH 07/19] EMSUSD-1073 - Update maya-usd (master builds only) with USD v24.03 * Fix for Pixar tests to adapt to change made in USD v24.03 in Tf loading python module. --- plugin/pxr/cmake/macros/Public.cmake | 10 +++++++++- plugin/pxr/cmake/macros/testWrapper.py | 6 ++++++ plugin/pxr/maya/lib/usdMaya/CMakeLists.txt | 7 +++++++ plugin/pxr/maya/plugin/pxrUsd/CMakeLists.txt | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/plugin/pxr/cmake/macros/Public.cmake b/plugin/pxr/cmake/macros/Public.cmake index 354e82e289..54baa7ab11 100644 --- a/plugin/pxr/cmake/macros/Public.cmake +++ b/plugin/pxr/cmake/macros/Public.cmake @@ -224,7 +224,7 @@ function(pxr_register_test TEST_NAME) cmake_parse_arguments(bt "RUN_SERIAL;PYTHON;REQUIRES_SHARED_LIBS;REQUIRES_PYTHON_MODULES" "CUSTOM_PYTHON;COMMAND;STDOUT_REDIRECT;STDERR_REDIRECT;DIFF_COMPARE;POST_COMMAND;POST_COMMAND_STDOUT_REDIRECT;POST_COMMAND_STDERR_REDIRECT;PRE_COMMAND;PRE_COMMAND_STDOUT_REDIRECT;PRE_COMMAND_STDERR_REDIRECT;FILES_EXIST;FILES_DONT_EXIST;CLEAN_OUTPUT;EXPECTED_RETURN_CODE;TESTENV" - "ENV;PRE_PATH;POST_PATH" + "ENV;PRE_PATH;POST_PATH;WIN_DLL_PATH" ${ARGN} ) @@ -344,6 +344,14 @@ function(pxr_register_test TEST_NAME) endforeach() endif() + if(WIN32) + if (bt_WIN_DLL_PATH) + foreach(path ${bt_WIN_DLL_PATH}) + set(testWrapperCmd ${testWrapperCmd} --win-dll-path=${path}) + endforeach() + endif() + endif() + # Look for resource files in the "usd" subdirectory relative to the # "lib" directory where the libraries are installed. # diff --git a/plugin/pxr/cmake/macros/testWrapper.py b/plugin/pxr/cmake/macros/testWrapper.py index 83652e764d..f45f2f85cf 100644 --- a/plugin/pxr/cmake/macros/testWrapper.py +++ b/plugin/pxr/cmake/macros/testWrapper.py @@ -78,6 +78,9 @@ def _parseArgs(): action='append', help='Path to prepend to the PATH env var.') parser.add_argument('--post-path', dest='postPaths', default=[], type=str, action='append', help='Path to append to the PATH env var.') + parser.add_argument('--win-dll-path', dest='win_dll_path', default=[], type=str, + action='append', + help='Path(s) to set in the PXR_USD_WINDOWS_DLL_PATH env var') parser.add_argument('--verbose', '-v', action='store_true', help='Verbose output.') parser.add_argument('cmd', metavar='CMD', type=str, nargs='+', @@ -251,6 +254,9 @@ def _runCommand(raw_command, stdout_redir, stderr_redir, env, paths = args.prePaths + paths + args.postPaths env['PATH'] = pathDelim.join(paths) + if args.win_dll_path: + env['PXR_USD_WINDOWS_DLL_PATH'] = pathDelim.join(args.win_dll_path) + # Avoid the just-in-time debugger where possible when running tests. env['ARCH_AVOID_JIT'] = '1' diff --git a/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt b/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt index 843bf295a8..32d0aa01b9 100644 --- a/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt +++ b/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt @@ -121,6 +121,7 @@ pxr_register_test(testUsdExportAssembly COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdExportAssembly" TESTENV testUsdExportAssembly ENV ${TEST_ENV} + WIN_DLL_PATH "${PXR_USD_LOCATION}/plugin/usd;${PXR_USD_LOCATION}/lib;${PXR_USD_LOCATION}/bin;${TEST_INSTALL_PREFIX}/maya/lib;${CMAKE_INSTALL_PREFIX}/lib" ) pxr_install_test_dir( @@ -132,6 +133,7 @@ pxr_register_test(testUsdExportAssemblyEdits COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdExportAssemblyEdits" TESTENV testUsdExportAssemblyEdits ENV ${TEST_ENV} + WIN_DLL_PATH "${PXR_USD_LOCATION}/plugin/usd;${PXR_USD_LOCATION}/lib;${PXR_USD_LOCATION}/bin;${TEST_INSTALL_PREFIX}/maya/lib;${CMAKE_INSTALL_PREFIX}/lib" ) pxr_install_test_dir( @@ -154,6 +156,7 @@ pxr_register_test(testUsdExportPointInstancer COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdExportPointInstancer" TESTENV testUsdExportPointInstancer ENV ${TEST_ENV} + WIN_DLL_PATH "${PXR_USD_LOCATION}/plugin/usd;${PXR_USD_LOCATION}/lib;${PXR_USD_LOCATION}/bin;${TEST_INSTALL_PREFIX}/maya/lib;${CMAKE_INSTALL_PREFIX}/lib" ) pxr_install_test_dir( @@ -187,6 +190,7 @@ pxr_register_test(testUsdMayaGetVariantSetSelections COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaGetVariantSetSelections" TESTENV testUsdMayaGetVariantSetSelections ENV ${TEST_ENV} + WIN_DLL_PATH "${PXR_USD_LOCATION}/plugin/usd;${PXR_USD_LOCATION}/lib;${PXR_USD_LOCATION}/bin;${TEST_INSTALL_PREFIX}/maya/lib;${CMAKE_INSTALL_PREFIX}/lib" ) pxr_install_test_dir( @@ -198,6 +202,7 @@ pxr_register_test(testUsdMayaModelKindProcessor COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaModelKindProcessor" TESTENV testUsdMayaModelKindProcessor ENV ${TEST_ENV} + WIN_DLL_PATH "${PXR_USD_LOCATION}/plugin/usd;${PXR_USD_LOCATION}/lib;${PXR_USD_LOCATION}/bin;${TEST_INSTALL_PREFIX}/maya/lib;${CMAKE_INSTALL_PREFIX}/lib" ) pxr_install_test_dir( @@ -209,6 +214,7 @@ pxr_register_test(testUsdMayaReferenceAssemblyEdits COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaReferenceAssemblyEdits" TESTENV testUsdMayaReferenceAssemblyEdits ENV ${TEST_ENV} + WIN_DLL_PATH "${PXR_USD_LOCATION}/plugin/usd;${PXR_USD_LOCATION}/lib;${PXR_USD_LOCATION}/bin;${TEST_INSTALL_PREFIX}/maya/lib;${CMAKE_INSTALL_PREFIX}/lib" ) pxr_install_test_dir( @@ -220,6 +226,7 @@ pxr_register_test(testUsdReferenceAssemblyChangeRepresentations COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdReferenceAssemblyChangeRepresentations" TESTENV testUsdReferenceAssemblyChangeRepresentations ENV ${TEST_ENV} + WIN_DLL_PATH "${PXR_USD_LOCATION}/plugin/usd;${PXR_USD_LOCATION}/lib;${PXR_USD_LOCATION}/bin;${TEST_INSTALL_PREFIX}/maya/lib;${CMAKE_INSTALL_PREFIX}/lib" ) pxr_install_test_dir( diff --git a/plugin/pxr/maya/plugin/pxrUsd/CMakeLists.txt b/plugin/pxr/maya/plugin/pxrUsd/CMakeLists.txt index f8259f9770..5b04b62f39 100644 --- a/plugin/pxr/maya/plugin/pxrUsd/CMakeLists.txt +++ b/plugin/pxr/maya/plugin/pxrUsd/CMakeLists.txt @@ -53,4 +53,5 @@ pxr_register_test(testPxrUsdAlembicChaser MAYA_DISABLE_CIP=1 MAYA_NO_STANDALONE_ATEXIT=1 MAYA_APP_DIR=/maya_profile + WIN_DLL_PATH "${PXR_USD_LOCATION}/plugin/usd;${PXR_USD_LOCATION}/lib;${PXR_USD_LOCATION}/bin;${TEST_INSTALL_PREFIX}/maya/lib;${CMAKE_INSTALL_PREFIX}/lib" ) From b7fd76575e80eee7c309aa80066800a02a1091d7 Mon Sep 17 00:00:00 2001 From: Zhicheng Ye Date: Wed, 24 Apr 2024 14:10:48 +1000 Subject: [PATCH 08/19] Minor fixes on AL migration guide, updated the Maya doc links to be 2025. --- plugin/al/MIGRATION_GUIDE.md | 46 +++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/plugin/al/MIGRATION_GUIDE.md b/plugin/al/MIGRATION_GUIDE.md index 5f42a197fd..751240349c 100644 --- a/plugin/al/MIGRATION_GUIDE.md +++ b/plugin/al/MIGRATION_GUIDE.md @@ -41,7 +41,7 @@ There is no equivalent nodes like these to [drive transformation and animation f - `AL_usd_ProxyUsdGeomCamera` -This node works similar as MayaUsd ProxyAccessor but for camera, in ADSK_USDMaya, there is native support of USD camera via the [Ufe::Camera interface](https://github.com/Autodesk/maya-usd/blob/release/v0.27.0/lib/usdUfe/ufe/UsdCamera.h#L30), USD camera (and derived schema cameras) could be interacted like other Maya cameras without any problem. +This node works similar as MayaUsd ProxyAccessor but for camera, in ADSK_USDMaya, there is native support of USD camera via the [Ufe::Camera interface](https://github.com/Autodesk/maya-usd/blob/release/v0.27.0/lib/usdUfe/ufe/UsdCamera.h#L30), USD camera (and derived schema cameras) could be interacted like other Maya cameras but with some limitations, for instance when viewing through a USD camera you cannot use the panning, zoom, and dolly. ### USD Stage Creation @@ -75,14 +75,14 @@ Both of proxy shapes support locking prims by inserting a special metadata but n There is no exact equivalent approach in ADSK_USDMaya comparing with AL_USDMaya, the alternatives could be: - Insert `mayaLock` metadata in all prims hierarchically; -- OR [Assign prims as Display Layers](https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=GUID-C52465E4-FA5F-46AF-A186-E20ABEDD9BF2) +- OR [Assign prims as Display Layers](https://help.autodesk.com/view/MAYAUL/2025/ENU/?guid=GUID-C52465E4-FA5F-46AF-A186-E20ABEDD9BF2) ### Prim Selectability | | AL_USDMaya | ADSK_USDMaya | | --- | --- | --- | | Doc | [See here](https://github.com/Autodesk/maya-usd/blob/release/v0.27.0/plugin/al/tutorials/selectability/README.md) | | -| Control via | Prim metadata
`al_usdmaya_selectability` | Maya [Display Layer](https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=GUID-C52465E4-FA5F-46AF-A186-E20ABEDD9BF2) (available since **2023.2** or above) | +| Control via | Prim metadata
`al_usdmaya_selectability` | Maya [Display Layer](https://help.autodesk.com/view/MAYAUL/2025/ENU/?guid=GUID-C52465E4-FA5F-46AF-A186-E20ABEDD9BF2) (available since **2023.2** or above) | | Applies To | Individual Prim | Individual Prim | | Example | def Xform "geo" (
    al_usdmaya_selectability = "unselectable"
)
{
} | | | Effectiveness | Affects the current prim and all its descendants | Affects the current prim and all its descendants | @@ -93,7 +93,7 @@ Note that for instances, there is a metadata "mayaSelectability" to [control](ht | | AL_USDMaya | ADSK_USDMaya | | --- | --- | --- | -| Doc | | [See here](https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=GUID-532E99C9-F638-49E3-9483-800FDB9B65D7) | +| Doc | | [See here](https://help.autodesk.com/view/MAYAUL/2025/ENU/?guid=GUID-532E99C9-F638-49E3-9483-800FDB9B65D7) | | Maya `optionVar` | `AL_usdmaya_pickMode` (enum) | `mayaUsd_SelectionKind` (string) | | Note | AL_USDMaya no longer supports this optionVar since moving forward to **VP2RenderDelegate** for sub-scene override.| | @@ -101,7 +101,7 @@ Note that for instances, there is a metadata "mayaSelectability" to [control](ht ### Push/pull workflow (Edit-As-Maya workflow) -AL_USDMaya has a custom Maya command `AL_usdmaya_TranslatePrim` (see [Commands](#commands) below) to "Push to Maya" and "Pull to USD" to edit geometries in Maya; the alternative in ADSK_USDMaya the new ["Edit As Maya"](https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=GUID-C1C08BA5-24EA-44FF-9497-71E0A6843744) workflow to author geometries (and materials). +AL_USDMaya has a custom Maya command `AL_usdmaya_TranslatePrim` (see [Commands](#commands) below) to "Push to Maya" and "Pull to USD" to edit geometries in Maya; the alternative in ADSK_USDMaya the new ["Edit As Maya"](https://help.autodesk.com/view/MAYAUL/2025/ENU/?guid=GUID-C1C08BA5-24EA-44FF-9497-71E0A6843744) workflow to author geometries (and materials). ### Translator Plugin System @@ -126,7 +126,7 @@ ADSK_USDMaya has a clear separation of: - [`PrimUpdater` plugin](https://github.com/Autodesk/maya-usd/blob/release/v0.27.0/lib/mayaUsd/fileio/primUpdaterRegistry.h#L34-L60) - Static mapping of USD data type and Maya data type - - Will be used for the ["Edit As Maya"](https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=GUID-C1C08BA5-24EA-44FF-9497-71E0A6843744) workflow + - Will be used for the ["Edit As Maya"](https://help.autodesk.com/view/MAYAUL/2025/ENU/?guid=GUID-C1C08BA5-24EA-44FF-9497-71E0A6843744) workflow - Import data from USD to Maya @@ -187,7 +187,7 @@ Example MEL function `mayaUsd_createStageFromFilePath` bundled in ADSK_USDMaya c #### `AL_usdmaya_TranslatePrim` -ADSK_USDMaya introduced a new ["Edit As Maya"](https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=GUID-C1C08BA5-24EA-44FF-9497-71E0A6843744) workflow to exchange data between USD and Maya, there are two equivalent Maya commands to push / pull USD data to/from Maya: +ADSK_USDMaya introduced a new ["Edit As Maya"](https://help.autodesk.com/view/MAYAUL/2025/ENU/?guid=GUID-C1C08BA5-24EA-44FF-9497-71E0A6843744) workflow to exchange data between USD and Maya, there are two equivalent Maya commands to push / pull USD data to/from Maya: - `mayaUsdEditAsMaya` - Equivalent implementation of AL's `AL_usdmaya_TranslatPrim` where "importPaths" or "updatePaths" or "forceImport" flag is being used, a.k.a "Push to Maya" @@ -195,7 +195,7 @@ ADSK_USDMaya introduced a new ["Edit As Maya"](https://help.autodesk.com/view/MA - `mayaUsdMergeToUsd` - Equivalent implementation of AL's `AL_usdmaya_TranslatPrim` where "teardownPaths" flag is being used, a.k.a "Pull to USD" -For more info about this new workflow in Maya, see the official ["Edit As Maya"](https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=GUID-C1C08BA5-24EA-44FF-9497-71E0A6843744) workflow doc. +For more info about this new workflow in Maya, see the official ["Edit As Maya"](https://help.autodesk.com/view/MAYAUL/2025/ENU/?guid=GUID-C1C08BA5-24EA-44FF-9497-71E0A6843744) workflow doc. If you have translators implemented for AL_USDMaya: @@ -229,7 +229,7 @@ No equivalent command in ADSK_USDMaya, recommends managing transform nodes with ### AL Event System and Callbacks Commands -AL_USDMaya implemented a custom event system (see [Core Event System](https://github.com/Autodesk/maya-usd/blob/release/v0.27.0/plugin/al/lib/AL_USDMaya/AL/docpages/docs_events.h) and [Maya Event System](https://github.com/Autodesk/maya-usd/blob/release/v0.27.0/plugin/al/lib/AL_USDMaya/AL/docpages/docs_mayaevents.h)) to group and prioritize global and per-node callback, there is no equivalent in ADSK_USDMaya, however, all of them can be easily reimplemented by native Maya [MMessage](https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=MAYA_API_REF_cpp_ref_class_m_message_html). +AL_USDMaya implemented a custom event system (see [Core Event System](https://github.com/Autodesk/maya-usd/blob/release/v0.27.0/plugin/al/lib/AL_USDMaya/AL/docpages/docs_events.h) and [Maya Event System](https://github.com/Autodesk/maya-usd/blob/release/v0.27.0/plugin/al/lib/AL_USDMaya/AL/docpages/docs_mayaevents.h)) to group and prioritize global and per-node callback, there is no equivalent in ADSK_USDMaya, however, all of them can be easily reimplemented by native Maya [MMessage](https://help.autodesk.com/view/MAYADEV/2025/ENU/?guid=MAYA_API_REF_cpp_ref_class_m_message_html). Commands below have no equivalent in ADSK_USDMaya, we recommend to reimplement with native Maya MMessage API and manage the callbacks and events separately (in your code): @@ -251,14 +251,38 @@ Commands below have no equivalent in ADSK_USDMaya, we recommend to reimplement w This command allows you to query dirty layers currently managed by LayerManager in AL_USDMaya, there is no equivalent command in ADSK_USDMaya, we recommend querying dirty layers via native USD API. +#### `AL_usdmaya_LayerCreateLayer` + +This command opens a new Sdf layer from path (with `-o` flag) or creates a new anonymous layer (without `-o` flag), and inserts as a sub layer into the root layer (with `-s` flag). + +Equivalent command and example usage in ADSK_USDMaya: + +- Create and insert a new anonymous layer into existing layer: + - **mayaUsdLayerEditor** -edit -addAnonymous "new_anon_layer_id" "existing_parent_layer_id"; +- Open and insert the new layer as the strongest layer (index `0`) into existing layer: + - **mayaUsdLayerEditor** -edit -insertSubPath 0 "/path/to/layer/file.usd" "existing_parent_layer_id"; + +ADSK_USDMaya provides both an [UI interface](https://help.autodesk.com/view/MAYAUL/2025/ENU/?guid=GUID-4FAD73CA-E775-4009-9DCB-3BC6792C465E) and [command line interface](https://github.com/Autodesk/maya-usd/blob/release/v0.27.0/lib/mayaUsd/commands/layerEditorCommand.cpp#L831-L868) to manage USD layers, it has more features and options compared to AL_USDMaya, please refer to the links for other usages. + +Recommend to use either native USD API or ADSK_USDMaya's **mayaUsdLayerEditor** command. + +#### `AL_usdmaya_LayerCurrentEditTarget` + +ADSK_USDMaya has similar command to get/set edit target but for **local layer** only: + +- **mayaUsdEditTarget** -q -et "|usdTest|usdTestShape"; +- **mayaUsdEditTarget** -e -et "target_layer_id" "|usdTest|usdTestShape"; + +`AL_usdmaya_LayerCurrentEditTarget` commands support setting edit targets to be a non-local layer, however, it is limited for references, it does not take into account sub layers in references and nested references. + +We recommend using native USD API for non-local edit target layer cases until there is better support in ADSK_USDMaya. + Following commands are wrappers around USD APIs, there is no equivalent commands in ADSK_USDMaya, recommend switching over to native USD APIs: - `AL_usdmaya_ChangeVariant` - `AL_usdmaya_ActivatePrim` - `AL_usdmaya_CreateUsdPrim` -- `AL_usdmaya_LayerCreateLayer` - `AL_usdmaya_LayerGetLayers` -- `AL_usdmaya_LayerCurrentEditTarget` - `AL_usdmaya_LayerSave` - `AL_usdmaya_LayerSaveMuted` From 8fa8c68bfcd0c59b7dcf25c90c36964c5c5e09a5 Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Fri, 19 Apr 2024 17:04:01 -0400 Subject: [PATCH 09/19] EMSUSD-209 graph the material in LookdevX - Detect if the LookdevX plugin is loaded. Everything else is turned off when not loaded. - Add a button to graph the material in a LookdevX tab. - Use a named tuple to hold text field info. - Refactor the code to show buttons and update the associated commands. - Use the lookdevXGraph command to open the tab. - Add a utility function to build a UFE path from a USD path. - Fixed that the AE would not update when assigning an existing material. --- .../resources/ae/usdschemabase/ae_template.py | 14 +- .../usdschemabase/material_custom_control.py | 128 ++++++++++++++---- 2 files changed, 109 insertions(+), 33 deletions(-) diff --git a/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py b/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py index 6f5896c65f..707dd74dc8 100644 --- a/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py +++ b/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py @@ -78,9 +78,16 @@ def _queueEditorRefresh(): # Custom control, but does not have any UI. Instead we use # this control to be notified from UFE when any attribute has changed -# so we can update the AE. This is to fix refresh issue -# when transform is added to a prim. +# so we can update the AE. class UfeAttributesObserver(ufe.Observer): + _watchedAttrs = { + # This is to fix refresh issue when transform is added to a prim. + UsdGeom.Tokens.xformOpOrder, + # This is to fix refresh issue when an existing material is assigned + # to the prim when it already had a another material. + UsdShade.Tokens.materialBinding, + } + def __init__(self, item): super(UfeAttributesObserver, self).__init__() self._item = item @@ -91,7 +98,7 @@ def __del__(self): def __call__(self, notification): refreshEditor = False if isinstance(notification, ufe.AttributeValueChanged): - if notification.name() == UsdGeom.Tokens.xformOpOrder: + if notification.name() in UfeAttributesObserver._watchedAttrs: refreshEditor = True if hasattr(ufe, "AttributeAdded") and isinstance(notification, ufe.AttributeAdded): refreshEditor = True @@ -127,6 +134,7 @@ def onReplace(self, *args): # Nothing needed here since we don't create any UI. pass + class MetaDataCustomControl(object): # Custom control for all prim metadata we want to display. def __init__(self, item, prim, useNiceName): diff --git a/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py b/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py index 7dd3f4c462..20fa8dd211 100644 --- a/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py +++ b/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py @@ -14,6 +14,7 @@ # from functools import partial +import collections import ufe import mayaUsd.ufe @@ -36,6 +37,8 @@ class MaterialCustomControl(object): getMayaUsdLibString('kLabelStrongerMaterial') : 'strongerThanDescendants', } + TextField = collections.namedtuple('TextField', ['layout', 'field', 'button']) + def __init__(self, item, prim, useNiceName): super(MaterialCustomControl, self).__init__() self.item = item @@ -46,22 +49,31 @@ def onCreate(self, *args): ''' Create the custom UI for the material. ''' - self.assignedMatLayout, self.assignedMatField, _ = self._createTextField( - 'material', 'kLabelAssignedMaterial') + # Note: icon image taken from LookdevX plugin. + hasLookdevX = self._hasLookdevX() + graphIcon = 'LookdevX.png' if hasLookdevX else None + + self.assignedMat = self._createTextField('material', 'kLabelAssignedMaterial', graphIcon) self.strengthMenu = self._createDropDownField( 'strength', 'kLabelMaterialStrength', ['kLabelWeakerMaterial', 'kLabelStrongerMaterial']) - self.inheritedMatLayout, self.inheritedMatField, _ = self._createTextField( - 'inherited', 'kLabelInheritedMaterial') + self.inheritedMat = self._createTextField('inherited', 'kLabelInheritedMaterial', graphIcon) + # Note: icon image taken from Maya resources. - self.fromPrimLayout, self.inheritedFromPrimField, self.gotoPrimButton = self._createTextField( - 'from prim', 'kLabelInheritedFromPrim', 'inArrow.png') + self.fromPrim = self._createTextField('from prim', 'kLabelInheritedFromPrim', 'inArrow.png') # Fill the UI. self._refreshUI() + @staticmethod + def _hasLookdevX(): + ''' + Verify if the LookdevX plugin is loaded. + ''' + return bool(cmds.pluginInfo('LookdevXMaya', query=True, loaded=True)) + def _createTextField(self, longName, uiNameRes, image=None): ''' Create a disabled text field group and an optional image button with the correct label. @@ -75,7 +87,7 @@ def _createTextField(self, longName, uiNameRes, image=None): button = cmds.symbolButton(enable=False, image=image) else: button = None - return (rowLayout, textField, button) + return MaterialCustomControl.TextField(rowLayout, textField, button) def _createDropDownField(self, longName, uiNameRes, elementsRes): ''' @@ -139,35 +151,32 @@ def _refreshUIForDirect(self, mat, strength): Refresh the UI when the material is directly on the prim. ''' # Note: hide UI elements before filling values. - cmds.button(self.gotoPrimButton, command='', e=True) - cmds.symbolButton(self.gotoPrimButton, edit=True, enable=False, visible=False) - cmds.rowLayout(self.inheritedMatLayout, edit=True, visible=False) - cmds.rowLayout(self.fromPrimLayout, edit=True, visible=False) + cmds.rowLayout(self.inheritedMat.layout, edit=True, visible=False) + cmds.rowLayout(self.fromPrim.layout, edit=True, visible=False) - self._fillUIValues(mat.GetPath().pathString, '', '', strength) + matPathStr = mat.GetPath().pathString + + self._fillGraphDirectButton(matPathStr) + self._fillGraphInheritedButton(None) + self._fillGotoPrimButton(None) + self._fillUIValues(matPathStr, '', '', strength) def _refreshUIForInherited(self, mat, matRel, directMatPath, strength): ''' Refresh the UI when the material is inherited from an ancestor prim. ''' - direct = directMatPath.pathString if directMatPath else '' - inherited = mat.GetPath().pathString - fromPath = matRel.GetPrim().GetPath().pathString - - ufePath = ufe.Path([ - self.item.path().segments[0], - ufe.PathSegment(fromPath, mayaUsd.ufe.getUsdRunTimeId(), '/')]) - ufePathStr = ufe.PathString.string(ufePath) - melCommand = 'updateAE "%s"' % ufePathStr - command = lambda *_: mel.eval(melCommand) + directPathStr = directMatPath.pathString if directMatPath else '' + inheritedPathStr = mat.GetPath().pathString + fromPathStr = matRel.GetPrim().GetPath().pathString # Note: fill values before showing UI elements. - self._fillUIValues(direct, inherited, fromPath, strength) + self._fillGraphDirectButton(directPathStr) + self._fillGraphInheritedButton(inheritedPathStr) + self._fillGotoPrimButton(fromPathStr) + self._fillUIValues(directPathStr, inheritedPathStr, fromPathStr, strength) - cmds.button(self.gotoPrimButton, command=command, e=True) - cmds.symbolButton(self.gotoPrimButton, edit=True, enable=True, visible=True) - cmds.rowLayout(self.inheritedMatLayout, edit=True, visible=True) - cmds.rowLayout(self.fromPrimLayout, edit=True, visible=True) + cmds.rowLayout(self.inheritedMat.layout, edit=True, visible=True) + cmds.rowLayout(self.fromPrim.layout, edit=True, visible=True) def _fillUIValues(self, direct, inherited, fromPath, strength): ''' @@ -190,13 +199,72 @@ def _fillUIValues(self, direct, inherited, fromPath, strength): strengthEnabled = True strengthAnnotation = getMayaUsdLibString('kLabelMaterialStrength') - cmds.textField(self.assignedMatField, edit=True, text=text, placeholderText=placeholder, + cmds.textField(self.assignedMat.field, edit=True, text=text, placeholderText=placeholder, annotation=annotation) - cmds.textField(self.inheritedMatField, edit=True, text=inherited) - cmds.textField(self.inheritedFromPrimField, edit=True, text=fromPath) + cmds.textField(self.inheritedMat.field, edit=True, text=inherited) + cmds.textField(self.fromPrim.field, edit=True, text=fromPath) cmds.optionMenuGrp(self.strengthMenu, edit=True, enable=strengthEnabled, visible=strengthVisible, value=strength, annotation=strengthAnnotation) + + def _fillGraphDirectButton(self, matPathStr): + ''' + Fill the direct material graph button with the correct command. + ''' + self._fillGraphButton(matPathStr, self.assignedMat.button) + + def _fillGraphInheritedButton(self, matPathStr): + ''' + Fill the inherited material graph button with the correct command. + ''' + self._fillGraphButton(matPathStr, self.inheritedMat.button) + + def _fillGraphButton(self, matPathStr, button): + ''' + Fill the graph button with the correct command. + ''' + # Note: only show the graph button if LookdevX was loaded when the UI + # was created. + if not button: + return + + # Note: only show the graph button if LookdevX is currently loaded. + hasLookdevX = self._hasLookdevX() + canGraph = bool(matPathStr and hasLookdevX) + cmds.symbolButton(button, edit=True, enable=canGraph, visible=hasLookdevX) + + if canGraph: + ufePathStr = self._createUFEPathFromUSDPath(matPathStr) + command = lambda *_: cmds.lookdevXGraph(graphNode=ufePathStr, tabName='USD') + else: + command = '' + cmds.button(button, edit=True, command=command) + + def _fillGotoPrimButton(self, fromPath): + ''' + Fill the goto-prim button with the correct command. + ''' + showButton = bool(fromPath) + cmds.symbolButton(self.fromPrim.button, edit=True, enable=showButton, visible=showButton) + + if fromPath: + ufePathStr = self._createUFEPathFromUSDPath(fromPath) + melCommand = 'updateAE "%s"' % ufePathStr + command = lambda *_: mel.eval(melCommand) + else: + command = '' + cmds.button(self.fromPrim.button, edit=True, command=command) + + def _createUFEPathFromUSDPath(self, usdPath): + ''' + Build a UFE path to a USD path on the same stage as the edited UFE item. + ''' + # Note: the UFE item is in the same stage, so we can use + # this UFE item to build the UFE path to the USD path. + ufePath = ufe.Path([ + self.item.path().segments[0], + ufe.PathSegment(usdPath, mayaUsd.ufe.getUsdRunTimeId(), '/')]) + return ufe.PathString.string(ufePath) From d157cab981f332b444f7e2be0cc8add36dbadc20 Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Thu, 25 Apr 2024 15:16:40 -0400 Subject: [PATCH 10/19] EMSUSD-209 Allow showing material in the chosen tab - Add a popup menu to the graph material buttons. - Allow creating a new tab or re-using an existing tab. - The material types is always USD since these are USD materials. --- .../usdschemabase/material_custom_control.py | 92 ++++++++++++++++--- .../scripts/mayaUsdLibRegisterStrings.py | 1 + 2 files changed, 78 insertions(+), 15 deletions(-) diff --git a/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py b/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py index 20fa8dd211..118e332c93 100644 --- a/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py +++ b/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py @@ -54,18 +54,20 @@ def onCreate(self, *args): graphIcon = 'LookdevX.png' if hasLookdevX else None self.assignedMat = self._createTextField('material', 'kLabelAssignedMaterial', graphIcon) + self.assignedMatMenu = self._createGraphMenu(self.assignedMat.button) self.strengthMenu = self._createDropDownField( 'strength', 'kLabelMaterialStrength', ['kLabelWeakerMaterial', 'kLabelStrongerMaterial']) self.inheritedMat = self._createTextField('inherited', 'kLabelInheritedMaterial', graphIcon) + self.inheritedMatMenu = self._createGraphMenu(self.inheritedMat.button) # Note: icon image taken from Maya resources. self.fromPrim = self._createTextField('from prim', 'kLabelInheritedFromPrim', 'inArrow.png') - + # Fill the UI. - self._refreshUI() + self._fillUI() @staticmethod def _hasLookdevX(): @@ -88,6 +90,15 @@ def _createTextField(self, longName, uiNameRes, image=None): else: button = None return MaterialCustomControl.TextField(rowLayout, textField, button) + + def _createGraphMenu(self, button): + ''' + Create a popup menu attached to the given button to graph a material. + ''' + if not button: + return None + + return cmds.popupMenu(parent=button, button=True) def _createDropDownField(self, longName, uiNameRes, elementsRes): ''' @@ -127,9 +138,9 @@ def onReplace(self, *args): # that case we don't need to update our controls since none will change. pass - def _refreshUI(self): + def _fillUI(self): ''' - Refresh the UI when the data is modified. + Fill the UI with the material data. ''' matAPI = UsdShade.MaterialBindingAPI(self.prim) mat, matRel = matAPI.ComputeBoundMaterial() @@ -142,13 +153,13 @@ def _refreshUI(self): strength = self.strengthLabels[token] if matRel.GetPrim() == self.prim: - self._refreshUIForDirect(mat, strength) + self._fillUIForDirect(mat, strength) else: - self._refreshUIForInherited(mat, matRel, directBinding.GetMaterialPath(), strength) + self._fillUIForInherited(mat, matRel, directBinding.GetMaterialPath(), strength) - def _refreshUIForDirect(self, mat, strength): + def _fillUIForDirect(self, mat, strength): ''' - Refresh the UI when the material is directly on the prim. + Fill the UI when the material is directly on the prim. ''' # Note: hide UI elements before filling values. cmds.rowLayout(self.inheritedMat.layout, edit=True, visible=False) @@ -161,9 +172,9 @@ def _refreshUIForDirect(self, mat, strength): self._fillGotoPrimButton(None) self._fillUIValues(matPathStr, '', '', strength) - def _refreshUIForInherited(self, mat, matRel, directMatPath, strength): + def _fillUIForInherited(self, mat, matRel, directMatPath, strength): ''' - Refresh the UI when the material is inherited from an ancestor prim. + Fill the UI when the material is inherited from an ancestor prim. ''' directPathStr = directMatPath.pathString if directMatPath else '' inheritedPathStr = mat.GetPath().pathString @@ -213,15 +224,15 @@ def _fillGraphDirectButton(self, matPathStr): ''' Fill the direct material graph button with the correct command. ''' - self._fillGraphButton(matPathStr, self.assignedMat.button) + self._fillGraphButton(matPathStr, self.assignedMat.button, self.assignedMatMenu) def _fillGraphInheritedButton(self, matPathStr): ''' Fill the inherited material graph button with the correct command. ''' - self._fillGraphButton(matPathStr, self.inheritedMat.button) + self._fillGraphButton(matPathStr, self.inheritedMat.button, self.inheritedMatMenu) - def _fillGraphButton(self, matPathStr, button): + def _fillGraphButton(self, matPathStr, button, menu): ''' Fill the graph button with the correct command. ''' @@ -237,10 +248,61 @@ def _fillGraphButton(self, matPathStr, button): if canGraph: ufePathStr = self._createUFEPathFromUSDPath(matPathStr) - command = lambda *_: cmds.lookdevXGraph(graphNode=ufePathStr, tabName='USD') + command = partial(MaterialCustomControl._fillGraphMenu, menu=menu, ufePathStr=ufePathStr) else: command = '' - cmds.button(button, edit=True, command=command) + cmds.popupMenu(menu, edit=True, postMenuCommand=command) + + @staticmethod + def _fillGraphMenu(*args, menu=None, ufePathStr=None): + ''' + Fill the popup menu with menu items for graphing materials when it gets shown to the user. + ''' + if not menu: + return + if not ufePathStr: + return + + cmds.popupMenu(menu, edit=True, deleteAllItems=True) + + # Allow opening a new tab. + command = partial(MaterialCustomControl._showInNewTab, ufePathStr=ufePathStr) + cmds.menuItem(parent=menu, label=getMayaUsdLibString('kLabelMaterialNewTab'), command=command) + + # Allow graphing in an existing tab. + # Requires intimate knowledge of the LookdevX window name... + lookdevXWindow = 'LookdevXGraphEditorControl' + if cmds.window(lookdevXWindow, exists=True): + tabNames = cmds.lxCompoundEditor(name=lookdevXWindow, tabNames=True, dataModel='USD') + else: + tabNames = cmds.lxCompoundEditor(tabNames=True, dataModel='USD') + + if tabNames: + cmds.menuItem(parent=menu, divider=True) + for tabName in tabNames: + command = partial(MaterialCustomControl._showInExistingTab, tabName=tabName, ufePathStr=ufePathStr) + cmds.menuItem(parent=menu, label=tabName, command=command) + + @staticmethod + def _showInNewTab(*args, ufePathStr=None): + ''' + Show a material in a new LookdevX tab. + ''' + if not ufePathStr: + return + tabName = cmds.lookdevXGraph(openNewTab='USD') + MaterialCustomControl._showInExistingTab(tabName=tabName, ufePathStr=ufePathStr) + + @staticmethod + def _showInExistingTab(*args, tabName=None, ufePathStr=None): + ''' + Show a material in a given existing LookdevX tab. + ''' + if not tabName: + return + if not ufePathStr: + return + cmds.lookdevXGraph(tabName=tabName, graphObject=ufePathStr) def _fillGotoPrimButton(self, fromPath): ''' diff --git a/lib/mayaUsd/resources/scripts/mayaUsdLibRegisterStrings.py b/lib/mayaUsd/resources/scripts/mayaUsdLibRegisterStrings.py index cd1d82e33c..7ce805f2cc 100644 --- a/lib/mayaUsd/resources/scripts/mayaUsdLibRegisterStrings.py +++ b/lib/mayaUsd/resources/scripts/mayaUsdLibRegisterStrings.py @@ -52,6 +52,7 @@ def mayaUsdLibRegisterStrings(): register('kLabelWeakerMaterial', 'Weaker than descendants') register('kLabelStrongerMaterial', 'Stronger than descendants') register('kTooltipInheritedStrength', 'This setting cannot be changed on this prim due to the strength setting on an ancestor') + register('kLabelMaterialNewTab', 'New Tab...') # mayaUsdAddMayaReference.py register('kErrorGroupPrimExists', 'Group prim "^1s" already exists under "^2s". Choose prim name other than "^1s" to proceed.') From f17d8eea9e48afbea9e3b971badc2d6f4a084381 Mon Sep 17 00:00:00 2001 From: Zhicheng Ye Date: Fri, 26 Apr 2024 11:04:20 +1000 Subject: [PATCH 11/19] Added USD for Maya introduction and installation links, updated UFE camera link. --- plugin/al/MIGRATION_GUIDE.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/al/MIGRATION_GUIDE.md b/plugin/al/MIGRATION_GUIDE.md index 751240349c..1a4009892d 100644 --- a/plugin/al/MIGRATION_GUIDE.md +++ b/plugin/al/MIGRATION_GUIDE.md @@ -11,6 +11,8 @@ In most cases, ADSK_USDMaya could be a drop-in replacement for AL_USDMaya. Please note that this documentation is not a complete feature comparison of AL_USDMaya and ADSK_USDMaya but mainly focuses on migration from one to another. +For a complete introduction of ADSK_USDMaya, please visit Autodesk's help page [here](https://help.autodesk.com/view/MAYAUL/2025/ENU/?guid=GUID-9E9D45F2-4DA9-497B-8D69-1573ED6B2BA8); for the detail instructions how to install latest release of ADSK_USDMaya, please visit [here](https://help.autodesk.com/view/MAYAUL/2025/ENU/?guid=GUID-8FB49D7F-8651-47CE-80FC-5C940E568C97). + [^1] To distinguish Animal Logic's version and Autodesk's version, we call Autodesk's version "ADSK_USDMaya" for convenience. [^2] This documentation is written based on the current latest release of `maya-usd-v0.27.0`. @@ -41,7 +43,7 @@ There is no equivalent nodes like these to [drive transformation and animation f - `AL_usd_ProxyUsdGeomCamera` -This node works similar as MayaUsd ProxyAccessor but for camera, in ADSK_USDMaya, there is native support of USD camera via the [Ufe::Camera interface](https://github.com/Autodesk/maya-usd/blob/release/v0.27.0/lib/usdUfe/ufe/UsdCamera.h#L30), USD camera (and derived schema cameras) could be interacted like other Maya cameras but with some limitations, for instance when viewing through a USD camera you cannot use the panning, zoom, and dolly. +This node works similar as MayaUsd ProxyAccessor but for camera, in ADSK_USDMaya, there is native support of USD camera via the [Ufe::Camera interface](https://github.com/Autodesk/maya-usd/blob/release/v0.27.0/lib/usdUfe/ufe/UsdCamera.h#L30) since version [0.18.0](https://help.autodesk.com/view/MAYAUL/2025/ENU/?guid=GUID-985DE87C-E902-49BC-A47D-5699498C4F32), USD camera (and derived schema cameras) could be interacted like other Maya cameras but with some limitations, for instance when viewing through a USD camera you cannot use the panning, zoom, and dolly. ### USD Stage Creation From 98aa56f572001197385811f7d402cb8de6c6caf2 Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Fri, 26 Apr 2024 08:56:21 -0400 Subject: [PATCH 12/19] EMSUSD-209 make code compatible with Python 2. --- .../resources/ae/usdschemabase/material_custom_control.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py b/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py index 118e332c93..ee9b8572ec 100644 --- a/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py +++ b/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py @@ -254,7 +254,7 @@ def _fillGraphButton(self, matPathStr, button, menu): cmds.popupMenu(menu, edit=True, postMenuCommand=command) @staticmethod - def _fillGraphMenu(*args, menu=None, ufePathStr=None): + def _fillGraphMenu(ignore1, ignore2, menu, ufePathStr): ''' Fill the popup menu with menu items for graphing materials when it gets shown to the user. ''' @@ -284,17 +284,17 @@ def _fillGraphMenu(*args, menu=None, ufePathStr=None): cmds.menuItem(parent=menu, label=tabName, command=command) @staticmethod - def _showInNewTab(*args, ufePathStr=None): + def _showInNewTab(ignore, ufePathStr): ''' Show a material in a new LookdevX tab. ''' if not ufePathStr: return tabName = cmds.lookdevXGraph(openNewTab='USD') - MaterialCustomControl._showInExistingTab(tabName=tabName, ufePathStr=ufePathStr) + MaterialCustomControl._showInExistingTab(ignore, tabName=tabName, ufePathStr=ufePathStr) @staticmethod - def _showInExistingTab(*args, tabName=None, ufePathStr=None): + def _showInExistingTab(ignore, tabName, ufePathStr): ''' Show a material in a given existing LookdevX tab. ''' From 7d562a4a98fe3314b48c4e224ba3abd33606d019 Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Wed, 24 Apr 2024 16:10:48 -0400 Subject: [PATCH 13/19] EMSUSD-1135 Add flag for export empty transform - Add a USD export job argument called includeEmptyTransforms. - It defaults to true. - Add a flag with the same name to the MayaUSD export command, with short flag named "-iet". - Document the new flag in the command readme. - Make it readable in the JobExportArgs Python class. - Implement post-export pruning of empty Xform and Scope. - Keep default prim even if empty - To be empty it has to have no children, no payload and no reference. - Add two unit tests, one including and one excluding empty transforms. - Add unit tests to verify that prims with payloads or refs are not considered empty. - Add unit test to verify that empty non Xform and non Scope are kept. - Add a unit test for the case the default prim is empty. --- lib/mayaUsd/commands/Readme.md | 1 + lib/mayaUsd/commands/baseExportCommand.cpp | 4 + lib/mayaUsd/commands/baseExportCommand.h | 1 + lib/mayaUsd/fileio/jobs/jobArgs.cpp | 8 +- lib/mayaUsd/fileio/jobs/jobArgs.h | 2 + lib/mayaUsd/fileio/jobs/writeJob.cpp | 80 +++++- lib/mayaUsd/fileio/jobs/writeJob.h | 3 + lib/mayaUsd/python/wrapPrimWriter.cpp | 1 + .../adsk/scripts/mayaUSDRegisterStrings.mel | 5 + .../adsk/scripts/mayaUsdTranslatorExport.mel | 7 + test/lib/usd/plugin/CMakeLists.txt | 8 + .../usd/plugin/plugInfoExportEmptyConfig.json | 15 + test/lib/usd/translators/CMakeLists.txt | 6 + .../translators/testUsdExportEmptyXforms.py | 262 ++++++++++++++++++ 14 files changed, 401 insertions(+), 2 deletions(-) create mode 100644 test/lib/usd/plugin/plugInfoExportEmptyConfig.json create mode 100644 test/lib/usd/translators/testUsdExportEmptyXforms.py diff --git a/lib/mayaUsd/commands/Readme.md b/lib/mayaUsd/commands/Readme.md index 7e60a3bdd2..c69f87cae5 100644 --- a/lib/mayaUsd/commands/Readme.md +++ b/lib/mayaUsd/commands/Readme.md @@ -172,6 +172,7 @@ their own purposes, similar to the Alembic export chaser example. | `-frameSample` | `-fs` | double (multi) | `0.0` | Specifies sample times used to multi-sample frames during animation export, where `0.0` refers to the current time sample. **This is an advanced option**; chances are, you probably want to set the `frameStride` parameter instead. But if you really do need fine-grained control on multi-sampling frames, see "Frame Samples" below. | | `-frameStride` | `-fst` | double | `1.0` | Specifies the increment between frames during animation export, e.g. a stride of `0.5` will give you twice as many time samples, whereas a stride of `2.0` will only give you time samples every other frame. The frame stride is computed before the frame samples are taken into account. **Note**: Depending on the frame stride, the last frame of the frame range may be skipped. For example, if your frame range is `[1.0, 3.0]` but you specify a stride of `0.3`, then the time samples in your USD file will be `1.0, 1.3, 1.6, 1.9, 2.2, 2.5, 2.8`, skipping the last frame time (`3.0`). | | `-ignoreWarnings` | `-ign` | bool | false | Ignore warnings, do not fail to export due to warnings | +| `-includeEmptyTransforms` | `-iet` | bool | true | Include Xform even if all they contain are other empty Xforms. | | `-kind` | `-k` | string | none | Specifies the required USD kind for *root prims* in the scene. (Does not affect kind for non-root prims.) If this flag is non-empty, then the specified kind will be set on any root prims in the scene without a `USD_kind` attribute (see the "Maya Custom Attributes" table below). Furthermore, if there are any root prims in the scene that do have a `USD_kind` attribute, then their `USD_kind` values will be validated to ensure they are derived from the kind specified by the `-kind` flag. For example, if the `-kind` flag is set to `group` and a root prim has `USD_kind=assembly`, then this is allowed because `assembly` derives from `group`. However, if the root prim has `USD_kind=subcomponent` instead, then `MayaUSDExportCommand` would stop with an error, since `subcomponent` does not derive from `group`. The validation behavior understands custom kinds that are registered using the USD kind registry, in addition to the built-in kinds. | | `-disableModelKindProcessor` | `-dmk` | bool | false | Disables the tagging of prim kinds based on the ModelKindProcessor. | | `-materialCollectionsPath` | `-mcp` | string | none | Path to the prim where material collections must be exported. | diff --git a/lib/mayaUsd/commands/baseExportCommand.cpp b/lib/mayaUsd/commands/baseExportCommand.cpp index 612c02d1f2..e55931bfc5 100644 --- a/lib/mayaUsd/commands/baseExportCommand.cpp +++ b/lib/mayaUsd/commands/baseExportCommand.cpp @@ -52,6 +52,10 @@ MSyntax MayaUSDExportCommand::createSyntax() kExportInstancesFlag, UsdMayaJobExportArgsTokens->exportInstances.GetText(), MSyntax::kBoolean); + syntax.addFlag( + kIncludeEmptyTransformsFlag, + UsdMayaJobExportArgsTokens->includeEmptyTransforms.GetText(), + MSyntax::kBoolean); syntax.addFlag( kExportRefsAsInstanceableFlag, UsdMayaJobExportArgsTokens->exportRefsAsInstanceable.GetText(), diff --git a/lib/mayaUsd/commands/baseExportCommand.h b/lib/mayaUsd/commands/baseExportCommand.h index 86aa7caad2..9fed2d1175 100644 --- a/lib/mayaUsd/commands/baseExportCommand.h +++ b/lib/mayaUsd/commands/baseExportCommand.h @@ -97,6 +97,7 @@ class MAYAUSD_CORE_PUBLIC MayaUSDExportCommand : public MPxCommand static constexpr auto kMetersPerUnit = "mpu"; static constexpr auto kExcludeExportTypesFlag = "eet"; static constexpr auto kDefaultPrimFlag = "dp"; + static constexpr auto kIncludeEmptyTransformsFlag = "iet"; // Short and Long forms of flags defined by this command itself: static constexpr auto kAppendFlag = "a"; diff --git a/lib/mayaUsd/fileio/jobs/jobArgs.cpp b/lib/mayaUsd/fileio/jobs/jobArgs.cpp index 17c6577c5b..4463aaf446 100644 --- a/lib/mayaUsd/fileio/jobs/jobArgs.cpp +++ b/lib/mayaUsd/fileio/jobs/jobArgs.cpp @@ -624,6 +624,8 @@ UsdMayaJobExportArgs::UsdMayaJobExportArgs( , exportComponentTags(extractBoolean(userArgs, UsdMayaJobExportArgsTokens->exportComponentTags)) , file(extractString(userArgs, UsdMayaJobExportArgsTokens->file)) , ignoreWarnings(extractBoolean(userArgs, UsdMayaJobExportArgsTokens->ignoreWarnings)) + , includeEmptyTransforms( + extractBoolean(userArgs, UsdMayaJobExportArgsTokens->includeEmptyTransforms)) , materialCollectionsPath( extractAbsolutePath(userArgs, UsdMayaJobExportArgsTokens->materialCollectionsPath)) , materialsScopeName(_GetMaterialsScopeName( @@ -726,7 +728,9 @@ std::ostream& operator<<(std::ostream& out, const UsdMayaJobExportArgs& exportAr << "exportVisibility: " << TfStringify(exportArgs.exportVisibility) << std::endl << "exportComponentTags: " << TfStringify(exportArgs.exportComponentTags) << std::endl << "file: " << exportArgs.file << std::endl - << "ignoreWarnings: " << TfStringify(exportArgs.ignoreWarnings) << std::endl; + << "ignoreWarnings: " << TfStringify(exportArgs.ignoreWarnings) << std::endl + << "includeEmptyTransforms: " << TfStringify(exportArgs.includeEmptyTransforms) + << std::endl; out << "includeAPINames (" << exportArgs.includeAPINames.size() << ")" << std::endl; for (const std::string& includeAPIName : exportArgs.includeAPINames) { out << " " << includeAPIName << std::endl; @@ -1001,6 +1005,7 @@ const VtDictionary& UsdMayaJobExportArgs::GetDefaultDictionary() d[UsdMayaJobExportArgsTokens->file] = std::string(); d[UsdMayaJobExportArgsTokens->filterTypes] = std::vector(); d[UsdMayaJobExportArgsTokens->ignoreWarnings] = false; + d[UsdMayaJobExportArgsTokens->includeEmptyTransforms] = true; d[UsdMayaJobExportArgsTokens->kind] = std::string(); d[UsdMayaJobExportArgsTokens->disableModelKindProcessor] = false; d[UsdMayaJobExportArgsTokens->materialCollectionsPath] = std::string(); @@ -1100,6 +1105,7 @@ const VtDictionary& UsdMayaJobExportArgs::GetGuideDictionary() d[UsdMayaJobExportArgsTokens->file] = _string; d[UsdMayaJobExportArgsTokens->filterTypes] = _stringVector; d[UsdMayaJobExportArgsTokens->ignoreWarnings] = _boolean; + d[UsdMayaJobExportArgsTokens->includeEmptyTransforms] = _boolean; d[UsdMayaJobExportArgsTokens->kind] = _string; d[UsdMayaJobExportArgsTokens->disableModelKindProcessor] = _boolean; d[UsdMayaJobExportArgsTokens->materialCollectionsPath] = _string; diff --git a/lib/mayaUsd/fileio/jobs/jobArgs.h b/lib/mayaUsd/fileio/jobs/jobArgs.h index 7c5bc4551d..3b0e3f2f29 100644 --- a/lib/mayaUsd/fileio/jobs/jobArgs.h +++ b/lib/mayaUsd/fileio/jobs/jobArgs.h @@ -88,6 +88,7 @@ TF_DECLARE_PUBLIC_TOKENS( (file) \ (filterTypes) \ (ignoreWarnings) \ + (includeEmptyTransforms) \ (kind) \ (disableModelKindProcessor) \ (materialCollectionsPath) \ @@ -221,6 +222,7 @@ struct UsdMayaJobExportArgs const bool exportComponentTags; const std::string file; const bool ignoreWarnings; + const bool includeEmptyTransforms; /// If this is not empty, then a set of collections are exported on the /// prim pointed to by the path, each representing the collection of diff --git a/lib/mayaUsd/fileio/jobs/writeJob.cpp b/lib/mayaUsd/fileio/jobs/writeJob.cpp index 8bf09d36a1..96edea4446 100644 --- a/lib/mayaUsd/fileio/jobs/writeJob.cpp +++ b/lib/mayaUsd/fileio/jobs/writeJob.cpp @@ -488,7 +488,7 @@ bool UsdMaya_WriteJob::_WriteFrame(double iFrame) bool UsdMaya_WriteJob::_FinishWriting() { - MayaUsd::ProgressBarScope progressBar(6); + MayaUsd::ProgressBarScope progressBar(7); UsdPrimSiblingRange usdRootPrims = mJobCtx.mStage->GetPseudoRoot().GetChildren(); @@ -586,6 +586,9 @@ bool UsdMaya_WriteJob::_FinishWriting() _PostCallback(); progressBar.advance(); + _PruneEmpties(); + progressBar.advance(); + TF_STATUS("Saving stage"); if (mJobCtx.mStage->GetRootLayer()->PermissionToSave()) { mJobCtx.mStage->GetRootLayer()->Save(); @@ -780,6 +783,81 @@ TfToken UsdMaya_WriteJob::_WriteVariants(const UsdPrim& usdRootPrim) return defaultPrim; } +namespace { +bool isEmptyPrim(const UsdPrim& prim) +{ + // Note: prim might have been removed previously. + if (!prim.IsValid()) + return false; + + static std::set emptyTypes = std::set({ TfToken("Xform"), TfToken("Scope") }); + TfToken primTypeName = prim.GetTypeName(); + if (emptyTypes.count(primTypeName) == 0) + return false; + + if (!prim.GetAllChildren().empty()) + return false; + + if (prim.HasAuthoredPayloads()) + return false; + + if (prim.HasAuthoredReferences()) + return false; + + return true; +} + +bool isEmptyPrim(const UsdStageRefPtr& stage, const SdfPath& path) +{ + return isEmptyPrim(stage->GetPrimAtPath(path)); +} + +std::vector +removeEmptyPrims(const UsdStageRefPtr& stage, const std::vector& toRemove) +{ + // Once we start removing empties, we need to re-check their parents. + std::vector toRecheck; + + for (const SdfPath& path : toRemove) { + stage->RemovePrim(path); + toRecheck.emplace_back(path.GetParentPath()); + } + return toRecheck; +} +} // namespace + +void UsdMaya_WriteJob::_PruneEmpties() +{ + if (mJobCtx.mArgs.includeEmptyTransforms) + return; + + SdfPath defaultPrimPath; + if (mJobCtx.mArgs.defaultPrim.size() > 0) { + if (mJobCtx.mArgs.defaultPrim[0] != '/') + defaultPrimPath = SdfPath(std::string("/") + mJobCtx.mArgs.defaultPrim); + else + defaultPrimPath = SdfPath(mJobCtx.mArgs.defaultPrim); + } + + std::vector toRemove; + + for (UsdPrim prim : mJobCtx.mStage->Traverse()) { + if (defaultPrimPath != prim.GetPath()) + if (isEmptyPrim(prim)) + toRemove.emplace_back(prim.GetPath()); + } + + while (toRemove.size()) { + std::vector toRecheck = removeEmptyPrims(mJobCtx.mStage, toRemove); + toRemove.clear(); + + for (const SdfPath& path : toRecheck) + if (defaultPrimPath != path) + if (isEmptyPrim(mJobCtx.mStage, path)) + toRemove.emplace_back(path); + } +} + void UsdMaya_WriteJob::_CreatePackage() const { // Since we're packaging a temporary stage file that has an diff --git a/lib/mayaUsd/fileio/jobs/writeJob.h b/lib/mayaUsd/fileio/jobs/writeJob.h index d51295447f..e5d814e8a6 100644 --- a/lib/mayaUsd/fileio/jobs/writeJob.h +++ b/lib/mayaUsd/fileio/jobs/writeJob.h @@ -73,6 +73,9 @@ class UsdMaya_WriteJob /// Writes the root prim variants based on the Maya render layers. TfToken _WriteVariants(const UsdPrim& usdRootPrim); + /// Remove empty xform and scope recursively if the options to include them is off. + void _PruneEmpties(); + /// Creates a usdz package from the write job's current USD stage. void _CreatePackage() const; diff --git a/lib/mayaUsd/python/wrapPrimWriter.cpp b/lib/mayaUsd/python/wrapPrimWriter.cpp index 92c616042e..b6df94b84d 100644 --- a/lib/mayaUsd/python/wrapPrimWriter.cpp +++ b/lib/mayaUsd/python/wrapPrimWriter.cpp @@ -563,6 +563,7 @@ void wrapJobExportArgs() make_getter( &UsdMayaJobExportArgs::geomSidedness, return_value_policy())) .def_readonly("ignoreWarnings", &UsdMayaJobExportArgs::ignoreWarnings) + .def_readonly("includeEmptyTransforms", &UsdMayaJobExportArgs::includeEmptyTransforms) .add_property( "includeAPINames", make_getter( diff --git a/plugin/adsk/scripts/mayaUSDRegisterStrings.mel b/plugin/adsk/scripts/mayaUSDRegisterStrings.mel index 846158ffa1..db95eb6998 100644 --- a/plugin/adsk/scripts/mayaUSDRegisterStrings.mel +++ b/plugin/adsk/scripts/mayaUSDRegisterStrings.mel @@ -177,6 +177,11 @@ global proc mayaUSDRegisterStrings() register("kExportMaterialsDefaultScopeName", "mtl"); register("kExportMergeShapesAnn", "Merges Maya transform and shape nodes into a single USD prim."); register("kExportMergeShapesLbl", "Merge Transform and Shape Nodes"); + register("kExportIncludeEmptyTransformsAnn", "If selected, transforms that don't contain objects other\n" + + "than transforms will be included as part of the export\n" + + "(ex: empty groups, or groups that contain empty groups,\n" + + "and so on)."); + register("kExportIncludeEmptyTransformsLbl", "Include Empty Transforms"); register("kExportNamespacesAnn", "By default, namespaces are exported to the USD file in the following format: nameSpaceExample_pPlatonic1"); register("kExportNamespacesLbl", "Include Namespaces"); register("kExportWorldspaceAnn", "Exports the root prims with their worldspace transform instead of their local transform."); diff --git a/plugin/adsk/scripts/mayaUsdTranslatorExport.mel b/plugin/adsk/scripts/mayaUsdTranslatorExport.mel index 99c04c4405..6634e1fea5 100644 --- a/plugin/adsk/scripts/mayaUsdTranslatorExport.mel +++ b/plugin/adsk/scripts/mayaUsdTranslatorExport.mel @@ -777,6 +777,7 @@ global proc mayaUsdTranslatorExport_EnableAllControls() { optionMenuGrp -e -en 1 exportInstancesPopup; checkBoxGrp -e -en 1 exportVisibilityCheckBox; checkBoxGrp -e -en 1 mergeTransformAndShapeCheckBox; + checkBoxGrp -e -en 1 includeEmptyTransformsCheckBox; checkBoxGrp -e -en 1 includeNamespacesCheckBox; checkBoxGrp -e -en 1 worldspaceCheckBox; } @@ -888,6 +889,8 @@ global proc mayaUsdTranslatorExport_SetFromOptions(string $currentOptions, int $ mayaUsdTranslatorExport_SetCheckbox($optionBreakDown[1], $enable, "exportVisibilityCheckBox"); } else if ($optionBreakDown[0] == "mergeTransformAndShape") { mayaUsdTranslatorExport_SetCheckbox($optionBreakDown[1], $enable, "mergeTransformAndShapeCheckBox"); + } else if ($optionBreakDown[0] == "includeEmptyTransforms") { + mayaUsdTranslatorExport_SetCheckbox($optionBreakDown[1], $enable, "includeEmptyTransformsCheckBox"); } else if ($optionBreakDown[0] == "stripNamespaces") { mayaUsdTranslatorExport_SetOppositeCheckbox($optionBreakDown[1], $enable, "includeNamespacesCheckBox"); } else if ($optionBreakDown[0] == "worldspace") { @@ -1211,6 +1214,9 @@ global proc int mayaUsdTranslatorExport (string $parent, checkBoxGrp -label "" -label1 `getMayaUsdString("kExportMergeShapesLbl")` -annotation `getMayaUsdString("kExportMergeShapesAnn")` mergeTransformAndShapeCheckBox; + checkBoxGrp -label "" -label1 `getMayaUsdString("kExportIncludeEmptyTransformsLbl")` -value1 1 + -annotation `getMayaUsdString("kExportIncludeEmptyTransformsAnn")` includeEmptyTransformsCheckBox; + checkBoxGrp -label "" -label1 `getMayaUsdString("kExportNamespacesLbl")` -annotation `getMayaUsdString("kExportNamespacesAnn")` includeNamespacesCheckBox; checkBoxGrp -label "" -label1 `getMayaUsdString("kExportWorldspaceLbl")` -annotation `getMayaUsdString("kExportWorldspaceAnn")` worldspaceCheckBox; @@ -1273,6 +1279,7 @@ global proc int mayaUsdTranslatorExport (string $parent, $currentOptions = mayaUsdTranslatorExport_AppendFromBoolPopup($currentOptions, "exportInstances", "exportInstancesPopup"); $currentOptions = mayaUsdTranslatorExport_AppendFromCheckbox($currentOptions, "exportVisibility", "exportVisibilityCheckBox"); $currentOptions = mayaUsdTranslatorExport_AppendFromCheckbox($currentOptions, "mergeTransformAndShape", "mergeTransformAndShapeCheckBox"); + $currentOptions = mayaUsdTranslatorExport_AppendFromCheckbox($currentOptions, "includeEmptyTransforms", "includeEmptyTransformsCheckBox"); $currentOptions = mayaUsdTranslatorExport_AppendOppositeFromCheckbox($currentOptions, "stripNamespaces", "includeNamespacesCheckBox"); $currentOptions = mayaUsdTranslatorExport_AppendFromCheckbox($currentOptions, "worldspace", "worldspaceCheckBox"); } diff --git a/test/lib/usd/plugin/CMakeLists.txt b/test/lib/usd/plugin/CMakeLists.txt index 0a87b18560..8665a74c01 100644 --- a/test/lib/usd/plugin/CMakeLists.txt +++ b/test/lib/usd/plugin/CMakeLists.txt @@ -271,3 +271,11 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/plugInfoSiteSpecificConfig.json" "${CMAKE_CURRENT_BINARY_DIR}/SiteSpecificConfig/plugInfo.json" ) +# ----------------------------------------------------------------------------- +# Export empty tests (testUsdExportEmptyXforms.py): +# ----------------------------------------------------------------------------- + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/plugInfoExportEmptyConfig.json" + "${CMAKE_CURRENT_BINARY_DIR}/ExportEmptyConfig/plugInfo.json" +) + diff --git a/test/lib/usd/plugin/plugInfoExportEmptyConfig.json b/test/lib/usd/plugin/plugInfoExportEmptyConfig.json new file mode 100644 index 0000000000..2e2da15d9f --- /dev/null +++ b/test/lib/usd/plugin/plugInfoExportEmptyConfig.json @@ -0,0 +1,15 @@ +{ + "Plugins": [ + { + "Info": { + "UsdMaya": { + "UsdExport": { + "chaser": ["AddPayloadOrRefChaser"] + } + } + }, + "Name": "AddPayloadOrRefChaser", + "Type": "resource" + } + ] +} diff --git a/test/lib/usd/translators/CMakeLists.txt b/test/lib/usd/translators/CMakeLists.txt index c2d6e5945f..1a2472b993 100644 --- a/test/lib/usd/translators/CMakeLists.txt +++ b/test/lib/usd/translators/CMakeLists.txt @@ -302,3 +302,9 @@ mayaUsd_add_test(testUsdImportExportSiteSpecificConfig ) set_property(TEST testUsdImportExportSiteSpecificConfig APPEND PROPERTY LABELS translators) +mayaUsd_add_test(testUsdExportEmptyXforms + PYTHON_MODULE testUsdExportEmptyXforms + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ENV + "${PXR_OVERRIDE_PLUGINPATH_NAME}=${CMAKE_CURRENT_BINARY_DIR}/../plugin/ExportEmptyConfig" +) diff --git a/test/lib/usd/translators/testUsdExportEmptyXforms.py b/test/lib/usd/translators/testUsdExportEmptyXforms.py new file mode 100644 index 0000000000..201c4972d8 --- /dev/null +++ b/test/lib/usd/translators/testUsdExportEmptyXforms.py @@ -0,0 +1,262 @@ +#!/usr/bin/env mayapy +# +# Copyright 2024 Autodesk +# +# 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. +# + +import os +import unittest + +from pxr import Usd + +from maya import cmds +from maya import standalone +import mayaUsd.lib + +import fixturesUtils + +class AddPayloadOrRefChaser(mayaUsd.lib.ExportChaser): + ''' + Export chaser used to add a payload or reference to a prim so that + we can test that a prim with a payload or ref is not considered empty. + + For this class to be found, the PXR_OVERRIDE_PLUGINPATH_NAME env var + must point to the location of the `plugInfo.json` file specific to + this chaser, which is in `ExportEmptyConfig` and setup by Cmake in + `test/lib/usd/plugin/plugInfoExportEmptyConfig.json` by the cmake + file in that folder. + ''' + + addPayloadOn = None + addRefOn = None + + def __init__(self, factoryContext, *args, **kwargs): + super(AddPayloadOrRefChaser, self).__init__(factoryContext, *args, **kwargs) + self.stage = factoryContext.GetStage() + + def PostExport(self): + ''' + Called by the MayaUSD USD export process at the end of the export. + ''' + self._addPayload(self.stage, self.addPayloadOn) + self._addRef(self.stage, self.addRefOn) + + # Clear stage so that we don't accidentally retain the USD stage. + self.stage = None + + # We must return true to keep the export going. + return True + + @staticmethod + def _addPayload(stage, path): + ''' + Add a payload to a prim on the stage. + ''' + if not stage: + return + + if not path: + return + + prim = stage.GetPrimAtPath(path) + if not prim: + return + + payloadFile = '/dummy/file/does/not/matter.usd' + prim.GetPayloads().AddPayload(path) + + @staticmethod + def _addRef(stage, path): + ''' + Add a USD reference to a prim on the stage. + ''' + if not stage: + return + + if not path: + return + + prim = stage.GetPrimAtPath(path) + if not prim: + return + + refFile = '/dummy/file/does/not/matter.usd' + prim.GetReferences().AddReference(refFile) + + +class testUsdExportEmptyXforms(unittest.TestCase): + + @classmethod + def tearDownClass(cls): + standalone.uninitialize() + + @classmethod + def setUpClass(cls): + inputPath = fixturesUtils.setUpClass(__file__) + + def _setupTest(self): + AddPayloadOrRefChaser.addPayloadOn = None + AddPayloadOrRefChaser.addRefOn = None + mayaUsd.lib.ExportChaser.Register(AddPayloadOrRefChaser, "AddPayloadOrRefChaser") + + def _createNestedEmpties(self): + ''' + Create a series of nested empty groups. + null1 + null2 + null3 + null4 + ''' + cmds.file(new=True, force=True) + cmds.CreateEmptyGroup() + cmds.CreateEmptyGroup() + cmds.CreateEmptyGroup() + cmds.CreateEmptyGroup() + cmds.parent('null2', 'null1') + cmds.parent('null3', 'null2') + cmds.parent('null4', 'null2') + + createdPrims = [ + '/null1', + '/null1/null2', + '/null1/null2/null3', + '/null1/null2/null4' + ] + return createdPrims + + def _exportToUSD(self, filename, includeEmpties, defaultPrimPath=None): + ''' + Export to USD, either including or excluding empty Xforms. + ''' + cmds.usdExport(file=filename, includeEmptyTransforms=includeEmpties, defaultPrim=defaultPrimPath) + + def _verifyPrims(self, stage, present = [], absent = []): + ''' + Verify if the Xforms are present or not, as expected. + ''' + for path in present: + prim = stage.GetPrimAtPath(path) + self.assertTrue(bool(prim), 'Expected path %s to be present' % path) + + for path in absent: + prim = stage.GetPrimAtPath(path) + self.assertFalse(bool(prim), 'Expected path %s to be absent' % path) + + def testExportIncludeEmpty(self): + self._setupTest() + includeEmpties = True + + createdPrims = self._createNestedEmpties() + + usdFilePath = os.path.abspath('UsdExportIncludeEmptyTest.usda') + cmds.select('null1') + self._exportToUSD(usdFilePath, includeEmpties) + + stage = Usd.Stage.Open(usdFilePath) + self.assertTrue(stage) + + self._verifyPrims(stage, present=createdPrims) + + def testExportExcludeEmpty(self): + self._setupTest() + includeEmpties = False + + createdPrims = self._createNestedEmpties() + + usdFilePath = os.path.abspath('UsdExportExcludeEmptyTest.usda') + cmds.select('null1') + self._exportToUSD(usdFilePath, includeEmpties) + + stage = Usd.Stage.Open(usdFilePath) + self.assertTrue(stage) + + self._verifyPrims(stage, absent=createdPrims) + + def testExportExcludeEmptyButKeepPrims(self): + self._setupTest() + includeEmpties = False + + createdPrims = self._createNestedEmpties() + + cmds.sphere()[0] + + usdFilePath = os.path.abspath('UsdExportExcludeEmptyTest.usda') + cmds.select('null1') + self._exportToUSD(usdFilePath, includeEmpties) + + stage = Usd.Stage.Open(usdFilePath) + self.assertTrue(stage) + + present = ["/nurbsSphere1", "/nurbsSphere1/mtl", "/nurbsSphere1/mtl/initialShadingGroup"] + self._verifyPrims(stage, absent=createdPrims, present=present) + + def testExportExcludeEmptyButDefaultPrim(self): + self._setupTest() + includeEmpties = False + + createdPrims = self._createNestedEmpties() + defaultPrimPath = '/null1/null2/null3' + + usdFilePath = os.path.abspath('UsdExportExcludeEmptyTest.usda') + cmds.select('null1') + self._exportToUSD(usdFilePath, includeEmpties, defaultPrimPath=defaultPrimPath) + + stage = Usd.Stage.Open(usdFilePath) + self.assertTrue(stage) + + present = createdPrims[:] + present.remove('/null1/null2/null4') + absent = ['/null1/null2/null4'] + self._verifyPrims(stage, absent=absent, present=present) + + def testExportExcludeEmptyWithPayload(self): + self._setupTest() + includeEmpties = False + AddPayloadOrRefChaser.addPayloadOn = '/null1/null2/null3' + + createdPrims = self._createNestedEmpties() + + usdFilePath = os.path.abspath('UsdExportExcludeEmptyTest.usda') + cmds.select('null1') + self._exportToUSD(usdFilePath, includeEmpties) + + stage = Usd.Stage.Open(usdFilePath) + self.assertTrue(stage) + + present = createdPrims[:] + present.remove('/null1/null2/null4') + absent = ['/null1/null2/null4'] + self._verifyPrims(stage, present=present, absent=absent) + + def testExportExcludeEmptyWithReference(self): + self._setupTest() + includeEmpties = False + AddPayloadOrRefChaser.addRefOn = '/null1/null2' + + self._createNestedEmpties() + + usdFilePath = os.path.abspath('UsdExportExcludeEmptyTest.usda') + cmds.select('null1') + self._exportToUSD(usdFilePath, includeEmpties) + + stage = Usd.Stage.Open(usdFilePath) + self.assertTrue(stage) + + present = ['/null1', '/null1/null2'] + absent = ['/null1/null2/null3', '/null1/null2/null4'] + self._verifyPrims(stage, present=present, absent=absent) + + +if __name__ == '__main__': + unittest.main(verbosity=2) From 82c35add9848f1c8d87ecfccfa154c41a02bc8b5 Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Fri, 26 Apr 2024 10:26:21 -0400 Subject: [PATCH 14/19] EMSUSD-209 add comments about why we ignore parameters --- .../resources/ae/usdschemabase/material_custom_control.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py b/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py index ee9b8572ec..8fb0a4abe4 100644 --- a/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py +++ b/lib/mayaUsd/resources/ae/usdschemabase/material_custom_control.py @@ -253,6 +253,8 @@ def _fillGraphButton(self, matPathStr, button, menu): command = '' cmds.popupMenu(menu, edit=True, postMenuCommand=command) + # Note: the ignore1 and ignore2 parameters are the values provided by the MEL callback + # specifying the menu and item being selected that we don't care about. @staticmethod def _fillGraphMenu(ignore1, ignore2, menu, ufePathStr): ''' @@ -283,6 +285,8 @@ def _fillGraphMenu(ignore1, ignore2, menu, ufePathStr): command = partial(MaterialCustomControl._showInExistingTab, tabName=tabName, ufePathStr=ufePathStr) cmds.menuItem(parent=menu, label=tabName, command=command) + # Note: the ignore parameter is the value provided by the MEL callback + # specifying the item being selected that we don't care about. @staticmethod def _showInNewTab(ignore, ufePathStr): ''' @@ -293,6 +297,8 @@ def _showInNewTab(ignore, ufePathStr): tabName = cmds.lookdevXGraph(openNewTab='USD') MaterialCustomControl._showInExistingTab(ignore, tabName=tabName, ufePathStr=ufePathStr) + # Note: the ignore parameter is the value provided by the MEL callback + # specifying the item being selected that we don't care about. @staticmethod def _showInExistingTab(ignore, tabName, ufePathStr): ''' From e1e9b0593a3c6790dba0c6c9e9b787ff2cff9fe0 Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Mon, 29 Apr 2024 15:27:27 -0400 Subject: [PATCH 15/19] EMSUSD-209 add unit test for the material custom control --- test/lib/testAttributeEditorTemplate.py | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/lib/testAttributeEditorTemplate.py b/test/lib/testAttributeEditorTemplate.py index b0992fa011..7ca547a665 100644 --- a/test/lib/testAttributeEditorTemplate.py +++ b/test/lib/testAttributeEditorTemplate.py @@ -181,6 +181,32 @@ def testAETemplate(self): frameLayout = self.searchForMayaControl(startLayout, cmds.frameLayout, sectionName) self.assertIsNotNone(frameLayout, 'Could not find Extra Attributes frameLayout') + def testAECustomMaterialControl(self): + '''Simple test for the MaterialCustomControl in AE template.''' + + cmds.file(new=True, force=True) + testFile = testUtils.getTestScene("MaterialX", "MayaSurfaces.usda") + shapeNode,shapeStage = mayaUtils.createProxyFromFile(testFile) + + # Select this prim which has a custom material control attribute. + cmds.select('|stage|stageShape,/pCube1', r=True) + + # Make sure the AE is visible. + import maya.mel + maya.mel.eval('openAEWindow') + + # In the AE there is a formLayout for each USD prim type. We start + # by making sure we can find the one for the mesh. + meshFormLayout = self.attrEdFormLayoutName('Mesh') + self.assertTrue(cmds.formLayout(meshFormLayout, exists=True)) + startLayout = cmds.formLayout(meshFormLayout, query=True, fullPathName=True) + self.assertIsNotNone(startLayout, 'Could not get full path for Mesh formLayout') + + # We can now search for the control for the meterial. + assignedMaterialControl = self.searchForMayaControl(meshFormLayout, cmds.text, 'Assigned Material') + self.assertIsNotNone(assignedMaterialControl, 'Could not find the "Assigned Material" control') + strengthControl = self.searchForMayaControl(meshFormLayout, cmds.optionMenuGrp, 'Strength') + self.assertIsNotNone(strengthControl, 'Could not find the "Strength" control') def testAECustomImageControl(self): '''Simple test for the customImageControlCreator in AE template.''' From 9ba30653fa2903dc57a5fe7413a2b4b902ab3c42 Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Mon, 29 Apr 2024 17:10:18 -0400 Subject: [PATCH 16/19] EMSUSD-209 fixed unit test Make sure the material section is expanded by default. --- lib/mayaUsd/resources/ae/usdschemabase/ae_template.py | 4 ++-- test/lib/testAttributeEditorTemplate.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py b/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py index 707dd74dc8..124799d2e9 100644 --- a/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py +++ b/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py @@ -992,10 +992,10 @@ def createMaterialAttributeSection(self): if not mat: return layoutName = getMayaUsdLibString('kLabelMaterial') - collapse = True + collapse = False with ufeAeTemplate.Layout(self, layoutName, collapse): createdControl = MaterialCustomControl(self.item, self.prim, self.useNiceName) - self.defineCustom(createdControl) + self.defineCustom(createdControl) def suppressArrayAttribute(self): # Suppress all array attributes. diff --git a/test/lib/testAttributeEditorTemplate.py b/test/lib/testAttributeEditorTemplate.py index 7ca547a665..498a25e9af 100644 --- a/test/lib/testAttributeEditorTemplate.py +++ b/test/lib/testAttributeEditorTemplate.py @@ -201,11 +201,16 @@ def testAECustomMaterialControl(self): self.assertTrue(cmds.formLayout(meshFormLayout, exists=True)) startLayout = cmds.formLayout(meshFormLayout, query=True, fullPathName=True) self.assertIsNotNone(startLayout, 'Could not get full path for Mesh formLayout') - + + # In the AE there is a formLayout for each USD prim type. We start + # by making sure we can find the one for the mesh. + materialFormLayout = self.searchForMayaControl(startLayout, cmds.frameLayout, 'Material') + self.assertIsNotNone(materialFormLayout, 'Could not find "Material" frameLayout') + # We can now search for the control for the meterial. - assignedMaterialControl = self.searchForMayaControl(meshFormLayout, cmds.text, 'Assigned Material') + assignedMaterialControl = self.searchForMayaControl(materialFormLayout, cmds.text, 'Assigned Material') self.assertIsNotNone(assignedMaterialControl, 'Could not find the "Assigned Material" control') - strengthControl = self.searchForMayaControl(meshFormLayout, cmds.optionMenuGrp, 'Strength') + strengthControl = self.searchForMayaControl(materialFormLayout, cmds.optionMenuGrp, 'Strength') self.assertIsNotNone(strengthControl, 'Could not find the "Strength" control') def testAECustomImageControl(self): From 932863583bc488d09ca1bee2807e0446bbda20cb Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Tue, 30 Apr 2024 09:34:24 -0400 Subject: [PATCH 17/19] EMSUSD01118 instance selection highlight Detect the need to redo the selection highlight by detecting if the instance count changed. Unfortunately, the instancer index version only changes when an instance was toggle off, not when togged on. Might be a bug or not in USD, but we work around it by tracking the instance count too. --- .../render/vp2RenderDelegate/proxyRenderDelegate.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.h b/lib/mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.h index b862e53d94..961925b583 100644 --- a/lib/mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.h +++ b/lib/mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.h @@ -425,27 +425,31 @@ class ProxyRenderDelegate //! The combined instancer index version and instance index change count the last time //! _Execute was called unsigned int _instanceIndex { 0 }; + //! The instance count the last time _Execute was called + unsigned int _instanceCount { 0 }; void sync(const HdChangeTracker& tracker) { _renderTag = tracker.GetRenderTagVersion(); _visibility = tracker.GetVisibilityChangeCount(); _instanceIndex = tracker.GetInstancerIndexVersion(); + _instanceCount = tracker.GetInstanceIndicesChangeCount(); } - bool renderTagValid(const HdChangeTracker& tracker) + bool renderTagValid(const HdChangeTracker& tracker) const { return _renderTag == tracker.GetRenderTagVersion(); } - bool visibilityValid(const HdChangeTracker& tracker) + bool visibilityValid(const HdChangeTracker& tracker) const { return _visibility == tracker.GetVisibilityChangeCount(); } - bool instanceIndexValid(const HdChangeTracker& tracker) + bool instanceIndexValid(const HdChangeTracker& tracker) const { - return _instanceIndex == tracker.GetInstancerIndexVersion(); + return _instanceIndex == tracker.GetInstancerIndexVersion() + && _instanceCount == tracker.GetInstanceIndicesChangeCount(); } void reset() @@ -453,6 +457,7 @@ class ProxyRenderDelegate _renderTag = 0; _visibility = 0; _instanceIndex = 0; + _instanceCount = 0; } }; HdChangeTrackerVersions _changeVersions; From 2b4ded9c98fb1e23dac541ed5bbde929d464e4ad Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Tue, 30 Apr 2024 10:48:56 -0400 Subject: [PATCH 18/19] EMSUSD-1118 support older USD versions The fix is only available in somewhat recent USD versions. Maya 2022 and 2024 are not supported. --- cmake/modules/FindUSD.cmake | 10 ++++++++++ lib/mayaUsd/CMakeLists.txt | 8 ++++++++ .../render/vp2RenderDelegate/proxyRenderDelegate.h | 11 ++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cmake/modules/FindUSD.cmake b/cmake/modules/FindUSD.cmake index 1030b1652b..be086525af 100644 --- a/cmake/modules/FindUSD.cmake +++ b/cmake/modules/FindUSD.cmake @@ -121,6 +121,16 @@ if(USD_INCLUDE_DIR) endif() endif() +# See if USD changetracker has instance count. +set(USD_HAS_TRACKER_INSTANCE_COUNT FALSE CACHE INTERNAL "USD.Track.InstanceCount") +if (USD_INCLUDE_DIR AND EXISTS "${USD_INCLUDE_DIR}/pxr/imaging/hd/changeTracker.h") + file(STRINGS ${USD_INCLUDE_DIR}/pxr/imaging/hd/changeTracker.h USD_HAS_API REGEX "GetInstanceIndicesChangeCount") + if(USD_HAS_API) + set(USD_HAS_TRACKER_INSTANCE_COUNT TRUE CACHE INTERNAL "USD.Track.InstanceCount") + message(STATUS "USD has tracker instance count") + endif() +endif() + # See if MaterialX shaders with color4 inputs exist natively in Sdr: # Not yet in a tagged USD version: https://github.com/PixarAnimationStudios/USD/pull/1894 set(USD_HAS_COLOR4_SDR_SUPPORT FALSE CACHE INTERNAL "USD.Sdr.PropertyTypes.Color4") diff --git a/lib/mayaUsd/CMakeLists.txt b/lib/mayaUsd/CMakeLists.txt index f12bf6797a..ec766b4c43 100644 --- a/lib/mayaUsd/CMakeLists.txt +++ b/lib/mayaUsd/CMakeLists.txt @@ -164,6 +164,14 @@ if (MAYA_HAS_GET_MEMBER_PATHS) ) endif() +message(STATUS "USD_HAS_TRACKER_INSTANCE_COUNT is ${USD_HAS_TRACKER_INSTANCE_COUNT}") +if (USD_HAS_TRACKER_INSTANCE_COUNT) + target_compile_definitions(${PROJECT_NAME} + PRIVATE + USD_HAS_TRACKER_INSTANCE_COUNT=1 + ) +endif() + message(STATUS "USD_HAS_COLOR4_SDR_SUPPORT is ${USD_HAS_COLOR4_SDR_SUPPORT}") if (USD_HAS_COLOR4_SDR_SUPPORT) target_compile_definitions(${PROJECT_NAME} diff --git a/lib/mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.h b/lib/mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.h index 961925b583..857f039f61 100644 --- a/lib/mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.h +++ b/lib/mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.h @@ -425,15 +425,19 @@ class ProxyRenderDelegate //! The combined instancer index version and instance index change count the last time //! _Execute was called unsigned int _instanceIndex { 0 }; +#ifdef USD_HAS_TRACKER_INSTANCE_COUNT //! The instance count the last time _Execute was called unsigned int _instanceCount { 0 }; +#endif void sync(const HdChangeTracker& tracker) { _renderTag = tracker.GetRenderTagVersion(); _visibility = tracker.GetVisibilityChangeCount(); _instanceIndex = tracker.GetInstancerIndexVersion(); +#ifdef USD_HAS_TRACKER_INSTANCE_COUNT _instanceCount = tracker.GetInstanceIndicesChangeCount(); +#endif } bool renderTagValid(const HdChangeTracker& tracker) const @@ -449,7 +453,10 @@ class ProxyRenderDelegate bool instanceIndexValid(const HdChangeTracker& tracker) const { return _instanceIndex == tracker.GetInstancerIndexVersion() - && _instanceCount == tracker.GetInstanceIndicesChangeCount(); +#ifdef USD_HAS_TRACKER_INSTANCE_COUNT + && _instanceCount == tracker.GetInstanceIndicesChangeCount() +#endif + ; } void reset() @@ -457,7 +464,9 @@ class ProxyRenderDelegate _renderTag = 0; _visibility = 0; _instanceIndex = 0; +#ifdef USD_HAS_TRACKER_INSTANCE_COUNT _instanceCount = 0; +#endif } }; HdChangeTrackerVersions _changeVersions; From 7dd8c085b07a675f5446919a1136e41c1dfc6f0b Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Tue, 30 Apr 2024 14:32:28 -0400 Subject: [PATCH 19/19] EMSUSD-1118 fix affect unit tests Explicitly set the selection instead of trying to change the images because the behavior is different between Maya 2022 and the later versions because the fix is only available starting with Maya 2023. It is simpler to make the text behave the same in all version by explicitly selecting the object that the image expect to be selected. (Even if it was by mistake in Maya 2022...) --- .../testVP2RenderDelegatePerInstanceInheritedData.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/lib/mayaUsd/render/vp2RenderDelegate/testVP2RenderDelegatePerInstanceInheritedData.py b/test/lib/mayaUsd/render/vp2RenderDelegate/testVP2RenderDelegatePerInstanceInheritedData.py index 28486b9c58..0a13e5e448 100644 --- a/test/lib/mayaUsd/render/vp2RenderDelegate/testVP2RenderDelegatePerInstanceInheritedData.py +++ b/test/lib/mayaUsd/render/vp2RenderDelegate/testVP2RenderDelegatePerInstanceInheritedData.py @@ -100,10 +100,13 @@ def testPerInstanceInheritedData(self): self.assertSnapshotClose('%s_ball_03_selected.png' % self._testName) ball_03_vis.Set('hidden') + cmds.select("|stage|stageShape,/root/group/ball_04") self.assertSnapshotClose('%s_ball_03_hidden.png' % self._testName) ball_04_vis.Set('hidden') + cmds.select("|stage|stageShape,/root/group/ball_05") self.assertSnapshotClose('%s_ball_03_and_04_hidden.png' % self._testName) ball_03_vis.Set('inherited') # this should show the object again + cmds.select("|stage|stageShape,/root/group/ball_03") self.assertSnapshotClose('%s_ball_04_hidden.png' % self._testName) ball_04_vis.Set('inherited') self.assertSnapshotClose('%s_shown_after_hidden.png' % self._testName)