diff --git a/pxr/usd/usd/apiSchemaBase.cpp b/pxr/usd/usd/apiSchemaBase.cpp index 35de4295e9..9a629b584a 100644 --- a/pxr/usd/usd/apiSchemaBase.cpp +++ b/pxr/usd/usd/apiSchemaBase.cpp @@ -102,6 +102,30 @@ PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE +/* static */ +TfTokenVector +UsdAPISchemaBase::_GetMultipleApplyInstanceNames(const UsdPrim &prim, + const TfType &schemaType) +{ + TfTokenVector instanceNames; + + auto appliedSchemas = prim.GetAppliedSchemas(); + if (appliedSchemas.empty()) { + return instanceNames; + } + + TfToken schemaTypeName = UsdSchemaRegistry::GetAPISchemaTypeName(schemaType); + + for (const auto &appliedSchema : appliedSchemas) { + std::pair typeNameAndInstance = + UsdSchemaRegistry::GetTypeNameAndInstance(appliedSchema); + if (typeNameAndInstance.first == schemaTypeName) { + instanceNames.emplace_back(typeNameAndInstance.second); + } + } + + return instanceNames; +} /* virtual */ bool diff --git a/pxr/usd/usd/apiSchemaBase.h b/pxr/usd/usd/apiSchemaBase.h index 752d5cdcf2..f1d264bb71 100644 --- a/pxr/usd/usd/apiSchemaBase.h +++ b/pxr/usd/usd/apiSchemaBase.h @@ -209,6 +209,11 @@ class UsdAPISchemaBase : public UsdSchemaBase return _instanceName; } + /// Returns a vector of names of API schema objects belonging to a + /// multiple-apply API schema applied to a given prim. + static TfTokenVector _GetMultipleApplyInstanceNames(const UsdPrim &prim, + const TfType &schemaType); + protected: /// Check whether this APISchema object is valid for the currently held /// prim. diff --git a/pxr/usd/usd/codegenTemplates/schemaClass.cpp b/pxr/usd/usd/codegenTemplates/schemaClass.cpp index 5d274b6ce9..bb0a41b371 100644 --- a/pxr/usd/usd/codegenTemplates/schemaClass.cpp +++ b/pxr/usd/usd/codegenTemplates/schemaClass.cpp @@ -94,6 +94,20 @@ TF_DEFINE_PRIVATE_TOKENS( return {{ cls.cppClassName }}(prim, name); } +/* static */ +std::vector<{{ cls.cppClassName }}> +{{ cls.cppClassName }}::GetAll(const UsdPrim &prim) +{ + std::vector<{{ cls.cppClassName }}> schemas; + + for (const auto &schemaName : + UsdAPISchemaBase::_GetMultipleApplyInstanceNames(prim, _GetStaticTfType())) { + schemas.emplace_back(prim, schemaName); + } + + return schemas; +} + {% endif %} {% endif %} {% if cls.isConcrete %} diff --git a/pxr/usd/usd/codegenTemplates/schemaClass.h b/pxr/usd/usd/codegenTemplates/schemaClass.h index 82dd13e5b6..45dfd1bd55 100644 --- a/pxr/usd/usd/codegenTemplates/schemaClass.h +++ b/pxr/usd/usd/codegenTemplates/schemaClass.h @@ -194,6 +194,13 @@ class {{ cls.cppClassName }} : public {{ cls.parentCppClassName }} {% endif -%} static {{ cls.cppClassName }} Get(const UsdPrim &prim, const TfToken &name); + + /// Return a vector of {{ cls.cppClassName }} holding the prim \p prim. + {% if useExportAPI -%} + {{ Upper(libraryName) }}_API + {% endif -%} + static std::vector<{{ cls.cppClassName }}> + GetAll(const UsdPrim &prim); {% endif %} {% endif %} diff --git a/pxr/usd/usd/codegenTemplates/wrapSchemaClass.cpp b/pxr/usd/usd/codegenTemplates/wrapSchemaClass.cpp index 2a2d17b390..1075d2cc21 100644 --- a/pxr/usd/usd/codegenTemplates/wrapSchemaClass.cpp +++ b/pxr/usd/usd/codegenTemplates/wrapSchemaClass.cpp @@ -169,6 +169,15 @@ void wrap{{ cls.cppClassName }}() {% endif %} .staticmethod("Get") {% endif %} +{% if cls.isMultipleApply %} + + .def("GetAll", + (std::vector<{{ cls.cppClassName }}>(*)(const UsdPrim &prim)) + &This::GetAll, + arg("prim"), + return_value_policy()) + .staticmethod("GetAll") +{% endif %} {% if cls.isConcrete %} .def("Define", &This::Define, (arg("stage"), arg("path"))) diff --git a/pxr/usd/usd/collectionAPI.cpp b/pxr/usd/usd/collectionAPI.cpp index 4892490819..b5251d18e5 100644 --- a/pxr/usd/usd/collectionAPI.cpp +++ b/pxr/usd/usd/collectionAPI.cpp @@ -72,6 +72,20 @@ UsdCollectionAPI::Get(const UsdPrim &prim, const TfToken &name) return UsdCollectionAPI(prim, name); } +/* static */ +std::vector +UsdCollectionAPI::GetAll(const UsdPrim &prim) +{ + std::vector schemas; + + for (const auto &schemaName : + UsdAPISchemaBase::_GetMultipleApplyInstanceNames(prim, _GetStaticTfType())) { + schemas.emplace_back(prim, schemaName); + } + + return schemas; +} + /* static */ bool diff --git a/pxr/usd/usd/collectionAPI.h b/pxr/usd/usd/collectionAPI.h index ca76458eae..888cd007d4 100644 --- a/pxr/usd/usd/collectionAPI.h +++ b/pxr/usd/usd/collectionAPI.h @@ -229,6 +229,11 @@ class UsdCollectionAPI : public UsdAPISchemaBase static UsdCollectionAPI Get(const UsdPrim &prim, const TfToken &name); + /// Return a vector of UsdCollectionAPI holding the prim \p prim. + USD_API + static std::vector + GetAll(const UsdPrim &prim); + /// Checks if the given name \p baseName is the base name of a property /// of CollectionAPI. USD_API @@ -424,7 +429,8 @@ class UsdCollectionAPI : public UsdAPISchemaBase static UsdCollectionAPI GetCollection(const UsdPrim &prim, const TfToken &name); - /// Returns all the named collections on the given USD prim. + /// Returns all the named collections on the given USD prim. + /// \deprecated Use GetAll(prim) instead. USD_API static std::vector GetAllCollections(const UsdPrim &prim); diff --git a/pxr/usd/usd/testenv/testUsdCollectionAPI.py b/pxr/usd/usd/testenv/testUsdCollectionAPI.py index 3a95f9fe99..7fecb5faca 100644 --- a/pxr/usd/usd/testenv/testUsdCollectionAPI.py +++ b/pxr/usd/usd/testenv/testUsdCollectionAPI.py @@ -582,7 +582,7 @@ def test_CollectionEquivalence(self): # ends up equivalent. # Get all collections on the root test prim - collections = Usd.CollectionAPI.GetAllCollections(testPrim) + collections = Usd.CollectionAPI.GetAll(testPrim) self.assertTrue(len(collections) > 1) # Each of their membership queries should be equal to itself, diff --git a/pxr/usd/usd/wrapCollectionAPI.cpp b/pxr/usd/usd/wrapCollectionAPI.cpp index 4bbb9fe91c..d008d2226a 100644 --- a/pxr/usd/usd/wrapCollectionAPI.cpp +++ b/pxr/usd/usd/wrapCollectionAPI.cpp @@ -124,6 +124,13 @@ void wrapUsdCollectionAPI() (arg("prim"), arg("name"))) .staticmethod("Get") + .def("GetAll", + (std::vector(*)(const UsdPrim &prim)) + &This::GetAll, + arg("prim"), + return_value_policy()) + .staticmethod("GetAll") + .def("CanApply", &_WrapCanApply, (arg("prim"), arg("name"))) .staticmethod("CanApply") diff --git a/pxr/usd/usdPhysics/driveAPI.cpp b/pxr/usd/usdPhysics/driveAPI.cpp index 492e3f4fe7..6855ff3de5 100644 --- a/pxr/usd/usdPhysics/driveAPI.cpp +++ b/pxr/usd/usdPhysics/driveAPI.cpp @@ -72,6 +72,20 @@ UsdPhysicsDriveAPI::Get(const UsdPrim &prim, const TfToken &name) return UsdPhysicsDriveAPI(prim, name); } +/* static */ +std::vector +UsdPhysicsDriveAPI::GetAll(const UsdPrim &prim) +{ + std::vector schemas; + + for (const auto &schemaName : + UsdAPISchemaBase::_GetMultipleApplyInstanceNames(prim, _GetStaticTfType())) { + schemas.emplace_back(prim, schemaName); + } + + return schemas; +} + /* static */ bool diff --git a/pxr/usd/usdPhysics/driveAPI.h b/pxr/usd/usdPhysics/driveAPI.h index e6d2206eda..119cfb0b99 100644 --- a/pxr/usd/usdPhysics/driveAPI.h +++ b/pxr/usd/usdPhysics/driveAPI.h @@ -147,6 +147,11 @@ class UsdPhysicsDriveAPI : public UsdAPISchemaBase static UsdPhysicsDriveAPI Get(const UsdPrim &prim, const TfToken &name); + /// Return a vector of UsdPhysicsDriveAPI holding the prim \p prim. + USDPHYSICS_API + static std::vector + GetAll(const UsdPrim &prim); + /// Checks if the given name \p baseName is the base name of a property /// of PhysicsDriveAPI. USDPHYSICS_API diff --git a/pxr/usd/usdPhysics/limitAPI.cpp b/pxr/usd/usdPhysics/limitAPI.cpp index b2056e88a0..472f813a03 100644 --- a/pxr/usd/usdPhysics/limitAPI.cpp +++ b/pxr/usd/usdPhysics/limitAPI.cpp @@ -72,6 +72,20 @@ UsdPhysicsLimitAPI::Get(const UsdPrim &prim, const TfToken &name) return UsdPhysicsLimitAPI(prim, name); } +/* static */ +std::vector +UsdPhysicsLimitAPI::GetAll(const UsdPrim &prim) +{ + std::vector schemas; + + for (const auto &schemaName : + UsdAPISchemaBase::_GetMultipleApplyInstanceNames(prim, _GetStaticTfType())) { + schemas.emplace_back(prim, schemaName); + } + + return schemas; +} + /* static */ bool diff --git a/pxr/usd/usdPhysics/limitAPI.h b/pxr/usd/usdPhysics/limitAPI.h index 0d5c7e389b..a33cc6ee23 100644 --- a/pxr/usd/usdPhysics/limitAPI.h +++ b/pxr/usd/usdPhysics/limitAPI.h @@ -140,6 +140,11 @@ class UsdPhysicsLimitAPI : public UsdAPISchemaBase static UsdPhysicsLimitAPI Get(const UsdPrim &prim, const TfToken &name); + /// Return a vector of UsdPhysicsLimitAPI holding the prim \p prim. + USDPHYSICS_API + static std::vector + GetAll(const UsdPrim &prim); + /// Checks if the given name \p baseName is the base name of a property /// of PhysicsLimitAPI. USDPHYSICS_API diff --git a/pxr/usd/usdPhysics/wrapDriveAPI.cpp b/pxr/usd/usdPhysics/wrapDriveAPI.cpp index 03c156413d..bd94fb1501 100644 --- a/pxr/usd/usdPhysics/wrapDriveAPI.cpp +++ b/pxr/usd/usdPhysics/wrapDriveAPI.cpp @@ -152,6 +152,13 @@ void wrapUsdPhysicsDriveAPI() (arg("prim"), arg("name"))) .staticmethod("Get") + .def("GetAll", + (std::vector(*)(const UsdPrim &prim)) + &This::GetAll, + arg("prim"), + return_value_policy()) + .staticmethod("GetAll") + .def("CanApply", &_WrapCanApply, (arg("prim"), arg("name"))) .staticmethod("CanApply") diff --git a/pxr/usd/usdPhysics/wrapLimitAPI.cpp b/pxr/usd/usdPhysics/wrapLimitAPI.cpp index d2844066e5..96a4550463 100644 --- a/pxr/usd/usdPhysics/wrapLimitAPI.cpp +++ b/pxr/usd/usdPhysics/wrapLimitAPI.cpp @@ -124,6 +124,13 @@ void wrapUsdPhysicsLimitAPI() (arg("prim"), arg("name"))) .staticmethod("Get") + .def("GetAll", + (std::vector(*)(const UsdPrim &prim)) + &This::GetAll, + arg("prim"), + return_value_policy()) + .staticmethod("GetAll") + .def("CanApply", &_WrapCanApply, (arg("prim"), arg("name"))) .staticmethod("CanApply")