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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_USD_SKEL_INBETWEEN_SHAPE_H
25 #define PXR_USD_USD_SKEL_INBETWEEN_SHAPE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usdSkel/api.h"
29 
30 #include "pxr/usd/usd/attribute.h"
31 #include "pxr/usd/usdSkel/tokens.h"
32 
34 
35 
36 /// \class UsdSkelInbetweenShape
37 ///
38 /// Schema wrapper for UsdAttribute for authoring and introspecting attributes
39 /// that serve as inbetween shapes of a UsdSkelBlendShape.
40 ///
41 /// Inbetween shapes allow an explicit shape to be specified when the blendshape
42 /// to which it's bound is evaluated at a certain weight. For example, rather
43 /// than performing piecewise linear interpolation between a primary shape and
44 /// the rest shape at weight 0.5, an inbetween shape could be defined at the
45 /// weight. For weight values greater than 0.5, a shape would then be resolved
46 /// by linearly interpolating between the inbetween shape and the primary
47 /// shape, while for weight values less than or equal to 0.5, the shape is
48 /// resolved by linearly interpolating between the inbetween shape and the
49 /// primary shape.
51 {
52 public:
53  /// Default constructor returns an invalid inbetween shape.
55 
56  /// Speculative constructor that will produce a valid UsdSkelInbetweenShape
57  /// when \p attr already represents an attribute that is an Inbetween, and
58  /// produces an \em invalid Inbetween otherwise (i.e.
59  /// \ref UsdSkelInbetweenShape_bool "operator bool()" will return false).
60  ///
61  /// Calling \c UsdSkelInbetweenShape::IsInbetween(attr) will return the same
62  /// truth value as this constructor, but if you plan to subsequently use the
63  /// Inbetween anyways, just use this constructor.
65  explicit UsdSkelInbetweenShape(const UsdAttribute& attr);
66 
67  /// Return the location at which the shape is applied.
69  bool GetWeight(float* weight) const;
70 
71  /// Set the location at which the shape is applied.
73  bool SetWeight(float weight) const;
74 
75  /// Has a weight value been explicitly authored on this shape?
76  ///
77  /// \sa GetWeight()
79  bool HasAuthoredWeight() const;
80 
81  /// Get the point offsets corresponding to this shape.
83  bool GetOffsets(VtVec3fArray* offsets) const;
84 
85  /// Set the point offsets corresponding to this shape.
87  bool SetOffsets(const VtVec3fArray& offsets) const;
88 
89  /// Returns a valid normal offsets attribute if the shape has normal
90  /// offsets. Returns an invalid attribute otherwise.
93 
94  /// Returns the existing normal offsets attribute if the shape has
95  /// normal offsets, or creates a new one.
98  CreateNormalOffsetsAttr(const VtValue &defaultValue = VtValue()) const;
99 
100  /// Get the normal offsets authored for this shape.
101  /// Normal offsets are optional, and may be left unspecified.
103  bool GetNormalOffsets(VtVec3fArray* offsets) const;
104 
105  /// Set the normal offsets authored for this shape.
107  bool SetNormalOffsets(const VtVec3fArray& offsets) const;
108 
109  /// Test whether a given UsdAttribute represents a valid Inbetween, which
110  /// implies that creating a UsdSkelInbetweenShape from the attribute will
111  /// succeed.
112  ///
113  /// Succes implies that \c attr.IsDefined() is true.
115  static bool IsInbetween(const UsdAttribute& attr);
116 
117  // ---------------------------------------------------------------
118  /// \name UsdAttribute API
119  // ---------------------------------------------------------------
120  /// @{
121 
122  /// Allow UsdSkelInbetweenShape to auto-convert to UsdAttribute,
123  /// so you can pass a UsdSkelInbetweenShape to any function that
124  /// accepts a UsdAttribute or const-ref thereto.
125  operator UsdAttribute const& () const { return _attr; }
126 
127  /// Explicit UsdAttribute extractor.
128  UsdAttribute const &GetAttr() const { return _attr; }
129 
130  /// Return true if the wrapped UsdAttribute::IsDefined(), and in
131  /// addition the attribute is identified as an Inbetween.
132  bool IsDefined() const { return IsInbetween(_attr); }
133 
134  /// \anchor UsdSkelInbetweenShape_bool
135  /// Return true if this Inbetween is valid for querying and
136  /// authoring values and metadata, which is identically equivalent
137  /// to IsDefined().
138  explicit operator bool() const {
139  return IsDefined() ? (bool)_attr : 0;
140  }
141 
142  bool operator==(const UsdSkelInbetweenShape& o) const {
143  return _attr == o._attr;
144  }
145 
146  bool operator!=(const UsdSkelInbetweenShape& o) const {
147  return !(*this == o);
148  }
149 
150  /// @}
151 
152 private:
153  friend class UsdSkelBlendShape;
154 
155  /// Validate that the given \p name is a valid attribute name for
156  /// an inbetween.
157  static bool _IsValidInbetweenName(const std::string& name,
158  bool quiet=false);
159 
160  /// Validate that the given \p name contains the inbetweens namespace.
161  /// Does not validate \p name as a legal property identifier.
162  static bool _IsNamespaced(const TfToken& name);
163 
164  /// Return \p name prepended with the proper inbetween namespace, if
165  /// it is not already prefixed.
166  ///
167  /// Does not validate \p name as a legal property identifier, but will
168  /// verify that \p name contains no reserved keywords, and will return
169  /// an empty TfToken if it does. If \p quiet is true, the verification
170  /// will be silent.
171  static TfToken _MakeNamespaced(const TfToken& name, bool quiet=false);
172 
173  static const TfToken& _GetNamespacePrefix();
174 
175  static const TfToken& _GetNormalOffsetsSuffix();
176 
177  UsdAttribute _GetNormalOffsetsAttr(bool create) const;
178 
179  /// Factory for UsdBlendShape's use, so that we can encapsulate the
180  /// logic of what discriminates an Inbetween in this class, while
181  /// preserving the pattern that attributes can only be created via
182  /// their container objects.
183  ///
184  /// The name of the created attribute may or may not be the specified
185  /// \p attrName, due to the possible need to apply property namespacing.
186  ///
187  /// \return an invalid Inbetween if we failed to create a valid
188  /// attribute, o ra valid Inbetween otherwise. It is not an error
189  /// to create over an existing, compatible attribute.
190  ///
191  /// \sa UsdPrim::CreateAttribute()
192  static UsdSkelInbetweenShape _Create(const UsdPrim& prim,
193  const TfToken& name);
194 
195  UsdAttribute _attr;
196 };
197 
198 
200 
201 #endif // PXR_USD_USD_SKEL_INBETWEEN_SHAPE_H
bool IsDefined() const
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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.
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2621
Definition: token.h:87
USDSKEL_API bool HasAuthoredWeight() const
USDSKEL_API bool GetWeight(float *weight) const
Return the location at which the shape is applied.
Definition: prim.h:133
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:40
bool operator!=(const UsdSkelInbetweenShape &o) const
USDSKEL_API bool GetNormalOffsets(VtVec3fArray *offsets) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
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:164
bool operator==(const UsdSkelInbetweenShape &o) const