7#ifndef PXR_USD_USD_OBJECT_H
8#define PXR_USD_USD_OBJECT_H
13#include "pxr/usd/usd/api.h"
18#include "pxr/usd/sdf/abstractData.h"
19#include "pxr/usd/sdf/path.h"
25PXR_NAMESPACE_OPEN_SCOPE
52template <UsdObjType Type>
53struct Const {
static const UsdObjType Value = Type; };
54template <
class T>
struct GetObjType {
55 static_assert(std::is_base_of<UsdObject, T>::value,
56 "Type T must be a subclass of UsdObject.");
58template <>
struct GetObjType<
UsdObject> : Const<UsdTypeObject> {};
59template <>
struct GetObjType<
UsdPrim> : Const<UsdTypePrim> {};
60template <>
struct GetObjType<
UsdProperty> : Const<UsdTypeProperty> {};
61template <>
struct GetObjType<
UsdAttribute> : Const<UsdTypeAttribute> {};
62template <>
struct GetObjType<
UsdRelationship> : Const<UsdTypeRelationship> {};
70 return (baseType == UsdTypeObject) || (baseType == subType) ||
71 (baseType == UsdTypeProperty && subType > UsdTypeProperty);
85 return type == UsdTypePrim ||
86 type == UsdTypeAttribute ||
87 type == UsdTypeRelationship;
129 if (_type == UsdTypePrim)
132 return (_type == UsdTypeAttribute &&
133 specType == SdfSpecTypeAttribute) ||
134 (_type == UsdTypeRelationship &&
135 specType == SdfSpecTypeRelationship);
139 explicit operator bool()
const {
148 return lhs._type == rhs._type &&
149 lhs._prim == rhs._prim &&
150 lhs._proxyPrimPath == rhs._proxyPrimPath &&
151 lhs._propName == rhs._propName;
157 return !(lhs == rhs);
168 friend size_t hash_value(
const UsdObject &obj) {
173 template <
class HashState>
174 friend void TfHashAppend(HashState &h,
const UsdObject &obj) {
175 h.Append(obj._type, obj._prim, obj._proxyPrimPath, obj._propName);
188 if (!_proxyPrimPath.
IsEmpty()) {
189 return _type == UsdTypePrim ?
192 else if (Usd_PrimDataConstPtr p = get_pointer(_prim)) {
193 return _type == UsdTypePrim ?
194 p->GetPath() : p->GetPath().AppendProperty(_propName);
203 if (!_proxyPrimPath.
IsEmpty()) {
204 return _proxyPrimPath;
206 else if (Usd_PrimDataConstPtr p = get_pointer(_prim)) {
231 return Is<T>() ? T(_type, _prim, _proxyPrimPath, _propName) : T();
241 static_assert(std::is_base_of<UsdObject, T>::value,
242 "Provided type T must derive from or be UsdObject");
354 const TfToken& key,
const TfToken &keyPath,
const T& value)
const;
650 static char GetNamespaceDelimiter()
651 {
return SdfPathTokens->namespaceDelimiter.GetText()[0]; }
655 bool _GetMetadataImpl(
const TfToken& key,
659 bool _GetMetadataImpl(
const TfToken& key,
664 bool _SetMetadataImpl(
const TfToken& key,
668 bool _SetMetadataImpl(
const TfToken& key,
673 template <
class Derived>
struct _Null {};
676 template <
class Derived>
678 : _type(_Detail::GetObjType<Derived>::Value) {}
681 UsdObject(
const Usd_PrimDataHandle &prim,
685 , _proxyPrimPath(proxyPrimPath)
687 TF_VERIFY(!_prim || _prim->GetPath() != _proxyPrimPath);
692 const Usd_PrimDataHandle &prim,
697 , _proxyPrimPath(proxyPrimPath)
698 , _propName(propName)
700 TF_VERIFY(!_prim || _prim->GetPath() != _proxyPrimPath);
704 UsdStage *_GetStage()
const {
return _prim->GetStage(); }
711 const Usd_PrimDataHandle &_Prim()
const {
return _prim; }
714 const TfToken &_PropName()
const {
return _propName; }
717 const SdfPath &_ProxyPrimPath()
const {
return _proxyPrimPath; }
721 std::string _GetObjectDescription(
const std::string &preface)
const;
730 Usd_PrimDataHandle _prim;
741 return _GetMetadataImpl(key, value);
749 return _SetMetadataImpl(key, value);
759 return _GetMetadataImpl(key, value, keyPath);
767 const T& value)
const
769 return _SetMetadataImpl(key, value, keyPath);
774UsdObject::_GetMetadataImpl(
const TfToken& key,
778 return _GetStage()->_GetMetadata(
779 *
this, key, keyPath,
true, value);
784UsdObject::_SetMetadataImpl(
const TfToken& key,
788 return _GetStage()->_SetMetadata(*
this, key, keyPath, value);
791PXR_NAMESPACE_CLOSE_SCOPE
A path value used to locate objects in layers or scenegraphs.
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().
SDF_API const TfToken & GetNameToken() const
Returns the name of the prim, property or relational attribute identified by the path,...
SDF_API SdfPath AppendProperty(TfToken const &propName) const
Creates a path by appending an element for propName to this path.
A user-extensible hashing mechanism for use with runtime hash tables.
Token for efficient comparison, assignment, and hashing of known strings.
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Base class for Usd scenegraph objects, providing common API.
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 bool SetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, const VtValue &value) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API bool SetHidden(bool hidden) const
Sets the value of the 'hidden' metadata field.
bool SetMetadata(const TfToken &key, const T &value) const
Set metadatum key's value to value.
USD_API bool SetDocumentation(const std::string &doc) const
Sets this object's documentation (metadata). Returns true on success.
friend bool operator!=(const UsdObject &lhs, const UsdObject &rhs)
Inequality comparison.
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.
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 bool HasCustomDataKey(const TfToken &keyPath) const
Return true if there are any authored or fallback opinions for the element identified by keyPath in t...
USD_API void ClearCustomData() const
Clear the authored opinion for this object's customData dictionary 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...
UsdObject()
Default constructor produces an invalid object.
USD_API bool GetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, VtValue *value) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API bool ClearDisplayName() const
Clears this object's display name (metadata) in the current EditTarget (only).
UsdPrim GetPrim() const
Return this object if it is a prim, otherwise return this object's nearest owning prim.
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 VtDictionary GetAssetInfo() const
Return this object's composed assetInfo dictionary.
USD_API void ClearCustomDataByKey(const TfToken &keyPath) const
Clear the authored opinion identified by keyPath in this object's customData dictionary at the curren...
USD_API bool ClearHidden() const
Clears the opinion for "Hidden" at the current EditTarget.
USD_API bool HasAuthoredDisplayName() const
Returns true if displayName was explicitly authored and GetMetadata() will return a meaningful value ...
bool Is() const
Return true if this object is convertible to T.
USD_API bool HasAuthoredAssetInfoKey(const TfToken &keyPath) const
Return true if there are any authored opinions (excluding fallback) for the element identified by key...
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 ClearAssetInfo() const
Clear the authored opinion for this object's assetInfo dictionary at the current EditTarget.
friend bool operator==(const UsdObject &lhs, const UsdObject &rhs)
Equality comparison.
USD_API bool SetDisplayName(const std::string &name) const
Sets this object's display name (metadata).
USD_API bool HasAuthoredHidden() const
Returns true if hidden was explicitly authored and GetMetadata() will return a meaningful value for H...
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.
SdfPath GetPath() const
Return the complete scene path to this object on its UsdStage, which may (UsdPrim) or may not (all ot...
const SdfPath & GetPrimPath() const
Return this object's path if this object is a prim, otherwise this object's nearest owning prim's pat...
USD_API VtValue GetCustomDataByKey(const TfToken &keyPath) const
Return the element identified by keyPath in this object's composed customData dictionary.
USD_API std::string GetDescription() const
Return a string that provides a brief summary description of the object.
USD_API bool HasAssetInfo() const
Return true if there are any authored or fallback opinions for this object's assetInfo dictionary,...
T As() const
Convert this UsdObject to another object type T if possible.
USD_API bool IsHidden() const
Gets the value of the 'hidden' metadata field, false if not authored.
USD_API void ClearAssetInfoByKey(const TfToken &keyPath) const
Clear the authored opinion identified by keyPath in this object's assetInfo dictionary at the current...
friend bool operator<(const UsdObject &lhs, const UsdObject &rhs)
Less-than operator.
USD_API bool HasAuthoredDocumentation() const
Returns true if documentation was explicitly authored and GetMetadata() will return a meaningful valu...
USD_API bool ClearDocumentation() const
Clears this object's documentation (metadata) in the current EditTarget (only).
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 bool SetMetadata(const TfToken &key, const VtValue &value) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
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 VtDictionary GetCustomData() const
Return this object's composed customData dictionary.
const TfToken & GetName() const
Return the full name of this object, i.e.
USD_API void SetCustomData(const VtDictionary &customData) const
Author this object's customData dictionary to customData at the current EditTarget.
bool IsValid() const
Return true if this is a valid object, false otherwise.
USD_API UsdMetadataValueMap GetAllAuthoredMetadata() const
Resolve and return all user-authored metadata on this object, sorted lexicographically.
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 void SetAssetInfo(const VtDictionary &customData) const
Author this object's assetInfo dictionary to assetInfo at the current EditTarget.
bool GetMetadata(const TfToken &key, T *value) const
Resolve the requested metadatum named key into value, returning true on success.
USD_API VtValue GetAssetInfoByKey(const TfToken &keyPath) const
Return the element identified by keyPath in this object's composed assetInfo dictionary.
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 HasCustomData() const
Return true if there are any authored or fallback opinions for this object's customData dictionary,...
USD_API bool HasAuthoredAssetInfo() const
Return true if there are any authored opinions (excluding fallback) for this object's assetInfo dicti...
USD_API bool GetMetadata(const TfToken &key, VtValue *value) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API bool ClearMetadata(const TfToken &key) const
Clears the authored key's value at the current EditTarget, returning false on error.
USD_API std::string GetDocumentation() const
Return this object's documentation (metadata).
USD_API UsdMetadataValueMap GetAllMetadata() const
Resolve and return all metadata (including both authored and fallback values) on this object,...
USD_API bool ClearMetadataByDictKey(const TfToken &key, const TfToken &keyPath) const
Clear any authored value identified by key and keyPath at the current EditTarget.
USD_API bool HasAuthoredCustomData() const
Return true if there are any authored opinions (excluding fallback) for this object's customData dict...
USD_API std::string GetDisplayName() const
Return this object's display name (metadata).
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Base class for UsdAttribute and UsdRelationship scenegraph objects.
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
The outermost container for scene description, which owns and presents composed prims as a scenegraph...
A map with string keys and VtValue values.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
bool UsdIsConvertible(UsdObjType from, UsdObjType to)
Return true if from is convertible to to, false otherwise.
bool UsdIsSubtype(UsdObjType baseType, UsdObjType subType)
Return true if subType is the same as or a subtype of baseType, false otherwise.
bool UsdIsConcrete(UsdObjType type)
Return true if type is a concrete object type, namely one of Prim, Attribute, or Relationship.
UsdObjType
Enum values to represent the various Usd object types.
SdfSpecType
An enum that specifies the type of an object.