24 #ifndef PXR_USD_USD_OBJECT_H 25 #define PXR_USD_USD_OBJECT_H 30 #include "pxr/usd/usd/api.h" 35 #include "pxr/usd/sdf/abstractData.h" 36 #include "pxr/usd/sdf/path.h" 38 #include <type_traits> 40 PXR_NAMESPACE_OPEN_SCOPE
67 template <UsdObjType Type>
68 struct Const {
static const UsdObjType Value = Type; };
69 template <
class T>
struct GetObjType {
70 static_assert(std::is_base_of<UsdObject, T>::value,
71 "Type T must be a subclass of UsdObject.");
73 template <>
struct GetObjType<
UsdObject> : Const<UsdTypeObject> {};
74 template <>
struct GetObjType<
UsdPrim> : Const<UsdTypePrim> {};
75 template <>
struct GetObjType<
UsdProperty> : Const<UsdTypeProperty> {};
76 template <>
struct GetObjType<
UsdAttribute> : Const<UsdTypeAttribute> {};
77 template <>
struct GetObjType<
UsdRelationship> : Const<UsdTypeRelationship> {};
85 return (baseType == UsdTypeObject) || (baseType == subType) ||
86 (baseType == UsdTypeProperty && subType > UsdTypeProperty);
100 return type == UsdTypePrim ||
101 type == UsdTypeAttribute ||
102 type == UsdTypeRelationship;
144 if (_type == UsdTypePrim)
147 return (_type == UsdTypeAttribute &&
148 specType == SdfSpecTypeAttribute) ||
149 (_type == UsdTypeRelationship &&
150 specType == SdfSpecTypeRelationship);
154 explicit operator bool()
const {
163 return lhs._type == rhs._type &&
164 lhs._prim == rhs._prim &&
165 lhs._proxyPrimPath == rhs._proxyPrimPath &&
166 lhs._propName == rhs._propName;
172 return !(lhs == rhs);
184 friend size_t hash_value(
const UsdObject &obj);
196 if (!_proxyPrimPath.
IsEmpty()) {
197 return _type == UsdTypePrim ?
200 else if (Usd_PrimDataConstPtr p = get_pointer(_prim)) {
201 return _type == UsdTypePrim ?
202 p->GetPath() : p->GetPath().AppendProperty(_propName);
211 if (!_proxyPrimPath.
IsEmpty()) {
212 return _proxyPrimPath;
214 else if (Usd_PrimDataConstPtr p = get_pointer(_prim)) {
239 return Is<T>() ? T(_type, _prim, _proxyPrimPath, _propName) : T();
249 static_assert(std::is_base_of<UsdObject, T>::value,
250 "Provided type T must derive from or be UsdObject");
362 const TfToken& key,
const TfToken &keyPath,
const T& value)
const;
658 static char GetNamespaceDelimiter()
659 {
return SdfPathTokens->namespaceDelimiter.GetText()[0]; }
663 bool _GetMetadataImpl(
const TfToken& key,
667 bool _GetMetadataImpl(
const TfToken& key,
672 bool _SetMetadataImpl(
const TfToken& key,
676 bool _SetMetadataImpl(
const TfToken& key,
681 template <
class Derived>
struct _Null {};
684 template <
class Derived>
686 : _type(_Detail::GetObjType<Derived>::Value) {}
689 UsdObject(
const Usd_PrimDataHandle &prim,
693 , _proxyPrimPath(proxyPrimPath)
695 TF_VERIFY(!_prim || _prim->GetPath() != _proxyPrimPath);
700 const Usd_PrimDataHandle &prim,
705 , _proxyPrimPath(proxyPrimPath)
706 , _propName(propName)
708 TF_VERIFY(!_prim || _prim->GetPath() != _proxyPrimPath);
712 UsdStage *_GetStage()
const {
return _prim->GetStage(); }
719 const Usd_PrimDataHandle &_Prim()
const {
return _prim; }
722 const TfToken &_PropName()
const {
return _propName; }
725 const SdfPath &_ProxyPrimPath()
const {
return _proxyPrimPath; }
729 std::string _GetObjectDescription(
const std::string &preface)
const;
738 Usd_PrimDataHandle _prim;
749 return _GetMetadataImpl(key, value);
757 return _SetMetadataImpl(key, value);
760 template <
typename T>
767 return _GetMetadataImpl(key, value, keyPath);
770 template <
typename T>
775 const T& value)
const 777 return _SetMetadataImpl(key, value, keyPath);
782 UsdObject::_GetMetadataImpl(
const TfToken& key,
786 return _GetStage()->_GetMetadata(
787 *
this, key, keyPath,
true, value);
792 UsdObject::_SetMetadataImpl(
const TfToken& key,
796 return _GetStage()->_SetMetadata(*
this, key, keyPath, value);
799 PXR_NAMESPACE_CLOSE_SCOPE
801 #endif //PXR_USD_USD_OBJECT_H USD_API void ClearCustomDataByKey(const TfToken &keyPath) const
Clear the authored opinion identified by keyPath in this object's customData dictionary at the curren...
bool SetMetadata(const TfToken &key, const T &value) const
Set metadatum key's value to value.
T As() const
Convert this UsdObject to another object type T if possible.
UsdObjType
Enum values to represent the various Usd object types.
USD_API bool SetDocumentation(const std::string &doc) const
Sets this object's documentation (metadata). Returns true on success.
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
USD_API bool ClearHidden() const
Clears the opinion for "Hidden" at the current EditTarget.
USD_API bool HasCustomData() const
Return true if there are any authored or fallback opinions for this object's customData dictionary,...
USD_API UsdStageWeakPtr GetStage() const
Return the stage that owns the object, and to whose state and lifetime this object's validity is tied...
USD_API bool SetDisplayName(const std::string &name) const
Sets this object's display name (metadata).
USD_API bool HasCustomDataKey(const TfToken &keyPath) const
Return true if there are any authored or fallback opinions for the element identified by keyPath in t...
bool UsdIsSubtype(UsdObjType baseType, UsdObjType subType)
Return true if subType is the same as or a subtype of baseType, false otherwise.
A map with string keys and VtValue values.
USD_API std::string GetDisplayName() const
Return this object's display name (metadata).
USD_API bool SetHidden(bool hidden) const
Sets the value of the 'hidden' metadata field.
friend bool operator<(const UsdObject &lhs, const UsdObject &rhs)
Less-than operator.
USD_API bool ClearDocumentation() const
Clears this object's documentation (metadata) in the current EditTarget (only).
The outermost container for scene description, which owns and presents composed prims as a scenegraph...
USD_API bool HasAuthoredCustomData() const
Return true if there are any authored opinions (excluding fallback) for this object's customData dict...
USD_API bool HasAuthoredMetadataDictKey(const TfToken &key, const TfToken &keyPath) const
Return true if there exists any authored opinion (excluding fallbacks) for key and keyPath.
bool SetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, const T &value) const
Author value to the field identified by key and keyPath at the current EditTarget.
USD_API void SetAssetInfo(const VtDictionary &customData) const
Author this object's assetInfo dictionary to assetInfo at the current EditTarget.
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
USD_API void SetCustomDataByKey(const TfToken &keyPath, const VtValue &value) const
Author the element identified by keyPath in this object's customData dictionary at the current EditTa...
USD_API bool HasAssetInfoKey(const TfToken &keyPath) const
Return true if there are any authored or fallback opinions for the element identified by keyPath in t...
USD_API bool ClearMetadataByDictKey(const TfToken &key, const TfToken &keyPath) const
Clear any authored value identified by key and keyPath at the current EditTarget.
bool UsdIsConcrete(UsdObjType type)
Return true if type is a concrete object type, namely one of Prim, Attribute, or Relationship.
USD_API std::string GetDocumentation() const
Return this object's documentation (metadata).
USD_API void SetAssetInfoByKey(const TfToken &keyPath, const VtValue &value) const
Author the element identified by keyPath in this object's assetInfo dictionary at the current EditTar...
USD_API VtValue GetCustomDataByKey(const TfToken &keyPath) const
Return the element identified by keyPath in this object's composed customData dictionary.
Token for efficient comparison, assignment, and hashing of known strings.
USD_API bool ClearMetadata(const TfToken &key) const
Clears the authored key's value at the current EditTarget, returning false on error.
USD_API void ClearAssetInfoByKey(const TfToken &keyPath) const
Clear the authored opinion identified by keyPath in this object's assetInfo dictionary at the current...
USD_API bool ClearDisplayName() const
Clears this object's display name (metadata) in the current EditTarget (only).
USD_API VtValue GetAssetInfoByKey(const TfToken &keyPath) const
Return the element identified by keyPath in this object's composed assetInfo dictionary.
USD_API VtDictionary GetAssetInfo() const
Return this object's composed assetInfo dictionary.
USD_API bool HasMetadataDictKey(const TfToken &key, const TfToken &keyPath) const
Return true if there exists any authored or fallback opinion for key and keyPath.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
USD_API void ClearAssetInfo() const
Clear the authored opinion for this object's assetInfo dictionary at the current EditTarget.
USD_API bool IsHidden() const
Gets the value of the 'hidden' metadata field, false if not authored.
Base class for Usd scenegraph objects, providing common API.
USD_API std::string GetDescription() const
Return a string that provides a brief summary description of the object.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
USD_API bool HasAuthoredAssetInfo() const
Return true if there are any authored opinions (excluding fallback) for this object's assetInfo dicti...
SDF_API const TfToken & GetNameToken() const
Returns the name of the prim, property or relational attribute identified by the path,...
A path value used to locate objects in layers or scenegraphs.
bool GetMetadata(const TfToken &key, T *value) const
Resolve the requested metadatum named key into value, returning true on success.
USD_API bool HasAuthoredCustomDataKey(const TfToken &keyPath) const
Return true if there are any authored opinions (excluding fallback) for the element identified by key...
USD_API VtDictionary GetCustomData() const
Return this object's composed customData dictionary.
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
USD_API bool HasMetadata(const TfToken &key) const
Returns true if the key has a meaningful value, that is, if GetMetadata() will provide a value,...
USD_API bool HasAssetInfo() const
Return true if there are any authored or fallback opinions for this object's assetInfo dictionary,...
bool UsdIsConvertible(UsdObjType from, UsdObjType to)
Return true if from is convertible to to, false otherwise.
Base class for UsdAttribute and UsdRelationship scenegraph objects.
SdfSpecType
An enum that specifies the type of an object.
USD_API UsdMetadataValueMap GetAllMetadata() const
Resolve and return all metadata (including both authored and fallback values) on this object,...
const SdfPath & GetPrimPath() const
Return this object's path if this object is a prim, otherwise this object's nearest owning prim's pat...
const TfToken & GetName() const
Return the full name of this object, i.e.
UsdObject()
Default constructor produces an invalid object.
SDF_API SdfPath AppendProperty(TfToken const &propName) const
Creates a path by appending an element for propName to this path.
friend bool operator==(const UsdObject &lhs, const UsdObject &rhs)
Equality comparison.
friend bool operator!=(const UsdObject &lhs, const UsdObject &rhs)
Inequality comparison.
USD_API bool HasAuthoredAssetInfoKey(const TfToken &keyPath) const
Return true if there are any authored opinions (excluding fallback) for the element identified by key...
USD_API bool HasAuthoredHidden() const
Returns true if hidden was explicitly authored and GetMetadata() will return a meaningful value for H...
USD_API UsdMetadataValueMap GetAllAuthoredMetadata() const
Resolve and return all user-authored metadata on this object, sorted lexicographically.
USD_API bool HasAuthoredDisplayName() const
Returns true if displayName was explicitly authored and GetMetadata() will return a meaningful value ...
bool IsValid() const
Return true if this is a valid object, false otherwise.
USD_API bool HasAuthoredDocumentation() const
Returns true if documentation was explicitly authored and GetMetadata() will return a meaningful valu...
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
static SDF_API const SdfPath & EmptyPath()
The empty path value, equivalent to SdfPath().
bool GetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, T *value) const
Resolve the requested dictionary sub-element keyPath of dictionary-valued metadatum named key into va...
USD_API void ClearCustomData() const
Clear the authored opinion for this object's customData dictionary at the current EditTarget.
UsdPrim GetPrim() const
Return this object if it is a prim, otherwise return this object's nearest owning prim.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
USD_API void SetCustomData(const VtDictionary &customData) const
Author this object's customData dictionary to customData at the current EditTarget.
USD_API bool HasAuthoredMetadata(const TfToken &key) const
Returns true if the key has an authored value, false if no value was authored or the only value avail...
SdfPath GetPath() const
Return the complete scene path to this object on its UsdStage, which may (UsdPrim) or may not (all ot...
bool Is() const
Return true if this object is convertible to T.