HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
attribute.h
Go to the documentation of this file.
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 
17 #include "pxr/usd/sdf/path.h"
18 #include "pxr/usd/sdf/types.h"
19 #include "pxr/base/vt/dictionary.h"
20 #include "pxr/base/vt/value.h"
21 #include "pxr/base/gf/interval.h"
22 
23 #include <string>
24 #include <type_traits>
25 #include <vector>
26 
28 
29 class UsdAttribute;
30 class UsdAttributeLimits;
31 class TsSpline;
32 
33 /// A std::vector of UsdAttributes.
34 typedef std::vector<UsdAttribute> UsdAttributeVector;
35 
36 /// \class UsdAttribute
37 ///
38 /// Scenegraph object for authoring and retrieving numeric, string, and array
39 /// valued data, sampled over time, or animated by a spline
40 ///
41 /// The allowed value types for UsdAttribute are dictated by the Sdf
42 /// ("Scene Description Foundations") core's data model, which we summarize in
43 /// \ref Usd_Page_Datatypes .
44 ///
45 /// \section Usd_AttributeQualities Attribute Defining Qualities
46 ///
47 /// In addition to its value type, an Attribute has two other defining
48 /// qualities:
49 /// \li <b>Variability</b> Expresses whether an attribute is intended to
50 /// have time samples or a spline (GetVariability() == \c SdfVariabilityVarying),
51 /// or only a default (GetVariability() == \c SdfVariabilityUniform). For more
52 /// on reasoning about time samples,
53 /// see \ref Usd_AttributeValueMethods "Value & Time-Sample Accessors".
54 ///
55 /// \li <b>Custom</b> Determines whether an attribute belongs to a
56 /// schema (IsCustom() == \c false), or is a user-defined, custom attribute.
57 /// schema attributes will always be defined on a prim of the schema type,
58 /// and may possess fallback values from the schema, whereas custom
59 /// attributes must always first be authored in order to be defined. Note
60 /// that \em custom is actually an aspect of UsdProperty, as UsdRelationship
61 /// can also be custom or provided by a schema.
62 ///
63 /// \section Usd_AttributeExistence Attribute Creation and Existence
64 ///
65 /// One can always create an attribute generically via
66 /// UsdPrim::CreateAttribute(), which ensures that an attribute "is defined"
67 /// in the current \ref UsdEditTarget . In order to author any metadata or
68 /// a default or timesample for an attribute, <em>it must first be defined</em>.
69 /// It is sufficient that the attribute be defined in any one of the layers
70 /// participating in the stage's current composition; for \em builtin
71 /// attributes (those belonging to the owning prim's defining schema, i.e.
72 /// the most specific subclass of UsdTypedSchema for which prim.IsA<schema>()
73 /// will evaluate to true) there need be no authored scene description, because
74 /// a definition is provided by the prim's schema definition.
75 ///
76 /// <b>Creating</b> an attribute does not imply that the attribute has a value.
77 /// More broadly, in the following code:
78 /// \code
79 /// if (UsdAttribute attr = prim.GetAttribute(TfToken("myAttr"))){
80 /// ...
81 /// }
82 /// \endcode
83 ///
84 /// The UsdAttribute passes the bool test, because it is defined; however,
85 /// inside the clause, we have no guarantee that attr has a value.
86 ///
87 /// \section Usd_AttributeInterpolation Attribute Value Interpolation
88 ///
89 /// UsdAttribute supports two interpolation behaviors when retrieving
90 /// attribute values at times where no value is explicitly authored.
91 /// The desired behavior may be specified via UsdStage::SetInterpolationType.
92 /// That behavior will be used for all calls to UsdAttribute::Get.
93 ///
94 /// Note that for attributes with spline value sources, the interpolation
95 /// behavior is determined by the spline itself, and the interpolation type
96 /// set on the stage is ignored.
97 ///
98 /// The supported interpolation types are:
99 ///
100 /// \li <b>Held</b> Attribute values are held constant between authored
101 /// values. An attribute's value will be equal to the nearest preceding
102 /// authored value. If there is no preceding authored value, the value
103 /// will be equal to the nearest subsequent value.
104 ///
105 /// \li <b>Linear</b> Attribute values are linearly interpolated between
106 /// authored values.
107 ///
108 /// Linear interpolation is only supported for certain data types. See
109 /// \ref USD_LINEAR_INTERPOLATION_TYPES for the list of these types. Types
110 /// that do not support linear interpolation will use held interpolation
111 /// instead.
112 ///
113 /// Linear interpolation is done element-by-element for array, vector,
114 /// and matrix data types. If linear interpolation is requested for
115 /// two array values with different sizes, held interpolation will
116 /// be used instead.
117 ///
118 /// \section Usd_AttributeBlocking Attribute Value Blocking
119 ///
120 /// While prims can effectively be removed from a scene by
121 /// \ref Usd_ActiveInactive "deactivating them," properties cannot. However,
122 /// it is possible to **block an attribute's value**, thus making the attribute
123 /// behave as if it has a definition (and possibly metadata), but no authored
124 /// value.
125 ///
126 ///
127 /// One blocks an attribute using UsdAttribute::Block(), which will block the
128 /// attribute in the stage's current UsdEditTarget, by authoring an
129 /// SdfValueBlock in the attribute's *default*, and only values authored in
130 /// weaker layers than the editTarget will be blocked. If the value block is
131 /// the strongest authored opinion for the attribute, the HasAuthoredValue()
132 /// method will return *false*, and the HasValue() and Get() methods will
133 /// only return *true* if the attribute possesses a fallback value from the
134 /// prim's schema. "Unblocking" a blocked attribute is as simple as setting
135 /// a *default* or timeSample value for the attribute in the same or stronger
136 /// layer.
137 ///
138 /// \subsection Usd_TimeVaryingAttributeBlocks Time-varying Blocks
139 ///
140 /// The semantics of \ref Usd_ValueClips_Overview "Value Clips" necessitate
141 /// the ability to selectively block an attribute's value for only some intervals
142 /// in its authored range of samples. One can block an attribute's value at
143 /// time *t* by calling `attr.Set(SdfValueBlock, t)` When an attribute is thusly
144 /// "partially blocked", UsdAttribute::Get() will succeed only for those time
145 /// intervals whose left/earlier bracketing timeSample is **not** SdfValueBlock.
146 ///
147 /// Due to this time-varying potential of value blocking, it may be the case
148 /// that an attribute's HasAuthoredValue() and HasValue() methods both return
149 /// *true* (because they do not and cannot consider time-varying blocks), but
150 /// Get() may yet return *false* over some intervals.
151 ///
152 /// \subsection Usd_AttributeAnimationBlocking Attribute Animation Blocking
153 ///
154 /// In addition to blocking all authored values, one can block only the
155 /// animation (time samples and spline) on an attribute in the intermediate
156 /// layers, allowing default values from the weaker layers to shine through.
157 ///
158 /// One blocks an attribute's animation using UsdAttribute::BlockAnimation(),
159 ///
160 /// \section Usd_AssetPathValuedAttributes Attributes of type SdfAssetPath and UsdAttribute::Get()
161 ///
162 /// If an attribute's value type is SdfAssetPath or SdfAssetPathArray, Get()
163 /// does extra work to perform variable expression evaluation and compute
164 /// resolved asset paths. The layer that has the strongest value opinion is
165 /// used as the anchor for "relative" asset paths. The unresolved results are
166 /// available through SdfAssetPath::GetAssetPath. The fully resolved path
167 /// (including any substitutions) can be retrieved with
168 /// SdfAssetPath::GetResolvedPath. The authored or evaluated paths may
169 /// be explicitly retrieved through SdfAssetPath::GetAuthoredPath and
170 /// SdfAssetPath::GetEvaluatedPath respectively.
171 ///
172 /// Clients that call Get() on many asset-path-valued attributes may wish to
173 /// employ an ArResolverScopedCache to improve asset path resolution
174 /// performance.
175 ///
176 /// \section Usd_AttributeArraySizeConstraint Array Size Constraint
177 ///
178 /// For array-valued attributes, the value returned by GetArraySizeConstraint()
179 /// encodes information about the expected number of elements as well as the
180 /// tuple-length (i.e., column count). See \ref
181 /// Usd_AttributeArraySizeConstraintAPI "Array Size Constraint" for details of
182 /// the encoding.
183 class UsdAttribute : public UsdProperty {
184 public:
185  /// Construct an invalid attribute.
187 
188  // --------------------------------------------------------------------- //
189  /// \name Core Metadata
190  // --------------------------------------------------------------------- //
191 
192  /// @{
193 
194  /// An attribute's variability expresses whether it is intended to have
195  /// time-samples or splines (\c SdfVariabilityVarying), or only a single
196  /// default value (\c SdfVariabilityUniform).
197  ///
198  /// Variability is required meta-data of all attributes, and its fallback
199  /// value is SdfVariabilityVarying.
200  USD_API
202 
203  /// Set the value for variability at the current EditTarget, return true
204  /// on success, false if the value can not be written.
205  ///
206  /// \b Note that this value should not be changed as it is typically either
207  /// automatically authored or provided by a property definition. This method
208  /// is provided primarily for fixing invalid scene description.
209  USD_API
210  bool SetVariability(SdfVariability variability) const;
211 
212  /// Return the "scene description" value type name for this attribute.
213  USD_API
215 
216  /// Set the value for typeName at the current EditTarget, return true on
217  /// success, false if the value can not be written.
218  ///
219  /// \b Note that this value should not be changed as it is typically either
220  /// automatically authored or provided by a property definition. This method
221  /// is provided primarily for fixing invalid scene description.
222  USD_API
223  bool SetTypeName(const SdfValueTypeName& typeName) const;
224 
225  /// Return the roleName for this attribute's typeName.
226  USD_API
227  TfToken GetRoleName() const;
228 
229  /// @}
230 
231  // --------------------------------------------------------------------- //
232  /// \anchor Usd_AttributeValueMethods
233  /// \name Value & Time-Sample Accessors
234  // --------------------------------------------------------------------- //
235 
236  /// @{
237 
238  /// Populates a vector with authored sample times.
239  /// Returns false only on error.
240  ///
241  /// This method uses the standard resolution semantics, so if a stronger
242  /// default value is authored over weaker time samples, the default value
243  /// will hide the underlying timesamples.
244  ///
245  /// \note This function will query all value clips that may contribute
246  /// time samples for this attribute, opening them if needed. This may be
247  /// expensive, especially if many clips are involved.
248  ///
249  /// \param times - on return, will contain the \em sorted, ascending
250  /// timeSample ordinates. Any data in \p times will be lost, as this
251  /// method clears \p times.
252  ///
253  /// \sa UsdAttribute::GetTimeSamplesInInterval
254  USD_API
255  bool GetTimeSamples(std::vector<double>* times) const;
256 
257  /// Populates a vector with authored sample times in \p interval.
258  /// Returns false only on an error.
259  ///
260  /// \note This function will only query the value clips that may
261  /// contribute time samples for this attribute in the given interval,
262  /// opening them if necessary.
263  ///
264  /// \param interval - the \ref GfInterval on which to gather time samples.
265  ///
266  /// \param times - on return, will contain the \em sorted, ascending
267  /// timeSample ordinates. Any data in \p times will be lost, as this
268  /// method clears \p times.
269  ///
270  /// \sa UsdAttribute::GetTimeSamples
271  USD_API
272  bool GetTimeSamplesInInterval(const GfInterval& interval,
273  std::vector<double>* times) const;
274 
275  /// Populates the given vector, \p times with the union of all the
276  /// authored sample times on all of the given attributes, \p attrs.
277  ///
278  /// \note This function will query all value clips that may contribute
279  /// time samples for the attributes in \p attrs, opening them if needed.
280  /// This may be expensive, especially if many clips are involved.
281  ///
282  /// The accumulated sample times will be in sorted (increasing) order and
283  /// will not contain any duplicates.
284  ///
285  /// This clears any existing values in the \p times vector before
286  /// accumulating sample times of the given attributes.
287  ///
288  /// \return false if any of the attributes in \p attr are invalid or if
289  /// there's an error when fetching time-samples for any of the attributes.
290  ///
291  /// \sa UsdAttribute::GetTimeSamples
292  /// \sa UsdAttribute::GetUnionedTimeSamplesInInterval
293  USD_API
294  static bool GetUnionedTimeSamples(const std::vector<UsdAttribute> &attrs,
295  std::vector<double> *times);
296 
297  /// Populates the given vector, \p times with the union of all the
298  /// authored sample times in the GfInterval, \p interval on all of the
299  /// given attributes, \p attrs.
300  ///
301  /// \note This function will only query the value clips that may
302  /// contribute time samples for the attributes in \p attrs, in the
303  /// given \p interval, opening them if necessary.
304  ///
305  /// The accumulated sample times will be in sorted (increasing) order and
306  /// will not contain any duplicates.
307  ///
308  /// This clears any existing values in the \p times vector before
309  /// accumulating sample times of the given attributes.
310  ///
311  /// \return false if any of the attributes in \p attr are invalid or if
312  /// there's an error fetching time-samples for any of the attributes.
313  ///
314  /// \sa UsdAttribute::GetTimeSamplesInInterval
315  /// \sa UsdAttribute::GetUnionedTimeSamples
316  USD_API
318  const std::vector<UsdAttribute> &attrs,
319  const GfInterval &interval,
320  std::vector<double> *times);
321 
322  /// Returns the number of time samples that have been authored.
323  ///
324  /// This method uses the standard resolution semantics, so if a stronger
325  /// default value is authored over weaker time samples, the default value
326  /// will hide the underlying timesamples.
327  ///
328  /// \note This function will query all value clips that may contribute
329  /// time samples for this attribute, opening them if needed. This may be
330  /// expensive, especially if many clips are involved.
331  USD_API
332  size_t GetNumTimeSamples() const;
333 
334  /// Populate \a lower and \a upper with the next greater and lesser
335  /// value relative to the \a desiredTime. Return false if no value exists
336  /// or an error occurs, true if either a default value or timeSamples exist.
337  ///
338  /// Use standard resolution semantics: if a stronger default value is
339  /// authored over weaker time samples, the default value hides the
340  /// underlying timeSamples.
341  ///
342  /// 1) If a sample exists at the \a desiredTime, set both upper and lower
343  /// to \a desiredTime.
344  ///
345  /// 2) If samples exist surrounding, but not equal to the \a desiredTime,
346  /// set lower and upper to the bracketing samples nearest to the
347  /// \a desiredTime.
348  ///
349  /// 3) If the \a desiredTime is outside of the range of authored samples,
350  /// clamp upper and lower to the nearest time sample.
351  ///
352  /// 4) If no samples exist, do not modify upper and lower and set
353  /// \a hasTimeSamples to false.
354  ///
355  /// In cases (1), (2) and (3), set \a hasTimeSamples to true.
356  ///
357  /// All four cases above are considered to be successful, thus the return
358  /// value will be true and no error message will be emitted.
359  USD_API
360  bool GetBracketingTimeSamples(double desiredTime,
361  double* lower,
362  double* upper,
363  bool* hasTimeSamples) const;
364 
365  /// Return true if this attribute has an authored default value, authored
366  /// time samples or a fallback value provided by a registered schema. If
367  /// the attribute has been \ref Usd_AttributeBlocking "blocked", then
368  /// return `true` if and only if it has a fallback value.
369  USD_API
370  bool HasValue() const;
371 
372  /// \deprecated This method is deprecated because it returns `true` even when
373  /// an attribute is blocked. Please use HasAuthoredValue() instead. If
374  /// you truly need to know whether the attribute has **any** authored
375  /// value opinions, *including blocks*, you can make the following query:
376  /// `attr.GetResolveInfo().HasAuthoredValueOpinion()`
377  ///
378  /// Return true if this attribute has either an authored default value or
379  /// authored time samples.
380  USD_API
381  bool HasAuthoredValueOpinion() const;
382 
383  /// Return true if this attribute has either an authored default value or
384  /// authored time samples. If the attribute has been
385  /// \ref Usd_AttributeBlocking "blocked", then return `false`
386  USD_API
387  bool HasAuthoredValue() const;
388 
389  /// Return true if this attribute has a fallback value provided by
390  /// a registered schema.
391  USD_API
392  bool HasFallbackValue() const;
393 
394  /// Return true if it is possible, but not certain, that this attribute's
395  /// value changes over time, false otherwise.
396  ///
397  /// If this function returns false, it is certain that this attribute's
398  /// value remains constant over time.
399  ///
400  /// This function checks if the attribute either has more than 1 time
401  /// samples or is spline valued. Which is more efficient than actually
402  /// counting the time samples or evaluating the spline, both of which
403  /// are potentially expensive operations.
404  USD_API
405  bool ValueMightBeTimeVarying() const;
406 
407  /// Perform value resolution to fetch the value of this attribute at the
408  /// requested UsdTimeCode \p time, which defaults to \em default.
409  ///
410  /// If no value is authored at \p time but values are authored at other
411  /// times, this function will return an interpolated value based on the
412  /// stage's interpolation type.
413  /// See \ref Usd_AttributeInterpolation.
414  ///
415  /// An attribute's value may be discontinuous at time samples. This happens
416  /// when the stage is in held interpolation mode or when the sample values
417  /// are not interpolatable. To obtain the attribute's value immediately
418  /// before a given time sample, use
419  /// \link UsdTimeCode::PreTime() UsdTimeCode::PreTime(time)\endlink. This
420  /// evaluates the limit of the attribute's value as time approaches the
421  /// given \p time from the left.
422  ///
423  /// For example, if a string-valued attribute has time samples
424  /// `{1.0: "foo", 2.0: "bar"}`, calling Get() with UsdTimeCode(2.0)
425  /// returns "bar", whereas calling Get() with UsdTimeCode::PreTime(2.0)
426  /// returns "foo". However, if the attribute's values are interpolatable,
427  /// such as `{1.0: 3.0, 2.0: 4.0}`, then calling Get() with UsdTimeCode(2.0)
428  /// and UsdTimeCode::PreTime(2.0) will both return 4.0, since the value
429  /// is continuous at time=2.0.
430  ///
431  /// If no value is authored and no fallback value is provided by the
432  /// schema for this attribute, this function will return false. If the
433  /// consumer's use-case requires a default value, the consumer will need
434  /// to provide one, possibly using GetTypeName().GetDefaultValue().
435  ///
436  /// Value resolution first needs to determine the source of the strongest
437  /// value opinion for this attribute at the requested UsdTimeCode \p time.
438  /// But often (i.e. unless the attribute is affected by
439  /// \ref Usd_Page_ValueClips "Value Clips") the source of the resolved value
440  /// does not vary over time. UsdAttributeQuery finds the source opinion and
441  /// saves it so that repeated calls to UsdAttributeQuery::Get() avoid
442  /// redundant work.
443  ///
444  /// This templated accessor is designed for high performance data-streaming
445  /// applications, allowing one to fetch data into the same container
446  /// repeatedly, avoiding memory allocations when possible (VtArray
447  /// containers will be resized as necessary to conform to the size of
448  /// data being read).
449  ///
450  /// This template is only instantiated for the valid scene description
451  /// value types and their corresponding VtArray containers. See
452  /// \ref Usd_Page_Datatypes for the complete list of types.
453  ///
454  /// Values are retrieved without regard to this attribute's variability.
455  /// For example, a uniform attribute may retrieve time sample values
456  /// if any are authored. However, the USD_VALIDATE_VARIABILITY TF_DEBUG
457  /// code will cause debug information to be output if values that are
458  /// inconsistent with this attribute's variability are retrieved.
459  /// See UsdAttribute::GetVariability for more details.
460  ///
461  /// \return true if there was a value to be read, it was of the type T
462  /// requested, and we read it successfully - false otherwise.
463  ///
464  /// For more details, see \ref Usd_ValueResolution , and also
465  /// \ref Usd_AssetPathValuedAttributes for information on how to
466  /// retrieve resolved asset paths from SdfAssetPath-valued attributes.
467  template <typename T>
469  static_assert(!std::is_const<T>::value, "");
470  static_assert(SdfValueTypeTraits<T>::IsValueType, "");
471  return _Get(value, time);
472  }
473  /// \overload
474  /// Type-erased access, often not as efficient as typed access.
475  USD_API
476  bool Get(VtValue* value, UsdTimeCode time = UsdTimeCode::Default()) const;
477 
478  /// If this attribute is a builtin attribute with a fallback value provided
479  /// by a schema, fetch that value and return true. Otherwise return false.
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 
489  /// \overload
490  /// Type-erased accessor for getting the fallback value.
491  USD_API
492  bool GetFallbackValue(VtValue* value) const;
493 
494  /// Perform value resolution to determine the source of the resolved
495  /// value of this attribute at the requested UsdTimeCode \p time.
496  USD_API
499 
500  /// Perform value resolution to determine the proximal source of the
501  /// resolved value of this attribute at any non-default time.
502  ///
503  /// Often (i.e. unless the attribute is affected by \ref Usd_Page_ValueClips
504  /// "Value Clips" or the authored values are composing value types like
505  /// VtArrayEdits or SdfPathExpressions) the source of the resolved value
506  /// does not vary over time. See UsdAttributeQuery as an example that takes
507  /// advantage of this quality of value resolution. Call the
508  /// GetResolveInfo() overload that takes a `time` to get a more complete
509  /// picture, and see UsdResolveInfo::GetSource() for more information.
510  ///
511  USD_API
513  GetResolveInfo() const;
514 
515  /// Set the value of this attribute in the current UsdEditTarget to
516  /// \p value at UsdTimeCode \p time, which defaults to \em default.
517  ///
518  /// Values are authored without regard to this attribute's variability.
519  /// For example, time sample values may be authored on a uniform
520  /// attribute. However, the USD_VALIDATE_VARIABILITY TF_DEBUG code
521  /// will cause debug information to be output if values that are
522  /// inconsistent with this attribute's variability are authored.
523  /// See UsdAttribute::GetVariability for more details.
524  ///
525  /// \return false and generate an error if type \c T does not match
526  /// this attribute's defined scene description type <b>exactly</b>,
527  /// or if there is no existing definition for the attribute, or if the
528  /// \p time is pre-time, which is only used to for querying for values at
529  /// the limit when the time is approached from the left.
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 ||
536  return _Set(value, time);
537  }
538 
539  /// \overload
540  /// As a convenience, we allow the setting of string value typed attributes
541  /// via a C string value.
542  USD_API
543  bool Set(const char* value, UsdTimeCode time = UsdTimeCode::Default()) const;
544 
545  /// \overload
546  USD_API
547  bool Set(const VtValue& value, UsdTimeCode time = UsdTimeCode::Default()) const;
548 
549  /// Returns true if this attribute has a spline as the strongest value
550  /// source.
551  USD_API
552  bool HasSpline() const;
553 
554  /// Returns a copy of the resolved spline if the spline is the strongest value
555  /// source.
556  ///
557  /// If the strongest opinion is not a spline, returns an empty spline.
558  USD_API
559  TsSpline GetSpline() const;
560 
561  /// Set the spline using the current edit target.
562  USD_API
563  bool SetSpline(const TsSpline &spline);
564 
565  /// Clears the authored default value, all time samples and spline for this
566  /// attribute at the current EditTarget and returns true on success.
567  ///
568  /// Calling clear when either no value is authored or no spec is present,
569  /// is a silent no-op returning true.
570  ///
571  /// This method does not affect any other data authored on this attribute.
572  USD_API
573  bool Clear() const;
574 
575  /// Clear the authored value for this attribute at the given
576  /// \a time, at the current EditTarget and return true on success.
577  /// UsdTimeCode::Default() can be used to clear the default value.
578  ///
579  /// Calling clear when either no value is authored or no spec is present,
580  /// is a silent no-op returning true.
581  ///
582  /// Issue a coding error if \p time is a pre-time, which is only used to
583  /// for querying for values at the limit when the time is approached from
584  /// the left.
585  USD_API
586  bool ClearAtTime(UsdTimeCode time) const;
587 
588  /// Shorthand for ClearAtTime(UsdTimeCode::Default()).
589  USD_API
590  bool ClearDefault() const;
591 
592  /// Remove all time samples or spline on an attribute and author a *block*
593  /// \c default value. This causes the attribute to resolve as
594  /// if there were no authored value opinions in weaker layers.
595  ///
596  /// See \ref Usd_AttributeBlocking for more information, including
597  /// information on time-varying blocking.
598  USD_API
599  void Block() const;
600 
601  /// Remove any timeSamples or spline on an attribute and authors an
602  /// *AnimationBlock* \c default value.
603  ///
604  /// This causes the attribute to resolve as if there were no authored
605  /// animation (time samples or spline) opinions but still allows default
606  /// values shine through.
607  ///
608  /// See \ref Usd_AttributeAnimationBlocking for more information.
609  USD_API
610  void BlockAnimation() const;
611 
612  /// @}
613 
614  /// \name Querying and Editing Connections
615  /// @{
616 
617  /// Adds \p source to the list of connections, in the position
618  /// specified by \p position.
619  ///
620  /// Issue an error if \p source identifies a prototype prim or an object
621  /// descendant to a prototype prim. It is not valid to author connections
622  /// to these objects.
623  ///
624  /// What data this actually authors depends on what data is currently
625  /// authored in the authoring layer, with respect to list-editing
626  /// semantics, which we will document soon
627  USD_API
628  bool AddConnection(const SdfPath& source,
630 
631  /// Removes \p target from the list of targets.
632  ///
633  /// Issue an error if \p source identifies a prototype prim or an object
634  /// descendant to a prototype prim. It is not valid to author connections
635  /// to these objects.
636  USD_API
637  bool RemoveConnection(const SdfPath& source) const;
638 
639  /// Make the authoring layer's opinion of the connection list explicit,
640  /// and set exactly to \p sources.
641  ///
642  /// Issue an error if \p source identifies a prototype prim or an object
643  /// descendant to a prototype prim. It is not valid to author connections
644  /// to these objects.
645  ///
646  /// If any path in \p sources is invalid, issue an error and return false.
647  USD_API
648  bool SetConnections(const SdfPathVector& sources) const;
649 
650  /// Remove all opinions about the connections list from the current edit
651  /// target.
652  USD_API
653  bool ClearConnections() const;
654 
655  /// Compose this attribute's connections and fill \p sources with the
656  /// result. All preexisting elements in \p sources are lost.
657  ///
658  /// Returns true if any connection path opinions have been authored and no
659  /// composition errors were encountered, returns false otherwise.
660  /// Note that authored opinions may include opinions that clear the
661  /// connections and a return value of true does not necessarily indicate
662  /// that \p sources will contain any connection paths.
663  ///
664  /// See \ref Usd_ScenegraphInstancing_TargetsAndConnections for details on
665  /// behavior when targets point to objects beneath instance prims.
666  ///
667  /// The result is not cached, and thus recomputed on each query.
668  USD_API
669  bool GetConnections(SdfPathVector* sources) const;
670 
671  /// Return true if this attribute has any authored opinions regarding
672  /// connections. Note that this includes opinions that remove connections,
673  /// so a true return does not necessarily indicate that this attribute has
674  /// connections.
675  USD_API
676  bool HasAuthoredConnections() const;
677 
678  /// @}
679 
680  // ---------------------------------------------------------------------- //
681  /// \anchor Usd_AttributeColorSpaceAPI
682  /// \name ColorSpace API
683  ///
684  /// The color space in which a given color or texture valued attribute is
685  /// authored is set as token-valued metadata 'colorSpace' on the attribute.
686  /// Please refer to GfColorSpaceNames for a list of built in color space
687  /// token values.
688  ///
689  /// For color or texture attributes that don't have an authored 'colorSpace'
690  /// value, the fallback color space may be authored on the owning prim,
691  /// and determined using the UsdColorSpaceAPI applied schema.
692  ///
693  /// \ref GfColorSpaceNames "Standard color space names"
694  ///
695  /// @{
696  // ---------------------------------------------------------------------- //
697 
698  /// Gets the color space in which the attribute is authored if it has been
699  /// explicitly set. If the color space is not authored, any color space
700  /// set on the attribute's prim definiton will be returned.
701  /// Use \ref UsdColorSpaceAPI in order to compute the color space taking
702  /// into account any inherited color spaces.
703  ///
704  /// \sa SetColorSpace()
705  /// \ref GfColorSpaceNames "Standard color space names"
706  /// \ref UsdColorSpaceAPI "Usd Prim Color Space API"
707  USD_API
708  TfToken GetColorSpace() const;
709 
710  /// Sets the color space of the attribute to \p colorSpace.
711  /// \param colorSpace The target color space for this attribute.
712  ///
713  /// \ref UsdColorSpaceAPI "Usd Prim Color Space API" provides methods
714  /// to compute an attribute's resolved color, considering any inherited
715  /// colorspaces. Standard color space names are listed in
716  /// \ref GfColorSpaceNames.
717  ///
718  /// \sa GetColorSpace()
719  USD_API
720  void SetColorSpace(const TfToken &colorSpace) const;
721 
722  /// Returns whether color space is authored on the attribute.
723  /// \sa GetColorSpace()
724  USD_API
725  bool HasColorSpace() const;
726 
727  /// Clears authored color space value on the attribute.
728  /// \sa SetColorSpace()
729  USD_API
730  bool ClearColorSpace() const;
731 
732  /// @}
733 
734  /// \name Limits Dictionary
735  ///
736  /// The limits dictionary contains minimum and maximum values for the
737  /// attribute, organized by purpose into sub-dictionaries (see, e.g.,
738  /// UsdAttribute::GetSoftLimits() and UsdAttribute::GetHardLimits()).
739  ///
740  /// Each sub-dictionary can store a minimum and maximum value for a
741  /// different purpose (encoded under the \c UsdLimitsKeys->Minimum and
742  /// \c UsdLimitsKeys->Maximum keys, respectively). For example the "soft"
743  /// sub-dictionary is for limits which usually hold but can be exceeded
744  /// as necessary.
745  ///
746  /// Limits sub-dictionaries may store additional related values as well (see
747  /// UsdAttributeLimits::Set()).
748  ///
749  /// For example, a limits dictionary might look like the following:
750  /// \code
751  /// def "MyPrim"
752  /// {
753  /// int attr = 7 (
754  /// limits = {
755  /// dictionary soft = {
756  /// int minimum = 5
757  /// int maximum = 10
758  /// bool customKey = 1
759  /// }
760  /// dictionary hard = {
761  /// int minimum = 0
762  /// int maximum = 15
763  /// }
764  /// dictionary customLimits = {
765  /// int maximum = 25
766  /// }
767  /// }
768  /// )
769  /// }
770  /// \endcode
771  ///
772  /// UsdAttribute's value authoring API does not enforce limits constraints,
773  /// but authored values that lie outside the hard limits will trigger
774  /// validation errors.
775  ///
776  /// @{
777 
778  /// Return the composed limits dictionary for the attribute.
779  ///
780  /// \sa GetSoftLimits()(), GetHardLimits()
781  USD_API
782  VtDictionary GetLimits() const;
783 
784  /// Set the limits dictionary for the attribute to \p limits, at the current
785  /// edit target. Return \c true on success.
786  ///
787  /// Limits values must be nested inside sub-dictionaries, and the types of
788  /// encoded minimum and maximum values must match the value type of the
789  /// attribute.
790  ///
791  /// Note that since this field is dictionary-valued, its composed value will
792  /// be the combination of all its entries as specified across all relevant
793  /// opinions. Overrides occur per-entry rather than the dictionary as a
794  /// whole.
795  ///
796  /// \sa GetSoftLimits(), GetHardLimits() for more convenient validation,
797  /// editing, and look-up API
798  USD_API
799  bool SetLimits(const VtDictionary& limits) const;
800 
801  /// Return whether a limits dictionary is authored for the attribute.
802  USD_API
803  bool HasAuthoredLimits() const;
804 
805  /// Clear the authored limits dictionary for the attribute, at the current
806  /// edit target.
807  ///
808  /// Note that since this field is dictionary-valued, clearing it at the
809  /// current edit target will not necessarily result in clearing the entire
810  /// composed value.
811  USD_API
812  bool ClearLimits() const;
813 
814  /// Return a UsdAttributeLimits object configured to edit the attribute's
815  /// soft limits sub-dictionary.
816  ///
817  /// Soft limits are intended to provide a value range that is typical or
818  /// useful for most purposes, but which may be exceeded as necessary.
819  ///
820  /// UsdAttribute's value authoring API does not enforce soft limits.
821  ///
822  /// \sa GetHardLimits()
823  USD_API
825 
826  /// Return a UsdAttributeLimits object configured to edit the attribute's
827  /// hard limits sub-dictionary.
828  ///
829  /// Hard limits are intended to provide a strict range that the attribute's
830  /// value is expected to conform to.
831  ///
832  /// UsdAttribute's value authoring API does not enforce hard limits, but an
833  /// authored value that lies outside the hard limits will trigger a
834  /// validation error.
835  ///
836  /// \sa GetSoftLimits()
837  USD_API
839 
840  /// Return a UsdAttributeLimits object configured to edit the attribute's
841  /// limits sub-dictionary given by \p key.
842  ///
843  /// Custom limits values are for use by clients for their own specific
844  /// purposes. UsdAttribute's value API does not enforce them.
845  ///
846  /// \sa GetSoftLimits(), GetHardLimits()
847  USD_API
848  UsdAttributeLimits GetLimits(const TfToken& key) const;
849 
850  /// @}
851 
852  /// \anchor Usd_AttributeArraySizeConstraintAPI
853  /// \name Array Size Constraint
854  ///
855  /// For array-valued attributes, the array size constraint value encodes
856  /// information about the expected number of elements and the tuple-length
857  /// (i.e., column count):
858  ///
859  /// \li If the value is 0 (the fallback), the array is dynamic and its size
860  /// is unrestricted.
861  /// \li If the value is greater than 0, it indicates the exact, fixed size
862  /// of the array.
863  /// \li If the value is less than 0, its absolute value is the array's
864  /// tuple-length. The array's size is unrestricted, but must be a multiple
865  /// of this tuple-length.
866  ///
867  /// UsdAttribute's value authoring API does not enforce these constraints,
868  /// but violating them will trigger validation errors.
869  ///
870  /// @{
871 
872  /// Return the array size constraint value for this attribute.
873  USD_API
874  int64_t GetArraySizeConstraint() const;
875 
876  /// Set the array size constraint value for this attribute.
877  USD_API
878  bool SetArraySizeConstraint(int64_t constraint) const;
879 
880  /// Return whether an array size constraint value is authored on this
881  /// attribute.
882  USD_API
883  bool HasAuthoredArraySizeConstraint() const;
884 
885  /// Clear the authored array size constraint value for this attribute at
886  /// the current edit target.
887  USD_API
888  bool ClearArraySizeConstraint() const;
889 
890  /// @}
891 
892  // ---------------------------------------------------------------------- //
893  // Private Methods and Members
894  // ---------------------------------------------------------------------- //
895 private:
896  friend class UsdAttributeQuery;
897  friend class UsdObject;
898  friend class UsdPrim;
899  friend class UsdSchemaBase;
900  friend class Usd_PrimData;
902 
903  UsdAttribute(const Usd_PrimDataHandle &prim,
904  const SdfPath &proxyPrimPath,
905  const TfToken &attrName)
906  : UsdProperty(UsdTypeAttribute, prim, proxyPrimPath, attrName) {}
907 
908  UsdAttribute(UsdObjType objType,
909  const Usd_PrimDataHandle &prim,
910  const SdfPath &proxyPrimPath,
911  const TfToken &propName)
912  : UsdProperty(objType, prim, proxyPrimPath, propName) {}
913 
914  SdfAttributeSpecHandle
915  _CreateSpec(const SdfValueTypeName &typeName, bool custom,
916  const SdfVariability &variability) const;
917 
918  // Like _CreateSpec(), but fail if this attribute is not built-in and there
919  // isn't already existing scene description to go on rather than stamping
920  // new information.
921  SdfAttributeSpecHandle _CreateSpec() const;
922 
923  bool _Create(const SdfValueTypeName &typeName, bool custom,
924  const SdfVariability &variability) const;
925 
926  template <typename T>
927  bool _Get(T* value, UsdTimeCode time) const;
928 
929  template <typename T>
930  bool _Set(const T& value, UsdTimeCode time) const;
931 
932  SdfPath
933  _GetPathForAuthoring(const SdfPath &path, std::string* whyNot) const;
934 };
935 
937 
938 #endif // PXR_USD_USD_ATTRIBUTE_H
UsdStage * _GetStage() const
Definition: object.h:704
USD_API TfToken GetRoleName() const
Return the roleName for this attribute's typeName.
USD_API bool ClearColorSpace() const
std::string upper(string_view a)
Return an all-upper case version of a (locale-independent).
Definition: strutil.h:500
USD_API bool ClearConnections() const
USD_API bool GetConnections(SdfPathVector *sources) const
USD_API bool GetBracketingTimeSamples(double desiredTime, double *lower, double *upper, bool *hasTimeSamples) const
USD_API bool SetSpline(const TsSpline &spline)
Set the spline using the current edit target.
static constexpr UsdTimeCode Default()
Definition: timeCode.h:113
#define USD_API
Definition: api.h:23
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Definition: attribute.h:468
USD_API bool SetConnections(const SdfPathVector &sources) const
USD_API bool HasAuthoredValueOpinion() const
GT_API const UT_StringHolder time
USD_API void Block() const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USD_API bool SetVariability(SdfVariability variability) const
bool GetFallbackValue(T *value) const
USD_API bool HasSpline() const
USD_API SdfValueTypeName GetTypeName() const
Return the "scene description" value type name for this attribute.
USD_API bool HasFallbackValue() const
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Quat< T > spline(const Quat< T > &q0, const Quat< T > &q1, const Quat< T > &q2, const Quat< T > &q3, T t) IMATH_NOEXCEPT
Definition: ImathQuat.h:621
UsdObjType
Definition: object.h:35
USD_API bool ClearAtTime(UsdTimeCode time) const
USD_API bool HasAuthoredValue() const
USD_API UsdResolveInfo GetResolveInfo() const
static USD_API bool GetUnionedTimeSamples(const std::vector< UsdAttribute > &attrs, std::vector< double > *times)
UsdAttribute()
Construct an invalid attribute.
Definition: attribute.h:186
USD_API int64_t GetArraySizeConstraint() const
Return the array size constraint value for this attribute.
GLsizei GLenum * sources
Definition: glcorearb.h:2542
Definition: token.h:70
friend struct UsdPrim_AttrConnectionFinder
Definition: attribute.h:901
USD_API bool AddConnection(const SdfPath &source, UsdListPosition position=UsdListPositionBackOfPrependList) const
USD_API bool SetLimits(const VtDictionary &limits) const
std::vector< class SdfPath > SdfPathVector
USD_API UsdAttributeLimits GetHardLimits() const
USD_API bool HasValue() const
USD_API bool GetTimeSamples(std::vector< double > *times) const
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
USD_API size_t GetNumTimeSamples() const
USD_API VtDictionary GetLimits() const
USD_API void SetColorSpace(const TfToken &colorSpace) const
Definition: prim.h:116
USD_API bool HasAuthoredConnections() const
bool Set(const T &value, UsdTimeCode time=UsdTimeCode::Default()) const
Definition: attribute.h:531
Definition: path.h:280
USD_API bool ClearDefault() const
Shorthand for ClearAtTime(UsdTimeCode::Default()).
bool GetFallbackValue(T *value) const
Definition: attribute.h:481
SdfVariability
Definition: types.h:159
USD_API TsSpline GetSpline() const
USD_API bool Clear() const
USD_API bool ClearArraySizeConstraint() const
std::vector< UsdAttribute > UsdAttributeVector
A std::vector of UsdAttributes.
Definition: attribute.h:31
std::string lower(string_view a)
Return an all-upper case version of a (locale-independent).
Definition: strutil.h:493
USD_API bool ClearLimits() const
USD_API bool HasAuthoredArraySizeConstraint() const
SIM_API const UT_StringHolder position
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USD_API bool SetArraySizeConstraint(int64_t constraint) const
Set the array size constraint value for this attribute.
USD_API bool GetTimeSamplesInInterval(const GfInterval &interval, std::vector< double > *times) const
USD_API TfToken GetColorSpace() const
static USD_API bool GetUnionedTimeSamplesInInterval(const std::vector< UsdAttribute > &attrs, const GfInterval &interval, std::vector< double > *times)
USD_API bool SetTypeName(const SdfValueTypeName &typeName) const
UsdListPosition
Definition: common.h:71
USD_API bool RemoveConnection(const SdfPath &source) const
USD_API bool ValueMightBeTimeVarying() const
USD_API UsdAttributeLimits GetSoftLimits() const
USD_API bool HasAuthoredLimits() const
Return whether a limits dictionary is authored for the attribute.
Definition: value.h:89
USD_API SdfVariability GetVariability() const
USD_API void BlockAnimation() const
USD_API bool HasColorSpace() const