From 0feb6e267be64d3103ac58eda39b45d408cf5c28 Mon Sep 17 00:00:00 2001 From: Paul Molodowitch Date: Mon, 30 Jan 2017 14:42:51 -0800 Subject: [PATCH] create single token for "usdVariantSet_" was a string constant USD_VARIANT_SET_PREFIX in referenceAssembly.cpp, and _tokens->VariantSetPlugNamePrefix in translatorModelAssembly --- .../maya/lib/usdMaya/referenceAssembly.cpp | 17 ++++++++--------- .../maya/lib/usdMaya/referenceAssembly.h | 6 ++++++ .../lib/usdMaya/translatorModelAssembly.cpp | 5 ++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/third_party/maya/lib/usdMaya/referenceAssembly.cpp b/third_party/maya/lib/usdMaya/referenceAssembly.cpp index 8859b76e95..0dd0350613 100644 --- a/third_party/maya/lib/usdMaya/referenceAssembly.cpp +++ b/third_party/maya/lib/usdMaya/referenceAssembly.cpp @@ -72,6 +72,7 @@ PXR_NAMESPACE_OPEN_SCOPE +TF_DEFINE_PUBLIC_TOKENS(PxrUsdMayaVariantSetTokens, PXRUSDMAYA_VARIANT_SET_TOKENS); TF_DEFINE_ENV_SETTING(PIXMAYA_USE_USD_REF_ASSEMBLIES, true, @@ -454,15 +455,13 @@ UsdMayaReferenceAssembly::getRepNamespace() const return emptyNS; } -static const std::string USD_VARIANT_SET_PREFIX("usdVariantSet_"); - // virtual MStatus UsdMayaReferenceAssembly::setDependentsDirty( const MPlug& dirtiedPlug, MPlugArray& affectedPlugs) { // Hardcoded dynamic attr naming: usdVariantSet_* // If an attr starts with "usdVariantSet_", then dirty the stage MString dirtiedPlugName = dirtiedPlug.partialName(); - const MString variantSetPrefix(USD_VARIANT_SET_PREFIX.c_str()); + const MString variantSetPrefix(PxrUsdMayaVariantSetTokens->PlugNamePrefix.GetText()); if ((dirtiedPlugName.length() > variantSetPrefix.length()) && (dirtiedPlugName.substring(0, variantSetPrefix.length()-1) == variantSetPrefix)) { @@ -537,11 +536,11 @@ std::set _GetVariantSetNamesForStageCache( } std::string attrName(attrPlug.partialName().asChar()); - if (!TfStringStartsWith(attrName, USD_VARIANT_SET_PREFIX)) { + if (!TfStringStartsWith(attrName, PxrUsdMayaVariantSetTokens->PlugNamePrefix)) { continue; } - std::string variantSet = attrName.substr(USD_VARIANT_SET_PREFIX.size()); + std::string variantSet = attrName.substr(PxrUsdMayaVariantSetTokens->PlugNamePrefix.GetString().size()); varSetNames.insert(variantSet); } return varSetNames; @@ -606,7 +605,7 @@ MStatus UsdMayaReferenceAssembly::computeInStageDataCached(MDataBlock& dataBlock TfToken modelName = UsdUtilsGetModelNameFromRootLayer(rootLayer); const std::set varSetNamesForCache = _GetVariantSetNamesForStageCache(depNodeFn); TF_FOR_ALL(variantSet, varSetNamesForCache) { - MString variantSetPlugName(USD_VARIANT_SET_PREFIX.c_str()); + MString variantSetPlugName(PxrUsdMayaVariantSetTokens->PlugNamePrefix.GetText()); variantSetPlugName += variantSet->c_str(); MPlug varSetPlg = depNodeFn.findPlug(variantSetPlugName, true); if (!varSetPlg.isNull()) { @@ -748,7 +747,7 @@ MStatus UsdMayaReferenceAssembly::computeOutStageData(MDataBlock& dataBlock) std::vector variantSetNames = usdPrim.GetVariantSets().GetNames(); MFnDependencyNode depNodeFn(thisMObject()); TF_FOR_ALL(variantSet, variantSetNames) { - MString variantSetPlugName(USD_VARIANT_SET_PREFIX.c_str()); + MString variantSetPlugName(PxrUsdMayaVariantSetTokens->PlugNamePrefix.GetText()); variantSetPlugName += variantSet->c_str(); MPlug varSetPlg = depNodeFn.findPlug(variantSetPlugName, true); if (!varSetPlg.isNull()) { @@ -806,7 +805,7 @@ bool UsdMayaReferenceAssembly::setInternalValueInContext( const MPlug& plug, bool setAttrSuccess = MPxAssembly::setInternalValueInContext(plug, dataHandle, ctx); - bool varSelChanged = TfStringStartsWith(plug.partialName().asChar(), USD_VARIANT_SET_PREFIX); + bool varSelChanged = TfStringStartsWith(plug.partialName().asChar(), PxrUsdMayaVariantSetTokens->PlugNamePrefix); if ( varSelChanged || (std::find(_psData.attrsAffectingRepresentation.begin(), @@ -889,7 +888,7 @@ std::map UsdMayaReferenceAssembly::GetVariantSetSelect std::vector variantSetNames = usdPrim.GetVariantSets().GetNames(); for (std::string variantSetName : variantSetNames) { - MString variantSetPlugName(USD_VARIANT_SET_PREFIX.c_str()); + MString variantSetPlugName(PxrUsdMayaVariantSetTokens->PlugNamePrefix.GetText()); variantSetPlugName += variantSetName.c_str(); MPlug variantSetPlg = depNodeFn.findPlug(variantSetPlugName, true); if (!variantSetPlg.isNull()) { diff --git a/third_party/maya/lib/usdMaya/referenceAssembly.h b/third_party/maya/lib/usdMaya/referenceAssembly.h index 07858bd8ed..434f33d8e3 100644 --- a/third_party/maya/lib/usdMaya/referenceAssembly.h +++ b/third_party/maya/lib/usdMaya/referenceAssembly.h @@ -43,6 +43,7 @@ #include +#include "pxr/base/tf/staticTokens.h" #include "pxr/base/tf/envSetting.h" #include "pxr/usd/sdf/layer.h" @@ -51,6 +52,11 @@ PXR_NAMESPACE_OPEN_SCOPE +#define PXRUSDMAYA_VARIANT_SET_TOKENS \ + ((PlugNamePrefix, "usdVariantSet_")) + +TF_DECLARE_PUBLIC_TOKENS(PxrUsdMayaVariantSetTokens, PXRUSDMAYA_VARIANT_SET_TOKENS); + extern TfEnvSetting PIXMAYA_USE_USD_ASSEM_NAMESPACE; diff --git a/third_party/maya/lib/usdMaya/translatorModelAssembly.cpp b/third_party/maya/lib/usdMaya/translatorModelAssembly.cpp index 7da5cd2740..32019cd748 100644 --- a/third_party/maya/lib/usdMaya/translatorModelAssembly.cpp +++ b/third_party/maya/lib/usdMaya/translatorModelAssembly.cpp @@ -73,7 +73,6 @@ TF_DEFINE_PRIVATE_TOKENS(_tokens, ((FilePathPlugName, "filePath")) ((PrimPathPlugName, "primPath")) ((KindPlugName, "kind")) - ((VariantSetPlugNamePrefix, "usdVariantSet_")) ((MayaProxyShapeNameSuffix, "Proxy")) @@ -176,7 +175,7 @@ PxrUsdMayaTranslatorModelAssembly::Create( const std::string& variantSetName = regVarSet.name; std::string variantSetPlugName = TfStringPrintf("%s%s", - _tokens->VariantSetPlugNamePrefix.GetText(), variantSetName.c_str()); + PxrUsdMayaVariantSetTokens->PlugNamePrefix.GetText(), variantSetName.c_str()); MPlug modelingVariantPlg = assemblyNode.findPlug(variantSetPlugName.c_str(), &status); if (status == MS::kSuccess) { @@ -391,7 +390,7 @@ PxrUsdMayaTranslatorModelAssembly::Read( std::string variantSelection = iter->second; std::string variantSetPlugName = TfStringPrintf("%s%s", - _tokens->VariantSetPlugNamePrefix.GetText(), variantSetName.c_str()); + PxrUsdMayaVariantSetTokens->PlugNamePrefix.GetText(), variantSetName.c_str()); MPlug varSetPlug = depNodeFn.findPlug(variantSetPlugName.c_str(), true, &status); if (status != MStatus::kSuccess) { MFnTypedAttribute typedAttrFn;