From c31602484bb35b12c217c1bb21d579921433d3ec Mon Sep 17 00:00:00 2001 From: Samuel Liu Date: Tue, 30 May 2023 03:07:26 -0400 Subject: [PATCH 1/5] Add new import arg excludePrimVarNamespaces --- lib/mayaUsd/fileio/jobs/jobArgs.cpp | 2 ++ lib/mayaUsd/fileio/jobs/jobArgs.h | 2 ++ lib/mayaUsd/fileio/primReaderArgs.cpp | 5 +++++ lib/mayaUsd/fileio/primReaderArgs.h | 3 +++ lib/mayaUsd/fileio/utils/meshReadUtils.cpp | 3 ++- lib/mayaUsd/fileio/utils/meshReadUtils.h | 3 ++- lib/mayaUsd/python/wrapPrimReader.cpp | 9 +++++++++ lib/usd/translators/meshReader.cpp | 2 +- 8 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/mayaUsd/fileio/jobs/jobArgs.cpp b/lib/mayaUsd/fileio/jobs/jobArgs.cpp index 66b7566f01..3054a66ffd 100644 --- a/lib/mayaUsd/fileio/jobs/jobArgs.cpp +++ b/lib/mayaUsd/fileio/jobs/jobArgs.cpp @@ -1097,6 +1097,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)) diff --git a/lib/mayaUsd/fileio/jobs/jobArgs.h b/lib/mayaUsd/fileio/jobs/jobArgs.h index 023e34142b..3ae5fc4a4b 100644 --- a/lib/mayaUsd/fileio/jobs/jobArgs.h +++ b/lib/mayaUsd/fileio/jobs/jobArgs.h @@ -139,6 +139,7 @@ TF_DECLARE_PUBLIC_TOKENS( (apiSchema) \ (assemblyRep) \ (excludePrimvar) \ + (excludePrimvarNamespace) \ (jobContext) \ (metadata) \ (shadingMode) \ @@ -322,6 +323,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; diff --git a/lib/mayaUsd/fileio/primReaderArgs.cpp b/lib/mayaUsd/fileio/primReaderArgs.cpp index 4ee7ce8081..f00ec094c5 100644 --- a/lib/mayaUsd/fileio/primReaderArgs.cpp +++ b/lib/mayaUsd/fileio/primReaderArgs.cpp @@ -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 diff --git a/lib/mayaUsd/fileio/primReaderArgs.h b/lib/mayaUsd/fileio/primReaderArgs.h index bab9a5ce65..d6649f2f0d 100644 --- a/lib/mayaUsd/fileio/primReaderArgs.h +++ b/lib/mayaUsd/fileio/primReaderArgs.h @@ -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; diff --git a/lib/mayaUsd/fileio/utils/meshReadUtils.cpp b/lib/mayaUsd/fileio/utils/meshReadUtils.cpp index 658de703e2..466346e79f 100644 --- a/lib/mayaUsd/fileio/utils/meshReadUtils.cpp +++ b/lib/mayaUsd/fileio/utils/meshReadUtils.cpp @@ -590,7 +590,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; diff --git a/lib/mayaUsd/fileio/utils/meshReadUtils.h b/lib/mayaUsd/fileio/utils/meshReadUtils.h index 36e0e92808..a6a3feeeb9 100644 --- a/lib/mayaUsd/fileio/utils/meshReadUtils.h +++ b/lib/mayaUsd/fileio/utils/meshReadUtils.h @@ -69,7 +69,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); diff --git a/lib/mayaUsd/python/wrapPrimReader.cpp b/lib/mayaUsd/python/wrapPrimReader.cpp index 0475221777..7201035ae5 100644 --- a/lib/mayaUsd/python/wrapPrimReader.cpp +++ b/lib/mayaUsd/python/wrapPrimReader.cpp @@ -437,6 +437,11 @@ void wrapJobImportArgs() make_getter( &UsdMayaJobImportArgs::excludePrimvarNames, return_value_policy())) + .add_property( + "excludePrimvarNamespaces", + make_getter( + &UsdMayaJobImportArgs::excludePrimvarNamespaces, + return_value_policy())) .def_readonly("importInstances", &UsdMayaJobImportArgs::importInstances) .def_readonly("importUSDZTextures", &UsdMayaJobImportArgs::importUSDZTextures) .def_readonly( @@ -496,6 +501,10 @@ void wrapPrimReaderArgs() "GetExcludePrimvarNames", &UsdMayaPrimReaderArgs::GetExcludePrimvarNames, return_internal_reference<>()) + .def( + "GetExcludePrimvarNamespaces", + &UsdMayaPrimReaderArgs::GetExcludePrimvarNamespaces, + return_internal_reference<>()) .def("GetUseAsAnimationCache", &UsdMayaPrimReaderArgs::GetUseAsAnimationCache); } diff --git a/lib/usd/translators/meshReader.cpp b/lib/usd/translators/meshReader.cpp index d3935330c0..b27fd8c7a7 100644 --- a/lib/usd/translators/meshReader.cpp +++ b/lib/usd/translators/meshReader.cpp @@ -126,7 +126,7 @@ 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()); From daad1e39f61e4fc16ac35c8be3de99bbb9da6646 Mon Sep 17 00:00:00 2001 From: Samuel Liu Date: Fri, 2 Jun 2023 00:55:55 -0400 Subject: [PATCH 2/5] Add ExcludePrimvarNamespace as a import flag --- lib/mayaUsd/commands/baseImportCommand.cpp | 5 +++++ lib/mayaUsd/commands/baseImportCommand.h | 1 + lib/mayaUsd/fileio/jobs/jobArgs.cpp | 2 ++ lib/mayaUsd/fileio/utils/meshReadUtils.cpp | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/lib/mayaUsd/commands/baseImportCommand.cpp b/lib/mayaUsd/commands/baseImportCommand.cpp index ae08bf54ce..548a31a256 100644 --- a/lib/mayaUsd/commands/baseImportCommand.cpp +++ b/lib/mayaUsd/commands/baseImportCommand.cpp @@ -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(), diff --git a/lib/mayaUsd/commands/baseImportCommand.h b/lib/mayaUsd/commands/baseImportCommand.h index 3dbb9056cb..6f57cd3704 100644 --- a/lib/mayaUsd/commands/baseImportCommand.h +++ b/lib/mayaUsd/commands/baseImportCommand.h @@ -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"; diff --git a/lib/mayaUsd/fileio/jobs/jobArgs.cpp b/lib/mayaUsd/fileio/jobs/jobArgs.cpp index 3054a66ffd..9eaf19dc9e 100644 --- a/lib/mayaUsd/fileio/jobs/jobArgs.cpp +++ b/lib/mayaUsd/fileio/jobs/jobArgs.cpp @@ -1157,6 +1157,7 @@ const VtDictionary& UsdMayaJobImportArgs::GetDefaultDictionary() = UsdMayaJobImportArgsTokens->Collapsed.GetString(); d[UsdMayaJobImportArgsTokens->apiSchema] = std::vector(); d[UsdMayaJobImportArgsTokens->excludePrimvar] = std::vector(); + d[UsdMayaJobImportArgsTokens->excludePrimvarNamespace] = std::vector(); d[UsdMayaJobImportArgsTokens->jobContext] = std::vector(); d[UsdMayaJobImportArgsTokens->metadata] = std::vector({ VtValue(SdfFieldKeys->Hidden.GetString()), @@ -1239,6 +1240,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; diff --git a/lib/mayaUsd/fileio/utils/meshReadUtils.cpp b/lib/mayaUsd/fileio/utils/meshReadUtils.cpp index 466346e79f..1cafc594c2 100644 --- a/lib/mayaUsd/fileio/utils/meshReadUtils.cpp +++ b/lib/mayaUsd/fileio/utils/meshReadUtils.cpp @@ -616,6 +616,24 @@ void UsdMayaMeshReadUtils::assignPrimvarsToMesh( continue; } + // Exclude primvars if they match with the exclude namespace + 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 From fdb75f24cecd816619be79ff9c16e3af09946355 Mon Sep 17 00:00:00 2001 From: Samuel Liu Date: Wed, 12 Jul 2023 14:39:52 -0400 Subject: [PATCH 3/5] Add unit test case for excludePrimvarNameSpace --- .../UsdImportColorSetsTest/UsdImportColorSetsTest.usda | 6 ++++++ test/lib/usd/translators/testUsdImportColorSets.py | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/test/lib/usd/translators/UsdImportColorSetsTest/UsdImportColorSetsTest.usda b/test/lib/usd/translators/UsdImportColorSetsTest/UsdImportColorSetsTest.usda index 0007169833..3c62807bfa 100644 --- a/test/lib/usd/translators/UsdImportColorSetsTest/UsdImportColorSetsTest.usda +++ b/test/lib/usd/translators/UsdImportColorSetsTest/UsdImportColorSetsTest.usda @@ -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" diff --git a/test/lib/usd/translators/testUsdImportColorSets.py b/test/lib/usd/translators/testUsdImportColorSets.py index a81a052366..5c4c17de3e 100644 --- a/test/lib/usd/translators/testUsdImportColorSets.py +++ b/test/lib/usd/translators/testUsdImportColorSets.py @@ -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() @@ -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) From a64b23e841521098acdb973239e68c93e51bbbb1 Mon Sep 17 00:00:00 2001 From: Samuel Liu Date: Wed, 12 Jul 2023 14:48:24 -0400 Subject: [PATCH 4/5] Clang format fix --- lib/mayaUsd/fileio/utils/meshReadUtils.cpp | 1 - lib/usd/translators/meshReader.cpp | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/mayaUsd/fileio/utils/meshReadUtils.cpp b/lib/mayaUsd/fileio/utils/meshReadUtils.cpp index 1cafc594c2..435166f901 100644 --- a/lib/mayaUsd/fileio/utils/meshReadUtils.cpp +++ b/lib/mayaUsd/fileio/utils/meshReadUtils.cpp @@ -628,7 +628,6 @@ void UsdMayaMeshReadUtils::assignPrimvarsToMesh( skipPrimvar = true; break; } - } if (skipPrimvar) { continue; diff --git a/lib/usd/translators/meshReader.cpp b/lib/usd/translators/meshReader.cpp index b27fd8c7a7..87e7e5a0b7 100644 --- a/lib/usd/translators/meshReader.cpp +++ b/lib/usd/translators/meshReader.cpp @@ -126,7 +126,10 @@ bool MayaUsdPrimReaderMesh::Read(UsdMayaPrimReaderContext& context) // assign primvars to mesh UsdMayaMeshReadUtils::assignPrimvarsToMesh( - mesh, meshRead.meshObject(), _GetArgs().GetExcludePrimvarNames(), _GetArgs().GetExcludePrimvarNamespaces()); + mesh, + meshRead.meshObject(), + _GetArgs().GetExcludePrimvarNames(), + _GetArgs().GetExcludePrimvarNamespaces()); // assign invisible faces UsdMayaMeshReadUtils::assignInvisibleFaces(mesh, meshRead.meshObject()); From 3725c921c38f6ca35f97094c1ced7632874ad389 Mon Sep 17 00:00:00 2001 From: Samuel Liu Date: Thu, 13 Jul 2023 14:53:28 -0400 Subject: [PATCH 5/5] Check for primvar in namespace before checking exclude namespace --- lib/mayaUsd/fileio/utils/meshReadUtils.cpp | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/mayaUsd/fileio/utils/meshReadUtils.cpp b/lib/mayaUsd/fileio/utils/meshReadUtils.cpp index 435166f901..15945dc251 100644 --- a/lib/mayaUsd/fileio/utils/meshReadUtils.cpp +++ b/lib/mayaUsd/fileio/utils/meshReadUtils.cpp @@ -616,21 +616,23 @@ void UsdMayaMeshReadUtils::assignPrimvarsToMesh( continue; } - // Exclude primvars if they match with the exclude namespace - 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; + // 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 (skipPrimvar) { - continue; } // If the primvar is called either displayColor or displayOpacity check