Skip to content

Commit

Permalink
Merge pull request #3223 from Autodesk/samuelliu-adsk/MAYA-128421/exc…
Browse files Browse the repository at this point in the history
…lude-namespace

EMSUSD-92 - Ability to exclude primvars with specific Namespace
  • Loading branch information
seando-adsk authored Jul 14, 2023
2 parents f72fa9a + 3725c92 commit 785f636
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/mayaUsd/commands/baseImportCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ MSyntax MayaUSDImportCommand::createSyntax()
UsdMayaJobImportArgsTokens->excludePrimvar.GetText(),
MSyntax::kString);
syntax.makeFlagMultiUse(kExcludePrimvarFlag);
syntax.addFlag(
kExcludePrimvarNamespaceFlag,
UsdMayaJobImportArgsTokens->excludePrimvarNamespace.GetText(),
MSyntax::kString);
syntax.makeFlagMultiUse(kExcludePrimvarNamespaceFlag);
syntax.addFlag(
kUseAsAnimationCacheFlag,
UsdMayaJobImportArgsTokens->useAsAnimationCache.GetText(),
Expand Down
1 change: 1 addition & 0 deletions lib/mayaUsd/commands/baseImportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class MAYAUSD_CORE_PUBLIC MayaUSDImportCommand : public MPxCommand
static constexpr auto kApiSchemaFlag = "api";
static constexpr auto kJobContextFlag = "jc";
static constexpr auto kExcludePrimvarFlag = "epv";
static constexpr auto kExcludePrimvarNamespaceFlag = "epn";
static constexpr auto kUseAsAnimationCacheFlag = "uac";
static constexpr auto kImportChaserFlag = "chr";
static constexpr auto kImportChaserArgsFlag = "cha";
Expand Down
4 changes: 4 additions & 0 deletions lib/mayaUsd/fileio/jobs/jobArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,8 @@ UsdMayaJobImportArgs::UsdMayaJobImportArgs(
UsdMayaJobImportArgsTokens->Import,
UsdMayaJobImportArgsTokens->Unloaded }))
, excludePrimvarNames(extractTokenSet(userArgs, UsdMayaJobImportArgsTokens->excludePrimvar))
, excludePrimvarNamespaces(
extractTokenSet(userArgs, UsdMayaJobImportArgsTokens->excludePrimvarNamespace))
, includeAPINames(extractTokenSet(userArgs, UsdMayaJobImportArgsTokens->apiSchema))
, jobContextNames(extractTokenSet(userArgs, UsdMayaJobImportArgsTokens->jobContext))
, includeMetadataKeys(extractTokenSet(userArgs, UsdMayaJobImportArgsTokens->metadata))
Expand Down Expand Up @@ -1185,6 +1187,7 @@ const VtDictionary& UsdMayaJobImportArgs::GetDefaultDictionary()
= UsdMayaJobImportArgsTokens->Collapsed.GetString();
d[UsdMayaJobImportArgsTokens->apiSchema] = std::vector<VtValue>();
d[UsdMayaJobImportArgsTokens->excludePrimvar] = std::vector<VtValue>();
d[UsdMayaJobImportArgsTokens->excludePrimvarNamespace] = std::vector<VtValue>();
d[UsdMayaJobImportArgsTokens->jobContext] = std::vector<VtValue>();
d[UsdMayaJobImportArgsTokens->metadata]
= std::vector<VtValue>({ VtValue(SdfFieldKeys->Hidden.GetString()),
Expand Down Expand Up @@ -1267,6 +1270,7 @@ const VtDictionary& UsdMayaJobImportArgs::GetGuideDictionary()
d[UsdMayaJobImportArgsTokens->assemblyRep] = _string;
d[UsdMayaJobImportArgsTokens->apiSchema] = _stringVector;
d[UsdMayaJobImportArgsTokens->excludePrimvar] = _stringVector;
d[UsdMayaJobImportArgsTokens->excludePrimvarNamespace] = _stringVector;
d[UsdMayaJobImportArgsTokens->jobContext] = _stringVector;
d[UsdMayaJobImportArgsTokens->metadata] = _stringVector;
d[UsdMayaJobImportArgsTokens->shadingMode] = _stringTupletVector;
Expand Down
2 changes: 2 additions & 0 deletions lib/mayaUsd/fileio/jobs/jobArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ TF_DECLARE_PUBLIC_TOKENS(
(apiSchema) \
(assemblyRep) \
(excludePrimvar) \
(excludePrimvarNamespace) \
(jobContext) \
(metadata) \
(shadingMode) \
Expand Down Expand Up @@ -327,6 +328,7 @@ struct UsdMayaJobImportArgs
{
const TfToken assemblyRep;
const TfToken::Set excludePrimvarNames;
const TfToken::Set excludePrimvarNamespaces;
const TfToken::Set includeAPINames;
const TfToken::Set jobContextNames;
const TfToken::Set includeMetadataKeys;
Expand Down
5 changes: 5 additions & 0 deletions lib/mayaUsd/fileio/primReaderArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ const TfToken::Set& UsdMayaPrimReaderArgs::GetExcludePrimvarNames() const
return _jobArgs.excludePrimvarNames;
}

const TfToken::Set& UsdMayaPrimReaderArgs::GetExcludePrimvarNamespaces() const
{
return _jobArgs.excludePrimvarNamespaces;
}

bool UsdMayaPrimReaderArgs::GetUseAsAnimationCache() const { return _jobArgs.useAsAnimationCache; }

PXR_NAMESPACE_CLOSE_SCOPE
3 changes: 3 additions & 0 deletions lib/mayaUsd/fileio/primReaderArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class UsdMayaPrimReaderArgs
MAYAUSD_CORE_PUBLIC
const TfToken::Set& GetExcludePrimvarNames() const;

MAYAUSD_CORE_PUBLIC
const TfToken::Set& GetExcludePrimvarNamespaces() const;

MAYAUSD_CORE_PUBLIC
bool GetUseAsAnimationCache() const;

Expand Down
22 changes: 21 additions & 1 deletion lib/mayaUsd/fileio/utils/meshReadUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,8 @@ void UsdMayaMeshReadUtils::setEmitNormalsTag(MFnMesh& meshFn, const bool emitNor
void UsdMayaMeshReadUtils::assignPrimvarsToMesh(
const UsdGeomMesh& mesh,
const MObject& meshObj,
const TfToken::Set& excludePrimvarSet)
const TfToken::Set& excludePrimvarSet,
const TfToken::Set& excludePrivarNamespaceSet)
{
if (meshObj.apiType() != MFn::kMesh) {
return;
Expand All @@ -621,6 +622,25 @@ void UsdMayaMeshReadUtils::assignPrimvarsToMesh(
continue;
}

// Exclude primvars if they match with the exclude namespac
if (primvar.NameContainsNamespaces()) {
std::string primVarString = fullName.GetString();
bool skipPrimvar = false;
for (const TfToken& primVarNameSpace : excludePrivarNamespaceSet) {
std::string primVarNameSpaceString = primVarNameSpace.GetString();

// The primVarString is a substring of excludePrimVarNamespace string from the
// beginning
if (primVarString.find(primVarNameSpaceString) == 0) {
skipPrimvar = true;
break;
}
}
if (skipPrimvar) {
continue;
}
}

// If the primvar is called either displayColor or displayOpacity check
// if it was really authored from the user. It may not have been
// authored by the user, for example if it was generated by shader
Expand Down
3 changes: 2 additions & 1 deletion lib/mayaUsd/fileio/utils/meshReadUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ MAYAUSD_CORE_PUBLIC
void assignPrimvarsToMesh(
const UsdGeomMesh& mesh,
const MObject& meshObj,
const TfToken::Set& excludePrimvarSet);
const TfToken::Set& excludePrimvarSet,
const TfToken::Set& excludePrimvarNamespaceSet);

MAYAUSD_CORE_PUBLIC
void assignInvisibleFaces(const UsdGeomMesh& mesh, const MObject& meshObj);
Expand Down
9 changes: 9 additions & 0 deletions lib/mayaUsd/python/wrapPrimReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ void wrapJobImportArgs()
make_getter(
&UsdMayaJobImportArgs::excludePrimvarNames,
return_value_policy<TfPySequenceToSet>()))
.add_property(
"excludePrimvarNamespaces",
make_getter(
&UsdMayaJobImportArgs::excludePrimvarNamespaces,
return_value_policy<TfPySequenceToSet>()))
.def_readonly("importInstances", &UsdMayaJobImportArgs::importInstances)
.def_readonly("importUSDZTextures", &UsdMayaJobImportArgs::importUSDZTextures)
.def_readonly(
Expand Down Expand Up @@ -512,6 +517,10 @@ void wrapPrimReaderArgs()
"GetExcludePrimvarNames",
&UsdMayaPrimReaderArgs::GetExcludePrimvarNames,
return_internal_reference<>())
.def(
"GetExcludePrimvarNamespaces",
&UsdMayaPrimReaderArgs::GetExcludePrimvarNamespaces,
return_internal_reference<>())
.def("GetUseAsAnimationCache", &UsdMayaPrimReaderArgs::GetUseAsAnimationCache);
}

Expand Down
5 changes: 4 additions & 1 deletion lib/usd/translators/meshReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ bool MayaUsdPrimReaderMesh::Read(UsdMayaPrimReaderContext& context)

// assign primvars to mesh
UsdMayaMeshReadUtils::assignPrimvarsToMesh(
mesh, meshRead.meshObject(), _GetArgs().GetExcludePrimvarNames());
mesh,
meshRead.meshObject(),
_GetArgs().GetExcludePrimvarNames(),
_GetArgs().GetExcludePrimvarNamespaces());

// assign invisible faces
UsdMayaMeshReadUtils::assignInvisibleFaces(mesh, meshRead.meshObject());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def Xform "UsdImportColorSetsTest" (
float[] primvars:ExcludeMeNot = [.5] (
interpolation = "constant"
)
float[] primvars:ExcludeMeNamespace:ExcludeMeToo:testExclude = [.5] (
interpolation = "constant"
)
float[] primvars:ExcludeMeNotNamespace:ExcludeMeNotEither:testExclude = [.5] (
interpolation = "constant"
)
int[] primvars:FaceColor_Full_kAlpha:indices = [0, 1, 2, 3, 4, 5]
color3f[] primvars:FaceColor_Full_kRGB = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 1, 0), (1, 0, 1), (0, 1, 1)] (
interpolation = "uniform"
Expand Down
9 changes: 8 additions & 1 deletion test/lib/usd/translators/testUsdImportColorSets.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def setUpClass(cls):

usdFile = os.path.join(inputPath, "UsdImportColorSetsTest", "UsdImportColorSetsTest.usda")
cmds.usdImport(file=usdFile, shadingMode=[['none', 'default'], ],
excludePrimvar='ExcludeMe')
excludePrimvar='ExcludeMe',excludePrimvarNamespace="ExcludeMeNamespace:ExcludeMeToo")

def _GetMayaMesh(self, meshName):
selectionList = OpenMaya.MSelectionList()
Expand Down Expand Up @@ -596,6 +596,13 @@ def testExcludePrimvars(self):
self.assertNotIn("ExcludeMe", colorSets)
self.assertIn("ExcludeMeNot", colorSets)

def testExcludePrimvarNameSpaces(self):
"""Tests excluding primvars when importing color sets."""
mayaCubeMesh = self._GetMayaMesh('ColorSetsCubeShape')
colorSets = mayaCubeMesh.getColorSetNames()
self.assertNotIn("ExcludeMeNamespace:ExcludeMeToo:testExclude", colorSets)
self.assertIn("ExcludeMeNotNamespace:ExcludeMeNotEither:testExclude", colorSets)


if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit 785f636

Please sign in to comment.