HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
inbetweenShape.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 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_SKEL_INBETWEEN_SHAPE_H
8 #define PXR_USD_USD_SKEL_INBETWEEN_SHAPE_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/usdSkel/api.h"
12 
13 #include "pxr/usd/usd/attribute.h"
14 #include "pxr/usd/usdSkel/tokens.h"
15 
17 
18 
19 /// \class UsdSkelInbetweenShape
20 ///
21 /// Schema wrapper for UsdAttribute for authoring and introspecting attributes
22 /// that serve as inbetween shapes of a UsdSkelBlendShape.
23 ///
24 /// Inbetween shapes allow an explicit shape to be specified when the blendshape
25 /// to which it's bound is evaluated at a certain weight. For example, rather
26 /// than performing piecewise linear interpolation between a primary shape and
27 /// the rest shape at weight 0.5, an inbetween shape could be defined at the
28 /// weight. For weight values greater than 0.5, a shape would then be resolved
29 /// by linearly interpolating between the inbetween shape and the primary
30 /// shape, while for weight values less than or equal to 0.5, the shape is
31 /// resolved by linearly interpolating between the inbetween shape and the
32 /// primary shape.
34 {
35 public:
36  /// Default constructor returns an invalid inbetween shape.
38 
39  /// Speculative constructor that will produce a valid UsdSkelInbetweenShape
40  /// when \p attr already represents an attribute that is an Inbetween, and
41  /// produces an \em invalid Inbetween otherwise (i.e.
42  /// \ref UsdSkelInbetweenShape_bool "operator bool()" will return false).
43  ///
44  /// Calling \c UsdSkelInbetweenShape::IsInbetween(attr) will return the same
45  /// truth value as this constructor, but if you plan to subsequently use the
46  /// Inbetween anyways, just use this constructor.
48  explicit UsdSkelInbetweenShape(const UsdAttribute& attr);
49 
50  /// Return the location at which the shape is applied.
52  bool GetWeight(float* weight) const;
53 
54  /// Set the location at which the shape is applied.
56  bool SetWeight(float weight) const;
57 
58  /// Has a weight value been explicitly authored on this shape?
59  ///
60  /// \sa GetWeight()
62  bool HasAuthoredWeight() const;
63 
64  /// Get the point offsets corresponding to this shape.
66  bool GetOffsets(VtVec3fArray* offsets) const;
67 
68  /// Set the point offsets corresponding to this shape.
70  bool SetOffsets(const VtVec3fArray& offsets) const;
71 
72  /// Returns a valid normal offsets attribute if the shape has normal
73  /// offsets. Returns an invalid attribute otherwise.
76 
77  /// Returns the existing normal offsets attribute if the shape has
78  /// normal offsets, or creates a new one.
81  CreateNormalOffsetsAttr(const VtValue &defaultValue = VtValue()) const;
82 
83  /// Get the normal offsets authored for this shape.
84  /// Normal offsets are optional, and may be left unspecified.
86  bool GetNormalOffsets(VtVec3fArray* offsets) const;
87 
88  /// Set the normal offsets authored for this shape.
90  bool SetNormalOffsets(const VtVec3fArray& offsets) const;
91 
92  /// Test whether a given UsdAttribute represents a valid Inbetween, which
93  /// implies that creating a UsdSkelInbetweenShape from the attribute will
94  /// succeed.
95  ///
96  /// Succes implies that \c attr.IsDefined() is true.
98  static bool IsInbetween(const UsdAttribute& attr);
99 
100  // ---------------------------------------------------------------
101  /// \name UsdAttribute API
102  // ---------------------------------------------------------------
103  /// @{
104 
105  /// Allow UsdSkelInbetweenShape to auto-convert to UsdAttribute,
106  /// so you can pass a UsdSkelInbetweenShape to any function that
107  /// accepts a UsdAttribute or const-ref thereto.
108  operator UsdAttribute const& () const { return _attr; }
109 
110  /// Explicit UsdAttribute extractor.
111  UsdAttribute const &GetAttr() const { return _attr; }
112 
113  /// Return true if the wrapped UsdAttribute::IsDefined(), and in
114  /// addition the attribute is identified as an Inbetween.
115  bool IsDefined() const { return IsInbetween(_attr); }
116 
117  /// \anchor UsdSkelInbetweenShape_bool
118  /// Return true if this Inbetween is valid for querying and
119  /// authoring values and metadata, which is identically equivalent
120  /// to IsDefined().
121  explicit operator bool() const {
122  return IsDefined() ? (bool)_attr : 0;
123  }
124 
125  bool operator==(const UsdSkelInbetweenShape& o) const {
126  return _attr == o._attr;
127  }
128 
129  bool operator!=(const UsdSkelInbetweenShape& o) const {
130  return !(*this == o);
131  }
132 
133  /// @}
134 
135 private:
136  friend class UsdSkelBlendShape;
137 
138  /// Validate that the given \p name is a valid attribute name for
139  /// an inbetween.
140  static bool _IsValidInbetweenName(const std::string& name,
141  bool quiet=false);
142 
143  /// Validate that the given \p name contains the inbetweens namespace.
144  /// Does not validate \p name as a legal property identifier.
145  static bool _IsNamespaced(const TfToken& name);
146 
147  /// Return \p name prepended with the proper inbetween namespace, if
148  /// it is not already prefixed.
149  ///
150  /// Does not validate \p name as a legal property identifier, but will
151  /// verify that \p name contains no reserved keywords, and will return
152  /// an empty TfToken if it does. If \p quiet is true, the verification
153  /// will be silent.
154  static TfToken _MakeNamespaced(const TfToken& name, bool quiet=false);
155 
156  static const TfToken& _GetNamespacePrefix();
157 
158  static const TfToken& _GetNormalOffsetsSuffix();
159 
160  UsdAttribute _GetNormalOffsetsAttr(bool create) const;
161 
162  /// Factory for UsdBlendShape's use, so that we can encapsulate the
163  /// logic of what discriminates an Inbetween in this class, while
164  /// preserving the pattern that attributes can only be created via
165  /// their container objects.
166  ///
167  /// The name of the created attribute may or may not be the specified
168  /// \p attrName, due to the possible need to apply property namespacing.
169  ///
170  /// \return an invalid Inbetween if we failed to create a valid
171  /// attribute, o ra valid Inbetween otherwise. It is not an error
172  /// to create over an existing, compatible attribute.
173  ///
174  /// \sa UsdPrim::CreateAttribute()
175  static UsdSkelInbetweenShape _Create(const UsdPrim& prim,
176  const TfToken& name);
177 
178  UsdAttribute _attr;
179 };
180 
181 
183 
184 #endif // PXR_USD_USD_SKEL_INBETWEEN_SHAPE_H
bool IsDefined() const
USDSKEL_API bool SetWeight(float weight) const
Set the location at which the shape is applied.
static USDSKEL_API bool IsInbetween(const UsdAttribute &attr)
USDSKEL_API bool SetNormalOffsets(const VtVec3fArray &offsets) const
Set the normal offsets authored for this shape.
USDSKEL_API bool SetOffsets(const VtVec3fArray &offsets) const
Set the point offsets corresponding to this shape.
OutGridT const XformOp bool bool
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2621
Definition: token.h:70
USDSKEL_API bool HasAuthoredWeight() const
USDSKEL_API bool GetWeight(float *weight) const
Return the location at which the shape is applied.
Definition: prim.h:116
USDSKEL_API bool GetOffsets(VtVec3fArray *offsets) const
Get the point offsets corresponding to this shape.
GLuint const GLchar * name
Definition: glcorearb.h:786
#define USDSKEL_API
Definition: api.h:23
bool operator!=(const UsdSkelInbetweenShape &o) const
USDSKEL_API bool GetNormalOffsets(VtVec3fArray *offsets) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
UsdSkelInbetweenShape()
Default constructor returns an invalid inbetween shape.
UsdAttribute const & GetAttr() const
Explicit UsdAttribute extractor.
USDSKEL_API UsdAttribute CreateNormalOffsetsAttr(const VtValue &defaultValue=VtValue()) const
USDSKEL_API UsdAttribute GetNormalOffsetsAttr() const
Definition: value.h:146
bool operator==(const UsdSkelInbetweenShape &o) const