Loading...
Searching...
No Matches
attribute.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_USD_ATTRIBUTE_H
8#define PXR_USD_USD_ATTRIBUTE_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/usd/api.h"
12#include "pxr/usd/usd/common.h"
13#include "pxr/usd/usd/property.h"
15
16#include "pxr/usd/sdf/abstractData.h"
17#include "pxr/usd/sdf/path.h"
18#include "pxr/usd/sdf/types.h"
20#include "pxr/base/vt/value.h"
22
23#include <string>
24#include <type_traits>
25#include <vector>
26
27PXR_NAMESPACE_OPEN_SCOPE
28
29class UsdAttribute;
31class TsSpline;
32
34typedef std::vector<UsdAttribute> UsdAttributeVector;
35
183class UsdAttribute : public UsdProperty {
184public:
187
188 // --------------------------------------------------------------------- //
190 // --------------------------------------------------------------------- //
191
193
200 USD_API
202
209 USD_API
210 bool SetVariability(SdfVariability variability) const;
211
213 USD_API
215
222 USD_API
223 bool SetTypeName(const SdfValueTypeName& typeName) const;
224
226 USD_API
228
230
231 // --------------------------------------------------------------------- //
234 // --------------------------------------------------------------------- //
235
237
254 USD_API
255 bool GetTimeSamples(std::vector<double>* times) const;
256
271 USD_API
273 std::vector<double>* times) const;
274
293 USD_API
294 static bool GetUnionedTimeSamples(const std::vector<UsdAttribute> &attrs,
295 std::vector<double> *times);
296
316 USD_API
318 const std::vector<UsdAttribute> &attrs,
319 const GfInterval &interval,
320 std::vector<double> *times);
321
331 USD_API
332 size_t GetNumTimeSamples() const;
333
359 USD_API
360 bool GetBracketingTimeSamples(double desiredTime,
361 double* lower,
362 double* upper,
363 bool* hasTimeSamples) const;
364
369 USD_API
370 bool HasValue() const;
371
380 USD_API
382
386 USD_API
387 bool HasAuthoredValue() const;
388
391 USD_API
392 bool HasFallbackValue() const;
393
404 USD_API
406
467 template <typename T>
468 bool Get(T* value, UsdTimeCode time = UsdTimeCode::Default()) const {
469 static_assert(!std::is_const<T>::value, "");
470 static_assert(SdfValueTypeTraits<T>::IsValueType, "");
471 return _Get(value, time);
472 }
475 USD_API
476 bool Get(VtValue* value, UsdTimeCode time = UsdTimeCode::Default()) const;
477
480 template <typename T>
481 bool GetFallbackValue(T* value) const {
482 static_assert(!std::is_const<T>::value);
483 static_assert(SdfValueTypeTraits<T>::IsValueType);
485 _GetStage()->_GetSchemaAttribute(*this);
486 return attrDef && attrDef.GetFallbackValue<T>(value);
487 }
488
491 USD_API
492 bool GetFallbackValue(VtValue* value) const;
493
496 USD_API
499
511 USD_API
514
530 template <typename T>
531 bool Set(const T& value, UsdTimeCode time = UsdTimeCode::Default()) const {
532 static_assert(!std::is_pointer<T>::value, "");
533 static_assert(SdfValueTypeTraits<T>::IsValueType ||
534 std::is_same<T, SdfValueBlock>::value ||
535 std::is_same<T, SdfAnimationBlock>::value, "");
536 return _Set(value, time);
537 }
538
542 USD_API
543 bool Set(const char* value, UsdTimeCode time = UsdTimeCode::Default()) const;
544
546 USD_API
547 bool Set(const VtValue& value, UsdTimeCode time = UsdTimeCode::Default()) const;
548
551 USD_API
552 bool HasSpline() const;
553
562 USD_API
564
567 USD_API
568 bool SetSpline(const TsSpline &spline) const;
569
577 USD_API
578 bool Clear() const;
579
590 USD_API
591 bool ClearAtTime(UsdTimeCode time) const;
592
594 USD_API
595 bool ClearDefault() const;
596
603 USD_API
604 void Block() const;
605
614 USD_API
615 void BlockAnimation() const;
616
618
621
632 USD_API
633 bool AddConnection(const SdfPath& source,
635
641 USD_API
642 bool RemoveConnection(const SdfPath& source) const;
643
652 USD_API
653 bool SetConnections(const SdfPathVector& sources) const;
654
657 USD_API
658 bool ClearConnections() const;
659
673 USD_API
674 bool GetConnections(SdfPathVector* sources) const;
675
680 USD_API
682
684
685 // ---------------------------------------------------------------------- //
701 // ---------------------------------------------------------------------- //
702
712 USD_API
714
724 USD_API
725 void SetColorSpace(const TfToken &colorSpace) const;
726
729 USD_API
730 bool HasColorSpace() const;
731
734 USD_API
735 bool ClearColorSpace() const;
736
738
782
786 USD_API
788
803 USD_API
804 bool SetLimits(const VtDictionary& limits) const;
805
807 USD_API
808 bool HasAuthoredLimits() const;
809
816 USD_API
817 bool ClearLimits() const;
818
828 USD_API
830
842 USD_API
844
852 USD_API
854
856
876
878 USD_API
879 int64_t GetArraySizeConstraint() const;
880
882 USD_API
883 bool SetArraySizeConstraint(int64_t constraint) const;
884
887 USD_API
889
892 USD_API
894
896
897 // ---------------------------------------------------------------------- //
898 // Private Methods and Members
899 // ---------------------------------------------------------------------- //
900private:
901 friend class UsdAttributeQuery;
902 friend class UsdObject;
903 friend class UsdPrim;
904 friend class UsdSchemaBase;
905 friend class Usd_PrimData;
906 friend struct UsdPrim_AttrConnectionFinder;
907
908 UsdAttribute(const Usd_PrimDataHandle &prim,
909 const SdfPath &proxyPrimPath,
910 const TfToken &attrName)
911 : UsdProperty(UsdTypeAttribute, prim, proxyPrimPath, attrName) {}
912
913 UsdAttribute(UsdObjType objType,
914 const Usd_PrimDataHandle &prim,
915 const SdfPath &proxyPrimPath,
916 const TfToken &propName)
917 : UsdProperty(objType, prim, proxyPrimPath, propName) {}
918
919 SdfAttributeSpecHandle
920 _CreateSpec(const SdfValueTypeName &typeName, bool custom,
921 const SdfVariability &variability) const;
922
923 // Like _CreateSpec(), but fail if this attribute is not built-in and there
924 // isn't already existing scene description to go on rather than stamping
925 // new information.
926 SdfAttributeSpecHandle _CreateSpec() const;
927
928 bool _Create(const SdfValueTypeName &typeName, bool custom,
929 const SdfVariability &variability) const;
930
931 template <typename T>
932 bool _Get(T* value, UsdTimeCode time) const;
933
934 template <typename T>
935 bool _Set(const T& value, UsdTimeCode time) const;
936
937 SdfPath
938 _GetPathForAuthoring(const SdfPath &path, std::string* whyNot) const;
939};
940
941PXR_NAMESPACE_CLOSE_SCOPE
942
943#endif // PXR_USD_USD_ATTRIBUTE_H
A basic mathematical interval class.
Definition interval.h:33
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
Represents a value type name, i.e.
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:71
A mathematical description of a curved function from time to value.
Definition spline.h:60
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition attribute.h:183
USD_API bool GetTimeSamples(std::vector< double > *times) const
Populates a vector with authored sample times.
USD_API TfToken GetRoleName() const
Return the roleName for this attribute's typeName.
USD_API bool Set(const char *value, UsdTimeCode time=UsdTimeCode::Default()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API bool GetBracketingTimeSamples(double desiredTime, double *lower, double *upper, bool *hasTimeSamples) const
Populate lower and upper with the next greater and lesser value relative to the desiredTime.
USD_API UsdResolveInfo GetResolveInfo(UsdTimeCode time) const
Perform value resolution to determine the source of the resolved value of this attribute at the reque...
USD_API bool ClearLimits() const
Clear the authored limits dictionary for the attribute, at the current edit target.
USD_API int64_t GetArraySizeConstraint() const
Return the array size constraint value for this attribute.
USD_API bool GetFallbackValue(VtValue *value) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API bool ClearDefault() const
Shorthand for ClearAtTime(UsdTimeCode::Default()).
USD_API bool Clear() const
Clears the authored default value, all time samples and spline for this attribute at the current Edit...
USD_API bool GetTimeSamplesInInterval(const GfInterval &interval, std::vector< double > *times) const
Populates a vector with authored sample times in interval.
USD_API bool SetTypeName(const SdfValueTypeName &typeName) const
Set the value for typeName at the current EditTarget, return true on success, false if the value can ...
USD_API bool HasSpline() const
Returns true if this attribute has a spline or value clips with an underlying spline format as the st...
USD_API bool HasAuthoredValueOpinion() const
USD_API bool SetVariability(SdfVariability variability) const
Set the value for variability at the current EditTarget, return true on success, false if the value c...
USD_API bool Set(const VtValue &value, UsdTimeCode time=UsdTimeCode::Default()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API UsdResolveInfo GetResolveInfo() const
Perform value resolution to determine the proximal source of the resolved value of this attribute at ...
static USD_API bool GetUnionedTimeSamples(const std::vector< UsdAttribute > &attrs, std::vector< double > *times)
Populates the given vector, times with the union of all the authored sample times on all of the given...
USD_API TfToken GetColorSpace() const
Gets the color space in which the attribute is authored if it has been explicitly set.
static USD_API bool GetUnionedTimeSamplesInInterval(const std::vector< UsdAttribute > &attrs, const GfInterval &interval, std::vector< double > *times)
Populates the given vector, times with the union of all the authored sample times in the GfInterval,...
USD_API bool ClearArraySizeConstraint() const
Clear the authored array size constraint value for this attribute at the current edit target.
USD_API bool RemoveConnection(const SdfPath &source) const
Removes target from the list of targets.
USD_API bool HasAuthoredArraySizeConstraint() const
Return whether an array size constraint value is authored on this attribute.
USD_API bool SetConnections(const SdfPathVector &sources) const
Make the authoring layer's opinion of the connection list explicit, and set exactly to sources.
USD_API bool ClearConnections() const
Remove all opinions about the connections list from the current edit target.
USD_API TsSpline GetSpline() const
Returns a copy of the resolved spline if the spline is the strongest value source,...
USD_API SdfVariability GetVariability() const
An attribute's variability expresses whether it is intended to have time-samples or splines (SdfVaria...
USD_API bool HasValue() const
Return true if this attribute has an authored default value, authored time samples or a fallback valu...
USD_API bool AddConnection(const SdfPath &source, UsdListPosition position=UsdListPositionBackOfPrependList) const
Adds source to the list of connections, in the position specified by position.
bool Set(const T &value, UsdTimeCode time=UsdTimeCode::Default()) const
Set the value of this attribute in the current UsdEditTarget to value at UsdTimeCode time,...
Definition attribute.h:531
USD_API SdfValueTypeName GetTypeName() const
Return the "scene description" value type name for this attribute.
USD_API bool HasAuthoredConnections() const
Return true if this attribute has any authored opinions regarding connections.
USD_API bool SetLimits(const VtDictionary &limits) const
Set the limits dictionary for the attribute to limits, at the current edit target.
USD_API bool ClearColorSpace() const
Clears authored color space value on the attribute.
USD_API void Block() const
Remove all time samples or spline on an attribute and author a block default value.
USD_API bool ClearAtTime(UsdTimeCode time) const
Clear the authored value for this attribute at the given time, at the current EditTarget and return t...
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Perform value resolution to fetch the value of this attribute at the requested UsdTimeCode time,...
Definition attribute.h:468
USD_API UsdAttributeLimits GetHardLimits() const
Return a UsdAttributeLimits object configured to edit the attribute's hard limits sub-dictionary.
USD_API bool Get(VtValue *value, UsdTimeCode time=UsdTimeCode::Default()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
USD_API bool SetArraySizeConstraint(int64_t constraint) const
Set the array size constraint value for this attribute.
USD_API bool HasColorSpace() const
Returns whether color space is authored on the attribute.
USD_API bool HasFallbackValue() const
Return true if this attribute has a fallback value provided by a registered schema.
USD_API bool GetConnections(SdfPathVector *sources) const
Compose this attribute's connections and fill sources with the result.
USD_API void SetColorSpace(const TfToken &colorSpace) const
Sets the color space of the attribute to colorSpace.
bool GetFallbackValue(T *value) const
If this attribute is a builtin attribute with a fallback value provided by a schema,...
Definition attribute.h:481
USD_API UsdAttributeLimits GetLimits(const TfToken &key) const
Return a UsdAttributeLimits object configured to edit the attribute's limits sub-dictionary given by ...
USD_API size_t GetNumTimeSamples() const
Returns the number of time samples that have been authored.
USD_API bool ValueMightBeTimeVarying() const
Return true if it is possible, but not certain, that this attribute's value changes over time,...
USD_API VtDictionary GetLimits() const
Return the composed limits dictionary for the attribute.
USD_API void BlockAnimation() const
Remove any timeSamples or spline on an attribute and authors an AnimationBlock default value.
USD_API bool SetSpline(const TsSpline &spline) const
Set the spline using the current edit target, authoring a spline as a local opinion to the correspond...
USD_API bool HasAuthoredValue() const
Return true if this attribute has either an authored default value or authored time samples.
USD_API bool HasAuthoredLimits() const
Return whether a limits dictionary is authored for the attribute.
USD_API UsdAttributeLimits GetSoftLimits() const
Return a UsdAttributeLimits object configured to edit the attribute's soft limits sub-dictionary.
UsdAttribute()
Construct an invalid attribute.
Definition attribute.h:186
Provides API for retrieving and authoring values within a particular sub-dictionary of the limits dic...
Object for efficiently making repeated queries for attribute values.
Base class for Usd scenegraph objects, providing common API.
Definition object.h:116
Accessor to a attribute's definition in the prim definition.
bool GetFallbackValue(T *value) const
Retrieves the fallback value of type T for this attribute and stores it in value if possible.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition prim.h:117
Base class for UsdAttribute and UsdRelationship scenegraph objects.
Definition property.h:38
Container for information about the source of an attribute's value, i.e.
Definition resolveInfo.h:55
The base class for all schema types in Usd.
Definition schemaBase.h:39
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition timeCode.h:72
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for 'default'.
Definition timeCode.h:113
A map with string keys and VtValue values.
Definition dictionary.h:52
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition value.h:90
UsdListPosition
Specifies a position to add items to lists.
Definition common.h:71
@ UsdListPositionBackOfPrependList
The position at the back of the prepend list.
Definition common.h:81
Basic Sdf data types.
SdfVariability
An enum that identifies variability types for attributes.
Definition types.h:159
UsdObjType
Enum values to represent the various Usd object types.
Definition object.h:36