From b46e26a1da27605e180ed6d41ee698faea3d043b Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:23:42 -0400 Subject: [PATCH 1/7] EMSUSD-751 - UsdUfe: Move Ufe::Attributes interface implementation * Tokens moved: generic and some of the meta data. * Functions moved: * prettifyName (python wrapper) * isConnected() * canRemoveSrcProperty() / canRemoveDstProperty() * usdTypeToUfe() / ufeTypeToUsd() * usdAttrFromUfeAttr() / attrFromUfeAttrInfo() * vtValueFromString() * splitString() * Classes moved: * UsdAttributesHandler/UsdAttributes/UsdAttribute/UsdAttributeHolder * UsdShaderAttributeDef/UsdShaderAttributeHolder/ * UsdAddAttributeCommand/UsdRemoveAttributeCommand/UsdRenameAttributeCommand * New (optional) DCC message (info/warning/error) functions. * Removed Maya setting isAttributeLocked function as a default implementation exists in UsdUfe. * Moved code from UsdShaderNodeDefHandler::usdDefinition() to UsdUfe::usdShaderNodeFromSceneItem(). * Removed mayaUsd inline prettifyName(). --- lib/mayaUsd/CMakeLists.txt | 14 - lib/mayaUsd/base/tokens.cpp | 1 - lib/mayaUsd/base/tokens.h | 27 +- lib/mayaUsd/nodes/proxyAccessor.cpp | 11 +- lib/mayaUsd/python/wrapTokens.cpp | 1 - lib/mayaUsd/python/wrapUtil.cpp | 2 - .../resources/ae/usdschemabase/ae_template.py | 6 +- .../usdschemabase/attribute_custom_control.py | 3 +- lib/mayaUsd/ufe/CMakeLists.txt | 30 -- lib/mayaUsd/ufe/Global.cpp | 13 +- lib/mayaUsd/ufe/UsdConnectionHandler.cpp | 47 +- lib/mayaUsd/ufe/UsdShaderNodeDef.cpp | 26 +- lib/mayaUsd/ufe/UsdShaderNodeDefHandler.cpp | 26 +- lib/mayaUsd/ufe/UsdUndoConnectionCommands.cpp | 57 +-- lib/mayaUsd/ufe/UsdUndoDeleteCommand.cpp | 4 +- lib/mayaUsd/ufe/Utils.cpp | 441 ------------------ lib/mayaUsd/ufe/Utils.h | 34 +- lib/mayaUsd/utils/CMakeLists.txt | 2 - lib/mayaUsd/utils/converter.cpp | 44 +- lib/mayaUsd/utils/converter.h | 37 +- lib/mayaUsd/utils/copyLayerPrims.cpp | 2 +- lib/mayaUsd/utils/selectability.cpp | 8 +- lib/mayaUsd/utils/util.h | 1 - lib/mayaUsdAPI/utils.cpp | 10 +- lib/usd/translators/mayaReferenceUpdater.cpp | 2 +- lib/usdUfe/CMakeLists.txt | 7 + lib/usdUfe/base/tokens.cpp | 2 + lib/usdUfe/base/tokens.h | 34 +- lib/usdUfe/python/wrapTokens.cpp | 2 + lib/usdUfe/python/wrapUtils.cpp | 4 +- lib/usdUfe/ufe/CMakeLists.txt | 43 +- lib/usdUfe/ufe/Global.cpp | 4 + lib/usdUfe/ufe/Global.h | 4 +- lib/{mayaUsd => usdUfe}/ufe/UsdAttribute.cpp | 138 +++--- lib/{mayaUsd => usdUfe}/ufe/UsdAttribute.h | 15 +- .../ufe/UsdAttributeHolder.cpp | 38 +- .../ufe/UsdAttributeHolder.h | 8 +- lib/{mayaUsd => usdUfe}/ufe/UsdAttributes.cpp | 40 +- lib/{mayaUsd => usdUfe}/ufe/UsdAttributes.h | 17 +- .../ufe/UsdAttributesHandler.cpp | 8 +- .../ufe/UsdAttributesHandler.h | 14 +- .../ufe/UsdShaderAttributeDef.cpp | 30 +- .../ufe/UsdShaderAttributeDef.h | 12 +- .../ufe/UsdShaderAttributeHolder.cpp | 24 +- .../ufe/UsdShaderAttributeHolder.h | 8 +- .../ufe/UsdUndoAttributesCommands.cpp | 12 +- .../ufe/UsdUndoAttributesCommands.h | 18 +- lib/usdUfe/ufe/Utils.cpp | 282 ++++++++++- lib/usdUfe/ufe/Utils.h | 52 ++- lib/usdUfe/utils/CMakeLists.txt | 2 + lib/usdUfe/utils/Utils.cpp | 16 + lib/usdUfe/utils/Utils.h | 5 + lib/{mayaUsd => usdUfe}/utils/editability.cpp | 14 +- lib/{mayaUsd => usdUfe}/utils/editability.h | 14 +- lib/usdUfe/utils/usdUtils.cpp | 233 +++++++++ lib/usdUfe/utils/usdUtils.h | 20 + plugin/adsk/plugin/adskMaterialCommands.cpp | 5 +- test/lib/mayaUsd/utils/testSplitString.cpp | 8 +- .../lib/mayaUsd/utils/testUtilsEditability.py | 7 +- .../mayaUsd/utils/testUtilsSelectability.py | 9 +- ...tilsSelectabilityPointInstanceSelection.py | 7 +- test/lib/ufe/testAttribute.py | 32 +- 62 files changed, 1044 insertions(+), 993 deletions(-) rename lib/{mayaUsd => usdUfe}/ufe/UsdAttribute.cpp (89%) rename lib/{mayaUsd => usdUfe}/ufe/UsdAttribute.h (99%) rename lib/{mayaUsd => usdUfe}/ufe/UsdAttributeHolder.cpp (95%) rename lib/{mayaUsd => usdUfe}/ufe/UsdAttributeHolder.h (95%) rename lib/{mayaUsd => usdUfe}/ufe/UsdAttributes.cpp (96%) rename lib/{mayaUsd => usdUfe}/ufe/UsdAttributes.h (91%) rename lib/{mayaUsd => usdUfe}/ufe/UsdAttributesHandler.cpp (88%) rename lib/{mayaUsd => usdUfe}/ufe/UsdAttributesHandler.h (77%) rename lib/{mayaUsd => usdUfe}/ufe/UsdShaderAttributeDef.cpp (92%) rename lib/{mayaUsd => usdUfe}/ufe/UsdShaderAttributeDef.h (87%) rename lib/{mayaUsd => usdUfe}/ufe/UsdShaderAttributeHolder.cpp (94%) rename lib/{mayaUsd => usdUfe}/ufe/UsdShaderAttributeHolder.h (95%) rename lib/{mayaUsd => usdUfe}/ufe/UsdUndoAttributesCommands.cpp (94%) rename lib/{mayaUsd => usdUfe}/ufe/UsdUndoAttributesCommands.h (90%) rename lib/{mayaUsd => usdUfe}/utils/editability.cpp (82%) rename lib/{mayaUsd => usdUfe}/utils/editability.h (84%) diff --git a/lib/mayaUsd/CMakeLists.txt b/lib/mayaUsd/CMakeLists.txt index f12bf6797a..2413b49bc4 100644 --- a/lib/mayaUsd/CMakeLists.txt +++ b/lib/mayaUsd/CMakeLists.txt @@ -63,13 +63,6 @@ if(DEFINED UFE_PREVIEW_VERSION_NUM) ) endif() -if (UFE_HAS_DISPLAY_NAME) - target_compile_definitions(${PROJECT_NAME} - PRIVATE - UFE_HAS_DISPLAY_NAME=1 - ) -endif() - if (UFE_DEFAULT_VALUE_SUPPORT) target_compile_definitions(${PROJECT_NAME} PRIVATE @@ -77,13 +70,6 @@ if (UFE_DEFAULT_VALUE_SUPPORT) ) endif() -if (UFE_HAS_NATIVE_TYPE_METADATA) - target_compile_definitions(${PROJECT_NAME} - PRIVATE - UFE_HAS_NATIVE_TYPE_METADATA=1 - ) -endif() - message(STATUS "MAYA_HAS_DEFAULT_MATERIAL_API is ${MAYA_HAS_DEFAULT_MATERIAL_API}") if (MAYA_HAS_DEFAULT_MATERIAL_API) target_compile_definitions(${PROJECT_NAME} diff --git a/lib/mayaUsd/base/tokens.cpp b/lib/mayaUsd/base/tokens.cpp index e898cdfe81..eb9f26d808 100644 --- a/lib/mayaUsd/base/tokens.cpp +++ b/lib/mayaUsd/base/tokens.cpp @@ -19,7 +19,6 @@ PXR_NAMESPACE_OPEN_SCOPE TF_DEFINE_PUBLIC_TOKENS(MayaUsdOptionVars, MAYA_USD_OPTIONVAR_TOKENS); TF_DEFINE_PUBLIC_TOKENS(MayaUsdMetadata, MAYA_USD_METADATA_TOKENS); -TF_DEFINE_PUBLIC_TOKENS(MayaUsdTokens, MAYA_USD_GENERIC_TOKENS); TF_DEFINE_PUBLIC_TOKENS(MayaUsdEditRoutingTokens, MAYA_USD_EDIT_ROUTING_TOKENS); PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/mayaUsd/base/tokens.h b/lib/mayaUsd/base/tokens.h index e7a8088ae9..207fb18bbd 100644 --- a/lib/mayaUsd/base/tokens.h +++ b/lib/mayaUsd/base/tokens.h @@ -82,46 +82,21 @@ TF_DECLARE_PUBLIC_TOKENS(MayaUsdOptionVars, MAYAUSD_CORE_PUBLIC, MAYA_USD_OPTION // - All words following "maya" are capitalized. This falls in line // with how Maya convert the metadata names to UI labels in the // attribute editor: spaces are inserted before isolated capital -// letters, tjhen everything is lower-cases, then the whole label +// letters, then everything is lower-cases, then the whole label // is title-case. So, for example, "mayaLock" becomes "Maya lock". // // clang-format off #define MAYA_USD_METADATA_TOKENS \ /* Selectability metadata to be used on prims */ \ ((Selectability, "mayaSelectability")) \ - /* Locking attribute metadata. A locked attribute */ \ - /* value cannot be changed. */ \ - ((Lock, "mayaLock")) \ /* Referenced layers. */ \ ((ReferencedLayers, "mayaSharedLayers")) \ /* Export file path. */ \ ((ExportFilePathToken, "mayaExportFilePath")) \ - /* Metadata for UI queries */ \ - ((UIName, "uiname")) \ - ((UIFolder, "uifolder")) \ - ((UIMin, "uimin")) \ - ((UIMax, "uimax")) \ - ((UISoftMin, "uisoftmin")) \ - ((UISoftMax, "uisoftmax")) \ // clang-format on TF_DECLARE_PUBLIC_TOKENS(MayaUsdMetadata, MAYAUSD_CORE_PUBLIC, MAYA_USD_METADATA_TOKENS); -// generic tokens in MayaUSD -// -// clang-format off -#define MAYA_USD_GENERIC_TOKENS \ - /* Metadata value to inherit the value from a */ \ - /* parent prim. Used in selectability. */ \ - ((Inherit, "inherit")) \ - /* Metadata value to turn on or off a feature. */ \ - /* Used in selectability and lock, for example. */ \ - ((On, "on")) \ - ((Off, "off")) \ -// clang-format on - -TF_DECLARE_PUBLIC_TOKENS(MayaUsdTokens, MAYAUSD_CORE_PUBLIC, MAYA_USD_GENERIC_TOKENS); - // Tokens for edit routing in MayaUSD // // clang-format off diff --git a/lib/mayaUsd/nodes/proxyAccessor.cpp b/lib/mayaUsd/nodes/proxyAccessor.cpp index 2482e66587..4f0fe8e2f7 100644 --- a/lib/mayaUsd/nodes/proxyAccessor.cpp +++ b/lib/mayaUsd/nodes/proxyAccessor.cpp @@ -351,7 +351,7 @@ void ProxyAccessor::collectAccessorItems(MObject node) item.converter = Converter::find(typeName, false); } else { - UsdAttribute attribute = prim.GetAttribute(item.property); + PXR_NS::UsdAttribute attribute = prim.GetAttribute(item.property); if (!attribute.IsDefined()) { TF_DEBUG(USDMAYA_PROXYACCESSOR) @@ -532,7 +532,7 @@ MStatus ProxyAccessor::computeInput( if (item.property.IsEmpty() || !item.converter) return MS::kFailure; - UsdAttribute itemAttribute = itemPrim.GetAttribute(item.property); + PXR_NS::UsdAttribute itemAttribute = itemPrim.GetAttribute(item.property); if (!itemAttribute.IsDefined()) { TF_CODING_ERROR( @@ -615,7 +615,7 @@ MStatus ProxyAccessor::computeOutput( itemDataHandle.set(visible ? 1 : 0); } else if (item.converter) { - UsdAttribute itemAttribute = itemPrim.GetAttribute(item.property); + PXR_NS::UsdAttribute itemAttribute = itemPrim.GetAttribute(item.property); // cache this! expensive call if (!itemAttribute.IsDefined()) { @@ -714,8 +714,9 @@ MStatus ProxyAccessor::stageChanged(const MObject& node, const UsdNotice::Object SdfPath changedPrimPath = changedPath.GetAbsoluteRootOrPrimPath(); const UsdPrim& changedPrim = stage->GetPrimAtPath(changedPrimPath); - const TfToken& changedPropertyToken = changedPath.GetNameToken(); - UsdAttribute changedAttribute = changedPrim.GetAttribute(changedPropertyToken); + const TfToken& changedPropertyToken = changedPath.GetNameToken(); + PXR_NS::UsdAttribute changedAttribute + = changedPrim.GetAttribute(changedPropertyToken); converter->convert(changedAttribute, changedPlug, args); diff --git a/lib/mayaUsd/python/wrapTokens.cpp b/lib/mayaUsd/python/wrapTokens.cpp index 5487182872..93688fb1f9 100644 --- a/lib/mayaUsd/python/wrapTokens.cpp +++ b/lib/mayaUsd/python/wrapTokens.cpp @@ -25,7 +25,6 @@ void wrapTokens() { TF_PY_WRAP_PUBLIC_TOKENS("OptionVarTokens", MayaUsdOptionVars, MAYA_USD_OPTIONVAR_TOKENS); TF_PY_WRAP_PUBLIC_TOKENS("MetadataTokens", MayaUsdMetadata, MAYA_USD_METADATA_TOKENS); - TF_PY_WRAP_PUBLIC_TOKENS("Tokens", MayaUsdTokens, MAYA_USD_GENERIC_TOKENS); TF_PY_WRAP_PUBLIC_TOKENS( "EditRoutingTokens", MayaUsdEditRoutingTokens, MAYA_USD_EDIT_ROUTING_TOKENS); } diff --git a/lib/mayaUsd/python/wrapUtil.cpp b/lib/mayaUsd/python/wrapUtil.cpp index ada902065a..7beba34c14 100644 --- a/lib/mayaUsd/python/wrapUtil.cpp +++ b/lib/mayaUsd/python/wrapUtil.cpp @@ -64,8 +64,6 @@ void wrapUtil() scope s = class_("Util", no_init) .def("IsAuthored", UsdMayaUtil::IsAuthored) - .def("prettifyName", &UsdMayaUtil::prettifyName) - .staticmethod("prettifyName") .def("getDictionaryFromEncodedOptions", getDictionaryFromEncodedOptions) .def( "getPathRelativeToMayaSceneFile", diff --git a/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py b/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py index 6dac372175..23601549c8 100644 --- a/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py +++ b/lib/mayaUsd/resources/ae/usdschemabase/ae_template.py @@ -199,7 +199,7 @@ def onCreate(self, *args): for k in allMetadata: # All extra metadata is for display purposes only - it is not editable, but we # allow keyboard focus so you copy the value. - mdLabel = mayaUsdLib.Util.prettifyName(k) if self.useNiceName else k + mdLabel = mayaUsdUfe.prettifyName(k) if self.useNiceName else k self.extraMetadata[k] = cmds.textFieldGrp(label=mdLabel, editable=False, enableKeyboardFocus=True) # Update all metadata values. @@ -552,7 +552,7 @@ def parseShaderAttributes(self): if not label: label = nodeDef.GetFamily() - self._attributeLayout = AEShaderLayout.Group(self._attributeLayout.name + ": " + mayaUsdLib.Util.prettifyName(label)) + self._attributeLayout = AEShaderLayout.Group(self._attributeLayout.name + ": " + mayaUsdUfe.prettifyName(label)) # Best option: Use ordering metadata found the Sdr properties: hasMetadataOrdering = False @@ -769,7 +769,7 @@ def sectionNameFromSchema(self, schemaTypeName): schemaTypeName = schemaTypeName.replace(p, r, 1) break - schemaTypeName = mayaUsdLib.Util.prettifyName(schemaTypeName) + schemaTypeName = mayaUsdUfe.prettifyName(schemaTypeName) # if the schema name ends with "api" or "API", trim it. if schemaTypeName.endswith("api") or schemaTypeName.endswith("API"): diff --git a/lib/mayaUsd/resources/ae/usdschemabase/attribute_custom_control.py b/lib/mayaUsd/resources/ae/usdschemabase/attribute_custom_control.py index 3df364dd7c..d75d5e4bbc 100644 --- a/lib/mayaUsd/resources/ae/usdschemabase/attribute_custom_control.py +++ b/lib/mayaUsd/resources/ae/usdschemabase/attribute_custom_control.py @@ -14,6 +14,7 @@ # import mayaUsd.lib +from mayaUsd import ufe as mayaUsdUfe from maya.OpenMaya import MGlobal @@ -30,7 +31,7 @@ def getNiceAttributeName(ufeAttr, attrName): attrName = ufeAttr.displayName elif hasattr(ufeAttr, "hasMetadata") and ufeAttr.hasMetadata("uiname"): attrName = str(ufeAttr.getMetadata("uiname")) - return mayaUsd.lib.Util.prettifyName(attrName) + return mayaUsdUfe.prettifyName(attrName) def cleanAndFormatTooltip(s): if not s: diff --git a/lib/mayaUsd/ufe/CMakeLists.txt b/lib/mayaUsd/ufe/CMakeLists.txt index d9df14d6e3..899c520860 100644 --- a/lib/mayaUsd/ufe/CMakeLists.txt +++ b/lib/mayaUsd/ufe/CMakeLists.txt @@ -15,10 +15,6 @@ target_sources(${PROJECT_NAME} ProxyShapeHierarchy.cpp ProxyShapeHierarchyHandler.cpp RotationUtils.cpp - UsdAttribute.cpp - UsdAttributeHolder.cpp - UsdAttributes.cpp - UsdAttributesHandler.cpp UsdPointInstanceOrientationModifier.cpp UsdPointInstancePositionModifier.cpp UsdPointInstanceScaleModifier.cpp @@ -124,22 +120,6 @@ if (UFE_UINODEGRAPHNODE_HAS_DISPLAYCOLOR) ) endif() - -if (UFE_ATTRIBUTES_GET_ENUMS) - target_compile_definitions(${PROJECT_NAME} - PRIVATE - UFE_ATTRIBUTES_GET_ENUMS=1 - ) -endif() - - -if (UFE_SCENEITEM_HAS_METADATA) - target_compile_definitions(${PROJECT_NAME} - PRIVATE - UFE_SCENEITEM_HAS_METADATA=1 - ) -endif() - if (UFE_CONTEXTOPS_HAS_OPTIONBOX) target_compile_definitions(${PROJECT_NAME} PRIVATE @@ -179,15 +159,12 @@ if(CMAKE_UFE_V4_FEATURES_AVAILABLE) PRIVATE UsdShaderNodeDef.cpp UsdShaderNodeDefHandler.cpp - UsdShaderAttributeDef.cpp - UsdShaderAttributeHolder.cpp UsdUndoCreateFromNodeDefCommand.cpp ProxyShapeCameraHandler.cpp UsdConnections.cpp UsdConnectionHandler.cpp UsdUINodeGraphNode.cpp UsdUINodeGraphNodeHandler.cpp - UsdUndoAttributesCommands.cpp UsdTransform3dRead.cpp UsdUndoConnectionCommands.cpp UsdUndoCreateStageWithNewLayerCommand.cpp @@ -207,10 +184,6 @@ set(HEADERS ProxyShapeHierarchy.h ProxyShapeHierarchyHandler.h RotationUtils.h - UsdAttribute.h - UsdAttributeHolder.h - UsdAttributes.h - UsdAttributesHandler.h UsdPointInstanceModifierBase.h UsdPointInstanceOrientationModifier.h UsdPointInstancePositionModifier.h @@ -295,15 +268,12 @@ if(CMAKE_UFE_V4_FEATURES_AVAILABLE) list(APPEND HEADERS UsdShaderNodeDef.h UsdShaderNodeDefHandler.h - UsdShaderAttributeDef.h - UsdShaderAttributeHolder.h UsdUndoCreateFromNodeDefCommand.h ProxyShapeCameraHandler.h UsdConnections.h UsdConnectionHandler.h UsdUINodeGraphNode.h UsdUINodeGraphNodeHandler.h - UsdUndoAttributesCommands.h UsdTransform3dRead.h UsdUndoConnectionCommands.h UsdUndoCreateStageWithNewLayerCommand.h diff --git a/lib/mayaUsd/ufe/Global.cpp b/lib/mayaUsd/ufe/Global.cpp index 41f5326d23..bd1a5d4201 100644 --- a/lib/mayaUsd/ufe/Global.cpp +++ b/lib/mayaUsd/ufe/Global.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -35,7 +34,6 @@ #include #include #include -#include #ifdef UFE_V3_FEATURES_AVAILABLE #define HAVE_PATH_MAPPING @@ -120,6 +118,10 @@ 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); } +void displayInfoMessage(const std::string& msg) { MGlobal::displayInfo(msg.c_str()); } +void displayWarningMessage(const std::string& msg) { MGlobal::displayWarning(msg.c_str()); } +void displayErrorMessage(const std::string& msg) { MGlobal::displayError(msg.c_str()); } + } // namespace namespace MAYAUSD_NS_DEF { @@ -175,9 +177,11 @@ MStatus initialize() dccFunctions.stagePathAccessorFn = MayaUsd::ufe::stagePath; dccFunctions.ufePathToPrimFn = MayaUsd::ufe::ufePathToPrim; dccFunctions.timeAccessorFn = MayaUsd::ufe::getTime; - dccFunctions.isAttributeLockedFn = MayaUsd::Editability::isAttributeLocked; dccFunctions.saveStageLoadRulesFn = MayaUsd::MayaUsdProxyShapeStageExtraData::saveLoadRules; dccFunctions.uniqueChildNameFn = MayaUsd::ufe::uniqueChildNameMayaStandard; + dccFunctions.displayMessageFn[static_cast(MessageType::kInfo)] = displayInfoMessage; + dccFunctions.displayMessageFn[static_cast(MessageType::kWarning)] = displayWarningMessage; + dccFunctions.displayMessageFn[static_cast(MessageType::KError)] = displayErrorMessage; dccFunctions.startWaitCursorFn = mayaStartWaitCursor; dccFunctions.stopWaitCursorFn = mayaStopWaitCursor; @@ -211,7 +215,6 @@ MStatus initialize() usdUfeHandlers.hierarchyHandler = MayaUsdHierarchyHandler::create(); #endif handlers.sceneItemOpsHandler = UsdSceneItemOpsHandler::create(); - handlers.attributesHandler = UsdAttributesHandler::create(); usdUfeHandlers.object3dHandler = MayaUsdObject3dHandler::create(); usdUfeHandlers.contextOpsHandler = MayaUsdContextOpsHandler::create(); usdUfeHandlers.uiInfoHandler = MayaUsdUIInfoHandler::create(); @@ -292,8 +295,6 @@ MStatus initialize() runTimeMgr.setTransform3dHandler(usdRtid, handlers.transform3dHandler); if (handlers.sceneItemOpsHandler) runTimeMgr.setSceneItemOpsHandler(usdRtid, handlers.sceneItemOpsHandler); - if (handlers.attributesHandler) - runTimeMgr.setAttributesHandler(usdRtid, handlers.attributesHandler); if (handlers.object3dHandler) runTimeMgr.setObject3dHandler(usdRtid, handlers.object3dHandler); if (handlers.contextOpsHandler) diff --git a/lib/mayaUsd/ufe/UsdConnectionHandler.cpp b/lib/mayaUsd/ufe/UsdConnectionHandler.cpp index 7a5baaf795..52ceca12e7 100644 --- a/lib/mayaUsd/ufe/UsdConnectionHandler.cpp +++ b/lib/mayaUsd/ufe/UsdConnectionHandler.cpp @@ -15,11 +15,13 @@ // #include -#include #include #include +#include #include +#include +#include #ifdef UFE_V4_FEATURES_AVAILABLE #include #endif @@ -43,37 +45,6 @@ namespace ufe { namespace { -UsdAttribute* usdAttrFromUfeAttr(const Ufe::Attribute::Ptr& attr) -{ - if (!attr) { - TF_RUNTIME_ERROR("Invalid attribute."); - return nullptr; - } - - if (attr->sceneItem()->runTimeId() != getUsdRunTimeId()) { - TF_RUNTIME_ERROR( - "Invalid runtime identifier for the attribute '" + attr->name() + "' in the node '" - + Ufe::PathString::string(attr->sceneItem()->path()) + "'."); - return nullptr; - } - - return dynamic_cast(attr.get()); -} - -bool isConnected(const PXR_NS::UsdAttribute& srcUsdAttr, const PXR_NS::UsdAttribute& dstUsdAttr) -{ - PXR_NS::SdfPathVector connectedAttrs; - dstUsdAttr.GetConnections(&connectedAttrs); - - for (PXR_NS::SdfPath path : connectedAttrs) { - if (path == srcUsdAttr.GetPath()) { - return true; - } - } - - return false; -} - PXR_NS::SdrShaderNodeConstPtr _GetShaderNodeDef(const PXR_NS::UsdPrim& prim, const PXR_NS::TfToken& attrName) { @@ -169,11 +140,11 @@ bool UsdConnectionHandler::createConnection( const Ufe::Attribute::Ptr& srcAttr, const Ufe::Attribute::Ptr& dstAttr) const { - UsdAttribute* srcUsdAttr = usdAttrFromUfeAttr(srcAttr); - UsdAttribute* dstUsdAttr = usdAttrFromUfeAttr(dstAttr); + auto srcUsdAttr = UsdUfe::usdAttrFromUfeAttr(srcAttr); + auto dstUsdAttr = UsdUfe::usdAttrFromUfeAttr(dstAttr); if (!srcUsdAttr || !dstUsdAttr - || isConnected(srcUsdAttr->usdAttribute(), dstUsdAttr->usdAttribute())) { + || UsdUfe::isConnected(srcUsdAttr->usdAttribute(), dstUsdAttr->usdAttribute())) { return false; } @@ -256,11 +227,11 @@ bool UsdConnectionHandler::deleteConnection( const Ufe::Attribute::Ptr& srcAttr, const Ufe::Attribute::Ptr& dstAttr) const { - UsdAttribute* srcUsdAttr = usdAttrFromUfeAttr(srcAttr); - UsdAttribute* dstUsdAttr = usdAttrFromUfeAttr(dstAttr); + auto srcUsdAttr = UsdUfe::usdAttrFromUfeAttr(srcAttr); + auto dstUsdAttr = UsdUfe::usdAttrFromUfeAttr(dstAttr); if (!srcUsdAttr || !dstUsdAttr - || !isConnected(srcUsdAttr->usdAttribute(), dstUsdAttr->usdAttribute())) { + || !UsdUfe::isConnected(srcUsdAttr->usdAttribute(), dstUsdAttr->usdAttribute())) { return false; } diff --git a/lib/mayaUsd/ufe/UsdShaderNodeDef.cpp b/lib/mayaUsd/ufe/UsdShaderNodeDef.cpp index 3c48610897..d95d6f0cf8 100644 --- a/lib/mayaUsd/ufe/UsdShaderNodeDef.cpp +++ b/lib/mayaUsd/ufe/UsdShaderNodeDef.cpp @@ -18,17 +18,19 @@ #include #ifdef UFE_V4_FEATURES_AVAILABLE -#include #include #include -#endif -#include "Global.h" -#include "Utils.h" +#include +#endif -#include +#include +#include #include +#include +#include + #include #include #include @@ -69,7 +71,7 @@ Ufe::ConstAttributeDefs getAttrs(const SdrShaderNodeConstPtr& shaderNodeDef) #ifndef UFE_V4_FEATURES_AVAILABLE std::ostringstream defaultValue; defaultValue << property->GetDefaultValue(); - Ufe::Attribute::Type type = usdTypeToUfe(property); + Ufe::Attribute::Type type = UsdUfe::usdTypeToUfe(property); attrs.emplace_back(Ufe::AttributeDef::create(name, type, defaultValue.str(), IOTYPE)); #else attrs.emplace_back(Ufe::AttributeDef::ConstPtr(new UsdShaderAttributeDef(property))); @@ -158,7 +160,7 @@ std::size_t UsdShaderNodeDef::nbClassifications() const // We have a client that stores Maya shader classifications in the Role. Let's split that into // subclassifications: - auto splitRoles = splitString(fShaderNodeDef->GetRole(), "/"); + auto splitRoles = UsdUfe::splitString(fShaderNodeDef->GetRole(), "/"); // Regular shader nodes provide at least 3 classification levels: // - family @@ -196,10 +198,10 @@ std::string UsdShaderNodeDef::classification(std::size_t level) const // We have a client that stores Maya shader classifications in the Role. Let's split that into // subclassifications: - auto splitRoles = splitString(fShaderNodeDef->GetRole(), "/"); + auto splitRoles = UsdUfe::splitString(fShaderNodeDef->GetRole(), "/"); if (level - 1 < splitRoles.size()) { - return UsdMayaUtil::prettifyName(splitRoles[splitRoles.size() - level]); + return UsdUfe::prettifyName(splitRoles[splitRoles.size() - level]); } if (level - 1 == splitRoles.size()) { @@ -284,16 +286,16 @@ typedef std::unordered_mapUIName.GetString(), + { UsdUfe::MetadataTokens->UIName.GetString(), [](const PXR_NS::SdrShaderNode& n) { std::string uiname; if (!n.GetLabel().IsEmpty()) { return n.GetLabel().GetString(); } if (!n.GetFamily().IsEmpty() && !_isArnoldWithIssue1214(n)) { - return UsdMayaUtil::prettifyName(n.GetFamily().GetString()); + return UsdUfe::prettifyName(n.GetFamily().GetString()); } - return UsdMayaUtil::prettifyName(n.GetName()); + return UsdUfe::prettifyName(n.GetName()); } }, { "doc", [](const PXR_NS::SdrShaderNode& n) { diff --git a/lib/mayaUsd/ufe/UsdShaderNodeDefHandler.cpp b/lib/mayaUsd/ufe/UsdShaderNodeDefHandler.cpp index ee051f9dd9..6a9f4a1ecd 100644 --- a/lib/mayaUsd/ufe/UsdShaderNodeDefHandler.cpp +++ b/lib/mayaUsd/ufe/UsdShaderNodeDefHandler.cpp @@ -19,9 +19,9 @@ #include "UsdShaderNodeDef.h" #include +#include #include -#include namespace MAYAUSD_NS_DEF { namespace ufe { @@ -40,29 +40,7 @@ UsdShaderNodeDefHandler::Ptr UsdShaderNodeDefHandler::create() PXR_NS::SdrShaderNodeConstPtr UsdShaderNodeDefHandler::usdDefinition(const Ufe::SceneItem::Ptr& item) { - UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast(item); - PXR_NAMESPACE_USING_DIRECTIVE - if (!TF_VERIFY(usdItem)) { - return nullptr; - } - PXR_NS::UsdPrim prim = usdItem->prim(); - PXR_NS::UsdShadeShader shader(prim); - if (!shader) { - return nullptr; - } - PXR_NS::TfToken mxNodeType; - shader.GetIdAttr().Get(&mxNodeType); - - // Careful around name and identifier. They are not the same concept. - // - // Here is one example from MaterialX to illustrate: - // - // ND_standard_surface_surfaceshader exists in 2 versions with identifiers: - // ND_standard_surface_surfaceshader (latest version) - // ND_standard_surface_surfaceshader_100 (version 1.0.0) - // Same name, 2 different identifiers. - PXR_NS::SdrRegistry& registry = PXR_NS::SdrRegistry::GetInstance(); - return registry.GetShaderNodeByIdentifier(mxNodeType); + return UsdUfe::usdShaderNodeFromSceneItem(item); } Ufe::NodeDef::Ptr UsdShaderNodeDefHandler::definition(const Ufe::SceneItem::Ptr& item) const diff --git a/lib/mayaUsd/ufe/UsdUndoConnectionCommands.cpp b/lib/mayaUsd/ufe/UsdUndoConnectionCommands.cpp index 51a23baa54..cd733cb813 100644 --- a/lib/mayaUsd/ufe/UsdUndoConnectionCommands.cpp +++ b/lib/mayaUsd/ufe/UsdUndoConnectionCommands.cpp @@ -16,13 +16,14 @@ #include "UsdUndoConnectionCommands.h" #include -#include -#include #include #include #include +#include +#include #include +#include #include #include @@ -40,34 +41,6 @@ MAYAUSD_VERIFY_CLASS_SETUP(Ufe::ConnectionResultUndoableCommand, UsdUndoCreateCo namespace { -Ufe::Attribute::Ptr attrFromUfeAttrInfo(const Ufe::AttributeInfo& attrInfo) -{ - auto item - = std::dynamic_pointer_cast(Ufe::Hierarchy::createItem(attrInfo.path())); - if (!item) { - TF_RUNTIME_ERROR("Invalid scene item."); - return nullptr; - } - return UsdAttributes(item).attribute(attrInfo.name()); -} - -UsdAttribute* usdAttrFromUfeAttr(const Ufe::Attribute::Ptr& attr) -{ - if (!attr) { - TF_RUNTIME_ERROR("Invalid attribute."); - return nullptr; - } - - if (attr->sceneItem()->runTimeId() != getUsdRunTimeId()) { - TF_RUNTIME_ERROR( - "Invalid runtime identifier for the attribute '" + attr->name() + "' in the node '" - + Ufe::PathString::string(attr->sceneItem()->path()) + "'."); - return nullptr; - } - - return dynamic_cast(attr.get()); -} - PXR_NS::SdrShaderNodeConstPtr _GetShaderNodeDef(const PXR_NS::UsdPrim& prim, const PXR_NS::TfToken& attrName) { @@ -144,10 +117,10 @@ void UsdUndoCreateConnectionCommand::execute() { UsdUndoBlock undoBlock(&_undoableItem); - auto srcAttr = attrFromUfeAttrInfo(*_srcInfo); - UsdAttribute* srcUsdAttr = usdAttrFromUfeAttr(srcAttr); - auto dstAttr = attrFromUfeAttrInfo(*_dstInfo); - UsdAttribute* dstUsdAttr = usdAttrFromUfeAttr(dstAttr); + auto srcAttr = UsdUfe::attrFromUfeAttrInfo(*_srcInfo); + auto srcUsdAttr = UsdUfe::usdAttrFromUfeAttr(srcAttr); + auto dstAttr = UsdUfe::attrFromUfeAttrInfo(*_dstInfo); + auto dstUsdAttr = UsdUfe::usdAttrFromUfeAttr(dstAttr); if (!srcUsdAttr || !dstUsdAttr) { _srcInfo = nullptr; @@ -155,7 +128,7 @@ void UsdUndoCreateConnectionCommand::execute() return; } - if (MayaUsd::ufe::isConnected(srcUsdAttr->usdAttribute(), dstUsdAttr->usdAttribute())) { + if (UsdUfe::isConnected(srcUsdAttr->usdAttribute(), dstUsdAttr->usdAttribute())) { return; } @@ -281,13 +254,13 @@ void UsdUndoDeleteConnectionCommand::execute() { UsdUndoBlock undoBlock(&_undoableItem); - auto srcAttr = attrFromUfeAttrInfo(*_srcInfo); - UsdAttribute* srcUsdAttr = usdAttrFromUfeAttr(srcAttr); - auto dstAttr = attrFromUfeAttrInfo(*_dstInfo); - UsdAttribute* dstUsdAttr = usdAttrFromUfeAttr(dstAttr); + auto srcAttr = UsdUfe::attrFromUfeAttrInfo(*_srcInfo); + auto srcUsdAttr = UsdUfe::usdAttrFromUfeAttr(srcAttr); + auto dstAttr = UsdUfe::attrFromUfeAttrInfo(*_dstInfo); + auto dstUsdAttr = UsdUfe::usdAttrFromUfeAttr(dstAttr); if (!srcUsdAttr || !dstUsdAttr - || !MayaUsd::ufe::isConnected(srcUsdAttr->usdAttribute(), dstUsdAttr->usdAttribute())) { + || !UsdUfe::isConnected(srcUsdAttr->usdAttribute(), dstUsdAttr->usdAttribute())) { return; } #if PXR_VERSION < 2302 @@ -307,11 +280,11 @@ void UsdUndoDeleteConnectionCommand::execute() // Remove attribute if it does not have a value, default value, or time samples. We do this // on Shader nodes and on the Material outputs since they are re-created automatically. // Other NodeGraph inputs and outputs require explicit removal. - if (MayaUsd::ufe::canRemoveDstProperty(dstUsdAttr->usdAttribute())) { + if (UsdUfe::canRemoveDstProperty(dstUsdAttr->usdAttribute())) { dstUsdAttr->usdPrim().RemoveProperty(dstUsdAttr->usdAttribute().GetName()); } - if (MayaUsd::ufe::canRemoveSrcProperty(srcUsdAttr->usdAttribute())) { + if (UsdUfe::canRemoveSrcProperty(srcUsdAttr->usdAttribute())) { srcUsdAttr->usdPrim().RemoveProperty(srcUsdAttr->usdAttribute().GetName()); } } diff --git a/lib/mayaUsd/ufe/UsdUndoDeleteCommand.cpp b/lib/mayaUsd/ufe/UsdUndoDeleteCommand.cpp index 43c896979c..2f43c5fc36 100644 --- a/lib/mayaUsd/ufe/UsdUndoDeleteCommand.cpp +++ b/lib/mayaUsd/ufe/UsdUndoDeleteCommand.cpp @@ -26,7 +26,7 @@ #include #ifdef UFE_V4_FEATURES_AVAILABLE -#include +#include #endif namespace MAYAUSD_NS_DEF { @@ -62,7 +62,7 @@ void UsdUndoDeleteCommand::execute() if (UsdUfe::applyCommandRestrictionNoThrow(_prim, "delete")) { #ifdef UFE_V4_FEATURES_AVAILABLE - UsdAttributes::removeAttributesConnections(_prim); + UsdUfe::UsdAttributes::removeAttributesConnections(_prim); #endif // Let removeAttributesConnections be run first as it will also cleanup // attributes that were authored only to be the destination of a connection. diff --git a/lib/mayaUsd/ufe/Utils.cpp b/lib/mayaUsd/ufe/Utils.cpp index d7f4b60910..40382d24c4 100644 --- a/lib/mayaUsd/ufe/Utils.cpp +++ b/lib/mayaUsd/ufe/Utils.cpp @@ -31,7 +31,6 @@ #include #include -#include #include #include #include @@ -73,8 +72,6 @@ namespace { constexpr auto kIllegalUFEPath = "Illegal UFE run-time path %s."; -typedef std::unordered_map TokenToSdfTypeMap; - } // anonymous namespace namespace MAYAUSD_NS_DEF { @@ -357,444 +354,6 @@ TfTokenVector getProxyShapePurposes(const Ufe::Path& path) return purposes; } -bool isConnected(const PXR_NS::UsdAttribute& srcUsdAttr, const PXR_NS::UsdAttribute& dstUsdAttr) -{ - PXR_NS::SdfPathVector connectedAttrs; - dstUsdAttr.GetConnections(&connectedAttrs); - - for (PXR_NS::SdfPath path : connectedAttrs) { - if (path == srcUsdAttr.GetPath()) { - return true; - } - } - - return false; -} - -bool canRemoveSrcProperty(const PXR_NS::UsdAttribute& srcAttr) -{ - - // Do not remove if it has a value. - if (srcAttr.HasValue()) { - return false; - } - - PXR_NS::SdfPathVector connectedAttrs; - srcAttr.GetConnections(&connectedAttrs); - - // Do not remove if it has connections. - if (!connectedAttrs.empty()) { - return false; - } - - const auto prim = srcAttr.GetPrim(); - - if (!prim) { - return false; - } - - PXR_NS::UsdShadeNodeGraph ngPrim(prim); - - if (!ngPrim) { - const auto primParent = prim.GetParent(); - - if (!primParent) { - return false; - } - - // Do not remove if there is a connection with a prim. - for (const auto& childPrim : primParent.GetChildren()) { - if (childPrim != prim) { - for (const auto& attribute : childPrim.GetAttributes()) { - const PXR_NS::UsdAttribute dstUsdAttr = attribute.As(); - if (isConnected(srcAttr, dstUsdAttr)) { - return false; - } - } - } - } - - // Do not remove if there is a connection with the parent prim. - for (const auto& attribute : primParent.GetAttributes()) { - const PXR_NS::UsdAttribute dstUsdAttr = attribute.As(); - if (isConnected(srcAttr, dstUsdAttr)) { - return false; - } - } - - return true; - } - - // Do not remove boundary properties even if there are connections. - return false; -} - -bool canRemoveDstProperty(const PXR_NS::UsdAttribute& dstAttr) -{ - - // Do not remove if it has a value. - if (dstAttr.HasValue()) { - return false; - } - - PXR_NS::SdfPathVector connectedAttrs; - dstAttr.GetConnections(&connectedAttrs); - - // Do not remove if it has connections. - if (!connectedAttrs.empty()) { - return false; - } - - const auto prim = dstAttr.GetPrim(); - - if (!prim) { - return false; - } - - PXR_NS::UsdShadeNodeGraph ngPrim(prim); - - if (!ngPrim) { - return true; - } - - UsdShadeMaterial asMaterial(prim); - if (asMaterial) { - const TfToken baseName = dstAttr.GetBaseName(); - // Remove Material intrinsic outputs since they are re-created automatically. - if (baseName == UsdShadeTokens->surface || baseName == UsdShadeTokens->volume - || baseName == UsdShadeTokens->displacement) { - return true; - } - } - - // Do not remove boundary properties even if there are connections. - return false; -} - -namespace { -// Do not expose that function. The input parameter does not provide enough information to -// distinguish between kEnum and kEnumString. -Ufe::Attribute::Type _UsdTypeToUfe(const SdfValueTypeName& usdType) -{ - // Map the USD type into UFE type. - static const std::unordered_map sUsdTypeToUfe { - { SdfValueTypeNames->Bool.GetHash(), Ufe::Attribute::kBool }, // bool - { SdfValueTypeNames->Int.GetHash(), Ufe::Attribute::kInt }, // int32_t - { SdfValueTypeNames->Float.GetHash(), Ufe::Attribute::kFloat }, // float - { SdfValueTypeNames->Double.GetHash(), Ufe::Attribute::kDouble }, // double - { SdfValueTypeNames->String.GetHash(), Ufe::Attribute::kString }, // std::string - { SdfValueTypeNames->Token.GetHash(), Ufe::Attribute::kString }, // TfToken - { SdfValueTypeNames->Int3.GetHash(), Ufe::Attribute::kInt3 }, // GfVec3i - { SdfValueTypeNames->Float3.GetHash(), Ufe::Attribute::kFloat3 }, // GfVec3f - { SdfValueTypeNames->Double3.GetHash(), Ufe::Attribute::kDouble3 }, // GfVec3d - { SdfValueTypeNames->Color3f.GetHash(), Ufe::Attribute::kColorFloat3 }, // GfVec3f - { SdfValueTypeNames->Color3d.GetHash(), Ufe::Attribute::kColorFloat3 }, // GfVec3d -#ifdef UFE_V4_FEATURES_AVAILABLE - { SdfValueTypeNames->Asset.GetHash(), Ufe::Attribute::kFilename }, // SdfAssetPath - { SdfValueTypeNames->Float2.GetHash(), Ufe::Attribute::kFloat2 }, // GfVec2f - { SdfValueTypeNames->Float4.GetHash(), Ufe::Attribute::kFloat4 }, // GfVec4f - { SdfValueTypeNames->Color4f.GetHash(), Ufe::Attribute::kColorFloat4 }, // GfVec4f - { SdfValueTypeNames->Color4d.GetHash(), Ufe::Attribute::kColorFloat4 }, // GfVec4d - { SdfValueTypeNames->Matrix3d.GetHash(), Ufe::Attribute::kMatrix3d }, // GfMatrix3d - { SdfValueTypeNames->Matrix4d.GetHash(), Ufe::Attribute::kMatrix4d }, // GfMatrix4d -#endif - }; - const auto iter = sUsdTypeToUfe.find(usdType.GetHash()); - if (iter != sUsdTypeToUfe.end()) { - return iter->second; - } else { - static const std::unordered_map sCPPTypeToUfe { - // There are custom Normal3f, Point3f types in USD. They can all be recognized by the - // underlying CPP type and if there is a Ufe type that matches, use it. - { "GfVec3i", Ufe::Attribute::kInt3 }, { "GfVec3d", Ufe::Attribute::kDouble3 }, - { "GfVec3f", Ufe::Attribute::kFloat3 }, -#ifdef UFE_V4_FEATURES_AVAILABLE - { "GfVec2f", Ufe::Attribute::kFloat2 }, { "GfVec4f", Ufe::Attribute::kFloat4 }, -#endif - }; - - const auto iter = sCPPTypeToUfe.find(usdType.GetCPPTypeName()); - if (iter != sCPPTypeToUfe.end()) { - return iter->second; - } else { - return Ufe::Attribute::kGeneric; - } - } -} -} // namespace - -Ufe::Attribute::Type usdTypeToUfe(const SdrShaderPropertyConstPtr& shaderProperty) -{ - Ufe::Attribute::Type retVal = Ufe::Attribute::kInvalid; - - const SdfValueTypeName typeName = shaderProperty->GetTypeAsSdfType().first; - if (typeName.GetHash() == SdfValueTypeNames->Token.GetHash()) { - static const TokenToSdfTypeMap tokenTypeToSdfType - = { { SdrPropertyTypes->Int, SdfValueTypeNames->Int }, - { SdrPropertyTypes->String, SdfValueTypeNames->String }, - { SdrPropertyTypes->Float, SdfValueTypeNames->Float }, - { SdrPropertyTypes->Color, SdfValueTypeNames->Color3f }, -#if defined(USD_HAS_COLOR4_SDR_SUPPORT) - { SdrPropertyTypes->Color4, SdfValueTypeNames->Color4f }, -#endif - { SdrPropertyTypes->Point, SdfValueTypeNames->Point3f }, - { SdrPropertyTypes->Normal, SdfValueTypeNames->Normal3f }, - { SdrPropertyTypes->Vector, SdfValueTypeNames->Vector3f }, - { SdrPropertyTypes->Matrix, SdfValueTypeNames->Matrix4d } }; - TokenToSdfTypeMap::const_iterator it - = tokenTypeToSdfType.find(shaderProperty->GetTypeAsSdfType().second); - if (it != tokenTypeToSdfType.end()) { - retVal = _UsdTypeToUfe(it->second); - } else { -#if PXR_VERSION < 2205 - // Pre-22.05 boolean inputs are special: - if (shaderProperty->GetType() == SdfValueTypeNames->Bool.GetAsToken()) { - retVal = _UsdTypeToUfe(SdfValueTypeNames->Bool); - } else -#endif - // There is no Matrix3d type in Sdr, so we need to infer it from Sdf until a fix - // similar to what was done to booleans is submitted to USD. This also means that - // there will be no default value for that type. - if (shaderProperty->GetType() == SdfValueTypeNames->Matrix3d.GetAsToken()) { - retVal = _UsdTypeToUfe(SdfValueTypeNames->Matrix3d); - } else { - retVal = Ufe::Attribute::kGeneric; - } - } - } else { - retVal = _UsdTypeToUfe(typeName); - } - - if (retVal == Ufe::Attribute::kString) { - if (!shaderProperty->GetOptions().empty()) { - retVal = Ufe::Attribute::kEnumString; - } -#ifdef UFE_V4_FEATURES_AVAILABLE - else if (shaderProperty->IsAssetIdentifier()) { - retVal = Ufe::Attribute::kFilename; - } -#endif - } - - return retVal; -} - -Ufe::Attribute::Type usdTypeToUfe(const PXR_NS::UsdAttribute& usdAttr) -{ - if (usdAttr.IsValid()) { - const SdfValueTypeName typeName = usdAttr.GetTypeName(); - Ufe::Attribute::Type type = _UsdTypeToUfe(typeName); - if (type == Ufe::Attribute::kString) { - // Both std::string and TfToken resolve to kString, but if there is a list of allowed - // tokens, then we use kEnumString instead. - if (usdAttr.GetPrim().GetPrimDefinition().GetPropertyMetadata( - usdAttr.GetName(), SdfFieldKeys->AllowedTokens, nullptr)) { - type = Ufe::Attribute::kEnumString; - } - UsdShadeNodeGraph asNodeGraph(usdAttr.GetPrim()); - if (asNodeGraph) { - // NodeGraph inputs can have enum metadata on them when they export an inner enum. - const auto portType = UsdShadeUtils::GetBaseNameAndType(usdAttr.GetName()).second; - if (portType == UsdShadeAttributeType::Input) { - const auto input = UsdShadeInput(usdAttr); - if (!input.GetSdrMetadataByKey(TfToken("enum")).empty()) { - return Ufe::Attribute::kEnumString; - } - } - // TfToken is also used in UsdShade as a Generic placeholder for connecting struct - // I/O. - if (usdAttr.GetTypeName() == SdfValueTypeNames->Token - && portType != UsdShadeAttributeType::Invalid) { - type = Ufe::Attribute::kGeneric; - } - } - } - return type; - } - - TF_RUNTIME_ERROR("Invalid USDAttribute: %s", usdAttr.GetPath().GetAsString().c_str()); - return Ufe::Attribute::kInvalid; -} - -SdfValueTypeName ufeTypeToUsd(const Ufe::Attribute::Type ufeType) -{ - // Map the USD type into UFE type. - static const std::unordered_map sUfeTypeToUsd { - { Ufe::Attribute::kBool, SdfValueTypeNames->Bool }, - { Ufe::Attribute::kInt, SdfValueTypeNames->Int }, - { Ufe::Attribute::kFloat, SdfValueTypeNames->Float }, - { Ufe::Attribute::kDouble, SdfValueTypeNames->Double }, - { Ufe::Attribute::kString, SdfValueTypeNames->String }, - // Not enough info at this point to differentiate between TfToken and std:string. - { Ufe::Attribute::kEnumString, SdfValueTypeNames->Token }, - { Ufe::Attribute::kInt3, SdfValueTypeNames->Int3 }, - { Ufe::Attribute::kFloat3, SdfValueTypeNames->Float3 }, - { Ufe::Attribute::kDouble3, SdfValueTypeNames->Double3 }, - { Ufe::Attribute::kColorFloat3, SdfValueTypeNames->Color3f }, - { Ufe::Attribute::kGeneric, SdfValueTypeNames->Token }, -#ifdef UFE_V4_FEATURES_AVAILABLE - { Ufe::Attribute::kFilename, SdfValueTypeNames->Asset }, - { Ufe::Attribute::kFloat2, SdfValueTypeNames->Float2 }, - { Ufe::Attribute::kFloat4, SdfValueTypeNames->Float4 }, - { Ufe::Attribute::kColorFloat4, SdfValueTypeNames->Color4f }, - { Ufe::Attribute::kMatrix3d, SdfValueTypeNames->Matrix3d }, - { Ufe::Attribute::kMatrix4d, SdfValueTypeNames->Matrix4d }, -#endif - }; - - const auto iter = sUfeTypeToUsd.find(ufeType); - if (iter != sUfeTypeToUsd.end()) { - return iter->second; - } else { - return SdfValueTypeName(); - } -} - -VtValue vtValueFromString(const SdfValueTypeName& typeName, const std::string& strValue) -{ - static const std::unordered_map> - sUsdConverterMap { - // Using the CPPTypeName prevents having to repeat converters for types that share the - // same VtValue representation like Float3, Color3f, Normal3f, Point3f, allowing support - // for more Sdf types without having to list them all. - { SdfValueTypeNames->Bool.GetCPPTypeName(), - [](const std::string& s) { return VtValue("true" == s ? true : false); } }, - { SdfValueTypeNames->Int.GetCPPTypeName(), - [](const std::string& s) { - return s.empty() ? VtValue() : VtValue(std::stoi(s.c_str())); - } }, - { SdfValueTypeNames->Float.GetCPPTypeName(), - [](const std::string& s) { - return s.empty() ? VtValue() : VtValue(std::stof(s.c_str())); - } }, - { SdfValueTypeNames->Double.GetCPPTypeName(), - [](const std::string& s) { - return s.empty() ? VtValue() : VtValue(std::stod(s.c_str())); - } }, - { SdfValueTypeNames->String.GetCPPTypeName(), - [](const std::string& s) { return VtValue(s); } }, - { SdfValueTypeNames->Token.GetCPPTypeName(), - [](const std::string& s) { return VtValue(TfToken(s)); } }, - { SdfValueTypeNames->Asset.GetCPPTypeName(), - [](const std::string& s) { return VtValue(SdfAssetPath(s)); } }, - { SdfValueTypeNames->Int3.GetCPPTypeName(), - [](const std::string& s) { - std::vectortokens = splitString(s, "()[], "); - if (tokens.size() == 3) { - return VtValue(GfVec3i( - std::stoi(tokens[0].c_str()), - std::stoi(tokens[1].c_str()), - std::stoi(tokens[2].c_str()))); - } - return VtValue(); - } }, - { SdfValueTypeNames->Float2.GetCPPTypeName(), - [](const std::string& s) { - std::vectortokens = splitString(s, "()[], "); - if (tokens.size() == 2) { - return VtValue( - GfVec2f(std::stof(tokens[0].c_str()), std::stof(tokens[1].c_str()))); - } - return VtValue(); - } }, - { SdfValueTypeNames->Float3.GetCPPTypeName(), - [](const std::string& s) { - std::vectortokens = splitString(s, "()[], "); - if (tokens.size() == 3) { - return VtValue(GfVec3f( - std::stof(tokens[0].c_str()), - std::stof(tokens[1].c_str()), - std::stof(tokens[2].c_str()))); - } - return VtValue(); - } }, - { SdfValueTypeNames->Float4.GetCPPTypeName(), - [](const std::string& s) { - std::vectortokens = splitString(s, "()[], "); - if (tokens.size() == 4) { - return VtValue(GfVec4f( - std::stof(tokens[0].c_str()), - std::stof(tokens[1].c_str()), - std::stof(tokens[2].c_str()), - std::stof(tokens[3].c_str()))); - } - return VtValue(); - } }, - { SdfValueTypeNames->Double3.GetCPPTypeName(), - [](const std::string& s) { - std::vectortokens = splitString(s, "()[], "); - if (tokens.size() == 3) { - return VtValue(GfVec3d( - std::stod(tokens[0].c_str()), - std::stod(tokens[1].c_str()), - std::stod(tokens[2].c_str()))); - } - return VtValue(); - } }, - { SdfValueTypeNames->Double4.GetCPPTypeName(), - [](const std::string& s) { - std::vectortokens = splitString(s, "()[], "); - if (tokens.size() == 4) { - return VtValue(GfVec4d( - std::stod(tokens[0].c_str()), - std::stod(tokens[1].c_str()), - std::stod(tokens[2].c_str()), - std::stod(tokens[3].c_str()))); - } - return VtValue(); - } }, - { SdfValueTypeNames->Matrix3d.GetCPPTypeName(), - [](const std::string& s) { - std::vectortokens = splitString(s, "()[], "); - if (tokens.size() == 9) { - double m[3][3]; - for (int i = 0, k = 0; i < 3; ++i) { - for (int j = 0; j < 3; ++j, ++k) { - m[i][j] = std::stod(tokens[k].c_str()); - } - } - return VtValue(GfMatrix3d(m)); - } - return VtValue(); - } }, - { SdfValueTypeNames->Matrix4d.GetCPPTypeName(), - [](const std::string& s) { - std::vectortokens = splitString(s, "()[], "); - if (tokens.size() == 16) { - double m[4][4]; - for (int i = 0, k = 0; i < 4; ++i) { - for (int j = 0; j < 4; ++j, ++k) { - m[i][j] = std::stod(tokens[k].c_str()); - } - } - return VtValue(GfMatrix4d(m)); - } - return VtValue(); - } }, - }; - const auto iter = sUsdConverterMap.find(typeName.GetCPPTypeName()); - if (iter != sUsdConverterMap.end()) { - return iter->second(strValue); - } - return {}; -} - -std::vector splitString(const std::string& str, const std::string& separators) -{ - std::vector split; - - std::string::size_type lastPos = str.find_first_not_of(separators, 0); - std::string::size_type pos = str.find_first_of(separators, lastPos); - - while (pos != std::string::npos || lastPos != std::string::npos) { - split.push_back(str.substr(lastPos, pos - lastPos)); - lastPos = str.find_first_not_of(separators, pos); - pos = str.find_first_of(separators, lastPos); - } - - return split; -} - #ifdef MAYA_HAS_DISPLAY_LAYER_API template void handleDisplayLayer( diff --git a/lib/mayaUsd/ufe/Utils.h b/lib/mayaUsd/ufe/Utils.h index 7753b911b5..39503e42c8 100644 --- a/lib/mayaUsd/ufe/Utils.h +++ b/lib/mayaUsd/ufe/Utils.h @@ -16,8 +16,8 @@ #pragma once #include -#include +#include #include #include @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -126,33 +125,6 @@ PXR_NS::UsdTimeCode getTime(const Ufe::Path& path); MAYAUSD_CORE_PUBLIC PXR_NS::TfTokenVector getProxyShapePurposes(const Ufe::Path& path); -//! Check if the src and dst attributes are connected. -//! \return True, if they are connected. -MAYAUSD_CORE_PUBLIC -bool isConnected(const PXR_NS::UsdAttribute& srcUsdAttr, const PXR_NS::UsdAttribute& dstUsdAttr); - -//! Check if a source connection property is allowed to be removed. -//! \return True, if the property can be removed. -MAYAUSD_CORE_PUBLIC -bool canRemoveSrcProperty(const PXR_NS::UsdAttribute& srcAttr); - -//! Check if a destination connection property is allowed to be removed. -//! \return True, if the property can be removed. -MAYAUSD_CORE_PUBLIC -bool canRemoveDstProperty(const PXR_NS::UsdAttribute& dstAttr); - -MAYAUSD_CORE_PUBLIC -Ufe::Attribute::Type usdTypeToUfe(const PXR_NS::UsdAttribute& usdAttr); - -MAYAUSD_CORE_PUBLIC -Ufe::Attribute::Type usdTypeToUfe(const PXR_NS::SdrShaderPropertyConstPtr& shaderProperty); - -MAYAUSD_CORE_PUBLIC -PXR_NS::SdfValueTypeName ufeTypeToUsd(const Ufe::Attribute::Type ufeType); - -PXR_NS::VtValue -vtValueFromString(const PXR_NS::SdfValueTypeName& typeName, const std::string& strValue); - //! Readability function to downcast a SceneItem::Ptr to a UsdSceneItem::Ptr. inline UsdSceneItem::Ptr downcast(const Ufe::SceneItem::Ptr& item) { @@ -187,10 +159,6 @@ inline PXR_NS::GfVec3d toUsd(const Ufe::Vector3d& src) return PXR_NS::GfVec3d(src.x(), src.y(), src.z()); } -//! Splits a string by each specified separator. -MAYAUSD_CORE_PUBLIC -std::vector splitString(const std::string& str, const std::string& separators); - class ReplicateExtrasFromUSD { public: diff --git a/lib/mayaUsd/utils/CMakeLists.txt b/lib/mayaUsd/utils/CMakeLists.txt index 6302d53e03..4acbc8e1f7 100644 --- a/lib/mayaUsd/utils/CMakeLists.txt +++ b/lib/mayaUsd/utils/CMakeLists.txt @@ -10,7 +10,6 @@ target_sources(${PROJECT_NAME} customLayerData.cpp diagnosticDelegate.cpp dynamicAttribute.cpp - editability.cpp json.cpp layerLocking.cpp layerMuting.cpp @@ -44,7 +43,6 @@ set(HEADERS copyLayerPrims.h diagnosticDelegate.h dynamicAttribute.h - editability.h hash.h json.h jsonConverter.h diff --git a/lib/mayaUsd/utils/converter.cpp b/lib/mayaUsd/utils/converter.cpp index 74c0af256c..f39967c076 100644 --- a/lib/mayaUsd/utils/converter.cpp +++ b/lib/mayaUsd/utils/converter.cpp @@ -690,14 +690,16 @@ struct MDataHandleConvert dst = MayaUsd::utils::ConvertMayaToLinear(dst); } - // MDataHandle <--> UsdAttribute - static void convert(const MDataHandle& src, UsdAttribute& dst, const ConverterArgs& args) + // MDataHandle <--> PXR_NS::UsdAttribute + static void + convert(const MDataHandle& src, PXR_NS::UsdAttribute& dst, const ConverterArgs& args) { USD_Type tmpDst; convert(src, tmpDst, args); dst.Set(tmpDst, args._timeCode); } - static void convert(const UsdAttribute& src, MDataHandle& dst, const ConverterArgs& args) + static void + convert(const PXR_NS::UsdAttribute& src, MDataHandle& dst, const ConverterArgs& args) { USD_Type tmpSrc; src.Get(&tmpSrc, args._timeCode); @@ -779,21 +781,24 @@ template MDGModifierUtils::set(plug, dst, tmpDst); } - // MPlug <--> UsdAttribute - static void convert(const MPlug& src, UsdAttribute& dst, const ConverterArgs& args) + // MPlug <--> PXR_NS::UsdAttribute + static void convert(const MPlug& src, PXR_NS::UsdAttribute& dst, const ConverterArgs& args) { USD_Type tmpDst; convert(src, tmpDst, args); dst.Set(tmpDst, args._timeCode); } - static void convert(const UsdAttribute& src, MPlug& dst, const ConverterArgs& args) + static void convert(const PXR_NS::UsdAttribute& src, MPlug& dst, const ConverterArgs& args) { USD_Type tmpSrc; src.Get(&tmpSrc, args._timeCode); convert(tmpSrc, dst, args); } - static void - convert(const UsdAttribute& src, MPlug& plug, MDGModifier& dst, const ConverterArgs& args) + static void convert( + const PXR_NS::UsdAttribute& src, + MPlug& plug, + MDGModifier& dst, + const ConverterArgs& args) { USD_Type tmpSrc; src.Get(&tmpSrc, args._timeCode); @@ -830,8 +835,9 @@ struct MArrayDataHandleConvert using USD_TypeArray = MakeUsdArrayT; using ElementConverter = MDataHandleConvert; - // MDataHandle <--> UsdAttribute - static void convert(const MDataHandle& src, UsdAttribute& dst, const ConverterArgs& args) + // MDataHandle <--> PXR_NS::UsdAttribute + static void + convert(const MDataHandle& src, PXR_NS::UsdAttribute& dst, const ConverterArgs& args) { MArrayDataHandle srcArray(src); const unsigned int srcSize = srcArray.elementCount(); @@ -849,7 +855,8 @@ struct MArrayDataHandleConvert dst.Set(tmpDst, args._timeCode); } - static void convert(const UsdAttribute& src, MDataHandle& dst, const ConverterArgs& args) + static void + convert(const PXR_NS::UsdAttribute& src, MDataHandle& dst, const ConverterArgs& args) { USD_TypeArray tmpSrc; src.Get(&tmpSrc, args._timeCode); @@ -916,8 +923,8 @@ struct MArrayPlugConvert using USD_TypeArray = MakeUsdArrayT; using ElementConverter = MPlugConvert; - // MPlug <--> UsdAttribute - static void convert(const MPlug& src, UsdAttribute& dst, const ConverterArgs& args) + // MPlug <--> PXR_NS::UsdAttribute + static void convert(const MPlug& src, PXR_NS::UsdAttribute& dst, const ConverterArgs& args) { const unsigned int srcSize = src.numElements(); @@ -931,7 +938,7 @@ struct MArrayPlugConvert dst.Set(tmpDst, args._timeCode); } - static void convert(const UsdAttribute& src, MPlug& dst, const ConverterArgs& args) + static void convert(const PXR_NS::UsdAttribute& src, MPlug& dst, const ConverterArgs& args) { USD_TypeArray tmpSrc; src.Get(&tmpSrc, args._timeCode); @@ -943,8 +950,11 @@ struct MArrayPlugConvert ElementConverter::convert(tmpSrc[i], srcElement, args); } } - static void - convert(const UsdAttribute& src, MPlug& plug, MDGModifier& dst, const ConverterArgs& args) + static void convert( + const PXR_NS::UsdAttribute& src, + MPlug& plug, + MDGModifier& dst, + const ConverterArgs& args) { USD_TypeArray tmpSrc; src.Get(&tmpSrc, args._timeCode); @@ -1146,7 +1156,7 @@ const Converter* Converter::find(const SdfValueTypeName& typeName, bool isArrayP return nullptr; } -const Converter* Converter::find(const MPlug& plug, const UsdAttribute& attr) +const Converter* Converter::find(const MPlug& plug, const PXR_NS::UsdAttribute& attr) { auto valueTypeName = getUsdTypeName(plug, false); diff --git a/lib/mayaUsd/utils/converter.h b/lib/mayaUsd/utils/converter.h index 9a62c3580a..d1e3fb340f 100644 --- a/lib/mayaUsd/utils/converter.h +++ b/lib/mayaUsd/utils/converter.h @@ -96,11 +96,11 @@ struct MAYAUSD_CORE_PUBLIC ConverterArgs final class MAYAUSD_CORE_PUBLIC Converter final { using MPlugToUsdAttrFn - = std::add_pointer::type; + = std::add_pointer::type; using UsdAttrToMPlugFn - = std::add_pointer::type; + = std::add_pointer::type; using UsdAttrToMDGModifierFn = std::add_pointer< - void(const UsdAttribute&, MPlug&, MDGModifier&, const ConverterArgs&)>::type; + void(const PXR_NS::UsdAttribute&, MPlug&, MDGModifier&, const ConverterArgs&)>::type; using MPlugToVtValueFn = std::add_pointer::type; using VtValueToMPlugFn @@ -108,10 +108,10 @@ class MAYAUSD_CORE_PUBLIC Converter final using VtValueToMDGModifierFn = std::add_pointer::type; - using MDataHandleToUsdAttrFn - = std::add_pointer::type; - using UsdAttrToMDataHandleFn - = std::add_pointer::type; + using MDataHandleToUsdAttrFn = std::add_pointer< + void(const MDataHandle&, PXR_NS::UsdAttribute&, const ConverterArgs&)>::type; + using UsdAttrToMDataHandleFn = std::add_pointer< + void(const PXR_NS::UsdAttribute&, MDataHandle&, const ConverterArgs&)>::type; using MDataHandleToVtValueFn = std::add_pointer::type; using VtValueToMDataHandleFn @@ -157,14 +157,14 @@ class MAYAUSD_CORE_PUBLIC Converter final static const Converter* find(const SdfValueTypeName& typeName, bool isArrayPlug); //! \brief Look for converter which allows translation for given pair of Maya's plug and //! Usd attribute. \return Valid pointer if conversion is supported. - static const Converter* find(const MPlug& plug, const UsdAttribute& attr); + static const Converter* find(const MPlug& plug, const PXR_NS::UsdAttribute& attr); //! \brief Return sdf value type name this converter is registered for. const SdfValueTypeName& usdType() const { return _usdTypeName; } //! \brief Validate if given pair of Maya's plug and Usd attribute is supported by this //! converter. - bool validate(const MPlug& plug, const UsdAttribute& usdAttr) const + bool validate(const MPlug& plug, const PXR_NS::UsdAttribute& usdAttr) const { return (usdAttr.GetTypeName() == _usdTypeName) && (getUsdTypeName(plug, false) == _usdTypeName); @@ -172,20 +172,23 @@ class MAYAUSD_CORE_PUBLIC Converter final //! \brief Read current value from given plug and set it on destination attribute. Use //! arguments to control converter behavior, like the time for setting value on attribute. - void convert(const MPlug& src, UsdAttribute& dst, const ConverterArgs& args) const + void convert(const MPlug& src, PXR_NS::UsdAttribute& dst, const ConverterArgs& args) const { _plugToAttr(src, dst, args); } //! \brief Read current value from given attribute and set it on destination plug. Use //! arguments to control converter behavior. - void convert(const UsdAttribute& src, MPlug& dst, const ConverterArgs& args) const + void convert(const PXR_NS::UsdAttribute& src, MPlug& dst, const ConverterArgs& args) const { _attrToPlug(src, dst, args); } //! \brief Read current value from given attribute and set it on destination plug using //! provided DG modifier. Use arguments to control converter behavior. - void - convert(const UsdAttribute& src, MPlug& plug, MDGModifier& dst, const ConverterArgs& args) const + void convert( + const PXR_NS::UsdAttribute& src, + MPlug& plug, + MDGModifier& dst, + const ConverterArgs& args) const { _attrToModifier(src, plug, dst, args); } @@ -212,14 +215,14 @@ class MAYAUSD_CORE_PUBLIC Converter final //! \brief Read current value from given data handle and set it on destination attribute. //! Use arguments to control converter behavior, like the time for setting value on //! attribute. - void convert(const MDataHandle& src, UsdAttribute& dst, const ConverterArgs& args) const + void convert(const MDataHandle& src, PXR_NS::UsdAttribute& dst, const ConverterArgs& args) const { _handleToAttr(src, dst, args); } //! \brief Read current value from given attribute and set it on destination data handle. //! Use arguments to control converter behavior, like the time for reading value from //! attribute. - void convert(const UsdAttribute& src, MDataHandle& dst, const ConverterArgs& args) const + void convert(const PXR_NS::UsdAttribute& src, MDataHandle& dst, const ConverterArgs& args) const { _attrToHandle(src, dst, args); } @@ -286,7 +289,7 @@ class MAYAUSD_CORE_PUBLIC Converter final //! Usd type this converter is operating with. const SdfValueTypeName& _usdTypeName; - // MPlug <--> UsdAttribute + // MPlug <--> PXR_NS::UsdAttribute //! Pointer to a function responsible for converting plug value to given usd attribute. MPlugToUsdAttrFn _plugToAttr { nullptr }; //! Pointer to a function responsible for converting usd attribute value to a given plug. @@ -304,7 +307,7 @@ class MAYAUSD_CORE_PUBLIC Converter final //! DG modifier. VtValueToMDGModifierFn _vtValueToModifier { nullptr }; - // MDataBlock <--> UsdAttribute + // MDataBlock <--> PXR_NS::UsdAttribute //! Pointer to a function responsible for converting data handle value to given usd //! attribute. MDataHandleToUsdAttrFn _handleToAttr { nullptr }; diff --git a/lib/mayaUsd/utils/copyLayerPrims.cpp b/lib/mayaUsd/utils/copyLayerPrims.cpp index a88b16779e..431d47ea2d 100644 --- a/lib/mayaUsd/utils/copyLayerPrims.cpp +++ b/lib/mayaUsd/utils/copyLayerPrims.cpp @@ -380,7 +380,7 @@ void renameTargetingPath( rel.SetTargets(targets); } else { // Retrieve the attribute so we can modify its targets. - UsdAttribute attr = prim.GetAttributeAtPath(targetingPath); + auto attr = prim.GetAttributeAtPath(targetingPath); if (attr) { // Modify all targets that were using the old path to now use the new path. SdfPathVector targets; diff --git a/lib/mayaUsd/utils/selectability.cpp b/lib/mayaUsd/utils/selectability.cpp index 2b69f0d137..54cbfcf553 100644 --- a/lib/mayaUsd/utils/selectability.cpp +++ b/lib/mayaUsd/utils/selectability.cpp @@ -17,6 +17,8 @@ #include +#include + #include PXR_NAMESPACE_OPEN_SCOPE @@ -89,11 +91,11 @@ Selectability::State Selectability::getLocalState(const UsdPrim& prim) if (!prim.GetMetadata(MayaUsdMetadata->Selectability, &selectability)) return kInherit; - if (selectability == MayaUsdTokens->Off) { + if (selectability == GenericTokens->Off) { return kOff; - } else if (selectability == MayaUsdTokens->On) { + } else if (selectability == GenericTokens->On) { return kOn; - } else if (selectability == MayaUsdTokens->Inherit) { + } else if (selectability == GenericTokens->Inherit) { return kInherit; } else { TF_WARN( diff --git a/lib/mayaUsd/utils/util.h b/lib/mayaUsd/utils/util.h index 94b2c9a7d4..e8231a8723 100644 --- a/lib/mayaUsd/utils/util.h +++ b/lib/mayaUsd/utils/util.h @@ -143,7 +143,6 @@ inline double ConvertMMToCM(const double mm) { return mm / MillimetersPerCentime inline double ConvertCMToMM(const double cm) { return cm * MillimetersPerCentimeter; } inline std::string SanitizeName(const std::string& name) { return UsdUfe::sanitizeName(name); } -inline std::string prettifyName(const std::string& name) { return UsdUfe::prettifyName(name); } /// Converts the given value \p mdistance in Maya's MDistance units to the /// equivalent value in USD's metersPerUnit. diff --git a/lib/mayaUsdAPI/utils.cpp b/lib/mayaUsdAPI/utils.cpp index f8f6bca926..40002b5b8b 100644 --- a/lib/mayaUsdAPI/utils.cpp +++ b/lib/mayaUsdAPI/utils.cpp @@ -25,18 +25,20 @@ #include #include +#include + namespace MAYAUSDAPI_NS_DEF { Ufe::Rtid getMayaRunTimeId() { return MayaUsd::ufe::getMayaRunTimeId(); } bool isConnected(const PXR_NS::UsdAttribute& srcUsdAttr, const PXR_NS::UsdAttribute& dstUsdAttr) { - return MayaUsd::ufe::isConnected(srcUsdAttr, dstUsdAttr); + return UsdUfe::isConnected(srcUsdAttr, dstUsdAttr); } PXR_NS::UsdStageWeakPtr usdStage(const Ufe::Attribute::Ptr& attribute) { - if (auto usdAttribute = std::dynamic_pointer_cast(attribute)) { + if (auto usdAttribute = std::dynamic_pointer_cast(attribute)) { return usdAttribute->usdPrim().GetStage(); } return nullptr; @@ -44,7 +46,7 @@ PXR_NS::UsdStageWeakPtr usdStage(const Ufe::Attribute::Ptr& attribute) PXR_NS::SdfValueTypeName usdAttributeType(const Ufe::Attribute::Ptr& attribute) { - if (auto usdAttribute = std::dynamic_pointer_cast(attribute)) { + if (auto usdAttribute = std::dynamic_pointer_cast(attribute)) { return usdAttribute->usdAttributeType(); } return PXR_NS::SdfValueTypeName(); @@ -55,7 +57,7 @@ bool getUsdValue( PXR_NS::VtValue& value, PXR_NS::UsdTimeCode time) { - if (auto usdAttribute = std::dynamic_pointer_cast(attribute)) { + if (auto usdAttribute = std::dynamic_pointer_cast(attribute)) { return usdAttribute->get(value, time); } return false; diff --git a/lib/usd/translators/mayaReferenceUpdater.cpp b/lib/usd/translators/mayaReferenceUpdater.cpp index 525d053941..43ebd48d71 100644 --- a/lib/usd/translators/mayaReferenceUpdater.cpp +++ b/lib/usd/translators/mayaReferenceUpdater.cpp @@ -72,7 +72,7 @@ void clearAutoEdit(const Ufe::Path& pulledPath) if (!prim.IsValid()) return; - UsdAttribute mayaAutoEditAttr = prim.GetAttribute(MayaUsd_SchemasTokens->mayaAutoEdit); + auto mayaAutoEditAttr = prim.GetAttribute(MayaUsd_SchemasTokens->mayaAutoEdit); if (mayaAutoEditAttr.IsValid()) mayaAutoEditAttr.Set(false); }); diff --git a/lib/usdUfe/CMakeLists.txt b/lib/usdUfe/CMakeLists.txt index 62365b6d28..a7df4332b6 100644 --- a/lib/usdUfe/CMakeLists.txt +++ b/lib/usdUfe/CMakeLists.txt @@ -81,6 +81,13 @@ if (UFE_SCENEITEM_HAS_METADATA) ) endif() +if (UFE_HAS_DISPLAY_NAME) + target_compile_definitions(${PROJECT_NAME} + PRIVATE + UFE_HAS_DISPLAY_NAME=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/usdUfe/base/tokens.cpp b/lib/usdUfe/base/tokens.cpp index 0995524e8e..5b2b3b871f 100644 --- a/lib/usdUfe/base/tokens.cpp +++ b/lib/usdUfe/base/tokens.cpp @@ -18,5 +18,7 @@ namespace USDUFE_NS_DEF { TF_DEFINE_PUBLIC_TOKENS(EditRoutingTokens, USDUFE_EDIT_ROUTING_TOKENS); +TF_DEFINE_PUBLIC_TOKENS(GenericTokens, USDUFE_GENERIC_TOKENS); +TF_DEFINE_PUBLIC_TOKENS(MetadataTokens, USDUFE_METADATA_TOKENS); } // namespace USDUFE_NS_DEF diff --git a/lib/usdUfe/base/tokens.h b/lib/usdUfe/base/tokens.h index 3c245c3e76..0fa2ab14c7 100644 --- a/lib/usdUfe/base/tokens.h +++ b/lib/usdUfe/base/tokens.h @@ -24,7 +24,7 @@ namespace USDUFE_NS_DEF { -// Tokens for edit routing in UsdUfe +// Tokens for edit routing: // // clang-format off #define USDUFE_EDIT_ROUTING_TOKENS \ @@ -52,6 +52,38 @@ PXR_NAMESPACE_USING_DIRECTIVE TF_DECLARE_PUBLIC_TOKENS(EditRoutingTokens, USDUFE_PUBLIC, USDUFE_EDIT_ROUTING_TOKENS); +// Generic tokens: +// +// clang-format off +#define USDUFE_GENERIC_TOKENS \ + /* Metadata value to inherit the value from a */ \ + /* parent prim. Used in selectability. */ \ + ((Inherit, "inherit")) \ + /* Metadata value to turn on or off a feature. */ \ + /* Used in selectability and lock, for example. */ \ + ((On, "on")) \ + ((Off, "off")) // clang-format on + +TF_DECLARE_PUBLIC_TOKENS(GenericTokens, USDUFE_PUBLIC, USDUFE_GENERIC_TOKENS); + +// Tokens that are used as metadata on prim and attributes: +// +// clang-format off +#define USDUFE_METADATA_TOKENS \ + /* Locking attribute metadata. A locked attribute */ \ + /* value cannot be changed. */ \ + /* TEMP (UsdUfe) - look at replacing mayaLock */ \ + ((Lock, "mayaLock")) \ + /* Metadata for UI queries */ \ + ((UIName, "uiname")) \ + ((UIFolder, "uifolder")) \ + ((UIMin, "uimin")) \ + ((UIMax, "uimax")) \ + ((UISoftMin, "uisoftmin")) \ + ((UISoftMax, "uisoftmax")) // clang-format on + +TF_DECLARE_PUBLIC_TOKENS(MetadataTokens, USDUFE_PUBLIC, USDUFE_METADATA_TOKENS); + } // namespace USDUFE_NS_DEF #endif // USDUFE_TOKENS_H diff --git a/lib/usdUfe/python/wrapTokens.cpp b/lib/usdUfe/python/wrapTokens.cpp index b05a03dc1d..fb6d3ba5b5 100644 --- a/lib/usdUfe/python/wrapTokens.cpp +++ b/lib/usdUfe/python/wrapTokens.cpp @@ -24,4 +24,6 @@ PXR_NAMESPACE_USING_DIRECTIVE void wrapTokens() { TF_PY_WRAP_PUBLIC_TOKENS("EditRoutingTokens", EditRoutingTokens, USDUFE_EDIT_ROUTING_TOKENS); + TF_PY_WRAP_PUBLIC_TOKENS("Tokens", GenericTokens, USDUFE_GENERIC_TOKENS); + TF_PY_WRAP_PUBLIC_TOKENS("MetadataTokens", MetadataTokens, USDUFE_METADATA_TOKENS); } diff --git a/lib/usdUfe/python/wrapUtils.cpp b/lib/usdUfe/python/wrapUtils.cpp index fe9bff11ca..82d5af354c 100644 --- a/lib/usdUfe/python/wrapUtils.cpp +++ b/lib/usdUfe/python/wrapUtils.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -103,7 +104,7 @@ bool _isAttributeEditAllowed(const PXR_NS::UsdAttribute& attr) void wrapUtils() { - // Because mayaUsd and UFE have incompatible Python bindings that do not + // Because UsdUfe and UFE have incompatible Python bindings that do not // know about each other (provided by Boost Python and pybind11, // respectively), we cannot pass in or return UFE objects such as Ufe::Path // here, and are forced to use strings. Use the tentative string @@ -122,5 +123,6 @@ void wrapUtils() def("isAnyLayerModifiable", _isAnyLayerModifiable); def("isEditTargetLayerModifiable", _isEditTargetLayerModifiable); def("getTime", _getTime); + def("prettifyName", &UsdUfe::prettifyName); def("isAttributeEditAllowed", _isAttributeEditAllowed); } diff --git a/lib/usdUfe/ufe/CMakeLists.txt b/lib/usdUfe/ufe/CMakeLists.txt index a20fc0deb8..a4f7e676d7 100644 --- a/lib/usdUfe/ufe/CMakeLists.txt +++ b/lib/usdUfe/ufe/CMakeLists.txt @@ -7,6 +7,10 @@ target_sources(${PROJECT_NAME} Global.cpp SetVariantSelectionCommand.cpp StagesSubject.cpp + UsdAttribute.cpp + UsdAttributeHolder.cpp + UsdAttributes.cpp + UsdAttributesHandler.cpp UsdCamera.cpp UsdCameraHandler.cpp UsdContextOps.cpp @@ -47,11 +51,20 @@ if(CMAKE_UFE_V3_FEATURES_AVAILABLE) ) endif() +if(CMAKE_UFE_V4_FEATURES_AVAILABLE) + target_sources(${PROJECT_NAME} + PRIVATE + UsdShaderAttributeDef.cpp + UsdShaderAttributeHolder.cpp + UsdUndoAttributesCommands.cpp + ) +endif() + if (UFE_SCENEITEM_HAS_METADATA) target_sources(${PROJECT_NAME} PRIVATE - UsdUndoClearSceneItemMetadataCommand.cpp - UsdUndoSetSceneItemMetadataCommand.cpp + UsdUndoClearSceneItemMetadataCommand.cpp + UsdUndoSetSceneItemMetadataCommand.cpp ) endif() @@ -62,11 +75,29 @@ if (UFE_CAMERA_HAS_RENDERABLE) ) endif() +if (UFE_ATTRIBUTES_GET_ENUMS) + target_compile_definitions(${PROJECT_NAME} + PRIVATE + UFE_ATTRIBUTES_GET_ENUMS=1 + ) +endif() + +if (UFE_HAS_NATIVE_TYPE_METADATA) + target_compile_definitions(${PROJECT_NAME} + PRIVATE + UFE_HAS_NATIVE_TYPE_METADATA=1 + ) +endif() + set(HEADERS Global.h SetVariantSelectionCommand.h StagesSubject.h UfeVersionCompat.h + UsdAttribute.h + UsdAttributeHolder.h + UsdAttributes.h + UsdAttributesHandler.h UsdCamera.h UsdCameraHandler.h UsdContextOps.h @@ -113,6 +144,14 @@ if (UFE_SCENEITEM_HAS_METADATA) ) endif() +if(CMAKE_UFE_V4_FEATURES_AVAILABLE) + list(APPEND HEADERS + UsdShaderAttributeDef.h + UsdShaderAttributeHolder.h + UsdUndoAttributesCommands.h + ) +endif() + # ----------------------------------------------------------------------------- # promote headers # ----------------------------------------------------------------------------- diff --git a/lib/usdUfe/ufe/Global.cpp b/lib/usdUfe/ufe/Global.cpp index 15dc170ef0..cd29ae7485 100644 --- a/lib/usdUfe/ufe/Global.cpp +++ b/lib/usdUfe/ufe/Global.cpp @@ -15,6 +15,7 @@ // #include "Global.h" +#include #include #include #include @@ -80,6 +81,7 @@ Ufe::Rtid initialize( UsdUfe::setIsRootChildFn(dccFunctions.isRootChildFn); if (dccFunctions.uniqueChildNameFn) UsdUfe::setUniqueChildNameFn(dccFunctions.uniqueChildNameFn); + UsdUfe::setDisplayMessageFn(dccFunctions.displayMessageFn); // Create a default stages subject if none is provided. if (nullptr == ss) { @@ -89,6 +91,8 @@ Ufe::Rtid initialize( // Copy all the input handlers into the Ufe handler struct and // create any default ones which are null. Ufe::RunTimeMgr::Handlers rtHandlers; + rtHandlers.attributesHandler + = handlers.attributesHandler ? handlers.attributesHandler : UsdAttributesHandler::create(); rtHandlers.hierarchyHandler = handlers.hierarchyHandler ? handlers.hierarchyHandler : UsdHierarchyHandler::create(); rtHandlers.object3dHandler diff --git a/lib/usdUfe/ufe/Global.h b/lib/usdUfe/ufe/Global.h index a194b7eb57..6049038c47 100644 --- a/lib/usdUfe/ufe/Global.h +++ b/lib/usdUfe/ufe/Global.h @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -48,6 +49,7 @@ struct USDUFE_PUBLIC DCCFunctions SaveStageLoadRulesFn saveStageLoadRulesFn = nullptr; IsRootChildFn isRootChildFn = nullptr; UniqueChildNameFn uniqueChildNameFn = nullptr; + DisplayMessageFn displayMessageFn[static_cast(MessageType::nbTypes)] = { nullptr }; // Optional: nothing will be done if no function is supplied. WaitCursorFn startWaitCursorFn = nullptr; @@ -69,7 +71,7 @@ struct USDUFE_PUBLIC Handlers // Ufe::SceneItemOpsHandler::Ptr sceneItemOpsHandler; // Ufe v2 handlers - // Ufe::AttributesHandler::Ptr attributesHandler; + Ufe::AttributesHandler::Ptr attributesHandler; Ufe::Object3dHandler::Ptr object3dHandler; Ufe::ContextOpsHandler::Ptr contextOpsHandler; Ufe::UIInfoHandler::Ptr uiInfoHandler; diff --git a/lib/mayaUsd/ufe/UsdAttribute.cpp b/lib/usdUfe/ufe/UsdAttribute.cpp similarity index 89% rename from lib/mayaUsd/ufe/UsdAttribute.cpp rename to lib/usdUfe/ufe/UsdAttribute.cpp index 22863265c5..a975009ba6 100644 --- a/lib/mayaUsd/ufe/UsdAttribute.cpp +++ b/lib/usdUfe/ufe/UsdAttribute.cpp @@ -15,13 +15,12 @@ // #include "UsdAttribute.h" -#include "Utils.h" #include "private/UfeNotifGuard.h" -#include - #include #include +#include +#include #include #include @@ -31,17 +30,15 @@ #include #include -#include - #include #include #include #ifdef UFE_V4_FEATURES_AVAILABLE -#include "UsdShaderAttributeDef.h" +#include #endif #ifdef UFE_V3_FEATURES_AVAILABLE -#include +#include #endif // Note: normally we would use this using directive, but here we cannot because @@ -60,7 +57,7 @@ static constexpr char kErrorMsgInvalidType[] namespace { -template bool setUsdAttr(MayaUsd::ufe::UsdAttribute& attr, const T& value) +template bool setUsdAttr(UsdUfe::UsdAttribute& attr, const T& value) { // USD Attribute Notification doubling problem: // As of 24-Nov-2019, calling Set() on a UsdAttribute causes two "info only" @@ -103,12 +100,11 @@ PXR_NS::UsdTimeCode getCurrentTime(const Ufe::SceneItem::Ptr& item) // Attributes with time samples will fail when calling Get with default time code. // So we'll always use the current time when calling Get. If there are no time // samples, it will fall-back to the default time code. - return MayaUsd::ufe::getTime(item->path()); + return UsdUfe::getTime(item->path()); } -std::string getUsdAttributeValueAsString( - const MayaUsd::ufe::UsdAttribute& attr, - const PXR_NS::UsdTimeCode& time) +std::string +getUsdAttributeValueAsString(const UsdUfe::UsdAttribute& attr, const PXR_NS::UsdTimeCode& time) { if (!attr.isValid() || #ifdef UFE_V4_FEATURES_AVAILABLE @@ -139,9 +135,7 @@ std::string getUsdAttributeValueAsString( } template -U getUsdAttributeVectorAsUfe( - const MayaUsd::ufe::UsdAttribute& attr, - const PXR_NS::UsdTimeCode& time) +U getUsdAttributeVectorAsUfe(const UsdUfe::UsdAttribute& attr, const PXR_NS::UsdTimeCode& time) { VtValue vt; if (!attr.isValid() || @@ -151,7 +145,7 @@ U getUsdAttributeVectorAsUfe( !attr.hasValue()) { #endif if (!attr.defaultValue().empty()) { - vt = MayaUsd::ufe::vtValueFromString(attr.usdAttributeType(), attr.defaultValue()); + vt = UsdUfe::vtValueFromString(attr.usdAttributeType(), attr.defaultValue()); } else { return U(); } @@ -167,9 +161,9 @@ U getUsdAttributeVectorAsUfe( template void setUsdAttributeVectorFromUfe( - MayaUsd::ufe::UsdAttribute& attr, - const U& value, - const PXR_NS::UsdTimeCode& time) + UsdUfe::UsdAttribute& attr, + const U& value, + const PXR_NS::UsdTimeCode& time) { T vec; std::copy(value.vector.data(), value.vector.data() + value.vector.size(), vec.data()); @@ -177,7 +171,7 @@ void setUsdAttributeVectorFromUfe( } template -U getUsdAttributeColorAsUfe(const MayaUsd::ufe::UsdAttribute& attr, const PXR_NS::UsdTimeCode& time) +U getUsdAttributeColorAsUfe(const UsdUfe::UsdAttribute& attr, const PXR_NS::UsdTimeCode& time) { VtValue vt; if (!attr.isValid() || @@ -187,7 +181,7 @@ U getUsdAttributeColorAsUfe(const MayaUsd::ufe::UsdAttribute& attr, const PXR_NS !attr.hasValue()) { #endif if (!attr.defaultValue().empty()) { - vt = MayaUsd::ufe::vtValueFromString(attr.usdAttributeType(), attr.defaultValue()); + vt = UsdUfe::vtValueFromString(attr.usdAttributeType(), attr.defaultValue()); } else { return U(); } @@ -202,9 +196,9 @@ U getUsdAttributeColorAsUfe(const MayaUsd::ufe::UsdAttribute& attr, const PXR_NS template void setUsdAttributeColorFromUfe( - MayaUsd::ufe::UsdAttribute& attr, - const U& value, - const PXR_NS::UsdTimeCode& time) + UsdUfe::UsdAttribute& attr, + const U& value, + const PXR_NS::UsdTimeCode& time) { T vec; std::copy(value.color.data(), value.color.data() + value.color.size(), vec.data()); @@ -213,14 +207,12 @@ void setUsdAttributeColorFromUfe( #ifdef UFE_V4_FEATURES_AVAILABLE template -U getUsdAttributeMatrixAsUfe( - const MayaUsd::ufe::UsdAttribute& attr, - const PXR_NS::UsdTimeCode& time) +U getUsdAttributeMatrixAsUfe(const UsdUfe::UsdAttribute& attr, const PXR_NS::UsdTimeCode& time) { VtValue vt; if (!attr.isValid() || !attr._hasValue()) { if (!attr.defaultValue().empty()) { - vt = MayaUsd::ufe::vtValueFromString(attr.usdAttributeType(), attr.defaultValue()); + vt = UsdUfe::vtValueFromString(attr.usdAttributeType(), attr.defaultValue()); } else { return U(); } @@ -237,9 +229,9 @@ U getUsdAttributeMatrixAsUfe( template void setUsdAttributeMatrixFromUfe( - MayaUsd::ufe::UsdAttribute& attr, - const U& value, - const PXR_NS::UsdTimeCode& time) + UsdUfe::UsdAttribute& attr, + const U& value, + const PXR_NS::UsdTimeCode& time) { T mat; std::copy( @@ -250,7 +242,7 @@ void setUsdAttributeMatrixFromUfe( } #endif -template > +template > class SetUndoableCommand : public UsdUfe::UsdUndoableCommand { public: @@ -285,9 +277,9 @@ class SetUndoableMetadataCommand : public UsdUfe::UsdUndoableCommand Ufe::UndoableCommand::Ptr TypedUsdAttribute::setCmd(con { const std::string errMsg = isEditAllowedMsg(); if (!errMsg.empty()) { - MGlobal::displayError(errMsg.c_str()); + displayMessage(MessageType::KError, errMsg); return nullptr; } @@ -857,7 +848,7 @@ template void TypedUsdAttribute::set(const T& value) // UsdAttributeBool: //------------------------------------------------------------------------------ -MAYAUSD_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeBool); +USDUFE_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeBool); /*static*/ UsdAttributeBool::Ptr @@ -871,7 +862,7 @@ UsdAttributeBool::create(const UsdSceneItem::Ptr& item, UsdAttributeHolder::UPtr // UsdAttributeInt: //------------------------------------------------------------------------------ -MAYAUSD_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeInt); +USDUFE_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeInt); /*static*/ UsdAttributeInt::Ptr @@ -885,7 +876,7 @@ UsdAttributeInt::create(const UsdSceneItem::Ptr& item, UsdAttributeHolder::UPtr& // UsdAttributeFloat: //------------------------------------------------------------------------------ -MAYAUSD_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeFloat); +USDUFE_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeFloat); /*static*/ UsdAttributeFloat::Ptr @@ -899,7 +890,7 @@ UsdAttributeFloat::create(const UsdSceneItem::Ptr& item, UsdAttributeHolder::UPt // UsdAttributeDouble: //------------------------------------------------------------------------------ -MAYAUSD_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeDouble); +USDUFE_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeDouble); /*static*/ UsdAttributeDouble::Ptr @@ -914,8 +905,8 @@ UsdAttributeDouble::create(const UsdSceneItem::Ptr& item, UsdAttributeHolder::UP //------------------------------------------------------------------------------ // Ensure that UsdAttributeString is properly setup. -MAYAUSD_VERIFY_CLASS_SETUP(Ufe::TypedAttribute, UsdAttributeString); -MAYAUSD_VERIFY_CLASS_BASE(UsdAttribute, UsdAttributeString); +USDUFE_VERIFY_CLASS_SETUP(Ufe::TypedAttribute, UsdAttributeString); +USDUFE_VERIFY_CLASS_BASE(UsdAttribute, UsdAttributeString); UsdAttributeString::UsdAttributeString( const UsdSceneItem::Ptr& item, @@ -960,7 +951,7 @@ Ufe::UndoableCommand::Ptr UsdAttributeString::setCmd(const std::string& value) const std::string errMsg = isEditAllowedMsg(); if (!errMsg.empty()) { - MGlobal::displayError(errMsg.c_str()); + displayMessage(MessageType::KError, errMsg); return nullptr; } @@ -972,8 +963,8 @@ Ufe::UndoableCommand::Ptr UsdAttributeString::setCmd(const std::string& value) //------------------------------------------------------------------------------ // Ensure that UsdAttributeToken is properly setup. -MAYAUSD_VERIFY_CLASS_SETUP(Ufe::TypedAttribute, UsdAttributeToken); -MAYAUSD_VERIFY_CLASS_BASE(UsdAttribute, UsdAttributeToken); +USDUFE_VERIFY_CLASS_SETUP(Ufe::TypedAttribute, UsdAttributeToken); +USDUFE_VERIFY_CLASS_BASE(UsdAttribute, UsdAttributeToken); UsdAttributeToken::UsdAttributeToken( const UsdSceneItem::Ptr& item, @@ -1018,7 +1009,7 @@ Ufe::UndoableCommand::Ptr UsdAttributeToken::setCmd(const std::string& value) const std::string errMsg = isEditAllowedMsg(); if (!errMsg.empty()) { - MGlobal::displayError(errMsg.c_str()); + displayMessage(MessageType::KError, errMsg); return nullptr; } @@ -1029,7 +1020,7 @@ Ufe::UndoableCommand::Ptr UsdAttributeToken::setCmd(const std::string& value) // UsdAttributeColorFloat3: //------------------------------------------------------------------------------ -MAYAUSD_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeColorFloat3); +USDUFE_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeColorFloat3); /*static*/ UsdAttributeColorFloat3::Ptr UsdAttributeColorFloat3::create( @@ -1045,7 +1036,7 @@ UsdAttributeColorFloat3::Ptr UsdAttributeColorFloat3::create( // UsdAttributeColorFloat4: //------------------------------------------------------------------------------ -MAYAUSD_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeColorFloat4); +USDUFE_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeColorFloat4); /*static*/ UsdAttributeColorFloat4::Ptr UsdAttributeColorFloat4::create( @@ -1061,7 +1052,7 @@ UsdAttributeColorFloat4::Ptr UsdAttributeColorFloat4::create( // UsdAttributeInt3: //------------------------------------------------------------------------------ -MAYAUSD_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeInt3); +USDUFE_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeInt3); /*static*/ UsdAttributeInt3::Ptr @@ -1076,7 +1067,7 @@ UsdAttributeInt3::create(const UsdSceneItem::Ptr& item, UsdAttributeHolder::UPtr // UsdAttributeFloat2: //------------------------------------------------------------------------------ -MAYAUSD_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeFloat2); +USDUFE_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeFloat2); /*static*/ UsdAttributeFloat2::Ptr @@ -1091,7 +1082,7 @@ UsdAttributeFloat2::create(const UsdSceneItem::Ptr& item, UsdAttributeHolder::UP // UsdAttributeFloat3: //------------------------------------------------------------------------------ -MAYAUSD_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeFloat3); +USDUFE_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeFloat3); /*static*/ UsdAttributeFloat3::Ptr @@ -1106,7 +1097,7 @@ UsdAttributeFloat3::create(const UsdSceneItem::Ptr& item, UsdAttributeHolder::UP // UsdAttributeFloat4: //------------------------------------------------------------------------------ -MAYAUSD_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeFloat4); +USDUFE_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeFloat4); /*static*/ UsdAttributeFloat4::Ptr @@ -1121,7 +1112,7 @@ UsdAttributeFloat4::create(const UsdSceneItem::Ptr& item, UsdAttributeHolder::UP // UsdAttributeDouble3: //------------------------------------------------------------------------------ -MAYAUSD_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeDouble3); +USDUFE_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeDouble3); /*static*/ UsdAttributeDouble3::Ptr @@ -1136,7 +1127,7 @@ UsdAttributeDouble3::create(const UsdSceneItem::Ptr& item, UsdAttributeHolder::U // UsdAttributeMatrix3d: //------------------------------------------------------------------------------ -MAYAUSD_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeMatrix3d); +USDUFE_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeMatrix3d); /*static*/ UsdAttributeMatrix3d::Ptr @@ -1150,7 +1141,7 @@ UsdAttributeMatrix3d::create(const UsdSceneItem::Ptr& item, UsdAttributeHolder:: // UsdAttributeMatrix4d: //------------------------------------------------------------------------------ -MAYAUSD_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeMatrix4d); +USDUFE_VERIFY_CLASS_SETUP(TypedUsdAttribute, UsdAttributeMatrix4d); /*static*/ UsdAttributeMatrix4d::Ptr @@ -1184,5 +1175,4 @@ bool UsdAttribute::setValue(const std::string& value) } #endif -} // namespace ufe -} // namespace MAYAUSD_NS_DEF +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdAttribute.h b/lib/usdUfe/ufe/UsdAttribute.h similarity index 99% rename from lib/mayaUsd/ufe/UsdAttribute.h rename to lib/usdUfe/ufe/UsdAttribute.h index 302b05f971..1978e10c08 100644 --- a/lib/mayaUsd/ufe/UsdAttribute.h +++ b/lib/usdUfe/ufe/UsdAttribute.h @@ -15,8 +15,8 @@ // #pragma once -#include "UsdAttributeHolder.h" - +#include +#include #include #include @@ -110,17 +110,16 @@ #endif #endif -namespace MAYAUSD_NS_DEF { -namespace ufe { +namespace USDUFE_NS_DEF { //! \brief Internal helper class to implement the pure virtual methods from Ufe::Attribute. -class MAYAUSD_CORE_PUBLIC UsdAttribute +class USDUFE_PUBLIC UsdAttribute { public: UsdAttribute(UsdAttributeHolder::UPtr&& attrHolder); ~UsdAttribute() = default; - MAYAUSD_DISALLOW_COPY_MOVE_AND_ASSIGNMENT(UsdAttribute); + USDUFE_DISALLOW_COPY_MOVE_AND_ASSIGNMENT(UsdAttribute); inline bool isAuthored() const { return _attrHolder->isAuthored(); } inline bool isValid() const { return _attrHolder->isValid(); } @@ -565,5 +564,5 @@ class UsdAttributeMatrix4d : public TypedUsdAttribute create(const UsdSceneItem::Ptr& item, UsdAttributeHolder::UPtr&& attrHolder); }; #endif -} // namespace ufe -} // namespace MAYAUSD_NS_DEF + +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdAttributeHolder.cpp b/lib/usdUfe/ufe/UsdAttributeHolder.cpp similarity index 95% rename from lib/mayaUsd/ufe/UsdAttributeHolder.cpp rename to lib/usdUfe/ufe/UsdAttributeHolder.cpp index 853bd4e61d..0b90edc594 100644 --- a/lib/mayaUsd/ufe/UsdAttributeHolder.cpp +++ b/lib/usdUfe/ufe/UsdAttributeHolder.cpp @@ -18,13 +18,13 @@ #include "Utils.h" #include "private/UfeNotifGuard.h" -#include - +#include #include +#include #include #include #ifdef UFE_V3_FEATURES_AVAILABLE -#include +#include #endif #include @@ -52,7 +52,7 @@ bool setUsdAttrMetadata( // since that is how you unlock. if (key == Ufe::Attribute::kLocked) { return attr.SetMetadata( - MayaUsdMetadata->Lock, value.get() ? MayaUsdTokens->On : MayaUsdTokens->Off); + MetadataTokens->Lock, value.get() ? GenericTokens->On : GenericTokens->Off); } // If attribute is locked don't allow setting Metadata. @@ -99,15 +99,14 @@ bool setUsdAttrMetadata( } // namespace -namespace MAYAUSD_NS_DEF { -namespace ufe { +namespace USDUFE_NS_DEF { //------------------------------------------------------------------------------ // UsdAttributeHolder: //------------------------------------------------------------------------------ // Ensure that UsdAttributeHolder is properly setup. -MAYAUSD_VERIFY_CLASS_VIRTUAL_DESTRUCTOR(UsdAttributeHolder); +USDUFE_VERIFY_CLASS_VIRTUAL_DESTRUCTOR(UsdAttributeHolder); UsdAttributeHolder::UsdAttributeHolder(const PXR_NS::UsdAttribute& usdAttr) : _usdAttr(usdAttr) @@ -245,9 +244,9 @@ Ufe::Value UsdAttributeHolder::getMetadata(const std::string& key) const // Special cases for known Ufe metadata keys. if (key == Ufe::Attribute::kLocked) { PXR_NS::TfToken lock; - bool ret = _usdAttr.GetMetadata(MayaUsdMetadata->Lock, &lock); + bool ret = _usdAttr.GetMetadata(MetadataTokens->Lock, &lock); if (ret) - return Ufe::Value((lock == MayaUsdTokens->On) ? true : false); + return Ufe::Value((lock == GenericTokens->On) ? true : false); return Ufe::Value(); } PXR_NS::TfToken tok(key); @@ -255,22 +254,22 @@ Ufe::Value UsdAttributeHolder::getMetadata(const std::string& key) const if (PXR_NS::UsdShadeInput::IsInput(_usdAttr)) { const PXR_NS::UsdShadeInput input(_usdAttr); std::string metadata = input.GetSdrMetadataByKey(tok); - if (metadata.empty() && key == MayaUsdMetadata->UIName) { + if (metadata.empty() && key == MetadataTokens->UIName) { // Strip and prettify: - metadata = UsdMayaUtil::prettifyName(input.GetBaseName().GetString()); + metadata = prettifyName(input.GetBaseName().GetString()); } return Ufe::Value(metadata); } else if (PXR_NS::UsdShadeOutput::IsOutput(_usdAttr)) { const PXR_NS::UsdShadeOutput output(_usdAttr); std::string metadata = output.GetSdrMetadataByKey(tok); - if (metadata.empty() && key == MayaUsdMetadata->UIName) { + if (metadata.empty() && key == MetadataTokens->UIName) { // Strip and prettify: - metadata = UsdMayaUtil::prettifyName(output.GetBaseName().GetString()); + metadata = prettifyName(output.GetBaseName().GetString()); } return Ufe::Value(metadata); } } - if (key == MayaUsdMetadata->UIName) { + if (key == MetadataTokens->UIName) { std::string niceName; // Non-shader case, but we still have light inputs and outputs to deal with: if (PXR_NS::UsdShadeInput::IsInput(_usdAttr)) { @@ -284,7 +283,7 @@ Ufe::Value UsdAttributeHolder::getMetadata(const std::string& key) const } const bool isNamespaced = niceName.find(":") != std::string::npos; - niceName = UsdMayaUtil::prettifyName(niceName); + niceName = prettifyName(niceName); if (!isNamespaced) { return Ufe::Value(niceName); @@ -518,7 +517,7 @@ bool UsdAttributeHolder::clearMetadata(const std::string& key) // Special cases for known Ufe metadata keys. if (key == Ufe::Attribute::kLocked) { - return _usdAttr.ClearMetadata(MayaUsdMetadata->Lock); + return _usdAttr.ClearMetadata(MetadataTokens->Lock); } if (key == SdfFieldKeys->ColorSpace) { @@ -537,11 +536,11 @@ bool UsdAttributeHolder::hasMetadata(const std::string& key) const if (isValid()) { // Special cases for known Ufe metadata keys. if (key == Ufe::Attribute::kLocked) { - result = _usdAttr.HasMetadata(MayaUsdMetadata->Lock); + result = _usdAttr.HasMetadata(MetadataTokens->Lock); if (result) { return true; } - } else if (key == MayaUsdMetadata->UIName) { + } else if (key == MetadataTokens->UIName) { return true; } @@ -641,5 +640,4 @@ UsdAttributeHolder::EnumOptions UsdAttributeHolder::getEnums() const return retVal; } -} // namespace ufe -} // namespace MAYAUSD_NS_DEF +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdAttributeHolder.h b/lib/usdUfe/ufe/UsdAttributeHolder.h similarity index 95% rename from lib/mayaUsd/ufe/UsdAttributeHolder.h rename to lib/usdUfe/ufe/UsdAttributeHolder.h index a1cdaa8142..1cc9cf5445 100644 --- a/lib/mayaUsd/ufe/UsdAttributeHolder.h +++ b/lib/usdUfe/ufe/UsdAttributeHolder.h @@ -15,7 +15,7 @@ // #pragma once -#include +#include #include #include @@ -23,8 +23,7 @@ #include -namespace MAYAUSD_NS_DEF { -namespace ufe { +namespace USDUFE_NS_DEF { //! \brief Internal helper class holding a USD attributes for query: class UsdAttributeHolder @@ -69,5 +68,4 @@ class UsdAttributeHolder PXR_NS::UsdAttribute _usdAttr; }; // UsdAttributeHolder -} // namespace ufe -} // namespace MAYAUSD_NS_DEF +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdAttributes.cpp b/lib/usdUfe/ufe/UsdAttributes.cpp similarity index 96% rename from lib/mayaUsd/ufe/UsdAttributes.cpp rename to lib/usdUfe/ufe/UsdAttributes.cpp index 647dfce4cc..51e47a484f 100644 --- a/lib/mayaUsd/ufe/UsdAttributes.cpp +++ b/lib/usdUfe/ufe/UsdAttributes.cpp @@ -15,10 +15,10 @@ // #include "UsdAttributes.h" -#include "Global.h" -#include "Utils.h" - -#include +#include +#include +#include +#include #include #include @@ -30,10 +30,9 @@ #include #ifdef UFE_V4_FEATURES_AVAILABLE -#include -#include -#include -#include +#include +#include +#include #endif // Note: normally we would use this using directive, but here we cannot because @@ -45,8 +44,7 @@ static constexpr char kErrorMsgUnknown[] = "Unknown UFE attribute type encountered"; #endif -namespace MAYAUSD_NS_DEF { -namespace ufe { +namespace USDUFE_NS_DEF { namespace { @@ -54,7 +52,7 @@ namespace { std::pair _GetSdrPropertyAndType(const Ufe::SceneItem::Ptr& item, const std::string& tokName) { - auto shaderNode = UsdShaderNodeDefHandler::usdDefinition(item); + auto shaderNode = usdShaderNodeFromSceneItem(item); if (shaderNode) { auto baseNameAndType = PXR_NS::UsdShadeUtils::GetBaseNameAndType(PXR_NS::TfToken(tokName)); switch (baseNameAndType.second) { @@ -72,9 +70,9 @@ _GetSdrPropertyAndType(const Ufe::SceneItem::Ptr& item, const std::string& tokNa // Ensure that UsdAttributes is properly setup. #ifdef UFE_V4_2_FEATURES_AVAILABLE -MAYAUSD_VERIFY_CLASS_SETUP(Ufe::Attributes_v4_2, UsdAttributes); +USDUFE_VERIFY_CLASS_SETUP(Ufe::Attributes_v4_2, UsdAttributes); #else -MAYAUSD_VERIFY_CLASS_SETUP(Ufe::Attributes, UsdAttributes); +USDUFE_VERIFY_CLASS_SETUP(Ufe::Attributes, UsdAttributes); #endif UsdAttributes::UsdAttributes(const UsdSceneItem::Ptr& item) @@ -258,7 +256,7 @@ std::vector UsdAttributes::attributeNames() const std::set nameSet; std::string name; #ifdef UFE_V4_FEATURES_AVAILABLE - PXR_NS::SdrShaderNodeConstPtr shaderNode = UsdShaderNodeDefHandler::usdDefinition(fItem); + PXR_NS::SdrShaderNodeConstPtr shaderNode = usdShaderNodeFromSceneItem(fItem); if (shaderNode) { auto addAttributeNames = [&names, &nameSet, &name]( @@ -451,10 +449,10 @@ static void removeSrcAttrConnections(PXR_NS::UsdPrim& prim, const PXR_NS::UsdAtt for (const auto& attribute : prim.GetAttributes()) { PXR_NS::UsdAttribute dstUsdAttr = attribute.As(); - if (MayaUsd::ufe::isConnected(srcUsdAttr, dstUsdAttr)) { + if (isConnected(srcUsdAttr, dstUsdAttr)) { UsdShadeConnectableAPI::DisconnectSource(dstUsdAttr, srcUsdAttr); // Check if we can remove the property. - if (MayaUsd::ufe::canRemoveDstProperty(dstUsdAttr)) { + if (canRemoveDstProperty(dstUsdAttr)) { // Remove the property. prim.RemoveProperty(dstUsdAttr.GetName()); } @@ -499,7 +497,7 @@ static void removeDstAttrConnections(const PXR_NS::UsdAttribute& dstUsdAttr) if (srcAttr) { UsdShadeConnectableAPI::DisconnectSource(dstUsdAttr, srcAttr); // Check if we can remove the property. - if (MayaUsd::ufe::canRemoveSrcProperty(srcAttr)) { + if (canRemoveSrcProperty(srcAttr)) { // Remove the property. connectedPrim.RemoveProperty(srcAttr.GetName()); } @@ -560,9 +558,7 @@ static void removeNodeGraphConnections(const PXR_NS::UsdAttribute& attr) void UsdAttributes::removeAttributesConnections(const PXR_NS::UsdPrim& prim) { - auto primParent = prim.GetParent(); - if (!primParent) { return; } @@ -748,7 +744,6 @@ Ufe::Attribute::Ptr UsdAttributes::doRenameAttribute( } #endif -#ifdef UFE_V4_FEATURES_AVAILABLE #ifdef UFE_ATTRIBUTES_GET_ENUMS UFE_ATTRIBUTES_BASE::Enums UsdAttributes::getEnums(const std::string& attrName) const { @@ -767,6 +762,5 @@ UFE_ATTRIBUTES_BASE::Enums UsdAttributes::getEnums(const std::string& attrName) return {}; } #endif -#endif -} // namespace ufe -} // namespace MAYAUSD_NS_DEF + +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdAttributes.h b/lib/usdUfe/ufe/UsdAttributes.h similarity index 91% rename from lib/mayaUsd/ufe/UsdAttributes.h rename to lib/usdUfe/ufe/UsdAttributes.h index 8310e08ff5..920af4dc94 100644 --- a/lib/mayaUsd/ufe/UsdAttributes.h +++ b/lib/usdUfe/ufe/UsdAttributes.h @@ -15,9 +15,8 @@ // #pragma once -#include -#include - +#include +#include #include #include @@ -35,18 +34,17 @@ #define UFE_ATTRIBUTES_BASE Ufe::Attributes #endif -namespace MAYAUSD_NS_DEF { -namespace ufe { +namespace USDUFE_NS_DEF { //! \brief Interface for USD Attributes. -class UsdAttributes : public UFE_ATTRIBUTES_BASE +class USDUFE_PUBLIC UsdAttributes : public UFE_ATTRIBUTES_BASE { public: typedef std::shared_ptr Ptr; UsdAttributes(const UsdSceneItem::Ptr& item); - MAYAUSD_DISALLOW_COPY_MOVE_AND_ASSIGNMENT(UsdAttributes); + USDUFE_DISALLOW_COPY_MOVE_AND_ASSIGNMENT(UsdAttributes); //! Create a UsdAttributes. static UsdAttributes::Ptr create(const UsdSceneItem::Ptr& item); @@ -86,11 +84,9 @@ class UsdAttributes : public UFE_ATTRIBUTES_BASE const std::string& originalName, const std::string& newName); #endif -#ifdef UFE_V4_FEATURES_AVAILABLE #ifdef UFE_ATTRIBUTES_GET_ENUMS UFE_ATTRIBUTES_BASE::Enums getEnums(const std::string& attrName) const override; #endif -#endif private: UsdSceneItem::Ptr fItem; @@ -100,5 +96,4 @@ class UsdAttributes : public UFE_ATTRIBUTES_BASE AttributeMap fUsdAttributes; }; // UsdAttributes -} // namespace ufe -} // namespace MAYAUSD_NS_DEF +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdAttributesHandler.cpp b/lib/usdUfe/ufe/UsdAttributesHandler.cpp similarity index 88% rename from lib/mayaUsd/ufe/UsdAttributesHandler.cpp rename to lib/usdUfe/ufe/UsdAttributesHandler.cpp index 048deb70ac..d45e075b37 100644 --- a/lib/mayaUsd/ufe/UsdAttributesHandler.cpp +++ b/lib/usdUfe/ufe/UsdAttributesHandler.cpp @@ -17,10 +17,9 @@ #include -namespace MAYAUSD_NS_DEF { -namespace ufe { +namespace USDUFE_NS_DEF { -MAYAUSD_VERIFY_CLASS_SETUP(Ufe::AttributesHandler, UsdAttributesHandler); +USDUFE_VERIFY_CLASS_SETUP(Ufe::AttributesHandler, UsdAttributesHandler); /*static*/ UsdAttributesHandler::Ptr UsdAttributesHandler::create() @@ -42,5 +41,4 @@ Ufe::Attributes::Ptr UsdAttributesHandler::attributes(const Ufe::SceneItem::Ptr& return usdAttributes; } -} // namespace ufe -} // namespace MAYAUSD_NS_DEF +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdAttributesHandler.h b/lib/usdUfe/ufe/UsdAttributesHandler.h similarity index 77% rename from lib/mayaUsd/ufe/UsdAttributesHandler.h rename to lib/usdUfe/ufe/UsdAttributesHandler.h index c36f50914c..de89cc50e9 100644 --- a/lib/mayaUsd/ufe/UsdAttributesHandler.h +++ b/lib/usdUfe/ufe/UsdAttributesHandler.h @@ -15,23 +15,22 @@ // #pragma once -#include -#include +#include +#include #include -namespace MAYAUSD_NS_DEF { -namespace ufe { +namespace USDUFE_NS_DEF { //! \brief Interface to create the USD Attributes interface objects. -class MAYAUSD_CORE_PUBLIC UsdAttributesHandler : public Ufe::AttributesHandler +class USDUFE_PUBLIC UsdAttributesHandler : public Ufe::AttributesHandler { public: typedef std::shared_ptr Ptr; UsdAttributesHandler() = default; - MAYAUSD_DISALLOW_COPY_MOVE_AND_ASSIGNMENT(UsdAttributesHandler); + USDUFE_DISALLOW_COPY_MOVE_AND_ASSIGNMENT(UsdAttributesHandler); //! Create a UsdAttributesHandler. static UsdAttributesHandler::Ptr create(); @@ -42,5 +41,4 @@ class MAYAUSD_CORE_PUBLIC UsdAttributesHandler : public Ufe::AttributesHandler private: }; // UsdAttributesHandler -} // namespace ufe -} // namespace MAYAUSD_NS_DEF +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdShaderAttributeDef.cpp b/lib/usdUfe/ufe/UsdShaderAttributeDef.cpp similarity index 92% rename from lib/mayaUsd/ufe/UsdShaderAttributeDef.cpp rename to lib/usdUfe/ufe/UsdShaderAttributeDef.cpp index f12ff7e918..290575f67d 100644 --- a/lib/mayaUsd/ufe/UsdShaderAttributeDef.cpp +++ b/lib/usdUfe/ufe/UsdShaderAttributeDef.cpp @@ -16,11 +16,9 @@ #include "UsdShaderAttributeDef.h" -#include "Global.h" -#include "Utils.h" - -#include -#include +#include +#include +#include #include #include @@ -29,10 +27,9 @@ #include #include -namespace MAYAUSD_NS_DEF { -namespace ufe { +namespace USDUFE_NS_DEF { -MAYAUSD_VERIFY_CLASS_SETUP(Ufe::AttributeDef, UsdShaderAttributeDef); +USDUFE_VERIFY_CLASS_SETUP(Ufe::AttributeDef, UsdShaderAttributeDef); PXR_NAMESPACE_USING_DIRECTIVE @@ -77,16 +74,16 @@ typedef std::unordered_mapUIName.GetString(), + { UsdUfe::MetadataTokens->UIName.GetString(), [](const PXR_NS::SdrShaderProperty& p) { return !p.GetLabel().IsEmpty() ? p.GetLabel().GetString() - : UsdMayaUtil::prettifyName(p.GetName().GetString()); + : UsdUfe::prettifyName(p.GetName().GetString()); } }, { "doc", [](const PXR_NS::SdrShaderProperty& p) { return !p.GetHelp().empty() ? p.GetHelp() : Ufe::Value(); } }, - { MayaUsdMetadata->UIFolder.GetString(), + { UsdUfe::MetadataTokens->UIFolder.GetString(), [](const PXR_NS::SdrShaderProperty& p) { return !p.GetPage().IsEmpty() ? p.GetPage().GetString() : Ufe::Value(); } }, @@ -115,7 +112,7 @@ static const MetadataMap _metaMap = { } return !r.empty() ? r : Ufe::Value(); } }, - { MayaUsdMetadata->UISoftMin + { UsdUfe::MetadataTokens->UISoftMin .GetString(), // Maya has 0-100 sliders. In rendering, sliders are 0-1. [](const PXR_NS::SdrShaderProperty& p) { // Will only be returned if the metadata does not exist. @@ -132,14 +129,14 @@ static const MetadataMap _metaMap = { }; // If there is a UIMin value, use it as the soft min. const NdrTokenMap& metadata = p.GetMetadata(); - auto it = metadata.find(MayaUsdMetadata->UIMin); + auto it = metadata.find(UsdUfe::MetadataTokens->UIMin); if (it != metadata.cend()) { return Ufe::Value(it->second); } auto itDefault = defaultSoftMin.find(usdTypeToUfe(&p)); return itDefault != defaultSoftMin.end() ? itDefault->second : Ufe::Value(); } }, - { MayaUsdMetadata->UISoftMax + { UsdUfe::MetadataTokens->UISoftMax .GetString(), // Maya has 0-100 sliders. In rendering, sliders are 0-1. [](const PXR_NS::SdrShaderProperty& p) { // Will only be returned if the metadata does not exist. @@ -156,7 +153,7 @@ static const MetadataMap _metaMap = { }; // If there is a UIMax value, use it as the soft max. const NdrTokenMap& metadata = p.GetMetadata(); - auto it = metadata.find(MayaUsdMetadata->UIMax); + auto it = metadata.find(UsdUfe::MetadataTokens->UIMax); if (it != metadata.cend()) { return Ufe::Value(it->second); } @@ -233,5 +230,4 @@ bool UsdShaderAttributeDef::hasMetadata(const std::string& key) const return false; } -} // namespace ufe -} // namespace MAYAUSD_NS_DEF +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdShaderAttributeDef.h b/lib/usdUfe/ufe/UsdShaderAttributeDef.h similarity index 87% rename from lib/mayaUsd/ufe/UsdShaderAttributeDef.h rename to lib/usdUfe/ufe/UsdShaderAttributeDef.h index 8eaa7a3ad8..2c7656ab4a 100644 --- a/lib/mayaUsd/ufe/UsdShaderAttributeDef.h +++ b/lib/usdUfe/ufe/UsdShaderAttributeDef.h @@ -15,17 +15,16 @@ // #pragma once -#include +#include #include #include -namespace MAYAUSD_NS_DEF { -namespace ufe { +namespace USDUFE_NS_DEF { //! \brief UsdShaderAttributeDef interface. -class MAYAUSD_CORE_PUBLIC UsdShaderAttributeDef : public Ufe::AttributeDef +class USDUFE_PUBLIC UsdShaderAttributeDef : public Ufe::AttributeDef { public: typedef std::shared_ptr Ptr; @@ -33,7 +32,7 @@ class MAYAUSD_CORE_PUBLIC UsdShaderAttributeDef : public Ufe::AttributeDef UsdShaderAttributeDef(const PXR_NS::SdrShaderPropertyConstPtr& shaderAttributeDef); - MAYAUSD_DISALLOW_COPY_MOVE_AND_ASSIGNMENT(UsdShaderAttributeDef); + USDUFE_DISALLOW_COPY_MOVE_AND_ASSIGNMENT(UsdShaderAttributeDef); //! \return The attributeDef's name. std::string name() const override; @@ -67,5 +66,4 @@ class MAYAUSD_CORE_PUBLIC UsdShaderAttributeDef : public Ufe::AttributeDef }; // UsdShaderAttributeDef -} // namespace ufe -} // namespace MAYAUSD_NS_DEF +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdShaderAttributeHolder.cpp b/lib/usdUfe/ufe/UsdShaderAttributeHolder.cpp similarity index 94% rename from lib/mayaUsd/ufe/UsdShaderAttributeHolder.cpp rename to lib/usdUfe/ufe/UsdShaderAttributeHolder.cpp index af69e31845..461d25f12f 100644 --- a/lib/mayaUsd/ufe/UsdShaderAttributeHolder.cpp +++ b/lib/usdUfe/ufe/UsdShaderAttributeHolder.cpp @@ -15,13 +15,12 @@ // #include "UsdShaderAttributeHolder.h" -#include "UsdShaderAttributeDef.h" -#include "Utils.h" - -#include +#include +#include +#include #ifdef UFE_V3_FEATURES_AVAILABLE -#include +#include #endif #include @@ -31,16 +30,15 @@ #include -namespace MAYAUSD_NS_DEF { -namespace ufe { +namespace USDUFE_NS_DEF { //------------------------------------------------------------------------------ // UsdShaderAttributeHolder: //------------------------------------------------------------------------------ // Ensure that UsdShaderAttributeHolder is properly setup. -MAYAUSD_VERIFY_CLASS_BASE(UsdAttributeHolder, UsdShaderAttributeHolder); -MAYAUSD_VERIFY_CLASS_VIRTUAL_DESTRUCTOR(UsdShaderAttributeHolder); +USDUFE_VERIFY_CLASS_BASE(UsdAttributeHolder, UsdShaderAttributeHolder); +USDUFE_VERIFY_CLASS_VIRTUAL_DESTRUCTOR(UsdShaderAttributeHolder); UsdShaderAttributeHolder::UsdShaderAttributeHolder( PXR_NS::UsdPrim usdPrim, @@ -164,8 +162,7 @@ std::string UsdShaderAttributeHolder::name() const std::string UsdShaderAttributeHolder::displayName() const { - Ufe::Value retVal - = UsdShaderAttributeDef(_sdrProp).getMetadata(PXR_NS::MayaUsdMetadata->UIName); + Ufe::Value retVal = UsdShaderAttributeDef(_sdrProp).getMetadata(MetadataTokens->UIName); std::string name = retVal.safeGet({}); if (!name.empty()) { return name; @@ -179,7 +176,7 @@ std::string UsdShaderAttributeHolder::documentation() const { return _sdrProp->G Ufe::Value UsdShaderAttributeHolder::getMetadata(const std::string& key) const { Ufe::Value retVal; - if (key == PXR_NS::MayaUsdMetadata->UIName) { + if (key == MetadataTokens->UIName) { retVal = UsdShaderAttributeDef(_sdrProp).getMetadata(key); if (!retVal.empty()) { return retVal; @@ -254,5 +251,4 @@ void UsdShaderAttributeHolder::_CreateUsdAttribute() } } -} // namespace ufe -} // namespace MAYAUSD_NS_DEF +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdShaderAttributeHolder.h b/lib/usdUfe/ufe/UsdShaderAttributeHolder.h similarity index 95% rename from lib/mayaUsd/ufe/UsdShaderAttributeHolder.h rename to lib/usdUfe/ufe/UsdShaderAttributeHolder.h index 6b8bc7fb4e..16620fadaa 100644 --- a/lib/mayaUsd/ufe/UsdShaderAttributeHolder.h +++ b/lib/usdUfe/ufe/UsdShaderAttributeHolder.h @@ -15,7 +15,7 @@ // #pragma once -#include "UsdAttributeHolder.h" +#include #include #include @@ -25,8 +25,7 @@ #include -namespace MAYAUSD_NS_DEF { -namespace ufe { +namespace USDUFE_NS_DEF { //! \brief Internal helper class holding a SdrShaderProperty, providing services to transparently // handle it as if it was a native USD attribute found in a regular schema: @@ -75,5 +74,4 @@ class UsdShaderAttributeHolder : public UsdAttributeHolder void _CreateUsdAttribute(); }; // UsdShaderAttributeHolder -} // namespace ufe -} // namespace MAYAUSD_NS_DEF +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdUndoAttributesCommands.cpp b/lib/usdUfe/ufe/UsdUndoAttributesCommands.cpp similarity index 94% rename from lib/mayaUsd/ufe/UsdUndoAttributesCommands.cpp rename to lib/usdUfe/ufe/UsdUndoAttributesCommands.cpp index 72b680cc4f..ee081f883d 100644 --- a/lib/mayaUsd/ufe/UsdUndoAttributesCommands.cpp +++ b/lib/usdUfe/ufe/UsdUndoAttributesCommands.cpp @@ -15,19 +15,18 @@ // #include "UsdUndoAttributesCommands.h" -#include +#include #include #include -namespace MAYAUSD_NS_DEF { -namespace ufe { +namespace USDUFE_NS_DEF { // Ensure that UsdAddAttributeCommand is properly setup. #ifdef UFE_V4_FEATURES_AVAILABLE -MAYAUSD_VERIFY_CLASS_SETUP(Ufe::AddAttributeUndoableCommand, UsdAddAttributeCommand); +USDUFE_VERIFY_CLASS_SETUP(Ufe::AddAttributeUndoableCommand, UsdAddAttributeCommand); #else -MAYAUSD_VERIFY_CLASS_SETUP(UsdUndoableCommand, UsdAddAttributeCommand); +USDUFE_VERIFY_CLASS_SETUP(UsdUndoableCommand, UsdAddAttributeCommand); #endif UsdAddAttributeCommand::UsdAddAttributeCommand( @@ -168,5 +167,4 @@ void UsdRenameAttributeCommand::setNewName(const std::string& newName) { _newNam #endif -} // namespace ufe -} // namespace MAYAUSD_NS_DEF +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/ufe/UsdUndoAttributesCommands.h b/lib/usdUfe/ufe/UsdUndoAttributesCommands.h similarity index 90% rename from lib/mayaUsd/ufe/UsdUndoAttributesCommands.h rename to lib/usdUfe/ufe/UsdUndoAttributesCommands.h index 14d79ff194..ae11832af0 100644 --- a/lib/mayaUsd/ufe/UsdUndoAttributesCommands.h +++ b/lib/usdUfe/ufe/UsdUndoAttributesCommands.h @@ -16,10 +16,9 @@ #ifndef USD_ATTRIBUTES_COMMANDS #define USD_ATTRIBUTES_COMMANDS -#include -#include - +#include #include +#include #include #include @@ -32,8 +31,7 @@ #include -namespace MAYAUSD_NS_DEF { -namespace ufe { +namespace USDUFE_NS_DEF { //! \brief Implementation of AddAttributeCommand class UsdAddAttributeCommand @@ -52,7 +50,7 @@ class UsdAddAttributeCommand const std::string& name, const Ufe::Attribute::Type& type); - MAYAUSD_DISALLOW_COPY_MOVE_AND_ASSIGNMENT(UsdAddAttributeCommand); + USDUFE_DISALLOW_COPY_MOVE_AND_ASSIGNMENT(UsdAddAttributeCommand); //! Create a UsdAddAttributeCommand static UsdAddAttributeCommand::Ptr create( @@ -84,7 +82,7 @@ class UsdRemoveAttributeCommand : public UsdUndoableCommand +#include +#include +#include +#include #include #include #include +#include #include #include #include +#include +#include +#include +#include #include #include #include +#include +#include #include +#include #include #include @@ -42,7 +54,7 @@ constexpr auto kIllegalUFEPath = "Illegal UFE run-time path %s."; constexpr auto kErrorMsgInvalidValueType = "Unexpected Ufe::Value type"; #endif -// typedef std::unordered_map TokenToSdfTypeMap; +typedef std::unordered_map TokenToSdfTypeMap; bool stringBeginsWithDigit(const std::string& inputString) { @@ -100,6 +112,8 @@ UsdUfe::UniqueChildNameFn gUniqueChildNameFn = nullptr; UsdUfe::WaitCursorFn gStartWaitCursorFn = nullptr; UsdUfe::WaitCursorFn gStopWaitCursorFn = nullptr; +UsdUfe::DisplayMessageFn gDisplayMessageFn[static_cast(MessageType::nbTypes)] = { nullptr }; + } // anonymous namespace namespace USDUFE_NS_DEF { @@ -224,7 +238,11 @@ void setIsAttributeLockedFn(IsAttributeLockedFn fn) bool isAttributedLocked(const PXR_NS::UsdAttribute& attr, std::string* errMsg /*= nullptr*/) { - return gIsAttributeLockedFn ? gIsAttributeLockedFn(attr, errMsg) : false; + // If we have (optional) attribute is locked function, use it. + // Otherwise use the default one supplied by UsdUfe. + if (gIsAttributeLockedFn) + return gIsAttributeLockedFn(attr, errMsg); + return Editability::isAttributeLocked(attr, errMsg); } void setSaveStageLoadRulesFn(SaveStageLoadRulesFn fn) @@ -379,6 +397,239 @@ SdfPath uniqueChildPath(const UsdStage& stage, const SdfPath& path) return path.ReplaceName(TfToken(uniqueName)); } +void setDisplayMessageFn(const DisplayMessageFn fns[static_cast(MessageType::nbTypes)]) +{ + // Each of the display message functions is allowed to be null in which case + // a default function will be used for each. + for (int i = 0; i < static_cast(MessageType::nbTypes); ++i) { + gDisplayMessageFn[i] = fns[i]; + } +} + +void displayMessage(MessageType type, const std::string& msg) +{ + // If we have an (optional) display message for the input type, use it. + // Otherwise use the default TF_ ones provided by USD. + auto messageFn = gDisplayMessageFn[static_cast(MessageType::kInfo)]; + if (messageFn) { + messageFn(msg); + } else { + switch (type) { + case MessageType::kInfo: TF_STATUS(msg); break; + case MessageType::kWarning: TF_WARN(msg); break; + case MessageType::KError: TF_RUNTIME_ERROR(msg); break; + default: break; + } + } +} + +namespace { +// Do not expose that function. The input parameter does not provide enough information to +// distinguish between kEnum and kEnumString. +Ufe::Attribute::Type _UsdTypeToUfe(const SdfValueTypeName& usdType) +{ + // Map the USD type into UFE type. + static const std::unordered_map sUsdTypeToUfe { + { SdfValueTypeNames->Bool.GetHash(), Ufe::Attribute::kBool }, // bool + { SdfValueTypeNames->Int.GetHash(), Ufe::Attribute::kInt }, // int32_t + { SdfValueTypeNames->Float.GetHash(), Ufe::Attribute::kFloat }, // float + { SdfValueTypeNames->Double.GetHash(), Ufe::Attribute::kDouble }, // double + { SdfValueTypeNames->String.GetHash(), Ufe::Attribute::kString }, // std::string + { SdfValueTypeNames->Token.GetHash(), Ufe::Attribute::kString }, // TfToken + { SdfValueTypeNames->Int3.GetHash(), Ufe::Attribute::kInt3 }, // GfVec3i + { SdfValueTypeNames->Float3.GetHash(), Ufe::Attribute::kFloat3 }, // GfVec3f + { SdfValueTypeNames->Double3.GetHash(), Ufe::Attribute::kDouble3 }, // GfVec3d + { SdfValueTypeNames->Color3f.GetHash(), Ufe::Attribute::kColorFloat3 }, // GfVec3f + { SdfValueTypeNames->Color3d.GetHash(), Ufe::Attribute::kColorFloat3 }, // GfVec3d +#ifdef UFE_V4_FEATURES_AVAILABLE + { SdfValueTypeNames->Asset.GetHash(), Ufe::Attribute::kFilename }, // SdfAssetPath + { SdfValueTypeNames->Float2.GetHash(), Ufe::Attribute::kFloat2 }, // GfVec2f + { SdfValueTypeNames->Float4.GetHash(), Ufe::Attribute::kFloat4 }, // GfVec4f + { SdfValueTypeNames->Color4f.GetHash(), Ufe::Attribute::kColorFloat4 }, // GfVec4f + { SdfValueTypeNames->Color4d.GetHash(), Ufe::Attribute::kColorFloat4 }, // GfVec4d + { SdfValueTypeNames->Matrix3d.GetHash(), Ufe::Attribute::kMatrix3d }, // GfMatrix3d + { SdfValueTypeNames->Matrix4d.GetHash(), Ufe::Attribute::kMatrix4d }, // GfMatrix4d +#endif + }; + const auto iter = sUsdTypeToUfe.find(usdType.GetHash()); + if (iter != sUsdTypeToUfe.end()) { + return iter->second; + } else { + static const std::unordered_map sCPPTypeToUfe { + // There are custom Normal3f, Point3f types in USD. They can all be recognized by the + // underlying CPP type and if there is a Ufe type that matches, use it. + { "GfVec3i", Ufe::Attribute::kInt3 }, { "GfVec3d", Ufe::Attribute::kDouble3 }, + { "GfVec3f", Ufe::Attribute::kFloat3 }, +#ifdef UFE_V4_FEATURES_AVAILABLE + { "GfVec2f", Ufe::Attribute::kFloat2 }, { "GfVec4f", Ufe::Attribute::kFloat4 }, +#endif + }; + + const auto iter = sCPPTypeToUfe.find(usdType.GetCPPTypeName()); + if (iter != sCPPTypeToUfe.end()) { + return iter->second; + } else { + return Ufe::Attribute::kGeneric; + } + } +} +} // namespace + +Ufe::Attribute::Type usdTypeToUfe(const SdrShaderPropertyConstPtr& shaderProperty) +{ + Ufe::Attribute::Type retVal = Ufe::Attribute::kInvalid; + + const SdfValueTypeName typeName = shaderProperty->GetTypeAsSdfType().first; + if (typeName.GetHash() == SdfValueTypeNames->Token.GetHash()) { + static const TokenToSdfTypeMap tokenTypeToSdfType + = { { SdrPropertyTypes->Int, SdfValueTypeNames->Int }, + { SdrPropertyTypes->String, SdfValueTypeNames->String }, + { SdrPropertyTypes->Float, SdfValueTypeNames->Float }, + { SdrPropertyTypes->Color, SdfValueTypeNames->Color3f }, +#if defined(USD_HAS_COLOR4_SDR_SUPPORT) + { SdrPropertyTypes->Color4, SdfValueTypeNames->Color4f }, +#endif + { SdrPropertyTypes->Point, SdfValueTypeNames->Point3f }, + { SdrPropertyTypes->Normal, SdfValueTypeNames->Normal3f }, + { SdrPropertyTypes->Vector, SdfValueTypeNames->Vector3f }, + { SdrPropertyTypes->Matrix, SdfValueTypeNames->Matrix4d } }; + TokenToSdfTypeMap::const_iterator it + = tokenTypeToSdfType.find(shaderProperty->GetTypeAsSdfType().second); + if (it != tokenTypeToSdfType.end()) { + retVal = _UsdTypeToUfe(it->second); + } else { +#if PXR_VERSION < 2205 + // Pre-22.05 boolean inputs are special: + if (shaderProperty->GetType() == SdfValueTypeNames->Bool.GetAsToken()) { + retVal = _UsdTypeToUfe(SdfValueTypeNames->Bool); + } else +#endif + // There is no Matrix3d type in Sdr, so we need to infer it from Sdf until a fix + // similar to what was done to booleans is submitted to USD. This also means that + // there will be no default value for that type. + if (shaderProperty->GetType() == SdfValueTypeNames->Matrix3d.GetAsToken()) { + retVal = _UsdTypeToUfe(SdfValueTypeNames->Matrix3d); + } else { + retVal = Ufe::Attribute::kGeneric; + } + } + } else { + retVal = _UsdTypeToUfe(typeName); + } + + if (retVal == Ufe::Attribute::kString) { + if (!shaderProperty->GetOptions().empty()) { + retVal = Ufe::Attribute::kEnumString; + } +#ifdef UFE_V4_FEATURES_AVAILABLE + else if (shaderProperty->IsAssetIdentifier()) { + retVal = Ufe::Attribute::kFilename; + } +#endif + } + + return retVal; +} + +Ufe::Attribute::Type usdTypeToUfe(const PXR_NS::UsdAttribute& usdAttr) +{ + if (usdAttr.IsValid()) { + const SdfValueTypeName typeName = usdAttr.GetTypeName(); + Ufe::Attribute::Type type = _UsdTypeToUfe(typeName); + if (type == Ufe::Attribute::kString) { + // Both std::string and TfToken resolve to kString, but if there is a list of allowed + // tokens, then we use kEnumString instead. + if (usdAttr.GetPrim().GetPrimDefinition().GetPropertyMetadata( + usdAttr.GetName(), SdfFieldKeys->AllowedTokens, nullptr)) { + type = Ufe::Attribute::kEnumString; + } + UsdShadeNodeGraph asNodeGraph(usdAttr.GetPrim()); + if (asNodeGraph) { + // NodeGraph inputs can have enum metadata on them when they export an inner enum. + const auto portType = UsdShadeUtils::GetBaseNameAndType(usdAttr.GetName()).second; + if (portType == UsdShadeAttributeType::Input) { + const auto input = UsdShadeInput(usdAttr); + if (!input.GetSdrMetadataByKey(TfToken("enum")).empty()) { + return Ufe::Attribute::kEnumString; + } + } + // TfToken is also used in UsdShade as a Generic placeholder for connecting struct + // I/O. + if (usdAttr.GetTypeName() == SdfValueTypeNames->Token + && portType != UsdShadeAttributeType::Invalid) { + type = Ufe::Attribute::kGeneric; + } + } + } + return type; + } + + TF_RUNTIME_ERROR("Invalid USDAttribute: %s", usdAttr.GetPath().GetAsString().c_str()); + return Ufe::Attribute::kInvalid; +} + +SdfValueTypeName ufeTypeToUsd(const Ufe::Attribute::Type ufeType) +{ + // Map the USD type into UFE type. + static const std::unordered_map sUfeTypeToUsd { + { Ufe::Attribute::kBool, SdfValueTypeNames->Bool }, + { Ufe::Attribute::kInt, SdfValueTypeNames->Int }, + { Ufe::Attribute::kFloat, SdfValueTypeNames->Float }, + { Ufe::Attribute::kDouble, SdfValueTypeNames->Double }, + { Ufe::Attribute::kString, SdfValueTypeNames->String }, + // Not enough info at this point to differentiate between TfToken and std:string. + { Ufe::Attribute::kEnumString, SdfValueTypeNames->Token }, + { Ufe::Attribute::kInt3, SdfValueTypeNames->Int3 }, + { Ufe::Attribute::kFloat3, SdfValueTypeNames->Float3 }, + { Ufe::Attribute::kDouble3, SdfValueTypeNames->Double3 }, + { Ufe::Attribute::kColorFloat3, SdfValueTypeNames->Color3f }, + { Ufe::Attribute::kGeneric, SdfValueTypeNames->Token }, +#ifdef UFE_V4_FEATURES_AVAILABLE + { Ufe::Attribute::kFilename, SdfValueTypeNames->Asset }, + { Ufe::Attribute::kFloat2, SdfValueTypeNames->Float2 }, + { Ufe::Attribute::kFloat4, SdfValueTypeNames->Float4 }, + { Ufe::Attribute::kColorFloat4, SdfValueTypeNames->Color4f }, + { Ufe::Attribute::kMatrix3d, SdfValueTypeNames->Matrix3d }, + { Ufe::Attribute::kMatrix4d, SdfValueTypeNames->Matrix4d }, +#endif + }; + + const auto iter = sUfeTypeToUsd.find(ufeType); + if (iter != sUfeTypeToUsd.end()) { + return iter->second; + } else { + return SdfValueTypeName(); + } +} + +UsdAttribute* usdAttrFromUfeAttr(const Ufe::Attribute::Ptr& attr) +{ + if (!attr) { + TF_RUNTIME_ERROR("Invalid attribute."); + return nullptr; + } + + if (attr->sceneItem()->runTimeId() != getUsdRunTimeId()) { + TF_RUNTIME_ERROR( + "Invalid runtime identifier for the attribute '" + attr->name() + "' in the node '" + + Ufe::PathString::string(attr->sceneItem()->path()) + "'."); + return nullptr; + } + + return dynamic_cast(attr.get()); +} + +Ufe::Attribute::Ptr attrFromUfeAttrInfo(const Ufe::AttributeInfo& attrInfo) +{ + auto item + = std::dynamic_pointer_cast(Ufe::Hierarchy::createItem(attrInfo.path())); + if (!item) { + TF_RUNTIME_ERROR("Invalid scene item."); + return nullptr; + } + return UsdAttributes(item).attribute(attrInfo.name()); +} + namespace { bool allowedInStrongerLayer( @@ -950,6 +1201,33 @@ Ufe::Value vtValueToUfeValue(const PXR_NS::VtValue& vtValue) } #endif +PXR_NS::SdrShaderNodeConstPtr usdShaderNodeFromSceneItem(const Ufe::SceneItem::Ptr& item) +{ + UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast(item); + PXR_NAMESPACE_USING_DIRECTIVE + if (!TF_VERIFY(usdItem)) { + return nullptr; + } + PXR_NS::UsdPrim prim = usdItem->prim(); + PXR_NS::UsdShadeShader shader(prim); + if (!shader) { + return nullptr; + } + PXR_NS::TfToken mxNodeType; + shader.GetIdAttr().Get(&mxNodeType); + + // Careful around name and identifier. They are not the same concept. + // + // Here is one example from MaterialX to illustrate: + // + // ND_standard_surface_surfaceshader exists in 2 versions with identifiers: + // ND_standard_surface_surfaceshader (latest version) + // ND_standard_surface_surfaceshader_100 (version 1.0.0) + // Same name, 2 different identifiers. + PXR_NS::SdrRegistry& registry = PXR_NS::SdrRegistry::GetInstance(); + return registry.GetShaderNodeByIdentifier(mxNodeType); +} + void setWaitCursorFns(WaitCursorFn startFn, WaitCursorFn stopFn) { gStartWaitCursorFn = startFn; diff --git a/lib/usdUfe/ufe/Utils.h b/lib/usdUfe/ufe/Utils.h index d84bc08ca9..dc88040371 100644 --- a/lib/usdUfe/ufe/Utils.h +++ b/lib/usdUfe/ufe/Utils.h @@ -19,9 +19,12 @@ #include #include +#include +#include #include #include +#include #include #include #include @@ -37,12 +40,16 @@ UFE_NS_DEF { + class Attribute; + class AttributeInfo; class PathSegment; class Selection; } namespace USDUFE_NS_DEF { +class UsdAttribute; + // DCC specific accessor functions. typedef PXR_NS::UsdStageWeakPtr (*StageAccessorFn)(const Ufe::Path&); typedef Ufe::Path (*StagePathAccessorFn)(PXR_NS::UsdStageWeakPtr); @@ -52,6 +59,7 @@ typedef bool (*IsAttributeLockedFn)(const PXR_NS::UsdAttribute& attr, std::strin 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 (*DisplayMessageFn)(const std::string& msg); typedef void (*WaitCursorFn)(); //------------------------------------------------------------------------------ @@ -114,7 +122,7 @@ PXR_NS::UsdTimeCode getTime(const Ufe::Path& path); //! Set the DCC specific USD attribute is locked test function. //! Use of this function is optional, if one is not supplied then -//! default value (false) will be returned by accessor function. +//! a default test function will be used. USDUFE_PUBLIC void setIsAttributeLockedFn(IsAttributeLockedFn fn); @@ -191,6 +199,42 @@ 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); +//! Support message types. +enum class MessageType +{ + kInfo, // Displays an information message, default = TF_STATUS + kWarning, // Displays a warning message, default = TF_WARN + KError, // Displays a error message, default = TF_RUNTIME_ERROR + + nbTypes +}; + +//! Set the DCC specific "displayMessage" functions. +//! Use of these functions is optional, if not supplied then default +//! TF_ message functions from USD will be used. +USDUFE_PUBLIC +void setDisplayMessageFn(const DisplayMessageFn fns[static_cast(MessageType::nbTypes)]); + +//! Displays a message of the given type using a DCC message function (if provided) +//! otherwise displays using a USD default message function (for each type).. +USDUFE_PUBLIC +void displayMessage(MessageType type, const std::string& msg); + +USDUFE_PUBLIC +Ufe::Attribute::Type usdTypeToUfe(const PXR_NS::UsdAttribute& usdAttr); + +USDUFE_PUBLIC +Ufe::Attribute::Type usdTypeToUfe(const PXR_NS::SdrShaderPropertyConstPtr& shaderProperty); + +USDUFE_PUBLIC +PXR_NS::SdfValueTypeName ufeTypeToUsd(const Ufe::Attribute::Type ufeType); + +USDUFE_PUBLIC +UsdAttribute* usdAttrFromUfeAttr(const Ufe::Attribute::Ptr& attr); + +USDUFE_PUBLIC +Ufe::Attribute::Ptr attrFromUfeAttrInfo(const Ufe::AttributeInfo& attrInfo); + //! Send notification for data model changes template void sendNotification(const Ufe::SceneItem::Ptr& item, const Ufe::Path& previousPath) @@ -223,6 +267,12 @@ USDUFE_PUBLIC PXR_NS::VtValue ufeValueToVtValue(const Ufe::Value& ufeValue); USDUFE_PUBLIC Ufe::Value vtValueToUfeValue(const PXR_NS::VtValue& vtValue); #endif // UFE_V3_FEATURES_AVAILABLE +//! Returns the Sdr shader node for the given SceneItem. If the +//! definition associated with the scene item's type is not found, a +//! nullptr is returned. +USDUFE_PUBLIC +PXR_NS::SdrShaderNodeConstPtr usdShaderNodeFromSceneItem(const Ufe::SceneItem::Ptr& item); + //------------------------------------------------------------------------------ // Verify edit restrictions. //------------------------------------------------------------------------------ diff --git a/lib/usdUfe/utils/CMakeLists.txt b/lib/usdUfe/utils/CMakeLists.txt index 3eea9a7f0c..82ad18cfea 100644 --- a/lib/usdUfe/utils/CMakeLists.txt +++ b/lib/usdUfe/utils/CMakeLists.txt @@ -3,6 +3,7 @@ # ----------------------------------------------------------------------------- target_sources(${PROJECT_NAME} PRIVATE + editability.cpp editRouter.cpp editRouterContext.cpp layers.cpp @@ -17,6 +18,7 @@ target_sources(${PROJECT_NAME} # promote headers # ----------------------------------------------------------------------------- set(HEADERS + editability.h editRouter.h editRouterContext.h layers.h diff --git a/lib/usdUfe/utils/Utils.cpp b/lib/usdUfe/utils/Utils.cpp index ff88a27fa0..c3c5666762 100644 --- a/lib/usdUfe/utils/Utils.cpp +++ b/lib/usdUfe/utils/Utils.cpp @@ -82,4 +82,20 @@ std::string prettifyName(const std::string& name) return prettyName; } +std::vector splitString(const std::string& str, const std::string& separators) +{ + std::vector split; + + std::string::size_type lastPos = str.find_first_not_of(separators, 0); + std::string::size_type pos = str.find_first_of(separators, lastPos); + + while (pos != std::string::npos || lastPos != std::string::npos) { + split.push_back(str.substr(lastPos, pos - lastPos)); + lastPos = str.find_first_not_of(separators, pos); + pos = str.find_first_of(separators, lastPos); + } + + return split; +} + } // namespace USDUFE_NS_DEF diff --git a/lib/usdUfe/utils/Utils.h b/lib/usdUfe/utils/Utils.h index bf83909ff6..6f4d10e8bc 100644 --- a/lib/usdUfe/utils/Utils.h +++ b/lib/usdUfe/utils/Utils.h @@ -19,6 +19,7 @@ #include #include +#include /// General utilities for working with the UsdUfe library. namespace USDUFE_NS_DEF { @@ -42,6 +43,10 @@ std::string sanitizeName(const std::string& name); USDUFE_PUBLIC std::string prettifyName(const std::string& name); +//! Splits a string by each specified separator. +USDUFE_PUBLIC +std::vector splitString(const std::string& str, const std::string& separators); + } // namespace USDUFE_NS_DEF #endif // USDUFE_UTIL_H diff --git a/lib/mayaUsd/utils/editability.cpp b/lib/usdUfe/utils/editability.cpp similarity index 82% rename from lib/mayaUsd/utils/editability.cpp rename to lib/usdUfe/utils/editability.cpp index dc2aea2858..690b90ebdd 100644 --- a/lib/mayaUsd/utils/editability.cpp +++ b/lib/usdUfe/utils/editability.cpp @@ -15,9 +15,9 @@ // #include "editability.h" -#include +#include -namespace MAYAUSD_NS_DEF { +namespace USDUFE_NS_DEF { namespace Editability { PXR_NAMESPACE_USING_DIRECTIVE @@ -33,15 +33,15 @@ bool isLocked(PXR_NS::UsdProperty property) return false; PXR_NS::TfToken lock; - if (!property.GetMetadata(MayaUsdMetadata->Lock, &lock)) + if (!property.GetMetadata(MetadataTokens->Lock, &lock)) return false; - if (lock == MayaUsdTokens->Off) { + if (lock == GenericTokens->Off) { return false; - } else if (lock == MayaUsdTokens->On) { + } else if (lock == GenericTokens->On) { return true; } else { - TF_WARN("Invalid token value [%s] for maya lock will be treated as [off].", lock.data()); + TF_WARN("Invalid token value [%s] for lock will be treated as [off].", lock.data()); return false; } } @@ -60,4 +60,4 @@ bool isAttributeLocked(const PXR_NS::UsdAttribute& attr, std::string* errMsg) } } // namespace Editability -} // namespace MAYAUSD_NS_DEF +} // namespace USDUFE_NS_DEF diff --git a/lib/mayaUsd/utils/editability.h b/lib/usdUfe/utils/editability.h similarity index 84% rename from lib/mayaUsd/utils/editability.h rename to lib/usdUfe/utils/editability.h index 55a0f22dc8..01f7a492ac 100644 --- a/lib/mayaUsd/utils/editability.h +++ b/lib/usdUfe/utils/editability.h @@ -13,8 +13,10 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#ifndef MAYA_USD_EDITABILITY_H -#define MAYA_USD_EDITABILITY_H +#ifndef USDUFE_EDITABILITY_H +#define USDUFE_EDITABILITY_H + +#include #include #include @@ -22,7 +24,7 @@ #include -namespace MAYAUSD_NS_DEF { +namespace USDUFE_NS_DEF { /*! \brief Determine the editability status of a property. */ @@ -30,14 +32,16 @@ namespace MAYAUSD_NS_DEF { namespace Editability { /*! \brief Verify if a property is locked. */ +USDUFE_PUBLIC bool isLocked(PXR_NS::UsdProperty property); /*! \brief Verify is an attribute is locked, optionally setting error message. */ +USDUFE_PUBLIC bool isAttributeLocked(const PXR_NS::UsdAttribute& attr, std::string* errMsg); } // namespace Editability -} // namespace MAYAUSD_NS_DEF +} // namespace USDUFE_NS_DEF -#endif // MAYA_USD_EDITABILITY_H +#endif // USDUFE_EDITABILITY_H diff --git a/lib/usdUfe/utils/usdUtils.cpp b/lib/usdUfe/utils/usdUtils.cpp index c3a3acbc64..49bc5d4161 100644 --- a/lib/usdUfe/utils/usdUtils.cpp +++ b/lib/usdUfe/utils/usdUtils.cpp @@ -16,8 +16,11 @@ #include "usdUtils.h" +#include + #include #include +#include #include #include #include @@ -27,6 +30,8 @@ #include #include #include +#include +#include PXR_NAMESPACE_USING_DIRECTIVE @@ -420,4 +425,232 @@ bool cleanReferencedPath(const UsdPrim& deletedPrim) bool isInternalReference(const SdfReference& ref) { return ref.IsInternal(); } +VtValue vtValueFromString(const SdfValueTypeName& typeName, const std::string& strValue) +{ + // clang-format off + static const std::unordered_map> + sUsdConverterMap { + // Using the CPPTypeName prevents having to repeat converters for types that share the + // same VtValue representation like Float3, Color3f, Normal3f, Point3f, allowing support + // for more Sdf types without having to list them all. + { SdfValueTypeNames->Bool.GetCPPTypeName(), + [](const std::string& s) { return VtValue("true" == s ? true : false); } }, + { SdfValueTypeNames->Int.GetCPPTypeName(), + [](const std::string& s) { + return s.empty() ? VtValue() : VtValue(std::stoi(s.c_str())); } }, + { SdfValueTypeNames->Float.GetCPPTypeName(), + [](const std::string& s) { + return s.empty() ? VtValue() : VtValue(std::stof(s.c_str())); } }, + { SdfValueTypeNames->Double.GetCPPTypeName(), + [](const std::string& s) { + return s.empty() ? VtValue() : VtValue(std::stod(s.c_str())); } }, + { SdfValueTypeNames->String.GetCPPTypeName(), + [](const std::string& s) { return VtValue(s); } }, + { SdfValueTypeNames->Token.GetCPPTypeName(), + [](const std::string& s) { return VtValue(TfToken(s)); } }, + { SdfValueTypeNames->Asset.GetCPPTypeName(), + [](const std::string& s) { return VtValue(SdfAssetPath(s)); } }, + { SdfValueTypeNames->Int3.GetCPPTypeName(), + [](const std::string& s) { + std::vector tokens = splitString(s, "()[], "); + if (tokens.size() == 3) { + return VtValue(GfVec3i( + std::stoi(tokens[0].c_str()), + std::stoi(tokens[1].c_str()), + std::stoi(tokens[2].c_str()))); + } + return VtValue(); } }, + { SdfValueTypeNames->Float2.GetCPPTypeName(), + [](const std::string& s) { + std::vector tokens = splitString(s, "()[], "); + if (tokens.size() == 2) { + return VtValue( + GfVec2f(std::stof(tokens[0].c_str()), std::stof(tokens[1].c_str()))); + } + return VtValue(); } }, + { SdfValueTypeNames->Float3.GetCPPTypeName(), + [](const std::string& s) { + std::vector tokens = splitString(s, "()[], "); + if (tokens.size() == 3) { + return VtValue(GfVec3f( + std::stof(tokens[0].c_str()), + std::stof(tokens[1].c_str()), + std::stof(tokens[2].c_str()))); + } + return VtValue(); } }, + { SdfValueTypeNames->Float4.GetCPPTypeName(), + [](const std::string& s) { + std::vector tokens = splitString(s, "()[], "); + if (tokens.size() == 4) { + return VtValue(GfVec4f( + std::stof(tokens[0].c_str()), + std::stof(tokens[1].c_str()), + std::stof(tokens[2].c_str()), + std::stof(tokens[3].c_str()))); + } + return VtValue(); } }, + { SdfValueTypeNames->Double3.GetCPPTypeName(), + [](const std::string& s) { + std::vector tokens = splitString(s, "()[], "); + if (tokens.size() == 3) { + return VtValue(GfVec3d( + std::stod(tokens[0].c_str()), + std::stod(tokens[1].c_str()), + std::stod(tokens[2].c_str()))); + } + return VtValue(); } }, + { SdfValueTypeNames->Double4.GetCPPTypeName(), + [](const std::string& s) { + std::vector tokens = splitString(s, "()[], "); + if (tokens.size() == 4) { + return VtValue(GfVec4d( + std::stod(tokens[0].c_str()), + std::stod(tokens[1].c_str()), + std::stod(tokens[2].c_str()), + std::stod(tokens[3].c_str()))); + } + return VtValue(); } }, + { SdfValueTypeNames->Matrix3d.GetCPPTypeName(), + [](const std::string& s) { + std::vector tokens = splitString(s, "()[], "); + if (tokens.size() == 9) { + double m[3][3]; + for (int i = 0, k = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j, ++k) { + m[i][j] = std::stod(tokens[k].c_str()); + } + } + return VtValue(GfMatrix3d(m)); + } + return VtValue(); } }, + { SdfValueTypeNames->Matrix4d.GetCPPTypeName(), + [](const std::string& s) { + std::vector tokens = splitString(s, "()[], "); + if (tokens.size() == 16) { + double m[4][4]; + for (int i = 0, k = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j, ++k) { + m[i][j] = std::stod(tokens[k].c_str()); + } + } + return VtValue(GfMatrix4d(m)); + } + return VtValue(); } }, + }; + // clang-format on + const auto iter = sUsdConverterMap.find(typeName.GetCPPTypeName()); + if (iter != sUsdConverterMap.end()) { + return iter->second(strValue); + } + return {}; +} + +bool isConnected(const PXR_NS::UsdAttribute& srcUsdAttr, const PXR_NS::UsdAttribute& dstUsdAttr) +{ + PXR_NS::SdfPathVector connectedAttrs; + dstUsdAttr.GetConnections(&connectedAttrs); + + for (PXR_NS::SdfPath path : connectedAttrs) { + if (path == srcUsdAttr.GetPath()) { + return true; + } + } + + return false; +} + +bool canRemoveSrcProperty(const PXR_NS::UsdAttribute& srcAttr) +{ + // Do not remove if it has a value. + if (srcAttr.HasValue()) { + return false; + } + + PXR_NS::SdfPathVector connectedAttrs; + srcAttr.GetConnections(&connectedAttrs); + + // Do not remove if it has connections. + if (!connectedAttrs.empty()) { + return false; + } + + const auto prim = srcAttr.GetPrim(); + if (!prim) { + return false; + } + + PXR_NS::UsdShadeNodeGraph ngPrim(prim); + if (!ngPrim) { + const auto primParent = prim.GetParent(); + + if (!primParent) { + return false; + } + + // Do not remove if there is a connection with a prim. + for (const auto& childPrim : primParent.GetChildren()) { + if (childPrim != prim) { + for (const auto& attribute : childPrim.GetAttributes()) { + const PXR_NS::UsdAttribute dstUsdAttr = attribute.As(); + if (isConnected(srcAttr, dstUsdAttr)) { + return false; + } + } + } + } + + // Do not remove if there is a connection with the parent prim. + for (const auto& attribute : primParent.GetAttributes()) { + const PXR_NS::UsdAttribute dstUsdAttr = attribute.As(); + if (isConnected(srcAttr, dstUsdAttr)) { + return false; + } + } + + return true; + } + + // Do not remove boundary properties even if there are connections. + return false; +} + +bool canRemoveDstProperty(const PXR_NS::UsdAttribute& dstAttr) +{ + // Do not remove if it has a value. + if (dstAttr.HasValue()) { + return false; + } + + PXR_NS::SdfPathVector connectedAttrs; + dstAttr.GetConnections(&connectedAttrs); + + // Do not remove if it has connections. + if (!connectedAttrs.empty()) { + return false; + } + + const auto prim = dstAttr.GetPrim(); + if (!prim) { + return false; + } + + PXR_NS::UsdShadeNodeGraph ngPrim(prim); + if (!ngPrim) { + return true; + } + + UsdShadeMaterial asMaterial(prim); + if (asMaterial) { + const TfToken baseName = dstAttr.GetBaseName(); + // Remove Material intrinsic outputs since they are re-created automatically. + if (baseName == UsdShadeTokens->surface || baseName == UsdShadeTokens->volume + || baseName == UsdShadeTokens->displacement) { + return true; + } + } + + // Do not remove boundary properties even if there are connections. + return false; +} + } // namespace USDUFE_NS_DEF diff --git a/lib/usdUfe/utils/usdUtils.h b/lib/usdUfe/utils/usdUtils.h index 95f45a2c45..3291c1ac7c 100644 --- a/lib/usdUfe/utils/usdUtils.h +++ b/lib/usdUfe/utils/usdUtils.h @@ -21,6 +21,8 @@ #include #include +#include +#include #include PXR_NAMESPACE_USING_DIRECTIVE @@ -51,6 +53,24 @@ bool cleanReferencedPath(const UsdPrim& deletedPrim); USDUFE_PUBLIC bool isInternalReference(const SdfReference&); +PXR_NS::VtValue +vtValueFromString(const PXR_NS::SdfValueTypeName& typeName, const std::string& strValue); + +//! Check if the src and dst attributes are connected. +//! \return True, if they are connected. +USDUFE_PUBLIC +bool isConnected(const PXR_NS::UsdAttribute& srcUsdAttr, const PXR_NS::UsdAttribute& dstUsdAttr); + +//! Check if a source connection property is allowed to be removed. +//! \return True, if the property can be removed. +USDUFE_PUBLIC +bool canRemoveSrcProperty(const PXR_NS::UsdAttribute& srcAttr); + +//! Check if a destination connection property is allowed to be removed. +//! \return True, if the property can be removed. +USDUFE_PUBLIC +bool canRemoveDstProperty(const PXR_NS::UsdAttribute& dstAttr); + } // namespace USDUFE_NS_DEF #endif // USDUFE_USDUTILS_H diff --git a/plugin/adsk/plugin/adskMaterialCommands.cpp b/plugin/adsk/plugin/adskMaterialCommands.cpp index 473d8961d5..8b1202e661 100644 --- a/plugin/adsk/plugin/adskMaterialCommands.cpp +++ b/plugin/adsk/plugin/adskMaterialCommands.cpp @@ -18,6 +18,7 @@ #include #include +#include #ifdef UFE_V4_FEATURES_AVAILABLE #include #endif @@ -130,8 +131,8 @@ MStatus ADSKMayaUSDGetMaterialsForRenderersCommand::doIt(const MArgList& argList auto sourceType = ufeNodeDef->classification(ufeNodeDef->nbClassifications() - 1); appendToResult(MString(TfStringPrintf( "%s/%s|%s", - UsdMayaUtil::prettifyName(sourceType).c_str(), - UsdMayaUtil::prettifyName(familyName).c_str(), + UsdUfe::prettifyName(sourceType).c_str(), + UsdUfe::prettifyName(familyName).c_str(), nodeDef->GetIdentifier().GetText()) .c_str())); } diff --git a/test/lib/mayaUsd/utils/testSplitString.cpp b/test/lib/mayaUsd/utils/testSplitString.cpp index 4930460687..8c795c1c5c 100644 --- a/test/lib/mayaUsd/utils/testSplitString.cpp +++ b/test/lib/mayaUsd/utils/testSplitString.cpp @@ -1,22 +1,22 @@ -#include +#include #include TEST(SplitString, basicTest) { std::string testString = "Hi, how are you?"; - std::vector tokens = MayaUsd::ufe::splitString(testString, ", ?"); + std::vector tokens = UsdUfe::splitString(testString, ", ?"); ASSERT_EQ(static_cast(tokens.size()), 4); ASSERT_STREQ(tokens[0].c_str(), "Hi"); ASSERT_STREQ(tokens[1].c_str(), "how"); ASSERT_STREQ(tokens[2].c_str(), "are"); ASSERT_STREQ(tokens[3].c_str(), "you"); - std::vector tokens2 = MayaUsd::ufe::splitString(testString, "!"); + std::vector tokens2 = UsdUfe::splitString(testString, "!"); ASSERT_EQ(static_cast(tokens2.size()), 1); ASSERT_STREQ(tokens2[0].c_str(), testString.c_str()); - std::vector tokens3 = MayaUsd::ufe::splitString(testString, ""); + std::vector tokens3 = UsdUfe::splitString(testString, ""); ASSERT_EQ(static_cast(tokens3.size()), 1); ASSERT_STREQ(tokens3[0].c_str(), testString.c_str()); } diff --git a/test/lib/mayaUsd/utils/testUtilsEditability.py b/test/lib/mayaUsd/utils/testUtilsEditability.py index 696625da7a..fe5bad64bd 100644 --- a/test/lib/mayaUsd/utils/testUtilsEditability.py +++ b/test/lib/mayaUsd/utils/testUtilsEditability.py @@ -28,15 +28,16 @@ import ufe import mayaUsd.ufe import mayaUsd.lib +import usdUfe class testUtilsEditability(unittest.TestCase): """ Tests editability of attributes. """ - lockToken = mayaUsd.lib.MetadataTokens.Lock - onToken = mayaUsd.lib.Tokens.On - offToken = mayaUsd.lib.Tokens.Off + lockToken = usdUfe.MetadataTokens.Lock + onToken = usdUfe.Tokens.On + offToken = usdUfe.Tokens.Off @classmethod def setUpClass(cls): diff --git a/test/lib/mayaUsd/utils/testUtilsSelectability.py b/test/lib/mayaUsd/utils/testUtilsSelectability.py index 90518964e0..5af0334855 100644 --- a/test/lib/mayaUsd/utils/testUtilsSelectability.py +++ b/test/lib/mayaUsd/utils/testUtilsSelectability.py @@ -29,7 +29,8 @@ import ufe import mayaUsd.ufe -import mayaUsd.lib +import mayaUsd.lib +import usdUfe try: from PySide2 import QtCore @@ -48,9 +49,9 @@ class testUtilsSelectability(unittest.TestCase): """ selectabilityToken = mayaUsd.lib.MetadataTokens.Selectability - onToken = mayaUsd.lib.Tokens.On - offToken = mayaUsd.lib.Tokens.Off - inheritToken = mayaUsd.lib.Tokens.Inherit + onToken = usdUfe.Tokens.On + offToken = usdUfe.Tokens.Off + inheritToken = usdUfe.Tokens.Inherit @classmethod def setUpClass(cls): diff --git a/test/lib/mayaUsd/utils/testUtilsSelectabilityPointInstanceSelection.py b/test/lib/mayaUsd/utils/testUtilsSelectabilityPointInstanceSelection.py index db8ed44a4f..74de446a37 100644 --- a/test/lib/mayaUsd/utils/testUtilsSelectabilityPointInstanceSelection.py +++ b/test/lib/mayaUsd/utils/testUtilsSelectabilityPointInstanceSelection.py @@ -21,6 +21,7 @@ from mayaUsd import lib as mayaUsdLib from mayaUsd import ufe as mayaUsdUfe +import usdUfe from maya import cmds from maya.api import OpenMayaUI as OMUI @@ -49,9 +50,9 @@ class testUtilsSelectabilityPointInstanceSelection(unittest.TestCase): """ selectabilityToken = mayaUsdLib.MetadataTokens.Selectability - onToken = mayaUsdLib.Tokens.On - offToken = mayaUsdLib.Tokens.Off - inheritToken = mayaUsdLib.Tokens.Inherit + onToken = usdUfe.Tokens.On + offToken = usdUfe.Tokens.Off + inheritToken = usdUfe.Tokens.Inherit @classmethod def setUpClass(cls): diff --git a/test/lib/ufe/testAttribute.py b/test/lib/ufe/testAttribute.py index 40b18173e7..e8d690e077 100644 --- a/test/lib/ufe/testAttribute.py +++ b/test/lib/ufe/testAttribute.py @@ -1980,25 +1980,25 @@ def testCreateUsdPreviewSurfaceAttribute(self): def testNamePrettification(self): '''Test the name prettification routine.''' - self.assertEqual(mayaUsdLib.Util.prettifyName("standard_surface"), "Standard Surface") - self.assertEqual(mayaUsdLib.Util.prettifyName("standardSurface"), "Standard Surface") - self.assertEqual(mayaUsdLib.Util.prettifyName("USDPreviewSurface"), "USD Preview Surface") - self.assertEqual(mayaUsdLib.Util.prettifyName("xformOp:rotateXYZ"), "Xform Op Rotate XYZ") - self.assertEqual(mayaUsdLib.Util.prettifyName("ior"), "Ior") - self.assertEqual(mayaUsdLib.Util.prettifyName("IOR"), "IOR") - self.assertEqual(mayaUsdLib.Util.prettifyName("specular_IOR"), "Specular IOR") - self.assertEqual(mayaUsdLib.Util.prettifyName("HwPtexTexture"), "Hw Ptex Texture") - self.assertEqual(mayaUsdLib.Util.prettifyName("fluid2D"), "Fluid2D") + self.assertEqual(mayaUsdUfe.prettifyName("standard_surface"), "Standard Surface") + self.assertEqual(mayaUsdUfe.prettifyName("standardSurface"), "Standard Surface") + self.assertEqual(mayaUsdUfe.prettifyName("USDPreviewSurface"), "USD Preview Surface") + self.assertEqual(mayaUsdUfe.prettifyName("xformOp:rotateXYZ"), "Xform Op Rotate XYZ") + self.assertEqual(mayaUsdUfe.prettifyName("ior"), "Ior") + self.assertEqual(mayaUsdUfe.prettifyName("IOR"), "IOR") + self.assertEqual(mayaUsdUfe.prettifyName("specular_IOR"), "Specular IOR") + self.assertEqual(mayaUsdUfe.prettifyName("HwPtexTexture"), "Hw Ptex Texture") + self.assertEqual(mayaUsdUfe.prettifyName("fluid2D"), "Fluid2D") # This is as expected as we do not insert space on digit<->alpha transitions: - self.assertEqual(mayaUsdLib.Util.prettifyName("Dx11Shader"), "Dx11Shader") + self.assertEqual(mayaUsdUfe.prettifyName("Dx11Shader"), "Dx11Shader") # Explicit substitutions - self.assertEqual(mayaUsdLib.Util.prettifyName("UsdPreviewSurface"), "USD Preview Surface") - self.assertEqual(mayaUsdLib.Util.prettifyName("mtlx"), "MaterialX") - self.assertEqual(mayaUsdLib.Util.prettifyName("gltf_pbr"), "glTF PBR") + self.assertEqual(mayaUsdUfe.prettifyName("UsdPreviewSurface"), "USD Preview Surface") + self.assertEqual(mayaUsdUfe.prettifyName("mtlx"), "MaterialX") + self.assertEqual(mayaUsdUfe.prettifyName("gltf_pbr"), "glTF PBR") # Caps tests - self.assertEqual(mayaUsdLib.Util.prettifyName("ALLCAPS"), "ALLCAPS") - self.assertEqual(mayaUsdLib.Util.prettifyName("MixedCAPS"), "Mixed CAPS") - self.assertEqual(mayaUsdLib.Util.prettifyName("CAPS10"), "CAPS10") + self.assertEqual(mayaUsdUfe.prettifyName("ALLCAPS"), "ALLCAPS") + self.assertEqual(mayaUsdUfe.prettifyName("MixedCAPS"), "Mixed CAPS") + self.assertEqual(mayaUsdUfe.prettifyName("CAPS10"), "CAPS10") @unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 4, 'Test only available in UFE v4 or greater') def testAttributeMetadataChanged(self): From 77919725dd77486220e258a796b60ca4b18735f9 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Tue, 23 Apr 2024 14:54:59 -0400 Subject: [PATCH 2/7] EMSUSD-751 - UsdUfe: Move Ufe::Attributes interface implementation * Removed mayaUsd inline SanitizeName(). --- lib/mayaUsd/fileio/shading/shadingModeExporterContext.cpp | 4 +++- lib/mayaUsd/fileio/shading/shadingModeImporter.cpp | 4 +++- lib/mayaUsd/fileio/shading/shadingModePxrRis.cpp | 4 +++- lib/mayaUsd/fileio/shading/shadingModeUseRegistry.cpp | 4 +++- lib/mayaUsd/ufe/UsdShaderNodeDef.cpp | 2 +- lib/mayaUsd/utils/util.h | 2 -- lib/usd/hdMaya/adapters/materialNetworkConverter.cpp | 5 +++-- lib/usd/translators/shading/mtlxBaseWriter.cpp | 6 ++++-- lib/usd/translators/shading/mtlxFileTextureWriter.cpp | 6 ++++-- lib/usd/translators/shading/mtlxPlace2dTextureWriter.cpp | 8 +++++--- lib/usd/translators/shading/mtlxSymmetricShaderWriter.cpp | 4 +++- lib/usd/translators/shading/usdFileTextureWriter.cpp | 6 ++++-- 12 files changed, 36 insertions(+), 19 deletions(-) diff --git a/lib/mayaUsd/fileio/shading/shadingModeExporterContext.cpp b/lib/mayaUsd/fileio/shading/shadingModeExporterContext.cpp index edef0323c7..18121955e6 100644 --- a/lib/mayaUsd/fileio/shading/shadingModeExporterContext.cpp +++ b/lib/mayaUsd/fileio/shading/shadingModeExporterContext.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include #include #include @@ -495,7 +497,7 @@ UsdPrim UsdMayaShadingModeExportContext::MakeStandardMaterialPrim( materialName = sgName.c_str(); } - materialName = UsdMayaUtil::SanitizeName(materialName); + materialName = UsdUfe::sanitizeName(materialName); UsdStageRefPtr stage = GetUsdStage(); if (UsdPrim materialParent = _GetMaterialParent(stage, GetExportArgs().materialsScopeName, assignmentsToBind)) { diff --git a/lib/mayaUsd/fileio/shading/shadingModeImporter.cpp b/lib/mayaUsd/fileio/shading/shadingModeImporter.cpp index ac3f3251d8..d2fccfda60 100644 --- a/lib/mayaUsd/fileio/shading/shadingModeImporter.cpp +++ b/lib/mayaUsd/fileio/shading/shadingModeImporter.cpp @@ -15,6 +15,8 @@ // #include "shadingModeImporter.h" +#include + #include #include #include @@ -100,7 +102,7 @@ UsdMayaShadingModeImportContext::GetShadingEngineName(const std::string& surface shadingEngineName = _shadeMaterial.GetPrim().GetName(); } else if (_boundPrim) { // We have no material, so we definitely want to use the surfaceNodeName here: - shadingEngineName = TfToken(UsdMayaUtil::SanitizeName(surfaceNodeName + "SG").c_str()); + shadingEngineName = TfToken(UsdUfe::sanitizeName(surfaceNodeName + "SG").c_str()); } return shadingEngineName; diff --git a/lib/mayaUsd/fileio/shading/shadingModePxrRis.cpp b/lib/mayaUsd/fileio/shading/shadingModePxrRis.cpp index 30b0eb0885..19e25ff917 100644 --- a/lib/mayaUsd/fileio/shading/shadingModePxrRis.cpp +++ b/lib/mayaUsd/fileio/shading/shadingModePxrRis.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include #include #include @@ -138,7 +140,7 @@ class PxrRisShadingModeExporter : public UsdMayaShadingModeExporter // well. currently, when we re-import, we don't get the display color so // it shows up as black. - const TfToken shaderPrimName(UsdMayaUtil::SanitizeName(depNode.name().asChar())); + const TfToken shaderPrimName(UsdUfe::sanitizeName(depNode.name().asChar())); const SdfPath shaderPath = materialPrim.GetPath().AppendChild(shaderPrimName); if (processedPaths->count(shaderPath) == 1u) { return stage->GetPrimAtPath(shaderPath); diff --git a/lib/mayaUsd/fileio/shading/shadingModeUseRegistry.cpp b/lib/mayaUsd/fileio/shading/shadingModeUseRegistry.cpp index 4acade569b..2724eb4144 100644 --- a/lib/mayaUsd/fileio/shading/shadingModeUseRegistry.cpp +++ b/lib/mayaUsd/fileio/shading/shadingModeUseRegistry.cpp @@ -25,6 +25,8 @@ #include #include +#include + #include #include #include @@ -121,7 +123,7 @@ class UseRegistryShadingModeExporter : public UsdMayaShadingModeExporter return nullptr; } - const TfToken shaderUsdPrimName(UsdMayaUtil::SanitizeName(depNodeFn.name().asChar())); + const TfToken shaderUsdPrimName(UsdUfe::sanitizeName(depNodeFn.name().asChar())); const SdfPath shaderUsdPath = parentPath.AppendChild(shaderUsdPrimName); diff --git a/lib/mayaUsd/ufe/UsdShaderNodeDef.cpp b/lib/mayaUsd/ufe/UsdShaderNodeDef.cpp index d95d6f0cf8..2c665086ca 100644 --- a/lib/mayaUsd/ufe/UsdShaderNodeDef.cpp +++ b/lib/mayaUsd/ufe/UsdShaderNodeDef.cpp @@ -368,7 +368,7 @@ Ufe::InsertChildCommand::Ptr UsdShaderNodeDef::createNodeCmd( parentItem, fShaderNodeDef->GetIdentifier()); } return UsdUndoCreateFromNodeDefCommand::create( - fShaderNodeDef, parentItem, UsdMayaUtil::SanitizeName(name.string())); + fShaderNodeDef, parentItem, UsdUfe::sanitizeName(name.string())); } return {}; } diff --git a/lib/mayaUsd/utils/util.h b/lib/mayaUsd/utils/util.h index e8231a8723..1867db0a21 100644 --- a/lib/mayaUsd/utils/util.h +++ b/lib/mayaUsd/utils/util.h @@ -142,8 +142,6 @@ inline double ConvertMMToCM(const double mm) { return mm / MillimetersPerCentime /// in millimeters. inline double ConvertCMToMM(const double cm) { return cm * MillimetersPerCentimeter; } -inline std::string SanitizeName(const std::string& name) { return UsdUfe::sanitizeName(name); } - /// Converts the given value \p mdistance in Maya's MDistance units to the /// equivalent value in USD's metersPerUnit. MAYAUSD_CORE_PUBLIC diff --git a/lib/usd/hdMaya/adapters/materialNetworkConverter.cpp b/lib/usd/hdMaya/adapters/materialNetworkConverter.cpp index aa5c2b4f10..e63a30fc37 100644 --- a/lib/usd/hdMaya/adapters/materialNetworkConverter.cpp +++ b/lib/usd/hdMaya/adapters/materialNetworkConverter.cpp @@ -20,7 +20,8 @@ #include #include #include -#include + +#include #include #include @@ -655,7 +656,7 @@ HdMaterialNode* HdMayaMaterialNetworkConverter::GetMaterial(const MObject& mayaN } TF_DEBUG(HDMAYA_ADAPTER_MATERIALS) .Msg("HdMayaMaterialNetworkConverter::GetMaterial(node=%s)\n", chr); - std::string usdNameStr = UsdMayaUtil::SanitizeName(chr); + std::string usdNameStr = UsdUfe::sanitizeName(chr); const auto materialPath = _prefix.AppendChild(TfToken(usdNameStr)); auto findResult = std::find_if( diff --git a/lib/usd/translators/shading/mtlxBaseWriter.cpp b/lib/usd/translators/shading/mtlxBaseWriter.cpp index f0154959d9..a25bebb2b7 100644 --- a/lib/usd/translators/shading/mtlxBaseWriter.cpp +++ b/lib/usd/translators/shading/mtlxBaseWriter.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include #include #include @@ -437,7 +439,7 @@ UsdAttribute MtlxUsd_BaseWriter::AddLuminance(int numChannels, UsdAttribute node TfToken luminanceName(TfStringPrintf( "%s_%s", _tokens->LuminancePrefix.GetText(), - UsdMayaUtil::SanitizeName(depNodeFn.name().asChar()).c_str())); + UsdUfe::sanitizeName(depNodeFn.name().asChar()).c_str())); const SdfPath luminancePath = nodegraphPath.AppendChild(luminanceName); UsdShadeShader luminanceSchema = UsdShadeShader::Define(GetUsdStage(), luminancePath); @@ -487,7 +489,7 @@ UsdAttribute MtlxUsd_BaseWriter::AddNormalMapping(UsdAttribute normalInput) TfToken nodeName(TfStringPrintf( "%s_%s_%s", _tokens->NormalMapPrefix.GetText(), - UsdMayaUtil::SanitizeName(depNodeFn.name().asChar()).c_str(), + UsdUfe::sanitizeName(depNodeFn.name().asChar()).c_str(), normalInput.GetBaseName().GetText())); SdfPath nodePath = nodegraphPath.AppendChild(nodeName); UsdShadeShader nodeSchema = UsdShadeShader::Define(GetUsdStage(), nodePath); diff --git a/lib/usd/translators/shading/mtlxFileTextureWriter.cpp b/lib/usd/translators/shading/mtlxFileTextureWriter.cpp index b454083d5b..1aec6b1bfc 100644 --- a/lib/usd/translators/shading/mtlxFileTextureWriter.cpp +++ b/lib/usd/translators/shading/mtlxFileTextureWriter.cpp @@ -25,6 +25,8 @@ #include #include +#include + #include #include #include @@ -117,7 +119,7 @@ MtlxUsd_FileWriter::MtlxUsd_FileWriter( SdfPath nodegraphPath = nodegraphSchema.GetPath(); SdfPath texPath - = nodegraphPath.AppendChild(TfToken(UsdMayaUtil::SanitizeName(depNodeFn.name().asChar()))); + = nodegraphPath.AppendChild(TfToken(UsdUfe::sanitizeName(depNodeFn.name().asChar()))); // Create a image shader as the "primary" shader for this writer. UsdShadeShader texSchema = UsdShadeShader::Define(GetUsdStage(), texPath); @@ -175,7 +177,7 @@ MtlxUsd_FileWriter::MtlxUsd_FileWriter( MString fileTextureName = depNodeFn.name(); fileTextureName += _tokens->fileTextureSuffix.GetText(); SdfPath fileTexturePath - = nodegraphPath.AppendChild(TfToken(UsdMayaUtil::SanitizeName(fileTextureName.asChar()))); + = nodegraphPath.AppendChild(TfToken(UsdUfe::sanitizeName(fileTextureName.asChar()))); UsdShadeShader fileTextureSchema = UsdShadeShader::Define(GetUsdStage(), fileTexturePath); _fileTexturePrim = fileTextureSchema.GetPrim(); diff --git a/lib/usd/translators/shading/mtlxPlace2dTextureWriter.cpp b/lib/usd/translators/shading/mtlxPlace2dTextureWriter.cpp index 931aa99a77..8d515655d9 100644 --- a/lib/usd/translators/shading/mtlxPlace2dTextureWriter.cpp +++ b/lib/usd/translators/shading/mtlxPlace2dTextureWriter.cpp @@ -24,6 +24,8 @@ #include #include +#include + #include #include #include @@ -115,7 +117,7 @@ MtlxUsd_Place2dTextureWriter::MtlxUsd_Place2dTextureWriter( SdfPath nodegraphPath = nodegraphSchema.GetPath(); SdfPath p2dTexPath - = nodegraphPath.AppendChild(TfToken(UsdMayaUtil::SanitizeName(depNodeFn.name().asChar()))); + = nodegraphPath.AppendChild(TfToken(UsdUfe::sanitizeName(depNodeFn.name().asChar()))); UsdShadeShader p2dTexSchema = UsdShadeShader::Define(GetUsdStage(), p2dTexPath); if (!TF_VERIFY( @@ -149,8 +151,8 @@ MtlxUsd_Place2dTextureWriter::MtlxUsd_Place2dTextureWriter( readerName += _tokens->PrimvarReaderSuffix.GetText(); // Only create a geompropvalue reader if there is no place2dtexture connected: - SdfPath primvarReaderPath = nodegraphSchema.GetPath().AppendChild( - TfToken(UsdMayaUtil::SanitizeName(readerName.asChar()))); + SdfPath primvarReaderPath + = nodegraphSchema.GetPath().AppendChild(TfToken(UsdUfe::sanitizeName(readerName.asChar()))); if (!GetUsdStage()->GetPrimAtPath(primvarReaderPath)) { UsdShadeShader primvarReaderSchema diff --git a/lib/usd/translators/shading/mtlxSymmetricShaderWriter.cpp b/lib/usd/translators/shading/mtlxSymmetricShaderWriter.cpp index 749a02e3d9..462c890bcc 100644 --- a/lib/usd/translators/shading/mtlxSymmetricShaderWriter.cpp +++ b/lib/usd/translators/shading/mtlxSymmetricShaderWriter.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include #include #include @@ -176,7 +178,7 @@ MtlxUsd_SymmetricShaderWriter::MtlxUsd_SymmetricShaderWriter( } nodePath = nodegraphSchema.GetPath().AppendChild( - TfToken(UsdMayaUtil::SanitizeName(depNodeFn.name().asChar()))); + TfToken(UsdUfe::sanitizeName(depNodeFn.name().asChar()))); } UsdShadeShader shaderSchema = UsdShadeShader::Define(GetUsdStage(), nodePath); if (!TF_VERIFY( diff --git a/lib/usd/translators/shading/usdFileTextureWriter.cpp b/lib/usd/translators/shading/usdFileTextureWriter.cpp index 1b021026cd..6e96cb44c0 100644 --- a/lib/usd/translators/shading/usdFileTextureWriter.cpp +++ b/lib/usd/translators/shading/usdFileTextureWriter.cpp @@ -22,6 +22,8 @@ #include #include +#include + #include #include #include @@ -593,7 +595,7 @@ void PxrUsdTranslators_FileTextureWriter::WriteTransform2dNode( if (primvarReaderShaderPath.GetName() == _tokens->PrimvarReaderShaderName.GetString()) { usdUvTransformName = TfStringPrintf( "%s_%s", - UsdMayaUtil::SanitizeName(depNodeFn.name().asChar()).c_str(), + UsdUfe::sanitizeName(depNodeFn.name().asChar()).c_str(), _tokens->UsdTransform2dShaderName.GetText()); } else { @@ -695,7 +697,7 @@ PxrUsdTranslators_FileTextureWriter::getPlace2DTexturePath(const MFnDependencyNo MPlug source = plug.source(&status); if (status == MS::kSuccess && !source.isNull()) { MFnDependencyNode sourceNode(source.node()); - usdUvTextureName = UsdMayaUtil::SanitizeName(sourceNode.name().asChar()); + usdUvTextureName = UsdUfe::sanitizeName(sourceNode.name().asChar()); } } From dcdd40553880f39d409b6fdc1a30244bf30c27ff Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:49:49 -0400 Subject: [PATCH 3/7] EMSUSD-751 - UsdUfe: Move Ufe::Attributes interface implementation * Moved 'using namespace UsdUfe' to mayaUsd to make sure that UsdUfe is properly using namespace. --- lib/mayaUsd/base/api.h | 12 ++++++++++++ lib/usdUfe/base/api.h | 11 ----------- lib/usdUfe/python/wrapTokens.cpp | 1 + lib/usdUfe/ufe/UsdAttributeHolder.cpp | 3 ++- lib/usdUfe/ufe/UsdContextOps.cpp | 2 +- lib/usdUfe/ufe/Utils.cpp | 3 ++- lib/usdUfe/utils/editRouter.cpp | 4 ++-- lib/usdUfe/utils/uiCallback.cpp | 4 ++-- 8 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/mayaUsd/base/api.h b/lib/mayaUsd/base/api.h index 7dc2ce1f75..00135d3c0f 100644 --- a/lib/mayaUsd/base/api.h +++ b/lib/mayaUsd/base/api.h @@ -78,3 +78,15 @@ // Convenience symbol versioning include: because api.h is widely // included, this reduces the need to explicitly include mayaUsd.h. #include + +// TEMP (UsdUfe) +// +// As the work-in-progress to move the UsdUfe code to a separate folder +// (and shared library) continues the namespace of the moved classes will +// be changed from MayaUsd::ufe -> UsdUfe. +// +// So temporarily add a using statement for this new namespace until the move +// is complete. At that the bulk of the files will have been moved and this +// using statement should be removed and any namespace cleanup done at that time. +#include +using namespace UsdUfe; diff --git a/lib/usdUfe/base/api.h b/lib/usdUfe/base/api.h index 75ec27c0d3..a5545d6d1b 100644 --- a/lib/usdUfe/base/api.h +++ b/lib/usdUfe/base/api.h @@ -44,14 +44,3 @@ // Convenience symbol versioning include: because api.h is widely // included, this reduces the need to explicitly include mayaUsd.h. #include - -// TEMP (UsdUfe) -// -// As the work-in-progress to move the UsdUfe code to a separate folder -// (and shared library) continues the namespace of the moved classes will -// be changed from MayaUsd::ufe -> UsdUfe. -// -// So temporarily add a using statement for this new namespace until the move -// is complete. At that the bulk of the files will have been moved and this -// using statement should be removed and any namespace cleanup done at that time. -using namespace UsdUfe; diff --git a/lib/usdUfe/python/wrapTokens.cpp b/lib/usdUfe/python/wrapTokens.cpp index fb6d3ba5b5..5aca32bd8f 100644 --- a/lib/usdUfe/python/wrapTokens.cpp +++ b/lib/usdUfe/python/wrapTokens.cpp @@ -23,6 +23,7 @@ PXR_NAMESPACE_USING_DIRECTIVE void wrapTokens() { + using namespace UsdUfe; TF_PY_WRAP_PUBLIC_TOKENS("EditRoutingTokens", EditRoutingTokens, USDUFE_EDIT_ROUTING_TOKENS); TF_PY_WRAP_PUBLIC_TOKENS("Tokens", GenericTokens, USDUFE_GENERIC_TOKENS); TF_PY_WRAP_PUBLIC_TOKENS("MetadataTokens", MetadataTokens, USDUFE_METADATA_TOKENS); diff --git a/lib/usdUfe/ufe/UsdAttributeHolder.cpp b/lib/usdUfe/ufe/UsdAttributeHolder.cpp index 0b90edc594..f4ed98f55a 100644 --- a/lib/usdUfe/ufe/UsdAttributeHolder.cpp +++ b/lib/usdUfe/ufe/UsdAttributeHolder.cpp @@ -52,7 +52,8 @@ bool setUsdAttrMetadata( // since that is how you unlock. if (key == Ufe::Attribute::kLocked) { return attr.SetMetadata( - MetadataTokens->Lock, value.get() ? GenericTokens->On : GenericTokens->Off); + UsdUfe::MetadataTokens->Lock, + value.get() ? UsdUfe::GenericTokens->On : UsdUfe::GenericTokens->Off); } // If attribute is locked don't allow setting Metadata. diff --git a/lib/usdUfe/ufe/UsdContextOps.cpp b/lib/usdUfe/ufe/UsdContextOps.cpp index 9a394b6598..302203f330 100644 --- a/lib/usdUfe/ufe/UsdContextOps.cpp +++ b/lib/usdUfe/ufe/UsdContextOps.cpp @@ -177,7 +177,7 @@ _computeLoadAndUnloadItems(const UsdPrim& prim) //! \brief Get groups of concrete schema prim types to list dynamically in the UI static const std::vector -getConcretePrimTypes(bool sorted, const UsdContextOps::SchemaNameMap& schemaPluginNiceNames) +getConcretePrimTypes(bool sorted, const UsdUfe::UsdContextOps::SchemaNameMap& schemaPluginNiceNames) { std::vector groups; diff --git a/lib/usdUfe/ufe/Utils.cpp b/lib/usdUfe/ufe/Utils.cpp index 1b0bdad1fa..e1e1997cd0 100644 --- a/lib/usdUfe/ufe/Utils.cpp +++ b/lib/usdUfe/ufe/Utils.cpp @@ -112,7 +112,8 @@ UsdUfe::UniqueChildNameFn gUniqueChildNameFn = nullptr; UsdUfe::WaitCursorFn gStartWaitCursorFn = nullptr; UsdUfe::WaitCursorFn gStopWaitCursorFn = nullptr; -UsdUfe::DisplayMessageFn gDisplayMessageFn[static_cast(MessageType::nbTypes)] = { nullptr }; +UsdUfe::DisplayMessageFn gDisplayMessageFn[static_cast(UsdUfe::MessageType::nbTypes)] + = { nullptr }; } // anonymous namespace diff --git a/lib/usdUfe/utils/editRouter.cpp b/lib/usdUfe/utils/editRouter.cpp index 023fe72585..5fed191ce4 100644 --- a/lib/usdUfe/utils/editRouter.cpp +++ b/lib/usdUfe/utils/editRouter.cpp @@ -46,7 +46,7 @@ UsdUfe::EditRouters& getRegisteredEditRouters() void editTargetLayer(const PXR_NS::VtDictionary& context, PXR_NS::VtDictionary& routingData) { // We expect a prim in the context. - auto found = context.find(EditRoutingTokens->Prim); + auto found = context.find(UsdUfe::EditRoutingTokens->Prim); if (found == context.end()) { return; } @@ -56,7 +56,7 @@ void editTargetLayer(const PXR_NS::VtDictionary& context, PXR_NS::VtDictionary& return; } auto layer = prim.GetStage()->GetEditTarget().GetLayer(); - routingData[EditRoutingTokens->Layer] = PXR_NS::VtValue(layer); + routingData[UsdUfe::EditRoutingTokens->Layer] = PXR_NS::VtValue(layer); } } // namespace diff --git a/lib/usdUfe/utils/uiCallback.cpp b/lib/usdUfe/utils/uiCallback.cpp index c20a83bf92..7b68803dfb 100644 --- a/lib/usdUfe/utils/uiCallback.cpp +++ b/lib/usdUfe/utils/uiCallback.cpp @@ -27,9 +27,9 @@ UsdUfe::UICallbacks& getRegisteredUICallbacks() return registeredUICallbacks; } -const std::vector& getEmptyCallbacks() +const std::vector& getEmptyCallbacks() { - static std::vector empty; + static std::vector empty; return empty; } From 33f48024018c6125f4086305fe6d955af9fbd42a Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Mon, 29 Apr 2024 16:33:21 -0400 Subject: [PATCH 4/7] EMSUSD-751 - UsdUfe: Move Ufe::Attributes interface implementation * Build fixes --- lib/usdUfe/ufe/UsdAttributeHolder.cpp | 14 +++++++------- lib/usdUfe/ufe/Utils.cpp | 7 ++++++- lib/usdUfe/ufe/Utils.h | 2 ++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/usdUfe/ufe/UsdAttributeHolder.cpp b/lib/usdUfe/ufe/UsdAttributeHolder.cpp index f4ed98f55a..a0a967299d 100644 --- a/lib/usdUfe/ufe/UsdAttributeHolder.cpp +++ b/lib/usdUfe/ufe/UsdAttributeHolder.cpp @@ -24,7 +24,7 @@ #include #include #ifdef UFE_V3_FEATURES_AVAILABLE -#include +#include #endif #include @@ -584,9 +584,9 @@ UsdAttributeHolder::EnumOptions UsdAttributeHolder::getEnums() const { UsdAttributeHolder::EnumOptions retVal; if (_usdAttr.IsValid()) { - VtTokenArray allowedTokens; + PXR_NS::VtTokenArray allowedTokens; if (_usdAttr.GetPrim().GetPrimDefinition().GetPropertyMetadata( - _usdAttr.GetName(), SdfFieldKeys->AllowedTokens, &allowedTokens)) { + _usdAttr.GetName(), PXR_NS::SdfFieldKeys->AllowedTokens, &allowedTokens)) { for (auto const& token : allowedTokens) { retVal.emplace_back(token.GetString(), ""); } @@ -594,10 +594,10 @@ UsdAttributeHolder::EnumOptions UsdAttributeHolder::getEnums() const // We might have a propagated enum copied into the created NodeGraph port, resulting from // connecting a shader enum property. PXR_NS::UsdShadeNodeGraph ngPrim(_usdAttr.GetPrim()); - if (ngPrim && UsdShadeInput::IsInput(_usdAttr)) { - const auto shaderInput = UsdShadeInput { _usdAttr }; - const auto enumLabels = shaderInput.GetSdrMetadataByKey(TfToken("enum")); - const auto enumValues = shaderInput.GetSdrMetadataByKey(TfToken("enumvalues")); + if (ngPrim && PXR_NS::UsdShadeInput::IsInput(_usdAttr)) { + const auto shaderInput = PXR_NS::UsdShadeInput { _usdAttr }; + const auto enumLabels = shaderInput.GetSdrMetadataByKey(PXR_NS::TfToken("enum")); + const auto enumValues = shaderInput.GetSdrMetadataByKey(PXR_NS::TfToken("enumvalues")); const std::vector allLabels = splitString(enumLabels, ", "); std::vector allValues = splitString(enumValues, ", "); diff --git a/lib/usdUfe/ufe/Utils.cpp b/lib/usdUfe/ufe/Utils.cpp index e1e1997cd0..a949625fdd 100644 --- a/lib/usdUfe/ufe/Utils.cpp +++ b/lib/usdUfe/ufe/Utils.cpp @@ -37,7 +37,6 @@ #include #include -#include #include #include #include @@ -45,6 +44,10 @@ #include #include +#ifdef UFE_V4_FEATURES_AVAILABLE +#include +#endif // UFE_V4_FEATURES_AVAILABLE + PXR_NAMESPACE_USING_DIRECTIVE namespace { @@ -620,6 +623,7 @@ UsdAttribute* usdAttrFromUfeAttr(const Ufe::Attribute::Ptr& attr) return dynamic_cast(attr.get()); } +#ifdef UFE_V4_FEATURES_AVAILABLE Ufe::Attribute::Ptr attrFromUfeAttrInfo(const Ufe::AttributeInfo& attrInfo) { auto item @@ -630,6 +634,7 @@ Ufe::Attribute::Ptr attrFromUfeAttrInfo(const Ufe::AttributeInfo& attrInfo) } return UsdAttributes(item).attribute(attrInfo.name()); } +#endif // UFE_V4_FEATURES_AVAILABLE namespace { diff --git a/lib/usdUfe/ufe/Utils.h b/lib/usdUfe/ufe/Utils.h index dc88040371..5e0e0f67a8 100644 --- a/lib/usdUfe/ufe/Utils.h +++ b/lib/usdUfe/ufe/Utils.h @@ -232,8 +232,10 @@ PXR_NS::SdfValueTypeName ufeTypeToUsd(const Ufe::Attribute::Type ufeType); USDUFE_PUBLIC UsdAttribute* usdAttrFromUfeAttr(const Ufe::Attribute::Ptr& attr); +#ifdef UFE_V4_FEATURES_AVAILABLE USDUFE_PUBLIC Ufe::Attribute::Ptr attrFromUfeAttrInfo(const Ufe::AttributeInfo& attrInfo); +#endif // UFE_V4_FEATURES_AVAILABLE //! Send notification for data model changes template From 5f0dbd38902a06144fd97918071346bbc65cd387 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Tue, 30 Apr 2024 11:09:56 -0400 Subject: [PATCH 5/7] EMSUSD-751 - UsdUfe: Move Ufe::Attributes interface implementation * Build fixes because of merging latest dev. * Fixed pxr plugin when building without tests. --- lib/mayaUsd/CMakeLists.txt | 15 ----- lib/usdUfe/CMakeLists.txt | 8 +++ .../pxr/maya/lib/pxrUsdMayaGL/CMakeLists.txt | 56 ++++++++++--------- 3 files changed, 37 insertions(+), 42 deletions(-) diff --git a/lib/mayaUsd/CMakeLists.txt b/lib/mayaUsd/CMakeLists.txt index 2413b49bc4..4cea01c23d 100644 --- a/lib/mayaUsd/CMakeLists.txt +++ b/lib/mayaUsd/CMakeLists.txt @@ -63,13 +63,6 @@ if(DEFINED UFE_PREVIEW_VERSION_NUM) ) endif() -if (UFE_DEFAULT_VALUE_SUPPORT) - target_compile_definitions(${PROJECT_NAME} - PRIVATE - UFE_DEFAULT_VALUE_SUPPORT=1 - ) -endif() - message(STATUS "MAYA_HAS_DEFAULT_MATERIAL_API is ${MAYA_HAS_DEFAULT_MATERIAL_API}") if (MAYA_HAS_DEFAULT_MATERIAL_API) target_compile_definitions(${PROJECT_NAME} @@ -150,14 +143,6 @@ if (MAYA_HAS_GET_MEMBER_PATHS) ) 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} - PRIVATE - USD_HAS_COLOR4_SDR_SUPPORT=1 - ) -endif() - message(STATUS "MAYA_HAS_DISPLAY_LAYER_API is ${MAYA_HAS_DISPLAY_LAYER_API}") if (MAYA_HAS_DISPLAY_LAYER_API) target_compile_definitions(${PROJECT_NAME} diff --git a/lib/usdUfe/CMakeLists.txt b/lib/usdUfe/CMakeLists.txt index a7df4332b6..1a0d26c82f 100644 --- a/lib/usdUfe/CMakeLists.txt +++ b/lib/usdUfe/CMakeLists.txt @@ -88,6 +88,14 @@ if (UFE_HAS_DISPLAY_NAME) ) endif() + +if (UFE_DEFAULT_VALUE_SUPPORT) + target_compile_definitions(${PROJECT_NAME} + PRIVATE + UFE_DEFAULT_VALUE_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/plugin/pxr/maya/lib/pxrUsdMayaGL/CMakeLists.txt b/plugin/pxr/maya/lib/pxrUsdMayaGL/CMakeLists.txt index 359a40b2c9..1112008524 100644 --- a/plugin/pxr/maya/lib/pxrUsdMayaGL/CMakeLists.txt +++ b/plugin/pxr/maya/lib/pxrUsdMayaGL/CMakeLists.txt @@ -1,32 +1,34 @@ -# Unit test scripts. -set(TEST_SCRIPT_FILES - testenv/testRefAssemblyDrawRepresentations.py - testenv/testBatchRendererIsolateSelection.py - testenv/testPxrUsdMayaGLInstancerDraw.py -) +if (BUILD_TESTS) + # Unit test scripts. + set(TEST_SCRIPT_FILES + testenv/testRefAssemblyDrawRepresentations.py + testenv/testBatchRendererIsolateSelection.py + testenv/testPxrUsdMayaGLInstancerDraw.py + ) -foreach(script ${TEST_SCRIPT_FILES}) - mayaUsd_get_unittest_target(target ${script}) - mayaUsd_add_test(${target} - INTERACTIVE - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - PYTHON_SCRIPT ${script} - ENV - "LD_LIBRARY_PATH=${ADDITIONAL_LD_LIBRARY_PATH}" + foreach(script ${TEST_SCRIPT_FILES}) + mayaUsd_get_unittest_target(target ${script}) + mayaUsd_add_test(${target} + INTERACTIVE + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + PYTHON_SCRIPT ${script} + ENV + "LD_LIBRARY_PATH=${ADDITIONAL_LD_LIBRARY_PATH}" - # Maya uses a very old version of GLEW, so we need support for - # pre-loading a newer version from elsewhere. - "LD_PRELOAD=${ADDITIONAL_LD_PRELOAD}" + # Maya uses a very old version of GLEW, so we need support for + # pre-loading a newer version from elsewhere. + "LD_PRELOAD=${ADDITIONAL_LD_PRELOAD}" - # All of the pxrUsdMayaGL tests exercise Pixar's batch renderer, so - # we turn the Viewport 2.0 render delegate off. - "MAYAUSD_DISABLE_VP2_RENDER_DELEGATE=1" + # All of the pxrUsdMayaGL tests exercise Pixar's batch renderer, so + # we turn the Viewport 2.0 render delegate off. + "MAYAUSD_DISABLE_VP2_RENDER_DELEGATE=1" - # Fallback to old color management. We will have to investigate - # and introduce OCIOv2 compatible version of these tests. - "MAYA_COLOR_MANAGEMENT_SYNCOLOR=1" - ) + # Fallback to old color management. We will have to investigate + # and introduce OCIOv2 compatible version of these tests. + "MAYA_COLOR_MANAGEMENT_SYNCOLOR=1" + ) - # Assign a CTest label to these tests for easy filtering. - set_property(TEST ${target} APPEND PROPERTY LABELS pxrUsdMayaGL) -endforeach() + # Assign a CTest label to these tests for easy filtering. + set_property(TEST ${target} APPEND PROPERTY LABELS pxrUsdMayaGL) + endforeach() +endif() From 6c86d1b5c4c0f4396980f145e3cfc8a8cf493e4b Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Wed, 1 May 2024 17:58:23 -0400 Subject: [PATCH 6/7] EMSUSD-751 - UsdUfe: Move Ufe::Attributes interface implementation * clang-format --- lib/mayaUsdAPI/utils.cpp | 1 - lib/usdUfe/ufe/Global.h | 2 +- lib/usdUfe/ufe/UsdClipboardCommands.cpp | 3 ++- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/mayaUsdAPI/utils.cpp b/lib/mayaUsdAPI/utils.cpp index 2830a859e3..a73e0a7fff 100644 --- a/lib/mayaUsdAPI/utils.cpp +++ b/lib/mayaUsdAPI/utils.cpp @@ -26,7 +26,6 @@ #include #include - #include namespace MAYAUSDAPI_NS_DEF { diff --git a/lib/usdUfe/ufe/Global.h b/lib/usdUfe/ufe/Global.h index 41ccf0ad71..dca2a91980 100644 --- a/lib/usdUfe/ufe/Global.h +++ b/lib/usdUfe/ufe/Global.h @@ -54,7 +54,7 @@ struct USDUFE_PUBLIC DCCFunctions IsRootChildFn isRootChildFn = nullptr; UniqueChildNameFn uniqueChildNameFn = nullptr; DefaultMaterialScopeNameFn defaultMaterialScopeNameFn = nullptr; - DisplayMessageFn displayMessageFn[static_cast(MessageType::nbTypes)] = { nullptr }; + DisplayMessageFn displayMessageFn[static_cast(MessageType::nbTypes)] = { nullptr }; // Optional: nothing will be done if no function is supplied. WaitCursorFn startWaitCursorFn = nullptr; diff --git a/lib/usdUfe/ufe/UsdClipboardCommands.cpp b/lib/usdUfe/ufe/UsdClipboardCommands.cpp index 484266c5c3..5b2b8b4798 100644 --- a/lib/usdUfe/ufe/UsdClipboardCommands.cpp +++ b/lib/usdUfe/ufe/UsdClipboardCommands.cpp @@ -63,7 +63,8 @@ void setClipboardMetadata( } } -void setClipboardMetadata(const UsdUfe::UsdUndoDuplicateSelectionCommand::Ptr& duplicateSelectionCmd) +void setClipboardMetadata( + const UsdUfe::UsdUndoDuplicateSelectionCommand::Ptr& duplicateSelectionCmd) { for (const auto& duplicatedItem : duplicateSelectionCmd->getDuplicatedItemsMap()) { const auto prim = duplicatedItem.first->prim(); From 63f6450a2feea1b04cd19ef43f4b2eff2ab17923 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Thu, 2 May 2024 10:13:20 -0400 Subject: [PATCH 7/7] EMSUSD-751 - UsdUfe: Move Ufe::Attributes interface implementation * Extra Linux/OSX build break fix. --- plugin/al/usdmayautils/AL/usdmaya/utils/DgNodeHelper.cpp | 2 ++ plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp | 1 + plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp | 2 ++ 3 files changed, 5 insertions(+) diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/DgNodeHelper.cpp b/plugin/al/usdmayautils/AL/usdmaya/utils/DgNodeHelper.cpp index 0cb7c167a0..865173c48a 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/DgNodeHelper.cpp +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/DgNodeHelper.cpp @@ -37,6 +37,8 @@ #include +using namespace UsdUfe; + namespace AL { namespace usdmaya { namespace utils { diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp b/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp index 65b0d01970..a2b031745f 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/DiffPrimVar.cpp @@ -27,6 +27,7 @@ #include PXR_NAMESPACE_USING_DIRECTIVE +using namespace UsdUfe; namespace AL { namespace usdmaya { diff --git a/plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp b/plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp index 600d4af0ff..93f9ec42b7 100644 --- a/plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp +++ b/plugin/al/usdmayautils/AL/usdmaya/utils/MeshUtils.cpp @@ -31,6 +31,8 @@ #include +using namespace UsdUfe; + namespace AL { namespace usdmaya { namespace utils {