Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create single token for "usdVariantSet_" #160

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions third_party/maya/lib/usdMaya/referenceAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -537,11 +536,11 @@ std::set<std::string> _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;
Expand Down Expand Up @@ -606,7 +605,7 @@ MStatus UsdMayaReferenceAssembly::computeInStageDataCached(MDataBlock& dataBlock
TfToken modelName = UsdUtilsGetModelNameFromRootLayer(rootLayer);
const std::set<std::string> 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()) {
Expand Down Expand Up @@ -748,7 +747,7 @@ MStatus UsdMayaReferenceAssembly::computeOutStageData(MDataBlock& dataBlock)
std::vector<std::string> 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()) {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -889,7 +888,7 @@ std::map<std::string, std::string> UsdMayaReferenceAssembly::GetVariantSetSelect

std::vector<std::string> 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()) {
Expand Down
6 changes: 6 additions & 0 deletions third_party/maya/lib/usdMaya/referenceAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

#include <boost/shared_ptr.hpp>

#include "pxr/base/tf/staticTokens.h"
#include "pxr/base/tf/envSetting.h"

#include "pxr/usd/sdf/layer.h"
Expand All @@ -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<bool> PIXMAYA_USE_USD_ASSEM_NAMESPACE;


Expand Down
5 changes: 2 additions & 3 deletions third_party/maya/lib/usdMaya/translatorModelAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ TF_DEFINE_PRIVATE_TOKENS(_tokens,
((FilePathPlugName, "filePath"))
((PrimPathPlugName, "primPath"))
((KindPlugName, "kind"))
((VariantSetPlugNamePrefix, "usdVariantSet_"))

((MayaProxyShapeNameSuffix, "Proxy"))

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down