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/value.h"
20 #include "pxr/base/gf/interval.h"
21 
22 #include <string>
23 #include <type_traits>
24 #include <vector>
25 
27 
28 
29 class UsdAttribute;
30 class TsSpline;
31 
32 /// A std::vector of UsdAttributes.
33 typedef std::vector<UsdAttribute> UsdAttributeVector;
34 
35 /// \class UsdAttribute
36 ///
37 /// Scenegraph object for authoring and retrieving numeric, string, and array
38 /// valued data, sampled over time, or animated by a spline
39 ///
40 /// The allowed value types for UsdAttribute are dictated by the Sdf
41 /// ("Scene Description Foundations") core's data model, which we summarize in
42 /// \ref Usd_Page_Datatypes .
43 ///
44 /// \section Usd_AttributeQualities Attribute Defining Qualities
45 ///
46 /// In addition to its value type, an Attribute has two other defining
47 /// qualities:
48 /// \li <b>Variability</b> Expresses whether an attribute is intended to
49 /// have time samples or a spline (GetVariability() == \c SdfVariabilityVarying),
50 /// or only a default (GetVariability() == \c SdfVariabilityUniform). For more
51 /// on reasoning about time samples,
52 /// see \ref Usd_AttributeValueMethods "Value & Time-Sample Accessors".
53 ///
54 /// \li <b>Custom</b> Determines whether an attribute belongs to a
55 /// schema (IsCustom() == \c false), or is a user-defined, custom attribute.
56 /// schema attributes will always be defined on a prim of the schema type,
57 /// and may possess fallback values from the schema, whereas custom
58 /// attributes must always first be authored in order to be defined. Note
59 /// that \em custom is actually an aspect of UsdProperty, as UsdRelationship
60 /// can also be custom or provided by a schema.
61 ///
62 /// \section Usd_AttributeExistence Attribute Creation and Existence
63 ///
64 /// One can always create an attribute generically via
65 /// UsdPrim::CreateAttribute(), which ensures that an attribute "is defined"
66 /// in the current \ref UsdEditTarget . In order to author any metadata or
67 /// a default or timesample for an attribute, <em>it must first be defined</em>.
68 /// It is sufficient that the attribute be defined in any one of the layers
69 /// participating in the stage's current composition; for \em builtin
70 /// attributes (those belonging to the owning prim's defining schema, i.e.
71 /// the most specific subclass of UsdTypedSchema for which prim.IsA<schema>()
72 /// will evaluate to true) there need be no authored scene description, because
73 /// a definition is provided by the prim's schema definition.
74 ///
75 /// <b>Creating</b> an attribute does not imply that the attribute has a value.
76 /// More broadly, in the following code:
77 /// \code
78 /// if (UsdAttribute attr = prim.GetAttribute(TfToken("myAttr"))){
79 /// ...
80 /// }
81 /// \endcode
82 ///
83 /// The UsdAttribute passes the bool test, because it is defined; however,
84 /// inside the clause, we have no guarantee that attr has a value.
85 ///
86 /// \section Usd_AttributeInterpolation Attribute Value Interpolation
87 ///
88 /// UsdAttribute supports two interpolation behaviors when retrieving
89 /// attribute values at times where no value is explicitly authored.
90 /// The desired behavior may be specified via UsdStage::SetInterpolationType.
91 /// That behavior will be used for all calls to UsdAttribute::Get.
92 ///
93 /// Note that for attributes with spline value sources, the interpolation
94 /// behavior is determined by the spline itself, and the interpolation type
95 /// set on the stage is ignored.
96 ///
97 /// The supported interpolation types are:
98 ///
99 /// \li <b>Held</b> Attribute values are held constant between authored
100 /// values. An attribute's value will be equal to the nearest preceding
101 /// authored value. If there is no preceding authored value, the value
102 /// will be equal to the nearest subsequent value.
103 ///
104 /// \li <b>Linear</b> Attribute values are linearly interpolated between
105 /// authored values.
106 ///
107 /// Linear interpolation is only supported for certain data types. See
108 /// \ref USD_LINEAR_INTERPOLATION_TYPES for the list of these types. Types
109 /// that do not support linear interpolation will use held interpolation
110 /// instead.
111 ///
112 /// Linear interpolation is done element-by-element for array, vector,
113 /// and matrix data types. If linear interpolation is requested for
114 /// two array values with different sizes, held interpolation will
115 /// be used instead.
116 ///
117 /// \section Usd_AttributeBlocking Attribute Value Blocking
118 ///
119 /// While prims can effectively be removed from a scene by
120 /// \ref Usd_ActiveInactive "deactivating them," properties cannot. However,
121 /// it is possible to **block an attribute's value**, thus making the attribute
122 /// behave as if it has a definition (and possibly metadata), but no authored
123 /// value.
124 ///
125 ///
126 /// One blocks an attribute using UsdAttribute::Block(), which will block the
127 /// attribute in the stage's current UsdEditTarget, by authoring an
128 /// SdfValueBlock in the attribute's *default*, and only values authored in
129 /// weaker layers than the editTarget will be blocked. If the value block is
130 /// the strongest authored opinion for the attribute, the HasAuthoredValue()
131 /// method will return *false*, and the HasValue() and Get() methods will
132 /// only return *true* if the attribute possesses a fallback value from the
133 /// prim's schema. "Unblocking" a blocked attribute is as simple as setting
134 /// a *default* or timeSample value for the attribute in the same or stronger
135 /// layer.
136 ///
137 /// \subsection Usd_TimeVaryingAttributeBlocks Time-varying Blocks
138 ///
139 /// The semantics of \ref Usd_ValueClips_Overview "Value Clips" necessitate
140 /// the ability to selectively block an attribute's value for only some intervals
141 /// in its authored range of samples. One can block an attribute's value at
142 /// time *t* by calling `attr.Set(SdfValueBlock, t)` When an attribute is thusly
143 /// "partially blocked", UsdAttribute::Get() will succeed only for those time
144 /// intervals whose left/earlier bracketing timeSample is **not** SdfValueBlock.
145 ///
146 /// Due to this time-varying potential of value blocking, it may be the case
147 /// that an attribute's HasAuthoredValue() and HasValue() methods both return
148 /// *true* (because they do not and cannot consider time-varying blocks), but
149 /// Get() may yet return *false* over some intervals.
150 ///
151 /// \section Usd_AssetPathValuedAttributes Attributes of type SdfAssetPath and UsdAttribute::Get()
152 ///
153 /// If an attribute's value type is SdfAssetPath or SdfAssetPathArray, Get()
154 /// does extra work to perform variable expression evaluation and compute
155 /// resolved asset paths. The layer that has the strongest value opinion is
156 /// used as the anchor for "relative" asset paths. The unresolved results are
157 /// available through SdfAssetPath::GetAssetPath. The fully resolved path
158 /// (including any substitutions) can be retrieved with
159 /// SdfAssetPath::GetResolvedPath. The authored or evaluated paths may
160 /// be explicitly retrieved through SdfAssetPath::GetAuthoredPath and
161 /// SdfAssetPath::GetEvaluatedPath respectively.
162 ///
163 /// Clients that call Get() on many asset-path-valued attributes may wish to
164 /// employ an ArResolverScopedCache to improve asset path resolution
165 /// performance.
166 ///
167 class UsdAttribute : public UsdProperty {
168 public:
169  /// Construct an invalid attribute.
171 
172  // --------------------------------------------------------------------- //
173  /// \name Core Metadata
174  // --------------------------------------------------------------------- //
175 
176  /// @{
177 
178  /// An attribute's variability expresses whether it is intended to have
179  /// time-samples or splines (\c SdfVariabilityVarying), or only a single
180  /// default value (\c SdfVariabilityUniform).
181  ///
182  /// Variability is required meta-data of all attributes, and its fallback
183  /// value is SdfVariabilityVarying.
184  USD_API
186 
187  /// Set the value for variability at the current EditTarget, return true
188  /// on success, false if the value can not be written.
189  ///
190  /// \b Note that this value should not be changed as it is typically either
191  /// automatically authored or provided by a property definition. This method
192  /// is provided primarily for fixing invalid scene description.
193  USD_API
194  bool SetVariability(SdfVariability variability) const;
195 
196  /// Return the "scene description" value type name for this attribute.
197  USD_API
199 
200  /// Set the value for typeName at the current EditTarget, return true on
201  /// success, false if the value can not be written.
202  ///
203  /// \b Note that this value should not be changed as it is typically either
204  /// automatically authored or provided by a property definition. This method
205  /// is provided primarily for fixing invalid scene description.
206  USD_API
207  bool SetTypeName(const SdfValueTypeName& typeName) const;
208 
209  /// Return the roleName for this attribute's typeName.
210  USD_API
211  TfToken GetRoleName() const;
212 
213  /// @}
214 
215  // --------------------------------------------------------------------- //
216  /// \anchor Usd_AttributeValueMethods
217  /// \name Value & Time-Sample Accessors
218  // --------------------------------------------------------------------- //
219 
220  /// @{
221 
222  /// Populates a vector with authored sample times.
223  /// Returns false only on error.
224  ///
225  /// This method uses the standard resolution semantics, so if a stronger
226  /// default value is authored over weaker time samples, the default value
227  /// will hide the underlying timesamples.
228  ///
229  /// \note This function will query all value clips that may contribute
230  /// time samples for this attribute, opening them if needed. This may be
231  /// expensive, especially if many clips are involved.
232  ///
233  /// \param times - on return, will contain the \em sorted, ascending
234  /// timeSample ordinates. Any data in \p times will be lost, as this
235  /// method clears \p times.
236  ///
237  /// \sa UsdAttribute::GetTimeSamplesInInterval
238  USD_API
239  bool GetTimeSamples(std::vector<double>* times) const;
240 
241  /// Populates a vector with authored sample times in \p interval.
242  /// Returns false only on an error.
243  ///
244  /// \note This function will only query the value clips that may
245  /// contribute time samples for this attribute in the given interval,
246  /// opening them if necessary.
247  ///
248  /// \param interval - the \ref GfInterval on which to gather time samples.
249  ///
250  /// \param times - on return, will contain the \em sorted, ascending
251  /// timeSample ordinates. Any data in \p times will be lost, as this
252  /// method clears \p times.
253  ///
254  /// \sa UsdAttribute::GetTimeSamples
255  USD_API
256  bool GetTimeSamplesInInterval(const GfInterval& interval,
257  std::vector<double>* times) const;
258 
259  /// Populates the given vector, \p times with the union of all the
260  /// authored sample times on all of the given attributes, \p attrs.
261  ///
262  /// \note This function will query all value clips that may contribute
263  /// time samples for the attributes in \p attrs, opening them if needed.
264  /// This may be expensive, especially if many clips are involved.
265  ///
266  /// The accumulated sample times will be in sorted (increasing) order and
267  /// will not contain any duplicates.
268  ///
269  /// This clears any existing values in the \p times vector before
270  /// accumulating sample times of the given attributes.
271  ///
272  /// \return false if any of the attributes in \p attr are invalid or if
273  /// there's an error when fetching time-samples for any of the attributes.
274  ///
275  /// \sa UsdAttribute::GetTimeSamples
276  /// \sa UsdAttribute::GetUnionedTimeSamplesInInterval
277  USD_API
278  static bool GetUnionedTimeSamples(const std::vector<UsdAttribute> &attrs,
279  std::vector<double> *times);
280 
281  /// Populates the given vector, \p times with the union of all the
282  /// authored sample times in the GfInterval, \p interval on all of the
283  /// given attributes, \p attrs.
284  ///
285  /// \note This function will only query the value clips that may
286  /// contribute time samples for the attributes in \p attrs, in the
287  /// given \p interval, opening them if necessary.
288  ///
289  /// The accumulated sample times will be in sorted (increasing) order and
290  /// will not contain any duplicates.
291  ///
292  /// This clears any existing values in the \p times vector before
293  /// accumulating sample times of the given attributes.
294  ///
295  /// \return false if any of the attributes in \p attr are invalid or if
296  /// there's an error fetching time-samples for any of the attributes.
297  ///
298  /// \sa UsdAttribute::GetTimeSamplesInInterval
299  /// \sa UsdAttribute::GetUnionedTimeSamples
300  USD_API
302  const std::vector<UsdAttribute> &attrs,
303  const GfInterval &interval,
304  std::vector<double> *times);
305 
306  /// Returns the number of time samples that have been authored.
307  ///
308  /// This method uses the standard resolution semantics, so if a stronger
309  /// default value is authored over weaker time samples, the default value
310  /// will hide the underlying timesamples.
311  ///
312  /// \note This function will query all value clips that may contribute
313  /// time samples for this attribute, opening them if needed. This may be
314  /// expensive, especially if many clips are involved.
315  USD_API
316  size_t GetNumTimeSamples() const;
317 
318  /// Populate \a lower and \a upper with the next greater and lesser
319  /// value relative to the \a desiredTime. Return false if no value exists
320  /// or an error occurs, true if either a default value or timeSamples exist.
321  ///
322  /// Use standard resolution semantics: if a stronger default value is
323  /// authored over weaker time samples, the default value hides the
324  /// underlying timeSamples.
325  ///
326  /// 1) If a sample exists at the \a desiredTime, set both upper and lower
327  /// to \a desiredTime.
328  ///
329  /// 2) If samples exist surrounding, but not equal to the \a desiredTime,
330  /// set lower and upper to the bracketing samples nearest to the
331  /// \a desiredTime.
332  ///
333  /// 3) If the \a desiredTime is outside of the range of authored samples,
334  /// clamp upper and lower to the nearest time sample.
335  ///
336  /// 4) If no samples exist, do not modify upper and lower and set
337  /// \a hasTimeSamples to false.
338  ///
339  /// In cases (1), (2) and (3), set \a hasTimeSamples to true.
340  ///
341  /// All four cases above are considered to be successful, thus the return
342  /// value will be true and no error message will be emitted.
343  USD_API
344  bool GetBracketingTimeSamples(double desiredTime,
345  double* lower,
346  double* upper,
347  bool* hasTimeSamples) const;
348 
349  /// Return true if this attribute has an authored default value, authored
350  /// time samples or a fallback value provided by a registered schema. If
351  /// the attribute has been \ref Usd_AttributeBlocking "blocked", then
352  /// return `true` if and only if it has a fallback value.
353  USD_API
354  bool HasValue() const;
355 
356  /// \deprecated This method is deprecated because it returns `true` even when
357  /// an attribute is blocked. Please use HasAuthoredValue() instead. If
358  /// you truly need to know whether the attribute has **any** authored
359  /// value opinions, *including blocks*, you can make the following query:
360  /// `attr.GetResolveInfo().HasAuthoredValueOpinion()`
361  ///
362  /// Return true if this attribute has either an authored default value or
363  /// authored time samples.
364  USD_API
365  bool HasAuthoredValueOpinion() const;
366 
367  /// Return true if this attribute has either an authored default value or
368  /// authored time samples. If the attribute has been
369  /// \ref Usd_AttributeBlocking "blocked", then return `false`
370  USD_API
371  bool HasAuthoredValue() const;
372 
373  /// Return true if this attribute has a fallback value provided by
374  /// a registered schema.
375  USD_API
376  bool HasFallbackValue() const;
377 
378  /// Return true if it is possible, but not certain, that this attribute's
379  /// value changes over time, false otherwise.
380  ///
381  /// If this function returns false, it is certain that this attribute's
382  /// value remains constant over time.
383  ///
384  /// This function checks if the attribute either has more than 1 time
385  /// samples or is spline valued. Which is more efficient than actually
386  /// counting the time samples or evaluating the spline, both of which
387  /// are potentially expensive operations.
388  USD_API
389  bool ValueMightBeTimeVarying() const;
390 
391  /// Perform value resolution to fetch the value of this attribute at the
392  /// requested UsdTimeCode \p time, which defaults to \em default.
393  ///
394  /// If no value is authored at \p time but values are authored at other
395  /// times, this function will return an interpolated value based on the
396  /// stage's interpolation type.
397  /// See \ref Usd_AttributeInterpolation.
398  ///
399  /// An attribute's value may be discontinuous at time samples. This happens
400  /// when the stage is in held interpolation mode or when the sample values
401  /// are not interpolatable. To obtain the attribute's value immediately
402  /// before a given time sample, use
403  /// \link UsdTimeCode::PreTime() UsdTimeCode::PreTime(time)\endlink. This
404  /// evaluates the limit of the attribute's value as time approaches the
405  /// given \p time from the left.
406  ///
407  /// For example, if a string-valued attribute has time samples
408  /// `{1.0: "foo", 2.0: "bar"}`, calling Get() with UsdTimeCode(2.0)
409  /// returns "bar", whereas calling Get() with UsdTimeCode::PreTime(2.0)
410  /// returns "foo". However, if the attribute's values are interpolatable,
411  /// such as `{1.0: 3.0, 2.0: 4.0}`, then calling Get() with UsdTimeCode(2.0)
412  /// and UsdTimeCode::PreTime(2.0) will both return 4.0, since the value
413  /// is continuous at time=2.0.
414  ///
415  /// If no value is authored and no fallback value is provided by the
416  /// schema for this attribute, this function will return false. If the
417  /// consumer's use-case requires a default value, the consumer will need
418  /// to provide one, possibly using GetTypeName().GetDefaultValue().
419  ///
420  /// Value resolution first needs to determine the source of the strongest
421  /// value opinion for this attribute at the requested UsdTimeCode \p time.
422  /// But often (i.e. unless the attribute is affected by
423  /// \ref Usd_Page_ValueClips "Value Clips") the source of the resolved value
424  /// does not vary over time. UsdAttributeQuery finds the source opinion and
425  /// saves it so that repeated calls to UsdAttributeQuery::Get() avoid
426  /// redundant work.
427  ///
428  /// This templated accessor is designed for high performance data-streaming
429  /// applications, allowing one to fetch data into the same container
430  /// repeatedly, avoiding memory allocations when possible (VtArray
431  /// containers will be resized as necessary to conform to the size of
432  /// data being read).
433  ///
434  /// This template is only instantiated for the valid scene description
435  /// value types and their corresponding VtArray containers. See
436  /// \ref Usd_Page_Datatypes for the complete list of types.
437  ///
438  /// Values are retrieved without regard to this attribute's variability.
439  /// For example, a uniform attribute may retrieve time sample values
440  /// if any are authored. However, the USD_VALIDATE_VARIABILITY TF_DEBUG
441  /// code will cause debug information to be output if values that are
442  /// inconsistent with this attribute's variability are retrieved.
443  /// See UsdAttribute::GetVariability for more details.
444  ///
445  /// \return true if there was a value to be read, it was of the type T
446  /// requested, and we read it successfully - false otherwise.
447  ///
448  /// For more details, see \ref Usd_ValueResolution , and also
449  /// \ref Usd_AssetPathValuedAttributes for information on how to
450  /// retrieve resolved asset paths from SdfAssetPath-valued attributes.
451  template <typename T>
453  static_assert(!std::is_const<T>::value, "");
454  static_assert(SdfValueTypeTraits<T>::IsValueType, "");
455  return _Get(value, time);
456  }
457  /// \overload
458  /// Type-erased access, often not as efficient as typed access.
459  USD_API
460  bool Get(VtValue* value, UsdTimeCode time = UsdTimeCode::Default()) const;
461 
462  /// Perform value resolution to determine the source of the resolved
463  /// value of this attribute at the requested UsdTimeCode \p time.
464  USD_API
467 
468  /// Perform value resolution to determine the source of the resolved
469  /// value of this attribute at any non-default time.
470  ///
471  /// Often (i.e. unless the attribute is affected by
472  /// \ref Usd_Page_ValueClips "Value Clips") the source of the resolved value
473  /// does not vary over time. See UsdAttributeQuery as an example that takes
474  /// advantage of this quality of value resolution.
475  USD_API
477  GetResolveInfo() const;
478 
479  /// Set the value of this attribute in the current UsdEditTarget to
480  /// \p value at UsdTimeCode \p time, which defaults to \em default.
481  ///
482  /// Values are authored without regard to this attribute's variability.
483  /// For example, time sample values may be authored on a uniform
484  /// attribute. However, the USD_VALIDATE_VARIABILITY TF_DEBUG code
485  /// will cause debug information to be output if values that are
486  /// inconsistent with this attribute's variability are authored.
487  /// See UsdAttribute::GetVariability for more details.
488  ///
489  /// \return false and generate an error if type \c T does not match
490  /// this attribute's defined scene description type <b>exactly</b>,
491  /// or if there is no existing definition for the attribute, or if the
492  /// \p time is pre-time, which is only used to for querying for values at
493  /// the limit when the time is approached from the left.
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 ||
499  return _Set(value, time);
500  }
501 
502  /// \overload
503  /// As a convenience, we allow the setting of string value typed attributes
504  /// via a C string value.
505  USD_API
506  bool Set(const char* value, UsdTimeCode time = UsdTimeCode::Default()) const;
507 
508  /// \overload
509  USD_API
510  bool Set(const VtValue& value, UsdTimeCode time = UsdTimeCode::Default()) const;
511 
512  /// Returns true if the attribute has a spline as a value source.
513  ///
514  /// That is if a stronger default value is authored over weaker spline
515  /// value, the default value will hide the spline value and return false.
516  USD_API
517  bool HasSpline() const;
518 
519  /// Returns a copy of the spline.
520  ///
521  /// If a stronger default value is authored over weaker spline value, the
522  /// default value will hide the spline value.
523  USD_API
524  TsSpline GetSpline() const;
525 
526  /// Set the spline using the current edit target.
527  USD_API
528  bool SetSpline(const TsSpline &spline);
529 
530  /// Clears the authored default value, all time samples and spline for this
531  /// attribute at the current EditTarget and returns true on success.
532  ///
533  /// Calling clear when either no value is authored or no spec is present,
534  /// is a silent no-op returning true.
535  ///
536  /// This method does not affect any other data authored on this attribute.
537  USD_API
538  bool Clear() const;
539 
540  /// Clear the authored value for this attribute at the given
541  /// \a time, at the current EditTarget and return true on success.
542  /// UsdTimeCode::Default() can be used to clear the default value.
543  ///
544  /// Calling clear when either no value is authored or no spec is present,
545  /// is a silent no-op returning true.
546  ///
547  /// Issue a coding error if \p time is a pre-time, which is only used to
548  /// for querying for values at the limit when the time is approached from
549  /// the left.
550  USD_API
551  bool ClearAtTime(UsdTimeCode time) const;
552 
553  /// Shorthand for ClearAtTime(UsdTimeCode::Default()).
554  USD_API
555  bool ClearDefault() const;
556 
557  /// Remove all time samples on an attribute and author a *block*
558  /// \c default value. This causes the attribute to resolve as
559  /// if there were no authored value opinions in weaker layers.
560  ///
561  /// See \ref Usd_AttributeBlocking for more information, including
562  /// information on time-varying blocking.
563  USD_API
564  void Block() const;
565 
566  /// @}
567 
568  /// \name Querying and Editing Connections
569  /// @{
570 
571  /// Adds \p source to the list of connections, in the position
572  /// specified by \p position.
573  ///
574  /// Issue an error if \p source identifies a prototype prim or an object
575  /// descendant to a prototype prim. It is not valid to author connections
576  /// to these objects.
577  ///
578  /// What data this actually authors depends on what data is currently
579  /// authored in the authoring layer, with respect to list-editing
580  /// semantics, which we will document soon
581  USD_API
582  bool AddConnection(const SdfPath& source,
584 
585  /// Removes \p target from the list of targets.
586  ///
587  /// Issue an error if \p source identifies a prototype prim or an object
588  /// descendant to a prototype prim. It is not valid to author connections
589  /// to these objects.
590  USD_API
591  bool RemoveConnection(const SdfPath& source) const;
592 
593  /// Make the authoring layer's opinion of the connection list explicit,
594  /// and set exactly to \p sources.
595  ///
596  /// Issue an error if \p source identifies a prototype prim or an object
597  /// descendant to a prototype prim. It is not valid to author connections
598  /// to these objects.
599  ///
600  /// If any path in \p sources is invalid, issue an error and return false.
601  USD_API
602  bool SetConnections(const SdfPathVector& sources) const;
603 
604  /// Remove all opinions about the connections list from the current edit
605  /// target.
606  USD_API
607  bool ClearConnections() const;
608 
609  /// Compose this attribute's connections and fill \p sources with the
610  /// result. All preexisting elements in \p sources are lost.
611  ///
612  /// Returns true if any connection path opinions have been authored and no
613  /// composition errors were encountered, returns false otherwise.
614  /// Note that authored opinions may include opinions that clear the
615  /// connections and a return value of true does not necessarily indicate
616  /// that \p sources will contain any connection paths.
617  ///
618  /// See \ref Usd_ScenegraphInstancing_TargetsAndConnections for details on
619  /// behavior when targets point to objects beneath instance prims.
620  ///
621  /// The result is not cached, and thus recomputed on each query.
622  USD_API
623  bool GetConnections(SdfPathVector* sources) const;
624 
625  /// Return true if this attribute has any authored opinions regarding
626  /// connections. Note that this includes opinions that remove connections,
627  /// so a true return does not necessarily indicate that this attribute has
628  /// connections.
629  USD_API
630  bool HasAuthoredConnections() const;
631 
632  /// @}
633 
634  // ---------------------------------------------------------------------- //
635  /// \anchor Usd_AttributeColorSpaceAPI
636  /// \name ColorSpace API
637  ///
638  /// The color space in which a given color or texture valued attribute is
639  /// authored is set as token-valued metadata 'colorSpace' on the attribute.
640  /// Please refer to GfColorSpaceNames for a list of built in color space
641  /// token values.
642  ///
643  /// For color or texture attributes that don't have an authored 'colorSpace'
644  /// value, the fallback color space may be authored on the owning prim,
645  /// and determined using the UsdColorSpaceAPI applied schema.
646  ///
647  /// \ref GfColorSpaceNames "Standard color space names"
648  ///
649  /// @{
650  // ---------------------------------------------------------------------- //
651 
652  /// Gets the color space in which the attribute is authored if it has been
653  /// explicitly set. If the color space is not authored, any color space
654  /// set on the attribute's prim definiton will be returned.
655  /// Use \ref UsdColorSpaceAPI in order to compute the color space taking
656  /// into account any inherited color spaces.
657  ///
658  /// \sa SetColorSpace()
659  /// \ref GfColorSpaceNames "Standard color space names"
660  /// \ref UsdColorSpaceAPI "Usd Prim Color Space API"
661  USD_API
662  TfToken GetColorSpace() const;
663 
664  /// Sets the color space of the attribute to \p colorSpace.
665  /// \param colorSpace The target color space for this attribute.
666  ///
667  /// \ref UsdColorSpaceAPI "Usd Prim Color Space API" provides methods
668  /// to compute an attribute's resolved color, considering any inherited
669  /// colorspaces. Standard color space names are listed in
670  /// \ref GfColorSpaceNames.
671  ///
672  /// \sa GetColorSpace()
673  USD_API
674  void SetColorSpace(const TfToken &colorSpace) const;
675 
676  /// Returns whether color space is authored on the attribute.
677  /// \sa GetColorSpace()
678  USD_API
679  bool HasColorSpace() const;
680 
681  /// Clears authored color space value on the attribute.
682  /// \sa SetColorSpace()
683  USD_API
684  bool ClearColorSpace() const;
685 
686  /// @}
687 
688  // ---------------------------------------------------------------------- //
689  // Private Methods and Members
690  // ---------------------------------------------------------------------- //
691 private:
692  friend class UsdAttributeQuery;
693  friend class UsdObject;
694  friend class UsdPrim;
695  friend class UsdSchemaBase;
696  friend class Usd_PrimData;
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 
733 
734 #endif // PXR_USD_USD_ATTRIBUTE_H
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
UsdObjType
Definition: object.h:34
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:452
USD_API bool SetConnections(const SdfPathVector &sources) const
USD_API bool HasAuthoredValueOpinion() const
GT_API const UT_StringHolder time
USD_API void Block() const
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USD_API bool SetVariability(SdfVariability variability) 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:576
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:170
GLsizei GLenum * sources
Definition: glcorearb.h:2542
Definition: token.h:70
friend struct UsdPrim_AttrConnectionFinder
Definition: attribute.h:697
USD_API bool AddConnection(const SdfPath &source, UsdListPosition position=UsdListPositionBackOfPrependList) const
std::vector< class SdfPath > SdfPathVector
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
std::vector< UsdAttribute > UsdAttributeVector
A std::vector of UsdAttributes.
Definition: attribute.h:30
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:495
Definition: path.h:273
USD_API bool ClearDefault() const
Shorthand for ClearAtTime(UsdTimeCode::Default()).
SdfVariability
Definition: types.h:156
USD_API TsSpline GetSpline() const
USD_API bool Clear() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
std::string lower(string_view a)
Return an all-upper case version of a (locale-independent).
Definition: strutil.h:493
SIM_API const UT_StringHolder position
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
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
Definition: value.h:146
USD_API SdfVariability GetVariability() const
USD_API bool HasColorSpace() const