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"
19#include "pxr/base/vt/value.h"
21
22#include <string>
23#include <type_traits>
24#include <vector>
25
26PXR_NAMESPACE_OPEN_SCOPE
27
28
29class UsdAttribute;
30class TsSpline;
31
33typedef std::vector<UsdAttribute> UsdAttributeVector;
34
167class UsdAttribute : public UsdProperty {
168public:
171
172 // --------------------------------------------------------------------- //
174 // --------------------------------------------------------------------- //
175
177
184 USD_API
186
193 USD_API
194 bool SetVariability(SdfVariability variability) const;
195
197 USD_API
199
206 USD_API
207 bool SetTypeName(const SdfValueTypeName& typeName) const;
208
210 USD_API
212
214
215 // --------------------------------------------------------------------- //
218 // --------------------------------------------------------------------- //
219
221
238 USD_API
239 bool GetTimeSamples(std::vector<double>* times) const;
240
255 USD_API
257 std::vector<double>* times) const;
258
277 USD_API
278 static bool GetUnionedTimeSamples(const std::vector<UsdAttribute> &attrs,
279 std::vector<double> *times);
280
300 USD_API
302 const std::vector<UsdAttribute> &attrs,
303 const GfInterval &interval,
304 std::vector<double> *times);
305
315 USD_API
316 size_t GetNumTimeSamples() const;
317
343 USD_API
344 bool GetBracketingTimeSamples(double desiredTime,
345 double* lower,
346 double* upper,
347 bool* hasTimeSamples) const;
348
353 USD_API
354 bool HasValue() const;
355
364 USD_API
366
370 USD_API
371 bool HasAuthoredValue() const;
372
375 USD_API
376 bool HasFallbackValue() const;
377
388 USD_API
390
451 template <typename T>
452 bool Get(T* value, UsdTimeCode time = UsdTimeCode::Default()) const {
453 static_assert(!std::is_const<T>::value, "");
454 static_assert(SdfValueTypeTraits<T>::IsValueType, "");
455 return _Get(value, time);
456 }
459 USD_API
460 bool Get(VtValue* value, UsdTimeCode time = UsdTimeCode::Default()) const;
461
464 USD_API
467
475 USD_API
478
494 template <typename T>
495 bool Set(const T& value, UsdTimeCode time = UsdTimeCode::Default()) const {
496 static_assert(!std::is_pointer<T>::value, "");
497 static_assert(SdfValueTypeTraits<T>::IsValueType ||
498 std::is_same<T, SdfValueBlock>::value, "");
499 return _Set(value, time);
500 }
501
505 USD_API
506 bool Set(const char* value, UsdTimeCode time = UsdTimeCode::Default()) const;
507
509 USD_API
510 bool Set(const VtValue& value, UsdTimeCode time = UsdTimeCode::Default()) const;
511
516 USD_API
517 bool HasSpline() const;
518
523 USD_API
525
527 USD_API
528 bool SetSpline(const TsSpline &spline);
529
537 USD_API
538 bool Clear() const;
539
550 USD_API
551 bool ClearAtTime(UsdTimeCode time) const;
552
554 USD_API
555 bool ClearDefault() const;
556
563 USD_API
564 void Block() const;
565
567
570
581 USD_API
582 bool AddConnection(const SdfPath& source,
584
590 USD_API
591 bool RemoveConnection(const SdfPath& source) const;
592
601 USD_API
602 bool SetConnections(const SdfPathVector& sources) const;
603
606 USD_API
607 bool ClearConnections() const;
608
622 USD_API
623 bool GetConnections(SdfPathVector* sources) const;
624
629 USD_API
631
633
634 // ---------------------------------------------------------------------- //
650 // ---------------------------------------------------------------------- //
651
661 USD_API
663
673 USD_API
674 void SetColorSpace(const TfToken &colorSpace) const;
675
678 USD_API
679 bool HasColorSpace() const;
680
683 USD_API
684 bool ClearColorSpace() const;
685
687
688 // ---------------------------------------------------------------------- //
689 // Private Methods and Members
690 // ---------------------------------------------------------------------- //
691private:
692 friend class UsdAttributeQuery;
693 friend class UsdObject;
694 friend class UsdPrim;
695 friend class UsdSchemaBase;
696 friend class Usd_PrimData;
697 friend struct UsdPrim_AttrConnectionFinder;
698
699 UsdAttribute(const Usd_PrimDataHandle &prim,
700 const SdfPath &proxyPrimPath,
701 const TfToken &attrName)
702 : UsdProperty(UsdTypeAttribute, prim, proxyPrimPath, attrName) {}
703
704 UsdAttribute(UsdObjType objType,
705 const Usd_PrimDataHandle &prim,
706 const SdfPath &proxyPrimPath,
707 const TfToken &propName)
708 : UsdProperty(objType, prim, proxyPrimPath, propName) {}
709
710 SdfAttributeSpecHandle
711 _CreateSpec(const SdfValueTypeName &typeName, bool custom,
712 const SdfVariability &variability) const;
713
714 // Like _CreateSpec(), but fail if this attribute is not built-in and there
715 // isn't already existing scene description to go on rather than stamping
716 // new information.
717 SdfAttributeSpecHandle _CreateSpec() const;
718
719 bool _Create(const SdfValueTypeName &typeName, bool custom,
720 const SdfVariability &variability) const;
721
722 template <typename T>
723 bool _Get(T* value, UsdTimeCode time) const;
724
725 template <typename T>
726 bool _Set(const T& value, UsdTimeCode time) const;
727
728 SdfPath
729 _GetPathForAuthoring(const SdfPath &path, std::string* whyNot) const;
730};
731
732PXR_NAMESPACE_CLOSE_SCOPE
733
734#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:274
Represents a value type name, i.e.
Definition: valueTypeName.h:71
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:59
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:167
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 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 the attribute has a spline as a value source.
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 source of the resolved value of this attribute at any non-d...
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 RemoveConnection(const SdfPath &source) const
Removes target from the list of targets.
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 spline.
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:495
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 ClearColorSpace() const
Clears authored color space value on the attribute.
USD_API void Block() const
Remove all time samples 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:452
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 SetSpline(const TsSpline &spline)
Set the spline using the current edit target.
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.
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 bool HasAuthoredValue() const
Return true if this attribute has either an authored default value or authored time samples.
UsdAttribute()
Construct an invalid attribute.
Definition: attribute.h:170
Object for efficiently making repeated queries for attribute values.
Base class for Usd scenegraph objects, providing common API.
Definition: object.h:115
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
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
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
UsdObjType
Enum values to represent the various Usd object types.
Definition: object.h:35
Basic Sdf data types.
SdfVariability
An enum that identifies variability types for attributes.
Definition: types.h:156